Fixed small bug in config parsing (thanks robgrady, bug 1306032)
[monky] / src / conky.c
index b600809..3342d50 100644 (file)
@@ -385,7 +385,7 @@ static int special_count;
 static int special_index;      /* used when drawing */
 #endif /* X11 */
 
-#define MAX_GRAPH_DEPTH 512    /* why 512? who knows. */
+#define MAX_GRAPH_DEPTH 256    /* why 256? cause an array of more then 256 doubles seems excessive, and who needs that kind of precision anyway? */
 
 static struct special_t *new_special(char *buf, int t)
 {
@@ -394,18 +394,6 @@ static struct special_t *new_special(char *buf, int t)
 
        buf[0] = SPECIAL_CHAR;
        buf[1] = '\0';
-       if (t == GRAPH && specials[special_count].graph == NULL) {
-               if (specials[special_count].width > 0
-                   && specials[special_count].width < MAX_GRAPH_DEPTH)
-                       specials[special_count].graph_width = specials[special_count].width - 3;        // subtract 3 for the box
-               else
-                       specials[special_count].graph_width =
-                           MAX_GRAPH_DEPTH;
-               specials[special_count].graph =
-                   calloc(specials[special_count].graph_width,
-                          sizeof(double));
-               specials[special_count].graph_scale = 100;
-       }
        specials[special_count].type = t;
        return &specials[special_count++];
 }
@@ -552,7 +540,17 @@ static unsigned int adjust_colors(unsigned int color)
 static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
 {
        struct special_t *s = new_special(buf, GRAPH);
-       s->width = (w < MAX_GRAPH_DEPTH) ? w : MAX_GRAPH_DEPTH;
+       s->width = w;
+       if (s->graph == NULL) {
+               if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
+                       s->graph_width = s->width - 3;  // subtract 3 for the box
+               } else {
+                       s->graph_width = MAX_GRAPH_DEPTH - 3;
+               }
+               s->graph = malloc(s->graph_width * sizeof(double));
+               memset(s->graph, 0, s->graph_width * sizeof(double));
+               s->graph_scale = 100;
+       }
        s->height = h;
        s->first_colour = adjust_colors(first_colour);
        s->last_colour = adjust_colors(second_colour);
@@ -561,9 +559,9 @@ static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsign
        } else {
                s->scaled = 1;
        }
