From 52c68c094c51b6df37856c08e976d44aa1a60c02 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 4 Jul 2009 21:43:45 -0600 Subject: [PATCH] Improved parsing of graph arguments. Removed "log"|"normal" arguments in favour of -l switch. --- ChangeLog | 2 + doc/variables.xml | 132 +++++++++++++++++++++++++---------------------------- src/conky.c | 24 ++++------ src/specials.c | 52 ++++++++------------- src/specials.h | 3 +- 5 files changed, 93 insertions(+), 120 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74f55e9..af00ce2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2009-07-04 * 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 * Fix escaping of comments in TEXT (sf.net #2813390, thanks Nils) diff --git a/doc/variables.xml b/doc/variables.xml index 8ff942c..47e7924 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -167,8 +167,8 @@ - + History graph of current load. @@ -637,17 +637,16 @@ - + CPU usage graph, with optional colours in hex, minus the #. See $cpu for more info on SMP. Uses a - logarithmic scale (to see small numbers) when you use "log" - instead of "normal". Takes the switch '-t' to use a - temperature gradient, which makes the gradient values - change depending on the amplitude of a particular graph - value (try it and see). + logarithmic scale (to see small numbers) when you use the + -l switch. Takes the switch '-t' to use a temperature + gradient, which makes the gradient values change depending + on the amplitude of a particular graph value (try it and + see). @@ -701,15 +700,14 @@ - + Disk IO graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when - you use "log" instead of "normal". Takes the switch '-t' to - use a temperature gradient, which makes the gradient values + you use -l switch. Takes the switch '-t' to use a + temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see). @@ -719,18 +717,16 @@ - + Disk IO graph for reads, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. Uses a logarithmic scale - (to see small numbers) when you use "log" instead of - "normal". Takes the switch '-t' to use a temperature - gradient, which makes the gradient values change depending - on the amplitude of a particular graph value (try it and - see). + (to see small numbers) when you use -l switch. Takes the + switch '-t' to use a temperature gradient, which makes the + gradient values change depending on the amplitude of a + particular graph value (try it and see). @@ -738,18 +734,16 @@ - + Disk IO graph for writes, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. Uses a logarithmic scale - (to see small numbers) when you use "log" instead of - "normal". Takes the switch '-t' to use a temperature - gradient, which makes the gradient values change depending - on the amplitude of a particular graph value (try it and - see). + (to see small numbers) when you use -l switch. Takes the + switch '-t' to use a temperature gradient, which makes the + gradient values change depending on the amplitude of a + particular graph value (try it and see). @@ -777,17 +771,16 @@ - + Download speed graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) - when you use "log" instead of "normal". Takes the switch - '-t' to use a temperature gradient, which makes the - gradient values change depending on the amplitude of a - particular graph value (try it and see). + when you use -l switch. Takes the switch '-t' to use a + temperature gradient, which makes the gradient values + change depending on the amplitude of a particular graph + value (try it and see). @@ -932,12 +925,12 @@ - + Same as execbar, but graphs values. Uses a - logaritmic scale when the log option is given (to see small - numbers). Values still have to be between 0 and 100. The - size for graphs can be controlled via the + logaritmic scale when the log option (-l switch) is given + (to see small numbers). Values still have to be between 0 + and 100. The size for graphs can be controlled via the default_graph_size config setting. Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph @@ -982,7 +975,7 @@ - + Same as execgraph, but takes an interval arg and graphs values. @@ -1733,16 +1726,15 @@ - + Load1 average graph, similar to xload, with optional colours in hex, minus the #. Uses a logarithmic - scale (to see small numbers) when you use "log" instead of - "normal". Takes the switch '-t' to use a temperature - gradient, which makes the gradient values change depending - on the amplitude of a particular graph value (try it and - see). + scale (to see small numbers) when you use the -l switch. + Takes the switch '-t' to use a temperature gradient, which + makes the gradient values change depending on the amplitude + of a particular graph value (try it and see). @@ -1789,17 +1781,16 @@ - + - Executes a Lua function with given parameters and - draws a graph. Expects result value to be any number, and - by default will scale to show the full range. See also - 'lua_load' on how to load scripts. Takes the switch '-t' to - use a temperature gradient, which makes the gradient values - change depending on the amplitude of a particular graph - value (try it and see). + Executes a Lua function with and draws a graph. + Expects result value to be any number, and by default will + scale to show the full range. See also 'lua_load' on how to + load scripts. Takes the switch '-t' to use a temperature + gradient, which makes the gradient values change depending + on the amplitude of a particular graph value (try it and + see). @@ -1922,14 +1913,14 @@ - + Memory usage graph. Uses a logarithmic scale (to - see small numbers) when you use "log" instead of "normal". - Takes the switch '-t' to use a temperature gradient, which - makes the gradient values change depending on the amplitude - of a particular graph value (try it and see). + see small numbers) when you use the -l switch. Takes the + switch '-t' to use a temperature gradient, which makes the + gradient values change depending on the amplitude of a + particular graph value (try it and see). @@ -3096,15 +3087,14 @@ - + Upload speed graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when - you use "log" instead of "normal". Takes the switch '-t' to - use a temperature gradient, which makes the gradient values + you use the -l switch. Takes the switch '-t' to use a + temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see). diff --git a/src/conky.c b/src/conky.c index 484c78e..d3bfc4d 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2825,10 +2825,10 @@ static struct text_object *construct_text_object(const char *s, if (buf) { obj->data.s = buf; } else { - CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> , [function parameters]"); + CRIT_ERR("lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]"); } } else { - CRIT_ERR("lua_graph needs arguments: <\"normal\"|\"log\"> , [function parameters]"); + CRIT_ERR("lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]"); } END OBJ(lua_gauge, 0) SIZE_DEFAULTS(gauge); @@ -4192,16 +4192,14 @@ static void generate_text_internal(char *p, int p_max_size, double barnum; 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)) { tempgrad = TRUE; cmd += strlen(" "TEMPGRAD); } + if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) { + showaslog = TRUE; + cmd += strlen(" "LOGGRAPH); + } read_exec(cmd, p, text_buffer_size); barnum = get_barnum(p); @@ -4244,16 +4242,14 @@ static void generate_text_internal(char *p, int p_max_size, char tempgrad = FALSE; 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)) { tempgrad = TRUE; cmd += strlen(" "TEMPGRAD); } + if (strstr(cmd, " "LOGGRAPH) && strlen(cmd) > strlen(" "LOGGRAPH)) { + showaslog = TRUE; + cmd += strlen(" "LOGGRAPH); + } obj->char_a = showaslog; obj->char_b = tempgrad; read_exec(cmd, p, text_buffer_size); diff --git a/src/specials.c b/src/specials.c index 6c51381..f5af204 100644 --- a/src/specials.c +++ b/src/specials.c @@ -107,9 +107,8 @@ char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour, unsigned int *scale, char *showaslog, char *tempgrad) { - const char *nographtype; - char buf[64]; - buf[0] = 0; + char buf[1024]; + memset(buf, 0, 1024); /* zero width means all space that is available */ *w = default_graph_width; @@ -118,74 +117,61 @@ char *scan_graph(const char *args, int *w, int *h, *last_colour = 0; *scale = 0; *tempgrad = FALSE; + *showaslog = FALSE; 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)) { *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 - 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; } *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; } - 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); } *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); } buf[0] = '\0'; *h = 25; *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; } *scale = 0; - if (sscanf(nographtype, "%x %x", first_colour, last_colour) == 2) { + if (sscanf(args, "%x %x", first_colour, last_colour) == 2) { 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); } *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); } buf[0] = '\0'; *first_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; } *scale = 0; - if (sscanf(nographtype, "%d,%d", h, w) == 2) { + if (sscanf(args, "%d,%d", h, w) == 2) { 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; //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); diff --git a/src/specials.h b/src/specials.h index 2590fff..ff16912 100644 --- a/src/specials.h +++ b/src/specials.h @@ -34,8 +34,7 @@ #define MAX_GRAPH_DEPTH 512 // don't use spaces in LOGGRAPH or NORMGRAPH if you change them -#define LOGGRAPH "log" -#define NORMGRAPH "normal" +#define LOGGRAPH "-l" #define TEMPGRAD "-t" enum special_types { -- 1.7.9.5