From: <nga...@us...> - 2008-06-21 12:47:18
|
Revision: 1186 http://conky.svn.sourceforge.net/conky/?rev=1186&view=rev Author: ngarofil Date: 2008-06-21 05:47:13 -0700 (Sat, 21 Jun 2008) Log Message: ----------- Rev 1178 to 1185 merged with conky1-extra Revision Links: -------------- http://conky.svn.sourceforge.net/conky/?rev=1178&view=rev Modified Paths: -------------- branches/conky1-extra/src/audacious.c branches/conky1-extra/src/conky.c Modified: branches/conky1-extra/src/audacious.c =================================================================== --- branches/conky1-extra/src/audacious.c 2008-06-21 09:25:37 UTC (rev 1185) +++ branches/conky1-extra/src/audacious.c 2008-06-21 12:47:13 UTC (rev 1186) @@ -109,13 +109,11 @@ int destroy_audacious_thread(void) { /* Is a worker is thread running? If not, no error. */ - if (!info.audacious.p_timed_thread) { - return 0; + if (info.audacious.p_timed_thread) { + timed_thread_destroy(info.audacious.p_timed_thread, + &info.audacious.p_timed_thread); } - timed_thread_destroy(info.audacious.p_timed_thread, - &info.audacious.p_timed_thread); - return 0; } Modified: branches/conky1-extra/src/conky.c =================================================================== --- branches/conky1-extra/src/conky.c 2008-06-21 09:25:37 UTC (rev 1185) +++ branches/conky1-extra/src/conky.c 2008-06-21 12:47:13 UTC (rev 1186) @@ -439,8 +439,8 @@ tcp_port_monitor_args_t tcp_port_monitor_args; #endif -static char *text = 0; -long text_lines; +static char *global_text = 0; +long global_text_lines; static int total_updates; @@ -783,19 +783,16 @@ s->last_colour = adjust_colors(second_colour); if (scale != 0) { s->scaled = 0; + s->graph_scale = scale; + s->show_scale = 0; } else { s->scaled = 1; + s->graph_scale = 1; + s->show_scale = 1; } /* if (s->width) { s->graph_width = s->width - 2; // subtract 2 for rectangle around } */ - if (s->scaled) { - s->graph_scale = 1; - s->show_scale = 1; - } else { - s->graph_scale = scale; - s->show_scale = 0; - } if (showaslog) { s->graph_scale = log10(s->graph_scale + 1); } @@ -940,6 +937,7 @@ new_special(buf, ALIGNR)->arg = c; } +// A postive offset pushes the text further left static inline void new_alignc(char *buf, long c) { new_special(buf, ALIGNC)->arg = c; @@ -1515,10 +1513,10 @@ struct text_object *text_objects; }; -static unsigned int global_text_object_count; -static struct text_object *global_text_objects; +static struct text_object_list *global_text_object_list; + static void generate_text_internal(char *p, int p_max_size, - struct text_object *objs, unsigned int object_count, + struct text_object_list *text_object_list, struct information *cur); #define MAXDATASIZE 1000 @@ -2011,26 +2009,30 @@ return 0; } +static inline void read_exec(const char *data, char *buf, const int size) +{ + FILE *fp = popen(data, "r"); + int length = fread(buf, 1, size, fp); + + pclose(fp); + buf[length] = '\0'; + if (length > 0 && buf[length - 1] == '\n') { + buf[length - 1] = '\0'; + } +} + void *threaded_exec(void *) __attribute__((noreturn)); void *threaded_exec(void *arg) { - FILE *fp; char *p2; - int n2; struct text_object *obj = (struct text_object *)arg; + while (1) { p2 = obj->data.texeci.buffer; - fp = popen(obj->data.texeci.cmd, "r"); - timed_thread_lock(obj->data.texeci.p_timed_thread); - n2 = fread(p2, 1, text_buffer_size, fp); - - pclose(fp); - p2[n2] = '\0'; - if (n2 && p2[n2 - 1] == '\n') { - p2[n2 - 1] = '\0'; - } + read_exec(obj->data.texeci.cmd, obj->data.texeci.buffer, + text_buffer_size); while (*p2) { if (*p2 == '\001') { *p2 = ' '; @@ -2052,75 +2054,81 @@ return obj; } -static void free_text_objects(unsigned int count, struct text_object *objs) +static void free_text_objects(struct text_object_list *text_object_list) { unsigned int i; + struct text_object *obj; - for (i = 0; i < count; i++) { - switch (objs[i].type) { + if (text_object_list == NULL) { + return; + } + + for (i = 0; i < text_object_list->text_object_count; i++) { + obj = &text_object_list->text_objects[i]; + switch (obj->type) { #ifndef __OpenBSD__ case OBJ_acpitemp: case OBJ_acpitempf: - close(objs[i].data.i); + close(obj->data.i); break; case OBJ_i2c: case OBJ_platform: case OBJ_hwmon: - close(objs[i].data.sysfs.fd); + close(obj->data.sysfs.fd); break; #endif /* !__OpenBSD__ */ case OBJ_time: case OBJ_utime: - free(objs[i].data.s); + free(obj->data.s); break; case OBJ_tztime: - free(objs[i].data.tztime.tz); - free(objs[i].data.tztime.fmt); + free(obj->data.tztime.tz); + free(obj->data.tztime.fmt); break; case OBJ_mboxscan: - free(objs[i].data.mboxscan.args); - free(objs[i].data.mboxscan.output); + free(obj->data.mboxscan.args); + free(obj->data.mboxscan.output); break; case OBJ_mails: case OBJ_new_mails: - free(objs[i].data.local_mail.box); + free(obj->data.local_mail.box); break; case OBJ_imap: free(info.mail); break; case OBJ_imap_unseen: - if (!objs[i].global_mode) { - free(objs[i].data.mail); + if (!obj->global_mode) { + free(obj->data.mail); } break; case OBJ_imap_messages: - if (!objs[i].global_mode) { - free(objs[i].data.mail); + if (!obj->global_mode) { + free(obj->data.mail); } break; case OBJ_pop3: free(info.mail); break; case OBJ_pop3_unseen: - if (!objs[i].global_mode) { - free(objs[i].data.mail); + if (!obj->global_mode) { + free(obj->data.mail); } break; case OBJ_pop3_used: - if (!objs[i].global_mode) { - free(objs[i].data.mail); + if (!obj->global_mode) { + free(obj->data.mail); } break; case OBJ_if_empty: case OBJ_if_existing: case OBJ_if_mounted: case OBJ_if_running: - free(objs[i].data.ifblock.s); - free(objs[i].data.ifblock.str); + free(obj->data.ifblock.s); + free(obj->data.ifblock.str); break; case OBJ_tail: - free(objs[i].data.tail.logfile); - free(objs[i].data.tail.buffer); + free(obj->data.tail.logfile); + free(obj->data.tail.buffer); break; case OBJ_text: case OBJ_font: @@ -2129,7 +2137,7 @@ case OBJ_execbar: case OBJ_execgraph: case OBJ_execp: - free(objs[i].data.s); + free(obj->data.s); break; #ifdef HAVE_ICONV case OBJ_iconv_start: @@ -2244,30 +2252,30 @@ #endif #ifdef RSS case OBJ_rss: - free(objs[i].data.rss.uri); - free(objs[i].data.rss.action); + free(obj->data.rss.uri); + free(obj->data.rss.action); break; #endif case OBJ_pre_exec: break; #ifndef __OpenBSD__ case OBJ_battery: - free(objs[i].data.s); + free(obj->data.s); break; case OBJ_battery_time: - free(objs[i].data.s); + free(obj->data.s); break; #endif /* !__OpenBSD__ */ case OBJ_execpi: case OBJ_execi: case OBJ_execibar: case OBJ_execigraph: - free(objs[i].data.execi.cmd); - free(objs[i].data.execi.buffer); + free(obj->data.execi.cmd); + free(obj->data.execi.buffer); break; case OBJ_texeci: - free(objs[i].data.texeci.cmd); - free(objs[i].data.texeci.buffer); + free(obj->data.texeci.cmd); + free(obj->data.texeci.buffer); break; case OBJ_nameserver: free_dns_data(); @@ -2281,9 +2289,9 @@ break; #ifdef HDDTEMP case OBJ_hddtemp: - free(objs[i].data.hddtemp.dev); - free(objs[i].data.hddtemp.addr); - free(objs[i].data.hddtemp.temp); + free(obj->data.hddtemp.dev); + free(obj->data.hddtemp.addr); + free(obj->data.hddtemp.temp); break; #endif case OBJ_entropy_avail: @@ -2311,11 +2319,11 @@ #ifdef SMAPI case OBJ_smapi: case OBJ_smapi_bat_perc: - free(objs[i].data.s); + free(obj->data.s); break; case OBJ_if_smapi_bat_installed: - free(objs[i].data.ifblock.s); - free(objs[i].data.ifblock.str); + free(obj->data.ifblock.s); + free(obj->data.ifblock.str); break; #endif #ifdef NVIDIA @@ -2346,13 +2354,13 @@ break; #endif case OBJ_scroll: - free(objs[i].data.scroll.text); + free(obj->data.scroll.text); break; } } - free(objs); - /* text_objects = NULL; - text_object_count = 0; */ + free(text_object_list->text_objects); + text_object_list->text_objects = NULL; + text_object_list->text_object_count = 0; } void scan_mixer_bar(const char *arg, int *a, int *w, int *h) @@ -2899,19 +2907,9 @@ END OBJ(pre_exec, 0) obj->type = OBJ_text; if (arg) { - FILE *fp = popen(arg, "r"); - unsigned int n; char buf[2048]; - n = fread(buf, 1, 2048, fp); - buf[n] = '\0'; - - if (n && buf[n - 1] == '\n') { - buf[n - 1] = '\0'; - } - - pclose(fp); - + read_exec(arg, buf, sizeof(buf)); obj->data.s = strndup(buf, text_buffer_size); } else { obj->data.s = strndup("", text_buffer_size); @@ -4021,7 +4019,7 @@ memset(retval, 0, sizeof(struct text_object_list)); retval->text_object_count = 0; - line = text_lines; + line = global_text_lines; while (*p) { if (*p == '\n') { @@ -4165,9 +4163,8 @@ static void extract_variable_text(const char *p) { - struct text_object_list *list; - - free_text_objects(global_text_object_count, global_text_objects); + free_text_objects(global_text_object_list); + free(global_text_object_list); if (tmpstring1) { free(tmpstring1); tmpstring1 = 0; @@ -4180,14 +4177,8 @@ free(text_buffer); text_buffer = 0; } - global_text_object_count = 0; - global_text_objects = NULL; - list = extract_variable_text_internal(p); - global_text_objects = list->text_objects; - global_text_object_count = list->text_object_count; - - free(list); + global_text_object_list = extract_variable_text_internal(p); } struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur) @@ -4195,8 +4186,7 @@ struct text_object_list *object_list = extract_variable_text_internal(txt); - generate_text_internal(p, max_user_text, object_list->text_objects, - object_list->text_object_count, cur); + generate_text_internal(p, max_user_text, object_list, cur); return object_list; } @@ -4281,6 +4271,52 @@ snprintf(dst, dst_size, "%s", obj->data.tail.buffer); } +static inline struct mail_s *ensure_mail_thread(struct text_object *obj, + void *thread(void *), const char *text) +{ + if (obj->global_mode && info.mail) { + // this means we use info + if (!info.mail->p_timed_thread) { + info.mail->p_timed_thread = + timed_thread_create(thread, + (void *) info.mail, info.mail->interval * 1000000); + if (!info.mail->p_timed_thread) { + ERR("Error creating %s timed thread", text); + } + timed_thread_register(info.mail->p_timed_thread, + &info.mail->p_timed_thread); + if (timed_thread_run(info.mail->p_timed_thread)) { + ERR("Error running %s timed thread", text); + } + } + return info.mail; + } else if (obj->data.mail) { + // this means we use obj + if (!obj->data.mail->p_timed_thread) { + obj->data.mail->p_timed_thread = + timed_thread_create(thread, + (void *) obj->data.mail, + obj->data.mail->interval * 1000000); + if (!obj->data.mail->p_timed_thread) { + ERR("Error creating %s timed thread", text); + } + timed_thread_register(obj->data.mail->p_timed_thread, + &obj->data.mail->p_timed_thread); + if (timed_thread_run(obj->data.mail->p_timed_thread)) { + ERR("Error running %s timed thread", text); + } + } + return obj->data.mail; + } else if (!obj->a) { + // something is wrong, warn once then stop + ERR("Theres a problem with your %s_unseen settings. " + "Check that the global %s settings are defined " + "properly (line %li).", global_text, global_text, obj->line); + obj->a++; + } + return NULL; +} + char *format_time(unsigned long timeval, const int width) { char buf[10]; @@ -4359,8 +4395,33 @@ } } +static inline double get_barnum(char *buf) +{ + char *c = buf; + double barnum; + + while (*c) { + if (*c == '\001') { + *c = ' '; + } + c++; + } + + if (sscanf(buf, "%lf", &barnum) == 0) { + ERR("reading execbar value failed (perhaps it's not the " + "correct format?)"); + return -1; + } + if (barnum > 100.0 || barnum < 0.0) { + ERR("your execbar value is not between 0 and 100, " + "therefore it will be ignored"); + return -1; + } + return barnum; +} + static void generate_text_internal(char *p, int p_max_size, - struct text_object *objs, unsigned int object_count, + struct text_object_list *text_object_list, struct information *cur) { unsigned int i; @@ -4372,8 +4433,8 @@ #endif p[0] = 0; - for (i = 0; i < object_count; i++) { - struct text_object *obj = &objs[i]; + for (i = 0; i < text_object_list->text_object_count; i++) { + struct text_object *obj = &(text_object_list->text_objects[i]); if (p_max_size < 1) { break; @@ -4871,218 +4932,102 @@ #endif /* IMLIB2 */ OBJ(exec) { - FILE *fp = popen(obj->data.s, "r"); - int length = fread(p, 1, p_max_size, fp); - - pclose(fp); - - p[length] = '\0'; + read_exec(obj->data.s, p, p_max_size); remove_deleted_chars(p); - if (length > 0 && p[length - 1] == '\n') { - p[length - 1] = '\0'; - } } OBJ(execp) { - FILE *fp; - struct information *my_info; + struct information *tmp_info; struct text_object_list *text_objects; - int length; - fp = popen(obj->data.s, "r"); - fread(p, 1, p_max_size, fp); - pclose(fp); + read_exec(obj->data.s, p, p_max_size); - my_info = malloc(sizeof(struct information)); - memcpy(my_info, cur, sizeof(struct information)); - text_objects = parse_conky_vars(p, p, my_info); + tmp_info = malloc(sizeof(struct information)); + memcpy(tmp_info, cur, sizeof(struct information)); + text_objects = parse_conky_vars(p, p, tmp_info); - length = strlen(p); - - p[length] = '\0'; - if (length > 0 && p[length - 1] == '\n') { - p[length - 1] = '\0'; - } - - free_text_objects(text_objects->text_object_count, text_objects->text_objects); + free_text_objects(text_objects); free(text_objects); - free(my_info); + free(tmp_info); } OBJ(execbar) { - 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'; - if (n2 && p[n2 - 1] == '\n') { - p[n2 - 1] = '\0'; - } + read_exec(obj->data.s, p, p_max_size); + barnum = get_barnum(p); - while (*p2) { - if (*p2 == '\001') { - *p2 = ' '; - } - p2++; + if (barnum >= 0.0) { + new_bar(p, 0, 4, round_to_int(barnum * 255.0)); } - - if (sscanf(p, "%lf", &barnum) == 0) { - ERR("reading execbar value failed (perhaps it's not the " - "correct format?)"); - } - if (barnum > 100 || barnum < 0) { - ERR("your execbar value is not between 0 and 100, " - "therefore it will be ignored"); - } else { - barnum = barnum / 100.0; - new_bar(p, 0, 4, (int) (barnum * 255.0)); - } } OBJ(execgraph) { char showaslog = FALSE; - char *p2 = p; - FILE *fp; - int n2; double barnum; if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) { showaslog = TRUE; - fp = popen(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), "r"); + read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, p_max_size); } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) { - fp = popen(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), "r"); + read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, p_max_size); } else { - fp = popen(obj->data.s, "r"); + read_exec(obj->data.s, p, p_max_size); } - n2 = fread(p, 1, p_max_size, fp); - pclose(fp); - p[n2] = '\0'; - if (n2 && p[n2 - 1] == '\n') { - p[n2 - 1] = '\0'; - } - while (*p2) { - if (*p2 == '\001') { - *p2 = ' '; - } - p2++; - } + barnum = get_barnum(p); - if (sscanf(p, "%lf", &barnum) == 0) { - ERR("reading execgraph value failed (perhaps it's not the " - "correct format?)"); + if (barnum >= 0.0) { + new_graph(p, 0, 25, obj->c, obj->d, round_to_int(barnum), + 100, 1, showaslog); } - if (barnum > 100 || barnum < 0) { - ERR("your execgraph value is not between 0 and 100, " - "therefore it will be ignored"); - } else { - new_graph(p, 0, 25, obj->c, obj->d, (int) (barnum), 100, 1, showaslog); - } } OBJ(execibar) { if (current_update_time - obj->data.execi.last_update - < obj->data.execi.interval) { - new_bar(p, 0, 4, (int) obj->f); - } else { - char *p2 = p; - FILE *fp = popen(obj->data.execi.cmd, "r"); - int n2 = fread(p, 1, p_max_size, fp); - float barnum; + >= obj->data.execi.interval) { + double barnum; - pclose(fp); - p[n2] = '\0'; - if (n2 && p[n2 - 1] == '\n') { - p[n2 - 1] = '\0'; - } + read_exec(obj->data.execi.cmd, p, p_max_size); + barnum = get_barnum(p); - while (*p2) { - if (*p2 == '\001') { - *p2 = ' '; - } - p2++; - } - - if (sscanf(p, "%f", &barnum) == 0) { - ERR("reading execibar value failed (perhaps it's not " - "the correct format?)"); - } - if (barnum > 100 || barnum < 0) { - ERR("your execibar value is not between 0 and 100, " - "therefore it will be ignored"); - } else { + if (barnum >= 0.0) { obj->f = 255 * barnum / 100.0; - new_bar(p, 0, 4, (int) obj->f); } obj->data.execi.last_update = current_update_time; } + new_bar(p, 0, 4, round_to_int(obj->f)); } OBJ(execigraph) { if (current_update_time - obj->data.execi.last_update - < obj->data.execi.interval) { - new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0, FALSE); - } else { - char *p2 = p; - FILE *fp = popen(obj->data.execi.cmd, "r"); - int n2 = fread(p, 1, p_max_size, fp); - float barnum; + >= obj->data.execi.interval) { + double barnum; - pclose(fp); - p[n2] = '\0'; - if (n2 && p[n2 - 1] == '\n') { - p[n2 - 1] = '\0'; - } + read_exec(obj->data.execi.cmd, p, p_max_size); + barnum = get_barnum(p); - while (*p2) { - if (*p2 == '\001') { - *p2 = ' '; - } - p2++; - } - - if (sscanf(p, "%f", &barnum) == 0) { - ERR("reading execigraph value failed (perhaps it's not " - "the correct format?)"); - } - if (barnum > 100 || barnum < 0) { - ERR("your execigraph value is not between 0 and 100, " - "therefore it will be ignored"); - } else { + if (barnum >= 0.0) { obj->f = barnum; - new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), - 100, 1, FALSE); } obj->data.execi.last_update = current_update_time; } + new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE); } OBJ(execi) { if (current_update_time - obj->data.execi.last_update - < obj->data.execi.interval - || obj->data.execi.interval == 0) { - snprintf(p, p_max_size, "%s", obj->data.execi.buffer); - } else { - char *output = obj->data.execi.buffer; - FILE *fp = popen(obj->data.execi.cmd, "r"); - - int length = fread(output, 1, text_buffer_size, fp); - - pclose(fp); - output[length] = '\0'; - if (length > 0 && output[length - 1] == '\n') { - output[length - 1] = '\0'; - } + >= obj->data.execi.interval + && obj->data.execi.interval != 0) { + read_exec(obj->data.execi.cmd, obj->data.execi.buffer, + p_max_size); obj->data.execi.last_update = current_update_time; - snprintf(p, p_max_size, "%s", output); } - // parse_conky_vars(output, p, cur); + snprintf(p, p_max_size, "%s", obj->data.execi.buffer); } OBJ(execpi) { struct text_object_list *text_objects = 0; - struct information *my_info = + struct information *tmp_info = malloc(sizeof(struct information)); - memcpy(my_info, cur, sizeof(struct information)); + memcpy(tmp_info, cur, sizeof(struct information)); if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) { - text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info); + text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info); } else { char *output = obj->data.execi.buffer; FILE *fp = popen(obj->data.execi.cmd, "r"); @@ -5095,12 +5040,12 @@ output[length - 1] = '\0'; } - text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info); + text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info); obj->data.execi.last_update = current_update_time; } - free_text_objects(text_objects->text_object_count, text_objects->text_objects); + free_text_objects(text_objects); free(text_objects); - free(my_info); + free(tmp_info); } OBJ(texeci) { if (!obj->data.texeci.p_timed_thread) { @@ -5122,189 +5067,40 @@ } #endif /* HAVE_POPEN */ OBJ(imap_unseen) { - if (obj->global_mode && info.mail) { - // this means we use info - if (!info.mail->p_timed_thread) { - info.mail->p_timed_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"); - } - timed_thread_register(info.mail->p_timed_thread, - &info.mail->p_timed_thread); - if (timed_thread_run(info.mail->p_timed_thread)) { - ERR("Error running imap timed thread"); - } - } - timed_thread_lock(info.mail->p_timed_thread); - snprintf(p, p_max_size, "%lu", info.mail->unseen); - timed_thread_unlock(info.mail->p_timed_thread); - } else if (obj->data.mail) { - // this means we use obj - if (!obj->data.mail->p_timed_thread) { - obj->data.mail->p_timed_thread = - timed_thread_create(&imap_thread, - (void *) obj->data.mail, - obj->data.mail->interval * 1000000); - if (!obj->data.mail->p_timed_thread) { - ERR("Error creating imap timed thread"); - } - timed_thread_register(obj->data.mail->p_timed_thread, - &obj->data.mail->p_timed_thread); - if (timed_thread_run(obj->data.mail->p_timed_thread)) { - ERR("Error running imap timed thread"); - } - } - timed_thread_lock(obj->data.mail->p_timed_thread); - snprintf(p, p_max_size, "%lu", obj->data.mail->unseen); - timed_thread_unlock(obj->data.mail->p_timed_thread); - } else if (!obj->a) { - // something is wrong, warn once then stop - ERR("Theres a problem with your imap_unseen settings. " - "Check that the global IMAP settings are defined " - "properly (line %li).", obj->line); - obj->a++; + struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap"); + + if (mail && mail->p_timed_thread) { + timed_thread_lock(mail->p_timed_thread); + snprintf(p, p_max_size, "%lu", mail->unseen); + timed_thread_unlock(mail->p_timed_thread); } } OBJ(imap_messages) { - if (obj->global_mode && info.mail) { - // this means we use info - if (!info.mail->p_timed_thread) { - info.mail->p_timed_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"); - } - timed_thread_register(info.mail->p_timed_thread, - &info.mail->p_timed_thread); - if (timed_thread_run(info.mail->p_timed_thread)) { - ERR("Error running imap timed thread"); - } - } - timed_thread_lock(info.mail->p_timed_thread); - snprintf(p, p_max_size, "%lu", info.mail->messages); - timed_thread_unlock(info.mail->p_timed_thread); - } else if (obj->data.mail) { - // this means we use obj - if (!obj->data.mail->p_timed_thread) { - obj->data.mail->p_timed_thread = - timed_thread_create(&imap_thread, - (void *) obj->data.mail, - obj->data.mail->interval * 1000000); - if (!obj->data.mail->p_timed_thread) { - ERR("Error creating imap timed thread"); - } - timed_thread_register(obj->data.mail->p_timed_thread, - &obj->data.mail->p_timed_thread); - if (timed_thread_run(obj->data.mail->p_timed_thread)) { - ERR("Error runninging imap timed thread"); - } - } - timed_thread_lock(obj->data.mail->p_timed_thread); - snprintf(p, p_max_size, "%lu", obj->data.mail->messages); - timed_thread_lock(obj->data.mail->p_timed_thread); - } else if (!obj->a) { - // something is wrong, warn once then stop - ERR("Theres a problem with your imap_messages settings. " - "Check that the global IMAP settings are defined " - "properly (line %li).", obj->line); - obj->a++; + struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap"); + + if (mail && mail->p_timed_thread) { + timed_thread_lock(mail->p_timed_thread); + snprintf(p, p_max_size, "%lu", mail->messages); + timed_thread_unlock(mail->p_timed_thread); } } OBJ(pop3_unseen) { - if (obj->global_mode && info.mail) { - // this means we use info - if (!info.mail->p_timed_thread) { - info.mail->p_timed_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"); - } - timed_thread_register(info.mail->p_timed_thread, - &info.mail->p_timed_thread); - if (timed_thread_run(info.mail->p_timed_thread)) { - ERR("Error running pop3 timed thread"); - } - } - timed_thread_lock(info.mail->p_timed_thread); - snprintf(p, p_max_size, "%lu", info.mail->unseen); - timed_thread_unlock(info.mail->p_timed_thread); - } else if (obj->data.mail) { - // this means we use obj - if (!obj->data.mail->p_timed_thread) { - obj->data.mail->p_timed_thread = - timed_thread_create(&pop3_thread, - (void *) obj->data.mail, - obj->data.mail->interval * 1000000); - if (!obj->data.mail->p_timed_thread) { - ERR("Error creating pop3 timed thread"); - } - timed_thread_register(obj->data.mail->p_timed_thread, - &obj->data.mail->p_timed_thread); - if (timed_thread_run(obj->data.mail->p_timed_thread)) { - ERR("Error running pop3 timed thread"); - } - } - timed_thread_lock(obj->data.mail->p_timed_thread); - snprintf(p, p_max_size, "%lu", obj->data.mail->unseen); - timed_thread_unlock(obj->data.mail->p_timed_thread); - } else if (!obj->a) { - // something is wrong, warn once then stop - ERR("Theres a problem with your pop3_unseen settings. " - "Check that the global POP3 settings are defined " - "properly (line %li).", obj->line); - obj->a++; + struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3"); + + if (mail && mail->p_timed_thread) { + timed_thread_lock(mail->p_timed_thread); + snprintf(p, p_max_size, "%lu", mail->unseen); + timed_thread_unlock(mail->p_timed_thread); } } OBJ(pop3_used) { - if (obj->global_mode && info.mail) { - // this means we use info - if (!info.mail->p_timed_thread) { - info.mail->p_timed_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"); - } - timed_thread_register(info.mail->p_timed_thread, - &info.mail->p_timed_thread); - if (timed_thread_run(info.mail->p_timed_thread)) { - ERR("Error running pop3 timed thread"); - } - } - timed_thread_lock(info.mail->p_timed_thread); + struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3"); + + if (mail && mail->p_timed_thread) { + timed_thread_lock(mail->p_timed_thread); snprintf(p, p_max_size, "%.1f", - info.mail->used / 1024.0 / 1024.0); - timed_thread_unlock(info.mail->p_timed_thread); - } else if (obj->data.mail) { - // this means we use obj - if (!obj->data.mail->p_timed_thread) { - obj->data.mail->p_timed_thread = - timed_thread_create(&pop3_thread, - (void *) obj->data.mail, - obj->data.mail->interval * 1000000); - if (!obj->data.mail->p_timed_thread) { - ERR("Error creating pop3 timed thread"); - } - timed_thread_register(obj->data.mail->p_timed_thread, - &obj->data.mail->p_timed_thread); - if (timed_thread_run(obj->data.mail->p_timed_thread)) { - ERR("Error running pop3 timed thread"); - } - } - timed_thread_lock(obj->data.mail->p_timed_thread); - snprintf(p, p_max_size, "%.1f", - obj->data.mail->used / 1024.0 / 1024.0); - timed_thread_unlock(obj->data.mail->p_timed_thread); - } else if (!obj->a) { - // something is wrong, warn once then stop - ERR("Theres a problem with your pop3_used settings. " - "Check that the global POP3 settings are defined " - "properly (line %li).", obj->line); - obj->a++; + mail->used / 1024.0 / 1024.0); + timed_thread_unlock(mail->p_timed_thread); } } OBJ(fs_bar) { @@ -5545,10 +5341,10 @@ } OBJ(if_empty) { struct text_object_list *text_objects; - struct information *my_info = + struct information *tmp_info = malloc(sizeof(struct information)); - memcpy(my_info, cur, sizeof(struct information)); - text_objects = parse_conky_vars(obj->data.ifblock.s, p, my_info); + memcpy(tmp_info, cur, sizeof(struct information)); + text_objects = parse_conky_vars(obj->data.ifblock.s, p, tmp_info); if (strlen(p) != 0) { i = obj->data.ifblock.pos; @@ -5557,9 +5353,9 @@ if_jumped = 0; } p[0] = '\0'; - free_text_objects(text_objects->text_object_count, text_objects->text_objects); + free_text_objects(text_objects); free(text_objects); - free(my_info); + free(tmp_info); } OBJ(if_existing) { struct stat tmp; @@ -6508,8 +6304,7 @@ p = text_buffer; - generate_text_internal(p, max_user_text, global_text_objects, - global_text_object_count, cur); + generate_text_internal(p, max_user_text, global_text_object_list, cur); if (stuff_in_upper_case) { char *tmp_p; @@ -7872,9 +7667,9 @@ #ifdef TCP_PORT_MONITOR info.p_tcp_port_monitor_collection = NULL; #endif - extract_variable_text(text); - free(text); - text = NULL; + extract_variable_text(global_text); + free(global_text); + global_text = NULL; if (tmpstring1) { free(tmpstring1); } @@ -7925,7 +7720,9 @@ free_fonts(); #endif /* X11 */ - free_text_objects(global_text_object_count, global_text_objects); + free_text_objects(global_text_object_list); + free(global_text_object_list); + global_text_object_list = NULL; if (tmpstring1) { free(tmpstring1); tmpstring1 = 0; @@ -7938,12 +7735,10 @@ free(text_buffer); text_buffer = 0; } - global_text_object_count = 0; - global_text_objects = NULL; - if (text) { - free(text); - text = 0; + if (global_text) { + free(global_text); + global_text = 0; } free(current_config); @@ -7974,6 +7769,7 @@ static int string_to_bool(const char *s) { if (!s) { + // Assumes an option without a true/false means true return 1; } else if (strcasecmp(s, "yes") == EQUAL) { return 1; @@ -8729,32 +8525,32 @@ } } CONF("text") { - if (text) { - free(text); - text = 0; + if (global_text) { + free(global_text); + global_text = 0; } - text = (char *) malloc(1); - text[0] = '\0'; + global_text = (char *) malloc(1); + global_text[0] = '\0'; while (!feof(fp)) { - unsigned int l = strlen(text); + unsigned int l = strlen(global_text); if (fgets(buf, 256, fp) == NULL) { break; } - text = (char *) realloc(text, l + strlen(buf) + 1); - strcat(text, buf); + global_text = (char *) realloc(global_text, l + strlen(buf) + 1); + strcat(global_text, buf); - if (strlen(text) > max_user_text) { + if (strlen(global_text) > max_user_text) { break; } } fclose(fp); - if (strlen(text) < 1) { + if (strlen(global_text) < 1) { CRIT_ERR("no text supplied in configuration; exiting"); } - text_lines = line + 1; + global_text_lines = line + 1; return; } #ifdef TCP_PORT_MONITOR @@ -8807,7 +8603,7 @@ // default to update_interval info.music_player_interval = update_interval; } - if (!text) { // didn't supply any text + if (!global_text) { // didn't supply any text CRIT_ERR("missing text block in configuration; exiting"); } } @@ -9057,12 +8853,12 @@ #endif #endif /* X11 */ case 't': - if (text) { - free(text); - text = 0; + if (global_text) { + free(global_text); + global_text = 0; } - text = strndup(optarg, max_user_text); - convert_escapes(text); + global_text = strndup(optarg, max_user_text); + convert_escapes(global_text); break; case 'u': @@ -9097,12 +8893,12 @@ #endif /* X11 */ /* generate text and get initial size */ - extract_variable_text(text); - if (text) { - free(text); - text = 0; + extract_variable_text(global_text); + if (global_text) { + free(global_text); + global_text = 0; } - text = NULL; + global_text = NULL; /* fork */ if (fork_to_background) { int pid = fork(); @@ -9152,9 +8948,7 @@ selected_font = 0; update_text_area(); /* to position text/window on screen */ -#endif /* X11 */ -#ifdef X11 #ifdef OWN_WINDOW if (own_window && !fixed_pos) { XMoveWindow(display, window.window, window.x, window.y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |