1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-05 13:38:33 +00:00

Improved parsing of graph arguments.

Removed "log"|"normal" arguments in	favour of -l switch.
This commit is contained in:
Brenden Matthews 2009-07-04 21:43:45 -06:00
parent 14d90ad7d1
commit 52c68c094c
5 changed files with 93 additions and 120 deletions

View File

@ -1,5 +1,7 @@
2009-07-04 2009-07-04
* Remove newline with comment only lines in TEXT * Remove newline with comment only lines in TEXT
* Improved parsing of graph arguments, removed "log"|"normal" arguments in
favour of -l switch
2009-07-01 2009-07-01
* Fix escaping of comments in TEXT (sf.net #2813390, thanks Nils) * Fix escaping of comments in TEXT (sf.net #2813390, thanks Nils)

View File

@ -167,8 +167,8 @@
<command> <command>
<option>apcupsd_loadgraph</option> <option>apcupsd_loadgraph</option>
</command> </command>
<option>("normal"|"log") (height),(width) (gradient <option>(height),(width) (gradient colour 1) (gradient
colour 1) (gradient colour 2) (scale) (-t)</option> colour 2) (scale) (-t) (-l)</option>
</term> </term>
<listitem>History graph of current load. <listitem>History graph of current load.
<para /></listitem> <para /></listitem>
@ -637,17 +637,16 @@
<command> <command>
<option>cpugraph</option> <option>cpugraph</option>
</command> </command>
<option>(cpuN) ("normal"|"log") (height),(width) <option>(cpuN) (height),(width) (gradient colour 1)
(gradient colour 1) (gradient colour 2) (scale) (gradient colour 2) (scale) (-t) (-l)</option>
(-t)</option>
</term> </term>
<listitem>CPU usage graph, with optional colours in hex, <listitem>CPU usage graph, with optional colours in hex,
minus the #. See $cpu for more info on SMP. Uses a minus the #. See $cpu for more info on SMP. Uses a
logarithmic scale (to see small numbers) when you use "log" logarithmic scale (to see small numbers) when you use the
instead of "normal". Takes the switch '-t' to use a -l switch. Takes the switch '-t' to use a temperature
temperature gradient, which makes the gradient values gradient, which makes the gradient values change depending
change depending on the amplitude of a particular graph on the amplitude of a particular graph value (try it and
value (try it and see). see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -701,15 +700,14 @@
<command> <command>
<option>diskiograph</option> <option>diskiograph</option>
</command> </command>
<option>(device) ("normal"|"log") (height),(width) <option>(device) (height),(width) (gradient colour 1)
(gradient colour 1) (gradient colour 2) (scale) (gradient colour 2) (scale) (-t) (-l)</option>
(-t)</option>
</term> </term>
<listitem>Disk IO graph, colours defined in hex, minus the <listitem>Disk IO graph, colours defined in hex, minus the
#. If scale is non-zero, it becomes the scale for the #. If scale is non-zero, it becomes the scale for the
graph. Uses a logarithmic scale (to see small numbers) when graph. Uses a logarithmic scale (to see small numbers) when
you use "log" instead of "normal". Takes the switch '-t' to you use -l switch. Takes the switch '-t' to use a
use a temperature gradient, which makes the gradient values temperature gradient, which makes the gradient values
change depending on the amplitude of a particular graph change depending on the amplitude of a particular graph
value (try it and see). value (try it and see).
<para /></listitem> <para /></listitem>
@ -719,18 +717,16 @@
<command> <command>
<option>diskiograph_read</option> <option>diskiograph_read</option>
</command> </command>
<option>(device) ("normal"|"log") (height),(width) <option>(device) (height),(width) (gradient colour 1)
(gradient colour 1) (gradient colour 2) (scale) (gradient colour 2) (scale) (-t) (-l)</option>
(-t)</option>
</term> </term>
<listitem>Disk IO graph for reads, colours defined in hex, <listitem>Disk IO graph for reads, colours defined in hex,
minus the #. If scale is non-zero, it becomes the scale for minus the #. If scale is non-zero, it becomes the scale for
the graph. Device as in diskio. Uses a logarithmic scale the graph. Device as in diskio. Uses a logarithmic scale
(to see small numbers) when you use "log" instead of (to see small numbers) when you use -l switch. Takes the
"normal". Takes the switch '-t' to use a temperature switch '-t' to use a temperature gradient, which makes the
gradient, which makes the gradient values change depending gradient values change depending on the amplitude of a
on the amplitude of a particular graph value (try it and particular graph value (try it and see).
see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -738,18 +734,16 @@
<command> <command>
<option>diskiograph_write</option> <option>diskiograph_write</option>
</command> </command>
<option>(device) ("normal"|"log") (height),(width) <option>(device) (height),(width) (gradient colour 1)
(gradient colour 1) (gradient colour 2) (scale) (gradient colour 2) (scale) (-t) (-l)</option>
(-t)</option>
</term> </term>
<listitem>Disk IO graph for writes, colours defined in hex, <listitem>Disk IO graph for writes, colours defined in hex,
minus the #. If scale is non-zero, it becomes the scale for minus the #. If scale is non-zero, it becomes the scale for
the graph. Device as in diskio. Uses a logarithmic scale the graph. Device as in diskio. Uses a logarithmic scale
(to see small numbers) when you use "log" instead of (to see small numbers) when you use -l switch. Takes the
"normal". Takes the switch '-t' to use a temperature switch '-t' to use a temperature gradient, which makes the
gradient, which makes the gradient values change depending gradient values change depending on the amplitude of a
on the amplitude of a particular graph value (try it and particular graph value (try it and see).
see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -777,17 +771,16 @@
<command> <command>
<option>downspeedgraph</option> <option>downspeedgraph</option>
</command> </command>
<option>(netdev) ("normal"|"log") (height),(width) <option>(netdev) (height),(width) (gradient colour 1)
(gradient colour 1) (gradient colour 2) (scale) (gradient colour 2) (scale) (-t) (-l)</option>
(-t)</option>
</term> </term>
<listitem>Download speed graph, colours defined in hex, <listitem>Download speed graph, colours defined in hex,
minus the #. If scale is non-zero, it becomes the scale for minus the #. If scale is non-zero, it becomes the scale for
the graph. Uses a logarithmic scale (to see small numbers) the graph. Uses a logarithmic scale (to see small numbers)
when you use "log" instead of "normal". Takes the switch when you use -l switch. Takes the switch '-t' to use a
'-t' to use a temperature gradient, which makes the temperature gradient, which makes the gradient values
gradient values change depending on the amplitude of a change depending on the amplitude of a particular graph
particular graph value (try it and see). value (try it and see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -932,12 +925,12 @@
<command> <command>
<option>execgraph</option> <option>execgraph</option>
</command> </command>
<option>("normal"|"log") (-t) command</option> <option>(-t) (-l) command</option>
</term> </term>
<listitem>Same as execbar, but graphs values. Uses a <listitem>Same as execbar, but graphs values. Uses a
logaritmic scale when the log option is given (to see small logaritmic scale when the log option (-l switch) is given
numbers). Values still have to be between 0 and 100. The (to see small numbers). Values still have to be between 0
size for graphs can be controlled via the and 100. The size for graphs can be controlled via the
default_graph_size config setting. Takes the switch '-t' to default_graph_size config setting. Takes the switch '-t' to
use a temperature gradient, which makes the gradient values use a temperature gradient, which makes the gradient values
change depending on the amplitude of a particular graph change depending on the amplitude of a particular graph
@ -982,7 +975,7 @@
<command> <command>
<option>execigraph</option> <option>execigraph</option>
</command> </command>
<option>interval ("normal"|"log") (-t) command</option> <option>interval (-t) (-l) command</option>
</term> </term>
<listitem>Same as execgraph, but takes an interval arg and <listitem>Same as execgraph, but takes an interval arg and
graphs values. graphs values.
@ -1733,16 +1726,15 @@
<command> <command>
<option>loadgraph</option> <option>loadgraph</option>
</command> </command>
<option>("normal"|"log") (height),(width) (gradient <option>(height),(width) (gradient colour 1) (gradient
colour 1) (gradient colour 2) (scale) (-t)</option> colour 2) (scale) (-t) (-l)</option>
</term> </term>
<listitem>Load1 average graph, similar to xload, with <listitem>Load1 average graph, similar to xload, with
optional colours in hex, minus the #. Uses a logarithmic optional colours in hex, minus the #. Uses a logarithmic
scale (to see small numbers) when you use "log" instead of scale (to see small numbers) when you use the -l switch.
"normal". Takes the switch '-t' to use a temperature Takes the switch '-t' to use a temperature gradient, which
gradient, which makes the gradient values change depending makes the gradient values change depending on the amplitude
on the amplitude of a particular graph value (try it and of a particular graph value (try it and see).
see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -1789,17 +1781,16 @@
<command> <command>
<option>lua_graph</option> <option>lua_graph</option>
</command> </command>
<option>function_name (function parameters) <option>function_name (height),(width) (gradient colour
("normal"|"log") (height),(width) (gradient colour 1) 1) (gradient colour 2) (scale) (-t) (-l)</option>
(gradient colour 2) (scale) (-t)</option>
</term> </term>
<listitem>Executes a Lua function with given parameters and <listitem>Executes a Lua function with and draws a graph.
draws a graph. Expects result value to be any number, and Expects result value to be any number, and by default will
by default will scale to show the full range. See also scale to show the full range. See also 'lua_load' on how to
'lua_load' on how to load scripts. Takes the switch '-t' to load scripts. Takes the switch '-t' to use a temperature
use a temperature gradient, which makes the gradient values gradient, which makes the gradient values change depending
change depending on the amplitude of a particular graph on the amplitude of a particular graph value (try it and
value (try it and see). see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -1922,14 +1913,14 @@
<command> <command>
<option>memgraph</option> <option>memgraph</option>
</command> </command>
<option>("normal"|"log") (height),(width) (gradient <option>(height),(width) (gradient colour 1) (gradient
colour 1) (gradient colour 2) (scale) (-t)</option> colour 2) (scale) (-t) (-l)</option>
</term> </term>
<listitem>Memory usage graph. Uses a logarithmic scale (to <listitem>Memory usage graph. Uses a logarithmic scale (to
see small numbers) when you use "log" instead of "normal". see small numbers) when you use the -l switch. Takes the
Takes the switch '-t' to use a temperature gradient, which switch '-t' to use a temperature gradient, which makes the
makes the gradient values change depending on the amplitude gradient values change depending on the amplitude of a
of a particular graph value (try it and see). particular graph value (try it and see).
<para /></listitem> <para /></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -3096,15 +3087,14 @@
<command> <command>
<option>upspeedgraph</option> <option>upspeedgraph</option>
</command> </command>
<option>(netdev) ("normal"|"log") (height),(width) <option>(netdev) (height),(width) (gradient colour 1)
(gradient colour 1) (gradient colour 2) (scale) (gradient colour 2) (scale) (-t) (-l)</option>
(-t)</option>
</term> </term>
<listitem>Upload speed graph, colours defined in hex, minus <listitem>Upload speed graph, colours defined in hex, minus
the #. If scale is non-zero, it becomes the scale for the the #. If scale is non-zero, it becomes the scale for the
graph. Uses a logarithmic scale (to see small numbers) when graph. Uses a logarithmic scale (to see small numbers) when
you use "log" instead of "normal". Takes the switch '-t' to you use the -l switch. Takes the switch '-t' to use a
use a temperature gradient, which makes the gradient values temperature gradient, which makes the gradient values
change depending on the amplitude of a particular graph change depending on the amplitude of a particular graph
value (try it and see). value (try it and see).
<para /></listitem> <para /></listitem>

View File

@ -2825,10 +2825,10 @@ static struct text_object *construct_text_object(const char *s,
if (buf) { if (buf) {
obj->data.s = buf; obj->data.s = buf;
} else { } else {
CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]"); CRIT_ERR("lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
} }
} else { } else {
CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> <height>,<width> <gradient colour 1> <gradient colour 2> <scale> <function name> [function parameters]"); CRIT_ERR("lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
} }
END OBJ(lua_gauge, 0) END OBJ(lua_gauge, 0)
SIZE_DEFAULTS(gauge); SIZE_DEFAULTS(gauge);
@ -4192,16 +4192,14 @@ static void generate_text_internal(char *p, int p_max_size,
double barnum; double barnum;
char *cmd = obj->data.s; char *cmd = obj->data.s;
if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
showaslog = TRUE;
cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
} else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
}
if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) { if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
tempgrad = TRUE; tempgrad = TRUE;
cmd += strlen(" "TEMPGRAD); cmd += strlen(" "TEMPGRAD);
} }
if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) {
showaslog = TRUE;
cmd += strlen(" "LOGGRAPH);
}
read_exec(cmd, p, text_buffer_size); read_exec(cmd, p, text_buffer_size);
barnum = get_barnum(p); barnum = get_barnum(p);
@ -4244,16 +4242,14 @@ static void generate_text_internal(char *p, int p_max_size,
char tempgrad = FALSE; char tempgrad = FALSE;
char *cmd = obj->data.execi.cmd; char *cmd = obj->data.execi.cmd;
if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
showaslog = TRUE;
cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
} else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
}
if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) { if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
tempgrad = TRUE; tempgrad = TRUE;
cmd += strlen(" "TEMPGRAD); cmd += strlen(" "TEMPGRAD);
} }
if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) {
showaslog = TRUE;
cmd += strlen(" "LOGGRAPH);
}
obj->char_a = showaslog; obj->char_a = showaslog;
obj->char_b = tempgrad; obj->char_b = tempgrad;
read_exec(cmd, p, text_buffer_size); read_exec(cmd, p, text_buffer_size);

