1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-28 13:00:45 +00:00

Replaced the global text_object array and count with a text_object_list

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1179 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Kevin Lyles 2008-06-21 09:24:51 +00:00
parent 01ca7ad07a
commit e528397a02

View File

@ -1475,10 +1475,10 @@ struct text_object_list {
struct text_object *text_objects; struct text_object *text_objects;
}; };
static unsigned int global_text_object_count; static struct text_object_list *global_text_object_list;
static struct text_object *global_text_objects;
static void generate_text_internal(char *p, int p_max_size, 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); struct information *cur);
#define MAXDATASIZE 1000 #define MAXDATASIZE 1000
@ -2012,75 +2012,81 @@ static struct text_object *new_text_object_internal(void)
return obj; 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; unsigned int i;
struct text_object *obj;
for (i = 0; i < count; i++) { if (text_object_list == NULL) {
switch (objs[i].type) { return;
}
for (i = 0; i < text_object_list->text_object_count; i++) {
obj = &text_object_list->text_objects[i];
switch (obj->type) {
#ifndef __OpenBSD__ #ifndef __OpenBSD__
case OBJ_acpitemp: case OBJ_acpitemp:
case OBJ_acpitempf: case OBJ_acpitempf:
close(objs[i].data.i); close(obj->data.i);
break; break;
case OBJ_i2c: case OBJ_i2c:
case OBJ_platform: case OBJ_platform:
case OBJ_hwmon: case OBJ_hwmon:
close(objs[i].data.sysfs.fd); close(obj->data.sysfs.fd);
break; break;
#endif /* !__OpenBSD__ */ #endif /* !__OpenBSD__ */
case OBJ_time: case OBJ_time:
case OBJ_utime: case OBJ_utime:
free(objs[i].data.s); free(obj->data.s);
break; break;
case OBJ_tztime: case OBJ_tztime:
free(objs[i].data.tztime.tz); free(obj->data.tztime.tz);
free(objs[i].data.tztime.fmt); free(obj->data.tztime.fmt);
break; break;
case OBJ_mboxscan: case OBJ_mboxscan:
free(objs[i].data.mboxscan.args); free(obj->data.mboxscan.args);
free(objs[i].data.mboxscan.output); free(obj->data.mboxscan.output);
break; break;
case OBJ_mails: case OBJ_mails:
case OBJ_new_mails: case OBJ_new_mails:
free(objs[i].data.local_mail.box); free(obj->data.local_mail.box);
break; break;
case OBJ_imap: case OBJ_imap:
free(info.mail); free(info.mail);
break; break;
case OBJ_imap_unseen: case OBJ_imap_unseen:
if (!objs[i].global_mode) { if (!obj->global_mode) {
free(objs[i].data.mail); free(obj->data.mail);
} }
break; break;
case OBJ_imap_messages: case OBJ_imap_messages:
if (!objs[i].global_mode) { if (!obj->global_mode) {
free(objs[i].data.mail); free(obj->data.mail);
} }
break; break;
case OBJ_pop3: case OBJ_pop3:
free(info.mail); free(info.mail);
break; break;
case OBJ_pop3_unseen: case OBJ_pop3_unseen:
if (!objs[i].global_mode) { if (!obj->global_mode) {
free(objs[i].data.mail); free(obj->data.mail);
} }
break; break;
case OBJ_pop3_used: case OBJ_pop3_used:
if (!objs[i].global_mode) { if (!obj->global_mode) {
free(objs[i].data.mail); free(obj->data.mail);
} }
break; break;
case OBJ_if_empty: case OBJ_if_empty:
case OBJ_if_existing: case OBJ_if_existing:
case OBJ_if_mounted: case OBJ_if_mounted:
case OBJ_if_running: case OBJ_if_running:
free(objs[i].data.ifblock.s); free(obj->data.ifblock.s);
free(objs[i].data.ifblock.str); free(obj->data.ifblock.str);
break; break;
case OBJ_tail: case OBJ_tail:
free(objs[i].data.tail.logfile); free(obj->data.tail.logfile);
free(objs[i].data.tail.buffer); free(obj->data.tail.buffer);
break; break;
case OBJ_text: case OBJ_text:
case OBJ_font: case OBJ_font:
@ -2089,7 +2095,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
case OBJ_execbar: case OBJ_execbar:
case OBJ_execgraph: case OBJ_execgraph:
case OBJ_execp: case OBJ_execp:
free(objs[i].data.s); free(obj->data.s);
break; break;
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
case OBJ_iconv_start: case OBJ_iconv_start:
@ -2204,30 +2210,30 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
#endif #endif
#ifdef RSS #ifdef RSS
case OBJ_rss: case OBJ_rss:
free(objs[i].data.rss.uri); free(obj->data.rss.uri);
free(objs[i].data.rss.action); free(obj->data.rss.action);
break; break;
#endif #endif
case OBJ_pre_exec: case OBJ_pre_exec:
break; break;
#ifndef __OpenBSD__ #ifndef __OpenBSD__
case OBJ_battery: case OBJ_battery:
free(objs[i].data.s); free(obj->data.s);
break; break;
case OBJ_battery_time: case OBJ_battery_time:
free(objs[i].data.s); free(obj->data.s);
break; break;
#endif /* !__OpenBSD__ */ #endif /* !__OpenBSD__ */
case OBJ_execpi: case OBJ_execpi:
case OBJ_execi: case OBJ_execi:
case OBJ_execibar: case OBJ_execibar:
case OBJ_execigraph: case OBJ_execigraph:
free(objs[i].data.execi.cmd); free(obj->data.execi.cmd);
free(objs[i].data.execi.buffer); free(obj->data.execi.buffer);
break; break;
case OBJ_texeci: case OBJ_texeci:
free(objs[i].data.texeci.cmd); free(obj->data.texeci.cmd);
free(objs[i].data.texeci.buffer); free(obj->data.texeci.buffer);
break; break;
case OBJ_nameserver: case OBJ_nameserver:
free_dns_data(); free_dns_data();
@ -2241,9 +2247,9 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
break; break;
#ifdef HDDTEMP #ifdef HDDTEMP
case OBJ_hddtemp: case OBJ_hddtemp:
free(objs[i].data.hddtemp.dev); free(obj->data.hddtemp.dev);
free(objs[i].data.hddtemp.addr); free(obj->data.hddtemp.addr);
free(objs[i].data.hddtemp.temp); free(obj->data.hddtemp.temp);
break; break;
#endif #endif
case OBJ_entropy_avail: case OBJ_entropy_avail:
@ -2271,11 +2277,11 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
#ifdef SMAPI #ifdef SMAPI
case OBJ_smapi: case OBJ_smapi:
case OBJ_smapi_bat_perc: case OBJ_smapi_bat_perc:
free(objs[i].data.s); free(obj->data.s);
break; break;
case OBJ_if_smapi_bat_installed: case OBJ_if_smapi_bat_installed:
free(objs[i].data.ifblock.s); free(obj->data.ifblock.s);
free(objs[i].data.ifblock.str); free(obj->data.ifblock.str);
break; break;
#endif #endif
#ifdef NVIDIA #ifdef NVIDIA
@ -2307,9 +2313,9 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
#endif #endif
} }
} }
free(objs); free(text_object_list->text_objects);
/* text_objects = NULL; text_object_list->text_objects = NULL;
text_object_count = 0; */ text_object_list->text_object_count = 0;
} }
void scan_mixer_bar(const char *arg, int *a, int *w, int *h) void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
@ -4096,9 +4102,8 @@ static struct text_object_list *extract_variable_text_internal(const char *const
static void extract_variable_text(const char *p) static void extract_variable_text(const char *p)
{ {
struct text_object_list *list; free_text_objects(global_text_object_list);
free(global_text_object_list);
free_text_objects(global_text_object_count, global_text_objects);
if (tmpstring1) { if (tmpstring1) {
free(tmpstring1); free(tmpstring1);
tmpstring1 = 0; tmpstring1 = 0;
@ -4111,14 +4116,8 @@ static void extract_variable_text(const char *p)
free(text_buffer); free(text_buffer);
text_buffer = 0; text_buffer = 0;
} }
global_text_object_count = 0;
global_text_objects = NULL;
list = extract_variable_text_internal(p); global_text_object_list = extract_variable_text_internal(p);
global_text_objects = list->text_objects;
global_text_object_count = list->text_object_count;
free(list);
} }
struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur) struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
@ -4126,8 +4125,7 @@ struct text_object_list *parse_conky_vars(char *txt, char *p, struct information
struct text_object_list *object_list = struct text_object_list *object_list =
extract_variable_text_internal(txt); extract_variable_text_internal(txt);
generate_text_internal(p, max_user_text, object_list->text_objects, generate_text_internal(p, max_user_text, object_list, cur);
object_list->text_object_count, cur);
return object_list; return object_list;
} }
@ -4291,7 +4289,7 @@ static inline void format_media_player_time(char *buf, const int size,
} }
static void generate_text_internal(char *p, int p_max_size, 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) struct information *cur)
{ {
unsigned int i; unsigned int i;
@ -4303,8 +4301,8 @@ static void generate_text_internal(char *p, int p_max_size,
#endif #endif
p[0] = 0; p[0] = 0;
for (i = 0; i < object_count; i++) { for (i = 0; i < text_object_list->text_object_count; i++) {
struct text_object *obj = &objs[i]; struct text_object *obj = &(text_object_list->text_objects[i]);
if (p_max_size < 1) { if (p_max_size < 1) {
break; break;
@ -4834,7 +4832,7 @@ static void generate_text_internal(char *p, int p_max_size,
p[length - 1] = '\0'; 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(text_objects);
free(my_info); free(my_info);
} }
@ -5019,7 +5017,7 @@ static void generate_text_internal(char *p, int p_max_size,
text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info); text_objects = parse_conky_vars(obj->data.execi.buffer, p, my_info);
obj->data.execi.last_update = current_update_time; 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(text_objects);
free(my_info); free(my_info);
} }
@ -5478,7 +5476,7 @@ static void generate_text_internal(char *p, int p_max_size,
if_jumped = 0; if_jumped = 0;
} }
p[0] = '\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(text_objects);
free(my_info); free(my_info);
} }
@ -6335,8 +6333,7 @@ static void generate_text(void)
p = text_buffer; p = text_buffer;
generate_text_internal(p, max_user_text, global_text_objects, generate_text_internal(p, max_user_text, global_text_object_list, cur);
global_text_object_count, cur);
if (stuff_in_upper_case) { if (stuff_in_upper_case) {
char *tmp_p; char *tmp_p;
@ -7709,7 +7706,9 @@ void clean_up(void)
free_fonts(); free_fonts();
#endif /* X11 */ #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) { if (tmpstring1) {
free(tmpstring1); free(tmpstring1);
tmpstring1 = 0; tmpstring1 = 0;
@ -7722,8 +7721,6 @@ void clean_up(void)
free(text_buffer); free(text_buffer);
text_buffer = 0; text_buffer = 0;
} }
global_text_object_count = 0;
global_text_objects = NULL;
if (text) { if (text) {
free(text); free(text);