the big relocation patch
[monky] / src / conky.c
index 945df07..8edbc24 100644 (file)
@@ -74,7 +74,7 @@
 /* #define SIGNAL_BLOCKING */
 #undef SIGNAL_BLOCKING
 
-static void print_version()
+static void print_version(void)
 {
        printf("Conky %s compiled %s for %s\n", VERSION, BUILD_DATE, BUILD_ARCH);
 
@@ -127,7 +127,7 @@ static void print_version()
        exit(0);
 }
 
-static char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
+static const char *suffixes[] = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "" };
 
 #ifdef X11
 
@@ -188,7 +188,7 @@ struct font_list *fonts = NULL;
 
 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
 
-static void set_font();
+static void set_font(void);
 
 int addfont(const char *data_in)
 {
@@ -241,7 +241,7 @@ void set_first_font(const char *data_in)
        }
 }
 
-void free_fonts()
+void free_fonts(void)
 {
        int i;
 
@@ -263,7 +263,7 @@ void free_fonts()
        selected_font = 0;
 }
 
-static void load_fonts()
+static void load_fonts(void)
 {
        int i;
 
@@ -476,10 +476,10 @@ static inline int calc_text_width(const char *s, int l)
 
                if (utf8_mode) {
                        XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
-                               (FcChar8 *) s, l, &gi);
+                               (const FcChar8 *) s, l, &gi);
                } else {
                        XftTextExtents8(display, fonts[selected_font].xftfont,
-                               (FcChar8 *) s, l, &gi);
+                               (const FcChar8 *) s, l, &gi);
                }
                return gi.xOff;
        } else
@@ -707,10 +707,11 @@ static void new_font(char *buf, char *args)
 
 inline void graph_append(struct special_t *graph, double f)
 {
+       int i;
+
        if (!graph->scaled && f > graph->graph_scale) {
                f = graph->graph_scale;
        }
-       int i;
 
        if (graph->scaled) {
                graph->graph_scale = 1;
@@ -727,7 +728,7 @@ inline void graph_append(struct special_t *graph, double f)
 }
 
 short colour_depth = 0;
-void set_up_gradient();
+void set_up_gradient(void);
 
 /* precalculated: 31/255, and 63/255 */
 #define CONST_8_TO_5_BITS 0.12156862745098
@@ -804,7 +805,7 @@ static char *scan_graph(const char *args, int *w, int *h,
        *scale = 0;
        /* graph's argument is either height or height,width */
        if (args) {
-               if (sscanf(args, "%d,%d %x %x %i", h, w, first_colour, last_colour,
+               if (sscanf(args, "%d,%d %x %x %u", h, w, first_colour, last_colour,
                                scale) == 5) {
                        return NULL;
                }
@@ -812,7 +813,7 @@ static char *scan_graph(const char *args, int *w, int *h,
                if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
                        return NULL;
                }
-               if (sscanf(args, "%63s %d,%d %x %x %i", buf, h, w, first_colour,
+               if (sscanf(args, "%63s %d,%d %x %x %u", buf, h, w, first_colour,
                                last_colour, scale) == 6) {
                        return strdup(buf);
                }
@@ -824,14 +825,14 @@ static char *scan_graph(const char *args, int *w, int *h,
                buf[0] = '\0';
                *h = 25;
                *w = 0;
-               if (sscanf(args, "%x %x %i", first_colour, last_colour, scale) == 3) {
+               if (sscanf(args, "%x %x %u", first_colour, last_colour, scale) == 3) {
                        return NULL;
                }
                *scale = 0;
                if (sscanf(args, "%x %x", first_colour, last_colour) == 2) {
                        return NULL;
                }
-               if (sscanf(args, "%63s %x %x %i", buf, first_colour, last_colour,
+               if (sscanf(args, "%63s %x %x %u", buf, first_colour, last_colour,
                                scale) == 4) {
                        return strdup(buf);
                }
@@ -842,14 +843,14 @@ static char *scan_graph(const char *args, int *w, int *h,
                buf[0] = '\0';
                *first_colour = 0;
                *last_colour = 0;
-               if (sscanf(args, "%d,%d %i", h, w, scale) == 3) {
+               if (sscanf(args, "%d,%d %u", h, w, scale) == 3) {
                        return NULL;
                }
                *scale = 0;
                if (sscanf(args, "%d,%d", h, w) == 2) {
                        return NULL;
                }
-               if (sscanf(args, "%63s %d,%d %i", buf, h, w, scale) < 4) {
+               if (sscanf(args, "%63s %d,%d %u", buf, h, w, scale) < 4) {
                        *scale = 0;
                        //TODO: check the return value and throw an error?
                        sscanf(args, "%63s %d,%d", buf, h, w);
@@ -969,14 +970,16 @@ static void convert_escapes(char *buf)
 /* Prints anything normally printed with snprintf according to the current value
  * of use_spacer.  Actually slightly more flexible than snprintf, as you can
  * safely specify the destination buffer as one of your inputs.  */
-static int spaced_print(char *buf, int size, char *format, int width,
-               char *func_name, ...) {
+static int spaced_print(char *buf, int size, const char *format, int width,
+               const char *func_name, ...) {
        int len;
        va_list argp;
+       char *tempbuf;
+
        if (size < 1) {
                return 0;
        }
-       char *tempbuf = malloc(size * sizeof(char));
+       tempbuf = malloc(size * sizeof(char));
 
        // Passes the varargs along to vsnprintf
        va_start(argp, func_name);
@@ -1004,9 +1007,9 @@ static int spaced_print(char *buf, int size, char *format, int width,
 }
 
 /* converts from bytes to human readable format (k, M, G, T) */
-static void human_readable(long long num, char *buf, int size, char *func_name)
+static void human_readable(long long num, char *buf, int size, const char *func_name)
 {
-       char **suffix = suffixes;
+       const char **suffix = suffixes;
        float fnum;
        int precision, len;
        static const int WIDTH = 10, SHORT_WIDTH = 8;
@@ -1451,8 +1454,8 @@ struct text_object_list {
        struct text_object *text_objects;
 };
 
-static unsigned int text_object_count;
-static struct text_object *text_objects;
+static unsigned int global_text_object_count;
+static struct text_object *global_text_objects;
 static void generate_text_internal(char *p, int p_max_size,
        struct text_object *objs, unsigned int object_count,
        struct information *cur);
@@ -1464,9 +1467,10 @@ static void generate_text_internal(char *p, int p_max_size,
 struct mail_s *parse_mail_args(char type, const char *arg)
 {
        struct mail_s *mail;
+       char *tmp;
+
        mail = malloc(sizeof(struct mail_s));
        memset(mail, 0, sizeof(struct mail_s));
-       char *tmp;
 
        if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
                        != 3) {
@@ -1520,8 +1524,8 @@ struct mail_s *parse_mail_args(char type, const char *arg)
        }
        tmp = strstr(arg, "-e ");
        if (tmp) {
-               tmp += 3;
                int len = 1024;
+               tmp += 3;
 
                if (tmp[0] == '\'') {
                        len = strstr(tmp + 1, "'") - tmp - 1;
@@ -1537,7 +1541,7 @@ struct mail_s *parse_mail_args(char type, const char *arg)
        return mail;
 }
 
-void *imap_thread(struct mail_s *mail)
+void *imap_thread(void *arg)
 {
        int sockfd, numbytes;
        char recvbuf[MAXDATASIZE];
@@ -1549,12 +1553,17 @@ void *imap_thread(struct mail_s *mail)
        struct stat stat_buf;
        struct hostent *he;
        struct sockaddr_in their_addr;  // connector's address information
+       struct mail_s *mail = (struct mail_s *)arg;
 
        if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
                herror("gethostbyname");
                exit(1);
        }
        while (fail < 5) {
+               struct timeval timeout;
+               int res;
+               fd_set fdset;
+
                if (fail > 0) {
                        ERR("Trying IMAP connection again for %s@%s (try %i/5)",
                                mail->user, mail->host, fail + 1);
@@ -1579,9 +1588,6 @@ void *imap_thread(struct mail_s *mail)
                        fail++;
                        goto next_iteration;
                }
-               struct timeval timeout;
-               int res;
-               fd_set fdset;
 
                timeout.tv_sec = 60;    // 60 second timeout i guess
                timeout.tv_usec = 0;
@@ -1722,7 +1728,7 @@ next_iteration:
        return 0;
 }
 
-void *pop3_thread(struct mail_s *mail)
+void *pop3_thread(void *arg)
 {
        int sockfd, numbytes;
        char recvbuf[MAXDATASIZE];
@@ -1733,12 +1739,17 @@ void *pop3_thread(struct mail_s *mail)
        struct stat stat_buf;
        struct hostent *he;
        struct sockaddr_in their_addr;  // connector's address information
+       struct mail_s *mail = (struct mail_s *)arg;
 
        if ((he = gethostbyname(mail->host)) == NULL) { // get the host info
                herror("gethostbyname");
                exit(1);
        }
        while (fail < 5) {
+               struct timeval timeout;
+               int res;
+               fd_set fdset;
+
                if (fail > 0) {
                        ERR("Trying POP3 connection again for %s@%s (try %i/5)",
                                mail->user, mail->host, fail + 1);
@@ -1763,9 +1774,6 @@ void *pop3_thread(struct mail_s *mail)
                        fail++;
                        goto next_iteration;
                }
-               struct timeval timeout;
-               int res;
-               fd_set fdset;
 
                timeout.tv_sec = 60;    // 60 second timeout i guess
                timeout.tv_usec = 0;
@@ -1922,14 +1930,18 @@ next_iteration:
        return 0;
 }
 
-void *threaded_exec(struct text_object *obj)
+void *threaded_exec(void *arg)
 {
+       FILE *fp;
+       char *p2;
+       int n2;
+       struct text_object *obj = (struct text_object *)arg;
        while (1) {
-               char *p2 = obj->data.texeci.buffer;
-               FILE *fp = popen(obj->data.texeci.cmd, "r");
+               p2 = obj->data.texeci.buffer;
+               fp = popen(obj->data.texeci.cmd, "r");
 
                timed_thread_lock(obj->data.texeci.p_timed_thread);
-               int n2 = fread(p2, 1, text_buffer_size, fp);
+               n2 = fread(p2, 1, text_buffer_size, fp);
 
                pclose(fp);
                p2[n2] = '\0';
@@ -1950,7 +1962,7 @@ void *threaded_exec(struct text_object *obj)
        return 0;
 }
 
-static struct text_object *new_text_object_internal()
+static struct text_object *new_text_object_internal(void)
 {
        struct text_object *obj = malloc(sizeof(struct text_object));
        memset(obj, 0, sizeof(struct text_object));
@@ -2708,7 +2720,7 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ(execgraph, 0)
                obj->data.s = strdup(arg ? arg : "");
        END OBJ(execibar, 0)
-               unsigned int n;
+               int n;
 
                if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
                        char buf[256];
@@ -2721,7 +2733,7 @@ static struct text_object *construct_text_object(const char *s,
                        obj->data.execi.cmd = strdup(arg + n);
                }
        END OBJ(execigraph, 0)
-               unsigned int n;
+               int n;
 
                if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
                        char buf[256];
@@ -2734,7 +2746,7 @@ static struct text_object *construct_text_object(const char *s,
                        obj->data.execi.cmd = strdup(arg + n);
                }
        END OBJ(execi, 0)
-               unsigned int n;
+               int n;
 
                if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
                        char buf[256];
@@ -2748,7 +2760,7 @@ static struct text_object *construct_text_object(const char *s,
                        obj->data.execi.buffer = malloc(text_buffer_size);
                }
        END OBJ(execpi, 0)
-               unsigned int n;
+               int n;
 
                if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
                        char buf[256];
@@ -2762,7 +2774,7 @@ static struct text_object *construct_text_object(const char *s,
                        obj->data.execi.buffer = malloc(text_buffer_size);
                }
        END OBJ(texeci, 0)
-               unsigned int n;
+               int n;
 
                if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
                        char buf[256];
@@ -3818,24 +3830,28 @@ static struct text_object *create_plain_text(const char *s)
        return obj;
 }
 
-static struct text_object_list *extract_variable_text_internal(const char *p)
+static struct text_object_list *extract_variable_text_internal(const char *const_p)
 {
        struct text_object_list *retval;
        struct text_object *obj;
-       const char *s = p;
+       char *p, *s, *orig_p;
+       long line;
+
+       p = strdup(const_p);
+       s = orig_p = p;
 
        retval = malloc(sizeof(struct text_object_list));
        memset(retval, 0, sizeof(struct text_object_list));
        retval->text_object_count = 0;
 
-       long line = text_lines;
+       line = text_lines;
 
        while (*p) {
                if (*p == '\n') {
                        line++;
                }
                if (*p == '$') {
-                       *(char *) p = '\0';
+                       *p = '\0';
                        obj = create_plain_text(s);
                        if (obj != NULL) {
                                // allocate memory for the object
@@ -3847,7 +3863,7 @@ static struct text_object_list *extract_variable_text_internal(const char *p)
                                        sizeof(struct text_object));
                                free(obj);
                        }
-                       *(char *) p = '$';
+                       *p = '$';
                        p++;
                        s = p;
 
@@ -3896,7 +3912,7 @@ static struct text_object_list *extract_variable_text_internal(const char *p)
 
                                /* if variable wasn't found in environment, use some special */
                                if (!var) {
-                                       char *p;
+                                       char *tmp_p;
                                        char *arg = 0;
 
                                        /* split arg */
@@ -3913,10 +3929,10 @@ static struct text_object_list *extract_variable_text_internal(const char *p)
                                        }
 
                                        /* lowercase variable name */
-                                       p = buf;
-                                       while (*p) {
-                                               *p = tolower(*p);
-                                               p++;
+                                       tmp_p = buf;
+                                       while (*tmp_p) {
+                                               *tmp_p = tolower(*tmp_p);
+                                               tmp_p++;
                                        }
 
                                        // create new object
@@ -3966,6 +3982,7 @@ static struct text_object_list *extract_variable_text_internal(const char *p)
                ERR("one or more $endif's are missing");
        }
 
+       free(orig_p);
        return retval;
 }
 
@@ -3973,7 +3990,7 @@ static void extract_variable_text(const char *p)
 {
        struct text_object_list *list;
 
-       free_text_objects(text_object_count, text_objects);
+       free_text_objects(global_text_object_count, global_text_objects);
        if (tmpstring1) {
                free(tmpstring1);
                tmpstring1 = 0;
@@ -3986,12 +4003,12 @@ static void extract_variable_text(const char *p)
                free(text_buffer);
                text_buffer = 0;
        }
-       text_object_count = 0;
-       text_objects = NULL;
+       global_text_object_count = 0;
+       global_text_objects = NULL;
 
        list = extract_variable_text_internal(p);
-       text_objects = list->text_objects;
-       text_object_count = list->text_object_count;
+       global_text_objects = list->text_objects;
+       global_text_object_count = list->text_object_count;
 
        free(list);
 }
@@ -4269,8 +4286,8 @@ static void generate_text_internal(char *p, int p_max_size,
                                get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
                        }
                        OBJ(battery_percent) {
-                               spaced_print(p, p_max_size, "%*d", pad_percents,
-                                               "battery_percent", get_battery_perct(obj->data.s));
+                               spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
+                                               pad_percents, get_battery_perct(obj->data.s));
                        }
                        OBJ(battery_bar) {
                                new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
@@ -4639,17 +4656,20 @@ static void generate_text_internal(char *p, int p_max_size,
                                }
                        }
                        OBJ(execp) {
-                               FILE *fp = popen(obj->data.s, "r");
-                               fread(p, 1, p_max_size, fp);
+                               FILE *fp;
+                               struct information *my_info;
+                               struct text_object_list *text_objects;
+                               int length;
 
+                               fp = popen(obj->data.s, "r");
+                               fread(p, 1, p_max_size, fp);
                                pclose(fp);
 
-                               struct information *my_info =
-                                       malloc(sizeof(struct information));
+                               my_info = malloc(sizeof(struct information));
                                memcpy(my_info, cur, sizeof(struct information));
-                               struct text_object_list *text_objects = parse_conky_vars(p, p, my_info);
+                               text_objects = parse_conky_vars(p, p, my_info);
 
-                               int length = strlen(p);
+                               length = strlen(p);
 
                                p[length] = '\0';
                                if (length > 0 && p[length - 1] == '\n') {
@@ -4664,6 +4684,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                char *p2 = p;
                                FILE *fp = popen(obj->data.s, "r");
                                int n2 = fread(p, 1, p_max_size, fp);
+                               double barnum;
 
                                pclose(fp);
                                p[n2] = '\0';
@@ -4677,7 +4698,6 @@ static void generate_text_internal(char *p, int p_max_size,
                                        }
                                        p2++;
                                }
-                               double barnum;
 
                                if (sscanf(p, "%lf", &barnum) == 0) {
                                        ERR("reading execbar value failed (perhaps it's not the "
@@ -4695,6 +4715,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                char *p2 = p;
                                FILE *fp = popen(obj->data.s, "r");
                                int n2 = fread(p, 1, p_max_size, fp);
+                               double barnum;
 
                                pclose(fp);
                                p[n2] = '\0';
@@ -4707,7 +4728,6 @@ static void generate_text_internal(char *p, int p_max_size,
                                        }
                                        p2++;
                                }
-                               double barnum;
 
                                if (sscanf(p, "%lf", &barnum) == 0) {
                                        ERR("reading execgraph value failed (perhaps it's not the "
@@ -4729,6 +4749,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        char *p2 = p;
                                        FILE *fp = popen(obj->data.execi.cmd, "r");
                                        int n2 = fread(p, 1, p_max_size, fp);
+                                       float barnum;
 
                                        pclose(fp);
                                        p[n2] = '\0';
@@ -4742,7 +4763,6 @@ static void generate_text_internal(char *p, int p_max_size,
                                                }
                                                p2++;
                                        }
-                                       float barnum;
 
                                        if (sscanf(p, "%f", &barnum) == 0) {
                                                ERR("reading execibar value failed (perhaps it's not "
@@ -4766,6 +4786,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        char *p2 = p;
                                        FILE *fp = popen(obj->data.execi.cmd, "r");
                                        int n2 = fread(p, 1, p_max_size, fp);
+                                       float barnum;
 
                                        pclose(fp);
                                        p[n2] = '\0';
@@ -4779,7 +4800,6 @@ static void generate_text_internal(char *p, int p_max_size,
                                                }
                                                p2++;
                                        }
-                                       float barnum;
 
                                        if (sscanf(p, "%f", &barnum) == 0) {
                                                ERR("reading execigraph value failed (perhaps it's not "
@@ -4818,10 +4838,10 @@ static void generate_text_internal(char *p, int p_max_size,
                                // parse_conky_vars(output, p, cur);
                        }
                        OBJ(execpi) {
+                               struct text_object_list *text_objects = 0;
                                struct information *my_info =
                                        malloc(sizeof(struct information));
                                memcpy(my_info, cur, sizeof(struct information));
-                               struct text_object_list *text_objects = 0;
 
                                if (current_update_time - obj->data.execi.last_update
                                                < obj->data.execi.interval
@@ -4849,7 +4869,7 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(texeci) {
                                if (!obj->data.texeci.p_timed_thread) {
                                        obj->data.texeci.p_timed_thread =
-                                               timed_thread_create((void *) threaded_exec,
+                                               timed_thread_create(&threaded_exec,
                                                (void *) obj, obj->data.texeci.interval * 1000000);
                                        if (!obj->data.texeci.p_timed_thread) {
                                                ERR("Error creating texeci timed thread");
@@ -4870,7 +4890,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use info
                                        if (!info.mail->p_timed_thread) {
                                                info.mail->p_timed_thread =
-                                                       timed_thread_create((void *) imap_thread,
+                                                       timed_thread_create(&imap_thread,
                                                        (void *) info.mail, info.mail->interval * 1000000);
                                                if (!info.mail->p_timed_thread) {
                                                        ERR("Error creating imap timed thread");
@@ -4888,7 +4908,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use obj
                                        if (!obj->data.mail->p_timed_thread) {
                                                obj->data.mail->p_timed_thread =
-                                                       timed_thread_create((void *) imap_thread,
+                                                       timed_thread_create(&imap_thread,
                                                        (void *) obj->data.mail,
                                                        obj->data.mail->interval * 1000000);
                                                if (!obj->data.mail->p_timed_thread) {
@@ -4916,7 +4936,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use info
                                        if (!info.mail->p_timed_thread) {
                                                info.mail->p_timed_thread =
-                                                       timed_thread_create((void *) imap_thread,
+                                                       timed_thread_create(&imap_thread,
                                                        (void *) info.mail, info.mail->interval * 1000000);
                                                if (!info.mail->p_timed_thread) {
                                                        ERR("Error creating imap timed thread");
@@ -4934,7 +4954,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use obj
                                        if (!obj->data.mail->p_timed_thread) {
                                                obj->data.mail->p_timed_thread =
-                                                       timed_thread_create((void *) imap_thread,
+                                                       timed_thread_create(&imap_thread,
                                                        (void *) obj->data.mail,
                                                        obj->data.mail->interval * 1000000);
                                                if (!obj->data.mail->p_timed_thread) {
@@ -4962,7 +4982,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use info
                                        if (!info.mail->p_timed_thread) {
                                                info.mail->p_timed_thread =
-                                                       timed_thread_create((void *) pop3_thread,
+                                                       timed_thread_create(&pop3_thread,
                                                        (void *) info.mail, info.mail->interval * 1000000);
                                                if (!info.mail->p_timed_thread) {
                                                        ERR("Error creating pop3 timed thread");
@@ -4980,7 +5000,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use obj
                                        if (!obj->data.mail->p_timed_thread) {
                                                obj->data.mail->p_timed_thread =
-                                                       timed_thread_create((void *) pop3_thread,
+                                                       timed_thread_create(&pop3_thread,
                                                        (void *) obj->data.mail,
                                                        obj->data.mail->interval * 1000000);
                                                if (!obj->data.mail->p_timed_thread) {
@@ -5008,7 +5028,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use info
                                        if (!info.mail->p_timed_thread) {
                                                info.mail->p_timed_thread =
-                                                       timed_thread_create((void *) pop3_thread,
+                                                       timed_thread_create(&pop3_thread,
                                                        (void *) info.mail, info.mail->interval * 1000000);
                                                if (!info.mail->p_timed_thread) {
                                                        ERR("Error creating pop3 timed thread");
@@ -5027,7 +5047,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        // this means we use obj
                                        if (!obj->data.mail->p_timed_thread) {
                                                obj->data.mail->p_timed_thread =
-                                                       timed_thread_create((void *) pop3_thread,
+                                                       timed_thread_create(&pop3_thread,
                                                        (void *) obj->data.mail,
                                                        obj->data.mail->interval * 1000000);
                                                if (!obj->data.mail->p_timed_thread) {
@@ -5070,9 +5090,9 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(fs_free_perc) {
                                if (obj->data.fs != NULL) {
                                        if (obj->data.fs->size) {
-                                               spaced_print(p, p_max_size, "%*d", pad_percents,
-                                                       "fs_free_perc", (int) ((obj->data.fs->avail * 100) /
-                                                       obj->data.fs->size));
+                                               spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
+                                                               pad_percents, (int) ((obj->data.fs->avail * 100) /
+                                                                       obj->data.fs->size));
                                        } else {
                                                snprintf(p, p_max_size, "0");
                                        }
@@ -5108,9 +5128,9 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(fs_used_perc) {
                                if (obj->data.fs != NULL) {
                                        if (obj->data.fs->size) {
-                                               spaced_print(p, 4, "%*d", pad_percents,
-                                                       "fs_used_perc", 100 - ((int) ((obj->data.fs->avail * 100) /
-                                                       obj->data.fs->size)));
+                                               spaced_print(p, 4, "%*d", 4, "fs_used_perc",
+                                                               pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
+                                                                               obj->data.fs->size)));
                                        } else {
                                                snprintf(p, p_max_size, "0");
                                        }
@@ -5185,9 +5205,9 @@ static void generate_text_internal(char *p, int p_max_size,
                                        } else if (!strcmp(obj->data.rss.action, "item_titles")) {
                                                if (data->item_count > 0) {
                                                        int itmp;
+                                                       int show;
 
                                                        p[0] = 0;
-                                                       int show;
 
                                                        if (obj->data.rss.act_par > data->item_count) {
                                                                show = data->item_count;
@@ -5283,11 +5303,12 @@ static void generate_text_internal(char *p, int p_max_size,
                                new_alignc(p, obj->data.i);
                        }
                        OBJ(if_empty) {
+                               struct text_object_list *text_objects;
                                struct information *my_info =
                                        malloc(sizeof(struct information));
-
                                memcpy(my_info, cur, sizeof(struct information));
-                               struct text_object_list *text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
+                               text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info);
+
                                if (strlen(p) != 0) {
                                        i = obj->data.ifblock.pos;
                                        if_jumped = 1;
@@ -5356,7 +5377,7 @@ static void generate_text_internal(char *p, int p_max_size,
                        }
                        OBJ(memperc) {
                                if (cur->memmax) {
-                                       spaced_print(p, p_max_size, "%*Lu", 4, "memperc",
+                                       spaced_print(p, p_max_size, "%*llu", 4, "memperc",
                                                pad_percents, cur->mem * 100 / cur->memmax);
                                }
                        }
@@ -5439,7 +5460,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                if (cur->swapmax == 0) {
                                        strncpy(p, "No swap", p_max_size);
                                } else {
-                                       spaced_print(p, p_max_size, "%*Lu", 4, "swapperc",
+                                       spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
                                                pad_percents, cur->swap * 100 / cur->swapmax);
                                }
                        }
@@ -5465,14 +5486,16 @@ static void generate_text_internal(char *p, int p_max_size,
                        }
                        OBJ(tztime) {
                                char *oldTZ = NULL;
+                               time_t t;
+                               struct tm *tm;
 
                                if (obj->data.tztime.tz) {
                                        oldTZ = getenv("TZ");
                                        setenv("TZ", obj->data.tztime.tz, 1);
                                        tzset();
                                }
-                               time_t t = time(NULL);
-                               struct tm *tm = localtime(&t);
+                               t = time(NULL);
+                               tm = localtime(&t);
 
                                setlocale(LC_TIME, "");
                                strftime(p, p_max_size, obj->data.tztime.fmt, tm);
@@ -5639,8 +5662,8 @@ static void generate_text_internal(char *p, int p_max_size,
                                }
                        }
                        OBJ(mpd_percent) {
-                               spaced_print(p, p_max_size, "%*d", pad_percents,
-                                               "mpd_percent", (int) (cur->mpd.progress * 100));
+                               spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
+                                               pad_percents, (int) (cur->mpd.progress * 100));
                        }
                        OBJ(mpd_bar) {
                                new_bar(p, obj->data.pair.a, obj->data.pair.b,
@@ -5891,11 +5914,12 @@ static void generate_text_internal(char *p, int p_max_size,
                                                < obj->data.tail.interval) {
                                        snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
                                } else {
-                                       obj->data.tail.last_update = current_update_time;
                                        FILE *fp;
                                        long nl = 0, bsize;
                                        int iter;
 
+                                       obj->data.tail.last_update = current_update_time;
+
                                        if (obj->data.tail.fd != -1) {
                                                tail_pipe(obj, p, p_max_size);
                                                goto head;
@@ -5967,11 +5991,12 @@ head:
                                                < obj->data.tail.interval) {
                                        snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
                                } else {
-                                       obj->data.tail.last_update = current_update_time;
                                        FILE *fp;
                                        long nl = 0;
                                        int iter;
 
+                                       obj->data.tail.last_update = current_update_time;
+
                                        fp = fopen(obj->data.tail.logfile, "rt");
                                        if (fp == NULL) {
                                                /* Send one message, but do not consistently spam
@@ -6145,7 +6170,7 @@ head:
 
 double current_update_time, last_update_time;
 
-static void generate_text()
+static void generate_text(void)
 {
        struct information *cur = &info;
        char *p;
@@ -6156,7 +6181,7 @@ static void generate_text()
 
        current_update_time = get_time();
 
-       update_stuff(cur);
+       update_stuff();
        /* fix diskio rates to b/s (use update_interval */
        diskio_read_value = diskio_read_value / update_interval;
        diskio_write_value = diskio_write_value / update_interval;
@@ -6168,7 +6193,8 @@ static void generate_text()
 
        p = text_buffer;
 
-       generate_text_internal(p, max_user_text, text_objects, text_object_count, cur);
+       generate_text_internal(p, max_user_text, global_text_objects,
+                       global_text_object_count, cur);
 
        if (stuff_in_upper_case) {
                char *p;
@@ -6186,7 +6212,7 @@ static void generate_text()
 }
 
 #ifdef X11
-static void set_font()
+static void set_font(void)
 {
 #ifdef XFT
        if (use_xft) {
@@ -6215,17 +6241,18 @@ static inline int get_string_width(const char *s)
 
 static inline int get_string_width_special(char *s)
 {
+#ifdef X11
+       char *p, *final;
+       int index = 1;
+       int width = 0;
+       unsigned int i;
+
        if (!s) {
                return 0;
        }
-#ifdef X11
-       char *p, *final;
 
        p = strdup(s);
        final = p;
-       int index = 1;
-       int width = 0;
-       unsigned int i;
 
        while (*p) {
                if (*p == SPECIAL_CHAR) {
@@ -6249,7 +6276,7 @@ static inline int get_string_width_special(char *s)
        free(final);
        return width;
 #else
-       return strlen(s);
+       return (s) ? strlen(s) : 0;
 #endif /* X11 */
 }
 
@@ -6257,7 +6284,7 @@ static inline int get_string_width_special(char *s)
 static void text_size_updater(char *s);
 
 int last_font_height;
-static void update_text_area()
+static void update_text_area(void)
 {
        int x, y;
 
@@ -6437,12 +6464,14 @@ static inline void set_foreground_color(long c)
 
 static void draw_string(const char *s)
 {
-       if (s[0] == '\0') {
-               return;
-       }
        int i, i2, pos, width_of_s;
        int max = 0;
        int added;
+       char space[2];
+
+       if (s[0] == '\0') {
+               return;
+       }
 
        width_of_s = get_string_width(s);
        if (out_to_console) {
@@ -6454,7 +6483,6 @@ static void draw_string(const char *s)
        strncpy(tmpstring1, s, text_buffer_size - 1);
        pos = 0;
        added = 0;
-       char space[2];
 
        snprintf(space, 2, " ");
 #ifdef X11
@@ -6507,10 +6535,10 @@ static void draw_string(const char *s)
                c2.color.alpha = fonts[selected_font].font_alpha;
                if (utf8_mode) {
                        XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
-                               cur_x, cur_y, (XftChar8 *) s, strlen(s));
+                               cur_x, cur_y, (const XftChar8 *) s, strlen(s));
                } else {
                        XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
-                               cur_x, cur_y, (XftChar8 *) s, strlen(s));
+                               cur_x, cur_y, (const XftChar8 *) s, strlen(s));
                }
        } else
 #endif
@@ -6525,8 +6553,9 @@ static void draw_string(const char *s)
 
 long redmask, greenmask, bluemask;
 
-void set_up_gradient()
+void set_up_gradient(void)
 {
+       int i;
 #ifdef X11
        colour_depth = DisplayPlanes(display, screen);
 #else
@@ -6536,7 +6565,6 @@ void set_up_gradient()
                ERR("using non-standard colour depth, gradients may look like a "
                        "lolly-pop");
        }
-       int i;
 
        redmask = 0;
        greenmask = 0;
@@ -6617,14 +6645,17 @@ inline unsigned long do_gradient(unsigned long first_colour,
 inline unsigned long gradient_max(unsigned long first_colour,
                unsigned long last_colour)
 {
+       int red1, green1, blue1;                                // first colour
+       int red2, green2, blue2;                                // second colour
+       int red3 = 0, green3 = 0, blue3 = 0;                    // difference
+       long redshift, greenshift;
+       int max;
+
        if (colour_depth == 0) {
                set_up_gradient();
        }
-       int red1, green1, blue1;                                // first colour
-       int red2, green2, blue2;                                // second colour
-       long redshift = (2 * colour_depth / 3 + colour_depth % 3);
-       long greenshift = (colour_depth / 3);
-       int red3 = 0, green3 = 0, blue3 = 0;    // difference
+       redshift = (2 * colour_depth / 3 + colour_depth % 3);
+       greenshift = (colour_depth / 3);
 
        red1 = (first_colour & redmask) >> redshift;
        green1 = (first_colour & greenmask) >> greenshift;
@@ -6635,7 +6666,7 @@ inline unsigned long gradient_max(unsigned long first_colour,
        red3 = abs(red1 - red2);
        green3 = abs(green1 - green2);
        blue3 = abs(blue1 - blue2);
-       int max = red3;
+       max = red3;
 
        if (green3 > max) {
                max = green3;
@@ -6650,11 +6681,12 @@ static void draw_line(char *s)
 {
 #ifdef X11
        char *p;
+       int cur_y_add = 0;
+       short font_h;
 
        cur_x = text_start_x;
        cur_y += font_ascent();
-       int cur_y_add = 0;
-       short font_h = font_height();
+       font_h = font_height();
 
        /* find specials and draw stuff */
        p = s;
@@ -6702,13 +6734,14 @@ static void draw_line(char *s)
 
                                case BAR:
                                {
+                                       int h, bar_usage, by;
                                        if (cur_x - text_start_x > maximum_width
                                                        && maximum_width > 0) {
                                                break;
                                        }
-                                       int h = specials[special_index].height;
-                                       int bar_usage = specials[special_index].arg;
-                                       int by = cur_y - (font_ascent() / 2) - 1;
+                                       h = specials[special_index].height;
+                                       bar_usage = specials[special_index].arg;
+                                       by = cur_y - (font_ascent() / 2) - 1;
 
                                        if (h < font_height()) {
                                                by -= h / 2 - 1;
@@ -6737,13 +6770,18 @@ static void draw_line(char *s)
 
                                case GRAPH:
                                {
+                                       int h, by, i, j = 0;
+                                       int gradient_size = 0;
+                                       float gradient_factor = 0;
+                                       float gradient_update = 0;
+                                       unsigned long last_colour = current_color;
+                                       unsigned long tmpcolour = current_color;
                                        if (cur_x - text_start_x > maximum_width
                                                        && maximum_width > 0) {
                                                break;
                                        }
-                                       int h = specials[special_index].height;
-                                       unsigned long last_colour = current_color;
-                                       int by = cur_y - (font_ascent() / 2) - 1;
+                                       h = specials[special_index].height;
+                                       by = cur_y - (font_ascent() / 2) - 1;
 
                                        if (h < font_height()) {
                                                by -= h / 2 - 1;
@@ -6763,12 +6801,6 @@ static void draw_line(char *s)
                                        }
                                        XSetLineAttributes(display, window.gc, 1, LineSolid,
                                                CapButt, JoinMiter);
-                                       int i;
-                                       int j = 0;
-                                       int gradient_size = 0;
-                                       float gradient_factor = 0;
-                                       float gradient_update = 0;
-                                       unsigned long tmpcolour = current_color;
 
                                        if (specials[special_index].last_colour != 0
                                                        || specials[special_index].first_colour != 0) {
@@ -6934,7 +6966,7 @@ static void draw_line(char *s)
 #endif /* X11 */
 }
 
-static void draw_text()
+static void draw_text(void)
 {
 #ifdef X11
        cur_y = text_start_y;
@@ -6965,7 +6997,7 @@ static void draw_text()
        for_each_line(text_buffer, draw_line);
 }
 
-static void draw_stuff()
+static void draw_stuff(void)
 {
 #ifdef X11
        selected_font = 0;
@@ -6980,8 +7012,8 @@ static void draw_stuff()
        }
 
        if (draw_outline) {
-               selected_font = 0;
                int i, j;
+               selected_font = 0;
 
                for (i = -1; i < 2; i++) {
                        for (j = -1; j < 2; j++) {
@@ -7038,7 +7070,7 @@ static void clear_text(int exposures)
 static int need_to_update;
 
 /* update_text() generates new text and clears old text area */
-static void update_text()
+static void update_text(void)
 {
        generate_text();
 #ifdef X11
@@ -7047,35 +7079,35 @@ static void update_text()
        need_to_update = 1;
 }
 
-static void main_loop()
+static void main_loop(void)
 {
 #ifdef SIGNAL_BLOCKING
        sigset_t newmask, oldmask;
-
-       sigemptyset(&newmask);
-       sigaddset(&newmask, SIGINT);
-       sigaddset(&newmask, SIGTERM);
-       sigaddset(&newmask, SIGUSR1);
 #endif
-
 #ifdef X11
        Region region = XCreateRegion();
 
 #ifdef HAVE_XDAMAGE
+       Damage damage;
+       XserverRegion region2, part;
        int event_base, error_base;
 
        if (!XDamageQueryExtension(display, &event_base, &error_base)) {
                ERR("Xdamage extension unavailable");
        }
-       Damage damage = XDamageCreate(display, window.window,
-               XDamageReportNonEmpty);
-       XserverRegion region2 = XFixesCreateRegionFromWindow(display,
-               window.window, 0);
-       XserverRegion part = XFixesCreateRegionFromWindow(display,
-               window.window, 0);
+       damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
+       region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
+       part = XFixesCreateRegionFromWindow(display, window.window, 0);
 #endif /* HAVE_XDAMAGE */
 #endif /* X11 */
 
+#ifdef SIGNAL_BLOCKING
+       sigemptyset(&newmask);
+       sigaddset(&newmask, SIGINT);
+       sigaddset(&newmask, SIGTERM);
+       sigaddset(&newmask, SIGUSR1);
+#endif
+
        info.looped = 0;
        while (total_run_times == 0 || info.looped < total_run_times) {
                info.looped++;
@@ -7519,7 +7551,7 @@ void clean_up(void)
        free_fonts();
 #endif /* X11 */
 
-       free_text_objects(text_object_count, text_objects);
+       free_text_objects(global_text_object_count, global_text_objects);
        if (tmpstring1) {
                free(tmpstring1);
                tmpstring1 = 0;
@@ -7532,8 +7564,8 @@ void clean_up(void)
                free(text_buffer);
                text_buffer = 0;
        }
-       text_object_count = 0;
-       text_objects = NULL;
+       global_text_object_count = 0;
+       global_text_objects = NULL;
 
        if (text) {
                free(text);
@@ -8409,6 +8441,10 @@ static const struct option longopts[] = {
 
 int main(int argc, char **argv)
 {
+#ifdef X11
+       char *s, *temp;
+       unsigned int x;
+#endif
        struct sigaction act, oact;
 
        g_signal_pending = 0;
@@ -8421,9 +8457,6 @@ int main(int argc, char **argv)
 
        /* handle command line parameters that don't change configs */
 #ifdef X11
-       char *s, *temp;
-       unsigned int x;
-
        if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
                        || ((s = getenv("LANG")) && *s)) {
                temp = (char *) malloc((strlen(s) + 1) * sizeof(char));