View File

@ -107,9 +107,8 @@ char *scan_graph(const char *args, int *w, int *h,
unsigned int *first_colour, unsigned int *last_colour, unsigned int *first_colour, unsigned int *last_colour,
unsigned int *scale, char *showaslog, char *tempgrad) unsigned int *scale, char *showaslog, char *tempgrad)
{ {
const char *nographtype; char buf[1024];
char buf[64]; memset(buf, 0, 1024);
buf[0] = 0;
/* zero width means all space that is available */ /* zero width means all space that is available */
*w = default_graph_width; *w = default_graph_width;
@ -118,74 +117,61 @@ char *scan_graph(const char *args, int *w, int *h,
*last_colour = 0; *last_colour = 0;
*scale = 0; *scale = 0;
*tempgrad = FALSE; *tempgrad = FALSE;
*showaslog = FALSE;
if (args) { if (args) {
// set showaslog and place the rest of the args in nographtype
if (strcasecmp(args, LOGGRAPH) == EQUAL) {
*showaslog = TRUE;
return NULL;
} else if (strcasecmp(args, NORMGRAPH) == EQUAL) {
*showaslog = FALSE;
return NULL;
} else if (strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) {
*showaslog = TRUE;
nographtype = &args[strlen(LOGGRAPH) + 1];
} else if (strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) {
*showaslog = FALSE;
nographtype = &args[strlen(NORMGRAPH) + 1];
} else {
*showaslog = FALSE;
nographtype = args;
}
if (strstr(args, " "TEMPGRAD)) { if (strstr(args, " "TEMPGRAD)) {
*tempgrad = TRUE; *tempgrad = TRUE;
} }
DBGP("printing graph as %s, other args are: %s", (*showaslog ? "log" : "normal"), nographtype); if (strstr(args, " "LOGGRAPH)) {
*showaslog = TRUE;
}
DBGP("printing graph as %s, other args are: %s", (*showaslog ? "log" : "normal"), args);
//check the rest of the args //check the rest of the args
if (sscanf(nographtype, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) { if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) {
return NULL; return NULL;
} }
*scale = 0; *scale = 0;
if (sscanf(nographtype, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) { if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
return NULL; return NULL;
} }
if (sscanf(nographtype, "%63s %d,%d %x %x %u", buf, h, w, first_colour, last_colour, scale) == 6) { if (sscanf(args, "%1023s %d,%d %x %x %u", buf, h, w, first_colour, last_colour, scale) == 6) {
return strndup(buf, text_buffer_size); return strndup(buf, text_buffer_size);
} }
*scale = 0; *scale = 0;
if (sscanf(nographtype, "%63s %d,%d %x %x", buf, h, w, first_colour, last_colour) == 5) { if (sscanf(args, "%1023s %d,%d %x %x", buf, h, w, first_colour, last_colour) == 5) {
return strndup(buf, text_buffer_size); return strndup(buf, text_buffer_size);
} }
buf[0] = '\0'; buf[0] = '\0';
*h = 25; *h = 25;
*w = 0; *w = 0;
if (sscanf(nographtype, "%x %x %u", first_colour, last_colour, scale) == 3) { if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
return NULL; return NULL;
} }
*scale = 0; *scale = 0;
if (sscanf(nographtype, "%x %x", first_colour, last_colour) == 2) { if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
return NULL; return NULL;
} }
if (sscanf(nographtype, "%63s %x %x %u", buf, first_colour, last_colour, scale) == 4) { if (sscanf(args, "%1023s %x %x %u", buf, first_colour, last_colour, scale) == 4) {
return strndup(buf, text_buffer_size); return strndup(buf, text_buffer_size);
} }
*scale = 0; *scale = 0;
if (sscanf(nographtype, "%63s %x %x", buf, first_colour, last_colour) == 3) { if (sscanf(args, "%1023s %x %x", buf, first_colour, last_colour) == 3) {
return strndup(buf, text_buffer_size); return strndup(buf, text_buffer_size);
} }
buf[0] = '\0'; buf[0] = '\0';
*first_colour = 0; *first_colour = 0;
*last_colour = 0; *last_colour = 0;
if (sscanf(nographtype, "%d,%d %u", h, w, scale) == 3) { if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
return NULL; return NULL;
} }
*scale = 0; *scale = 0;
if (sscanf(nographtype, "%d,%d", h, w) == 2) { if (sscanf(args, "%d,%d", h, w) == 2) {
return NULL; return NULL;
} }
if (sscanf(nographtype, "%63s %d,%d %u", buf, h, w, scale) < 4) { if (sscanf(args, "%1023s %d,%d %u", buf, h, w, scale) < 4) {
*scale = 0; *scale = 0;
//TODO: check the return value and throw an error? //TODO: check the return value and throw an error?
sscanf(nographtype, "%63s %d,%d", buf, h, w); sscanf(args, "%1023s %d,%d", buf, h, w);
} }
return strndup(buf, text_buffer_size); return strndup(buf, text_buffer_size);

View File

@ -34,8 +34,7 @@
#define MAX_GRAPH_DEPTH 512 #define MAX_GRAPH_DEPTH 512
// don't use spaces in LOGGRAPH or NORMGRAPH if you change them // don't use spaces in LOGGRAPH or NORMGRAPH if you change them
#define LOGGRAPH "log" #define LOGGRAPH "-l"
#define NORMGRAPH "normal"
#define TEMPGRAD "-t" #define TEMPGRAD "-t"
enum special_types { enum special_types {