-       if (s->width) {
+       /*if (s->width) {
                s->graph_width = s->width - 3;  // subtract 3 for rectangle around
-       }
+       }*/
        if (s->scaled) {
                s->graph_scale = 1;
        } else {
@@ -1126,7 +1124,7 @@ if (s[0] == '#') {
                        arg += 4;
                }
                                (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
-} else {
+                       } else {
        (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
        obj->data.cpu_index = 0;
                        }
@@ -1298,7 +1296,7 @@ if (s[0] == '#') {
        if (!arg) {
                ERR("i2c needs arguments");
                obj->type = OBJ_text;
-               obj->data.s = strdup("${i2c}");
+               //obj->data.s = strdup("${i2c}");
                return;
        }
 
@@ -1309,12 +1307,12 @@ if (s[0] == '#') {
                obj->data.i2c.fd =
                    open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
                                    obj->data.i2c.devtype);
-               strcpy(obj->data.i2c.type, buf2);
+               strncpy(obj->data.i2c.type, buf2, 63);
        } else {
                obj->data.i2c.fd =
                    open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
                                    obj->data.i2c.devtype);
-               strcpy(obj->data.i2c.type, buf2);
+               strncpy(obj->data.i2c.type, buf2, 63);
        }
 
        END OBJ(top, INFO_TOP)
@@ -1323,7 +1321,7 @@ if (s[0] == '#') {
        if (!arg) {
                ERR("top needs arguments");
                obj->type = OBJ_text;
-               obj->data.s = strdup("${top}");
+               //obj->data.s = strdup("${top}");
                return;
        }
        if (sscanf(arg, "%63s %i", buf, &n) == 2) {
@@ -2784,11 +2782,11 @@ static void generate_text()
                                }
                                seconds = tmp;
                                if (days > 0)
-                                       snprintf(p, n, "%i days %i:%i:%2i",
+                                       snprintf(p, n, "%i days %i:%02i:%02i",
                                                 days, hours, minutes,
                                                 seconds);
-                               else if (days > 0)
-                                       snprintf(p, n, "%i:%i:%02i", hours,
+                               else if (hours > 0)
+                                       snprintf(p, n, "%i:%02i:%02i", hours,
                                                 minutes, seconds);
                                else
                                        snprintf(p, n, "%i:%02i", minutes,
@@ -2813,11 +2811,11 @@ static void generate_text()
                                seconds = tmp;
                                if (days > 0)
                                        snprintf(p, n,
-                                                "%i days %i:%i:%02i",
+                                                "%i days %i:%02i:%02i",
                                                 days, hours, minutes,
                                                 seconds);
-                               else if (days > 0)
-                                       snprintf(p, n, "%i:%i:%02i", hours,
+                               else if (hours > 0)
+                                       snprintf(p, n, "%i:%02i:%02i", hours,
                                                 minutes, seconds);
                                else
                                        snprintf(p, n, "%i:%02i", minutes,
@@ -2919,7 +2917,7 @@ static void generate_text()
                                        else {
                                                obj->data.tail.readlines = 0;
 
-                                               while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL) {
+                                               while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
                                                        if (added >= 30) {
                                                                freelasttail(head);
                                                        }
@@ -2944,7 +2942,7 @@ static void generate_text()
                                                        headtmp = headtmp->next;
                                                        for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
                                                                if (headtmp) {
-                                                                       strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20 / obj->data.tail.wantedlines) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
+                                                                       strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
                                                                        headtmp = headtmp->next;
                                                                }
                                                        }
@@ -2979,7 +2977,7 @@ static void generate_text()
                                        }
                                        else {
                                                obj->data.tail.readlines = 0;
-                                               while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
+                                               while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
                                                        addtail(&head, obj->data.tail.buffer);
                                                        obj->data.tail.readlines++;
                                                }
@@ -2995,7 +2993,7 @@ static void generate_text()
                                                        strcpy(obj->data.tail.buffer, headtmp->data);
                                                        headtmp = headtmp->next;
                                                        while (headtmp) {
-                                                               strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20 / obj->data.tail.wantedlines) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
+                                                               strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
                                                                headtmp = headtmp->next;
                                                        }
                                                        freetail(freetmp);
@@ -3533,7 +3531,7 @@ static void draw_line(char *s)
 
                        case BAR:
                                {
-                                       if (cur_x > maximum_width - text_start_x && maximum_width > 0) {
+                                       if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
                                                break;
                                        }
                                        int h =
@@ -3589,7 +3587,7 @@ static void draw_line(char *s)
 
                        case GRAPH:
                        {
-                                       if (cur_x > maximum_width - text_start_x && maximum_width > 0) {
+                                       if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
                                                break;
                                        }
                                        int h =
@@ -3850,8 +3848,9 @@ static void clear_text(int exposures)
 #ifdef XDBE
        if (use_xdbe) {
                return;         /* The swap action is XdbeBackground, which clears */
-       }
+       } else
 #endif
+       {
        /* there is some extra space for borders and outlines */
        XClearArea(display, window.drawable,
                   text_start_x - border_margin - 1,
@@ -3859,6 +3858,7 @@ static void clear_text(int exposures)
                   text_width + border_margin * 2 + 2,
                   text_height + border_margin * 2 + 2,
                   exposures ? True : 0);
+       }
 }
 #endif /* X11 */
 
@@ -4060,6 +4060,7 @@ static void main_loop()
                                                || ev.xconfigure.y != 0)) {
                                                fixed_pos = 1;
                                }*/
+                                       set_font();
                                }
                                break;
 #endif
@@ -4331,7 +4332,7 @@ static void load_config_file(const char *f)
 #define CONF2(a) if (strcasecmp(name, a) == 0)
 #define CONF(a) else CONF2(a)
 #define CONF3(a,b) \
-else if (strcasecmp(name, a) == 0 || strcasecmp(name, a) == 0)
+else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
 
 
 #ifdef X11