scan_graph: allow giving a "hint" about a good scale value
authorPhil Sutter <phil@nwl.cc>
Thu, 5 Nov 2009 23:05:08 +0000 (00:05 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 5 Nov 2009 23:10:00 +0000 (00:10 +0100)
This is more or less a temporary fix to restore the former behaviour. In
the long term objects will define a max value, which will be of use for
all kinds of meters.

src/common.c
src/core.c
src/diskio.c
src/exec.c
src/net_stat.c
src/specials.c
src/specials.h

index 3ad8f45..18c8eef 100644 (file)
@@ -448,7 +448,7 @@ void scan_loadgraph_arg(struct text_object *obj, const char *arg)
 {
        char *buf = 0;
 
-       buf = scan_graph(obj, arg);
+       buf = scan_graph(obj, arg, 0);
        if (buf)
                free(buf);
 }
index cad4be4..cb20336 100644 (file)
@@ -353,7 +353,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(cpugraph, &update_cpu_usage)
                char *buf = 0;
                SCAN_CPU(arg, obj->data.i);
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 100);
                DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
                if (buf) free(buf);
        END OBJ(loadgraph, &update_load_average)
@@ -613,7 +613,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #ifdef X11
        END OBJ(memgraph, &update_meminfo)
                char *buf = 0;
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 100);
 
                if (buf) free(buf);
 #endif /* X11*/
@@ -902,7 +902,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #ifdef X11
        END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
                char *buf = 0;
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 0);
                if (buf) {
                        obj->data.s = buf;
                } else {
@@ -984,7 +984,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #ifdef X11
        END OBJ(apcupsd_loadgraph, &update_apcupsd)
                char* buf = 0;
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 0);
                if (buf) free(buf);
        END OBJ(apcupsd_loadgauge, &update_apcupsd)
                scan_gauge(obj, arg);
index c042139..20db99c 100644 (file)
@@ -143,7 +143,7 @@ void print_diskio(struct text_object *obj, int dir, char *p, int p_max_size)
 void parse_diskiograph_arg(struct text_object *obj, const char *arg)
 {
        char *buf = 0;
-       buf = scan_graph(obj, arg);
+       buf = scan_graph(obj, arg, 0);
 
        obj->data.opaque = prepare_diskio_stat(dev_name(buf));
        if (buf)
index 3f3297d..e228e09 100644 (file)
@@ -244,7 +244,7 @@ void scan_execgraph_arg(struct text_object *obj, const char *arg)
        ed = malloc(sizeof(struct execi_data));
        memset(ed, 0, sizeof(struct execi_data));
 
-       buf = scan_graph(obj, arg);
+       buf = scan_graph(obj, arg, 100);
        if (!buf) {
                NORM_ERR("missing command argument to execgraph object");
                return;
index 3a143f9..51cb4b6 100644 (file)
@@ -193,7 +193,7 @@ void print_addrs(struct text_object *obj, char *p, int p_max_size)
 void parse_net_stat_graph_arg(struct text_object *obj, const char *arg, void *free_at_crash)
 {
        char *buf = 0;
-       buf = scan_graph(obj, arg);
+       buf = scan_graph(obj, arg, 0);
 
        // default to DEFAULTNETDEV
        if (buf) {
index f604154..b5ab637 100644 (file)
@@ -145,7 +145,7 @@ char *scan_font(const char *args)
        return NULL;
 }
 
-char *scan_graph(struct text_object *obj, const char *args)
+char *scan_graph(struct text_object *obj, const char *args, int defscale)
 {
        struct graph *g;
        char buf[1024];
@@ -160,7 +160,7 @@ char *scan_graph(struct text_object *obj, const char *args)
        g->height = default_graph_height;
        g->first_colour = 0;
        g->last_colour = 0;
-       g->scale = 0;
+       g->scale = defscale;
        g->tempgrad = FALSE;
        g->showaslog = FALSE;
        if (args) {
@@ -173,14 +173,14 @@ char *scan_graph(struct text_object *obj, const char *args)
                if (sscanf(args, "%d,%d %x %x %u", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
                        return NULL;
                }
-               g->scale = 0;
+               g->scale = defscale;
                if (sscanf(args, "%d,%d %x %x", &g->height, &g->width, &g->first_colour, &g->last_colour) == 4) {
                        return NULL;
                }
                if (sscanf(args, "%1023s %d,%d %x %x %u", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
                        return strndup(buf, text_buffer_size);
                }
-               g->scale = 0;
+               g->scale = defscale;
                if (sscanf(args, "%1023s %d,%d %x %x", buf, &g->height, &g->width, &g->first_colour, &g->last_colour) == 5) {
                        return strndup(buf, text_buffer_size);
                }
@@ -190,14 +190,14 @@ char *scan_graph(struct text_object *obj, const char *args)
                if (sscanf(args, "%x %x %u", &g->first_colour, &g->last_colour, &g->scale) == 3) {
                        return NULL;
                }
-               g->scale = 0;
+               g->scale = defscale;
                if (sscanf(args, "%x %x", &g->first_colour, &g->last_colour) == 2) {
                        return NULL;
                }
                if (sscanf(args, "%1023s %x %x %u", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
                        return strndup(buf, text_buffer_size);
                }
-               g->scale = 0;
+               g->scale = defscale;
                if (sscanf(args, "%1023s %x %x", buf, &g->first_colour, &g->last_colour) == 3) {
                        return strndup(buf, text_buffer_size);
                }
@@ -207,12 +207,12 @@ char *scan_graph(struct text_object *obj, const char *args)
                if (sscanf(args, "%d,%d %u", &g->height, &g->width, &g->scale) == 3) {
                        return NULL;
                }
-               g->scale = 0;
+               g->scale = defscale;
                if (sscanf(args, "%d,%d", &g->height, &g->width) == 2) {
                        return NULL;
                }
                if (sscanf(args, "%1023s %d,%d %u", buf, &g->height, &g->width, &g->scale) < 4) {
-                       g->scale = 0;
+                       g->scale = defscale;
                        //TODO: check the return value and throw an error?
                        sscanf(args, "%1023s %d,%d", buf, &g->height, &g->width);
                }
index e3eb065..054df91 100644 (file)
@@ -98,7 +98,7 @@ const char *scan_bar(struct text_object *, const char *);
 #ifdef X11
 const char *scan_gauge(struct text_object *, const char *);
 char *scan_font(const char *);
-char *scan_graph(struct text_object *, const char *);
+char *scan_graph(struct text_object *, const char *, int);
 void scan_tab(struct text_object *, const char *);
 void scan_stippled_hr(struct text_object *, const char*);