From ede0838e1794485141bb82e3a0f153f383a44b28 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sun, 29 Nov 2009 20:43:46 +0100 Subject: [PATCH] drop struct information parameter from generate_text_internal() --- src/algebra.c | 6 +---- src/combine.c | 2 +- src/common.c | 13 ++++------ src/conky.c | 19 ++++----------- src/conky.h | 6 ++--- src/exec.c | 14 ++--------- src/proc.c | 64 +++++++++++++++++++++++++------------------------- src/scroll.c | 2 +- src/timeinfo.c | 2 +- src/user.c | 4 ++-- 10 files changed, 51 insertions(+), 81 deletions(-) diff --git a/src/algebra.c b/src/algebra.c index 4fa5e975..80fcce43 100644 --- a/src/algebra.c +++ b/src/algebra.c @@ -248,12 +248,9 @@ int check_if_match(struct text_object *obj) { char expression[max_user_text]; int val; - struct information *tmp_info; int result = 1; - tmp_info = malloc(sizeof(struct information)); - memcpy(tmp_info, &info, sizeof(struct information)); - generate_text_internal(expression, max_user_text, *obj->sub, tmp_info); + generate_text_internal(expression, max_user_text, *obj->sub); DBGP("parsed arg into '%s'", expression); val = compare(expression); @@ -262,6 +259,5 @@ int check_if_match(struct text_object *obj) } else if (!val) { result = 0; } - free(tmp_info); return result; } diff --git a/src/combine.c b/src/combine.c index 573a74a6..9d95fda6 100644 --- a/src/combine.c +++ b/src/combine.c @@ -115,7 +115,7 @@ void print_combine(struct text_object *obj, char *p, int p_max_size) ll_rows[i] = malloc(sizeof(struct llrows)); current[i] = ll_rows[i]; for(j=0; jsub; - generate_text_internal(buf[i], max_user_text, *objsub, &info); + generate_text_internal(buf[i], max_user_text, *objsub); for(j=0; buf[i][j] != 0; j++) { if(buf[i][j] == '\t') buf[i][j] = ' '; if(buf[i][j] == '\n') { diff --git a/src/common.c b/src/common.c index 10104616..05d20da0 100644 --- a/src/common.c +++ b/src/common.c @@ -612,18 +612,13 @@ void print_evaluate(struct text_object *obj, char *p, int p_max_size) int if_empty_iftest(struct text_object *obj) { char buf[max_user_text]; - struct information *tmp_info; int result = 1; - tmp_info = malloc(sizeof(struct information)); - memcpy(tmp_info, &info, sizeof(struct information)); - - generate_text_internal(buf, max_user_text, *obj->sub, tmp_info); + generate_text_internal(buf, max_user_text, *obj->sub); if (strlen(buf) != 0) { result = 0; } - free(tmp_info); return result; } @@ -750,7 +745,7 @@ void print_to_bytes(struct text_object *obj, char *p, int p_max_size) long long bytes; char unit[16]; // 16 because we can also have long names (like mega-bytes) - generate_text_internal(buf, max_user_text, *obj->sub, &info); + generate_text_internal(buf, max_user_text, *obj->sub); if(sscanf(buf, "%lli%s", &bytes, unit) == 2 && strlen(unit) < 16){ if(strncasecmp("b", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes); else if(strncasecmp("k", unit, 1) == 0) snprintf(buf, max_user_text, "%lli", bytes * 1024); @@ -771,7 +766,7 @@ void print_blink(struct text_object *obj, char *p, int p_max_size) memset(buf, 0, max_user_text); if (visible) { - generate_text_internal(buf, max_user_text, *obj->sub, &info); + generate_text_internal(buf, max_user_text, *obj->sub); last_len = strlen(buf); } else { for (int i = 0; i < last_len; i++) @@ -789,7 +784,7 @@ void print_include(struct text_object *obj, char *p, int p_max_size) if (!obj->sub) return; - generate_text_internal(buf, max_user_text, *obj->sub, &info); + generate_text_internal(buf, max_user_text, *obj->sub); snprintf(p, p_max_size, "%s", buf); } diff --git a/src/conky.c b/src/conky.c index 0c8b0c7f..02e0815e 100644 --- a/src/conky.c +++ b/src/conky.c @@ -689,10 +689,10 @@ static void extract_variable_text(const char *p) } void parse_conky_vars(struct text_object *root, const char *txt, - char *p, int p_max_size, struct information *cur) + char *p, int p_max_size) { extract_variable_text_internal(root, txt); - generate_text_internal(p, p_max_size, *root, cur); + generate_text_internal(p, p_max_size, *root); } /* substitutes all occurrences of '\n' with SECRIT_MULTILINE_CHAR, which allows @@ -730,8 +730,7 @@ void substitute_newlines(char *p, long l) * so we need to jump always. If we encounter an ENDIF, it's corresponding IF * or ELSE has not jumped, and there is nothing to do. */ -void generate_text_internal(char *p, int p_max_size, - struct text_object root, struct information *cur) +void generate_text_internal(char *p, int p_max_size, struct text_object root) { struct text_object *obj; size_t a; @@ -740,9 +739,6 @@ void generate_text_internal(char *p, int p_max_size, buff_in[0] = 0; #endif /* HAVE_ICONV */ - /* \o/ */ - (void)cur; - p[0] = 0; obj = root.next; while (obj && p_max_size > 0) { @@ -786,23 +782,18 @@ void generate_text_internal(char *p, int p_max_size, void evaluate(const char *text, char *p, int p_max_size) { - struct information *tmp_info; struct text_object subroot; - tmp_info = malloc(sizeof(struct information)); - memcpy(tmp_info, &info, sizeof(struct information)); - parse_conky_vars(&subroot, text, p, p_max_size, tmp_info); + parse_conky_vars(&subroot, text, p, p_max_size); DBGP("evaluated '%s' to '%s'", text, p); free_text_objects(&subroot, 1); - free(tmp_info); } double current_update_time, next_update_time, last_update_time; static void generate_text(void) { - struct information *cur = &info; char *p; unsigned int i, j, k; @@ -820,7 +811,7 @@ static void generate_text(void) p = text_buffer; - generate_text_internal(p, max_user_text, global_root_object, cur); + generate_text_internal(p, max_user_text, global_root_object); if(max_text_width > 0) { for(i = 0, j = 0; p[i] != 0; i++) { if(p[i] == '\n') j = 0; diff --git a/src/conky.h b/src/conky.h index 696f6928..51481aaa 100644 --- a/src/conky.h +++ b/src/conky.h @@ -355,9 +355,7 @@ void set_update_interval(double interval); #define UNUSED(a) (void)a #define UNUSED_ATTR __attribute__ ((unused)) -void parse_conky_vars(struct text_object *, const char *, - char *, int, struct information *); +void parse_conky_vars(struct text_object *, const char *, char *, int); -void generate_text_internal(char *, int, struct text_object, - struct information *); +void generate_text_internal(char *, int, struct text_object); #endif /* _conky_h_ */ diff --git a/src/exec.c b/src/exec.c index 2db4d410..196a60da 100644 --- a/src/exec.c +++ b/src/exec.c @@ -278,7 +278,6 @@ void print_exec(struct text_object *obj, char *p, int p_max_size) void print_execp(struct text_object *obj, char *p, int p_max_size) { - struct information *tmp_info; struct text_object subroot; char *buf; @@ -286,13 +285,9 @@ void print_execp(struct text_object *obj, char *p, int p_max_size) memset(buf, 0, text_buffer_size); read_exec(obj->data.s, buf, text_buffer_size); - - tmp_info = malloc(sizeof(struct information)); - memcpy(tmp_info, &info, sizeof(struct information)); - parse_conky_vars(&subroot, buf, p, p_max_size, tmp_info); + parse_conky_vars(&subroot, buf, p, p_max_size); free_text_objects(&subroot, 1); - free(tmp_info); free(buf); } @@ -316,14 +311,10 @@ void print_execpi(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = obj->data.opaque; struct text_object subroot; - struct information *tmp_info; if (!ed) return; - tmp_info = malloc(sizeof(struct information)); - memcpy(tmp_info, &info, sizeof(struct information)); - if (time_to_update(ed)) { if (!ed->buffer) ed->buffer = malloc(text_buffer_size); @@ -331,9 +322,8 @@ void print_execpi(struct text_object *obj, char *p, int p_max_size) read_exec(ed->cmd, ed->buffer, text_buffer_size); ed->last_update = current_update_time; } - parse_conky_vars(&subroot, ed->buffer, p, p_max_size, tmp_info); + parse_conky_vars(&subroot, ed->buffer, p, p_max_size); free_text_objects(&subroot, 1); - free(tmp_info); } void print_texeci(struct text_object *obj, char *p, int p_max_size) diff --git a/src/proc.c b/src/proc.c index 5cb8bb06..a4943576 100644 --- a/src/proc.c +++ b/src/proc.c @@ -114,7 +114,7 @@ void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char buf[max_user_text]; - generate_text_internal(buf, max_user_text, *obj->sub, &info); + generate_text_internal(buf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/root", buf); pid_readlink(pathbuf, p, p_max_size); } @@ -126,7 +126,7 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size) char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(*(objbuf) != 0) { snprintf(pathbuf, 64, PROCDIR "/%s/cmdline", objbuf); @@ -152,7 +152,7 @@ void print_pid_cwd(struct text_object *obj, char *p, int p_max_size) char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf); bytes_read = readlink(pathbuf, buf, p_max_size); if(bytes_read != -1) { @@ -171,7 +171,7 @@ void print_pid_environ(struct text_object *obj, char *p, int p_max_size) char objbuf[max_user_text]; char *buf, *var=strdup(obj->data.s);; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(sscanf(objbuf, "%d %s", &pid, var) == 2) { for(i = 0; var[i] != 0; i++) { var[i] = toupper(var[i]); @@ -203,7 +203,7 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size) char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf); buf = readfile(pathbuf, &total_read, 1); @@ -225,7 +225,7 @@ void print_pid_exe(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf); pid_readlink(pathbuf, p, p_max_size); } @@ -237,7 +237,7 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(*(obj->data.s) != 0) { snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); @@ -261,7 +261,7 @@ void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) { struct ll_string* files_back = NULL; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); dir = opendir(objbuf); if(dir != NULL) { @@ -296,7 +296,7 @@ void print_pid_parent(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -323,7 +323,7 @@ void print_pid_priority(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(*(objbuf) != 0) { snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); @@ -346,7 +346,7 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -372,7 +372,7 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); @@ -392,7 +392,7 @@ void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/fd/2", objbuf); pid_readlink(pathbuf, p, p_max_size); @@ -402,7 +402,7 @@ void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) { char objbuf[max_user_text]; char pathbuf[64]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/fd/0", objbuf); pid_readlink(pathbuf, p, p_max_size); @@ -412,7 +412,7 @@ void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/fd/1", objbuf); pid_readlink(pathbuf, p, p_max_size); @@ -423,7 +423,7 @@ void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* fre char objbuf[max_user_text]; /* FIXME */ - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(strlen(arg) > 0) { obj->data.s = strdup(arg); @@ -480,7 +480,7 @@ void print_pid_threads(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -507,7 +507,7 @@ void print_pid_thread_list(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf); dir = opendir(pathbuf); @@ -532,7 +532,7 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p, int p_max_size) char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(*(objbuf) != 0) { snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); @@ -554,7 +554,7 @@ void print_pid_time_usermode(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(*(objbuf) != 0) { snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); @@ -576,7 +576,7 @@ void print_pid_time(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); if(*(objbuf) != 0) { snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); @@ -599,7 +599,7 @@ void print_pid_uid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -626,7 +626,7 @@ void print_pid_euid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -654,7 +654,7 @@ void print_pid_suid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -683,7 +683,7 @@ void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -714,7 +714,7 @@ void print_pid_gid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -741,7 +741,7 @@ void print_pid_egid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -769,7 +769,7 @@ void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -798,7 +798,7 @@ void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -827,7 +827,7 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size, con char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -898,7 +898,7 @@ void print_pid_read(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf); buf = readfile(pathbuf, &bytes_read, 1); @@ -925,7 +925,7 @@ void print_pid_write(struct text_object *obj, char *p, int p_max_size) { char pathbuf[64]; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf); buf = readfile(pathbuf, &bytes_read, 1); diff --git a/src/scroll.c b/src/scroll.c index 388c8aa0..7bb9485c 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -88,7 +88,7 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size) if (!sd) return; - generate_text_internal(buf, max_user_text, *obj->sub, &info); + generate_text_internal(buf, max_user_text, *obj->sub); for(j = 0; buf[j] != 0; j++) { switch(buf[j]) { case '\n': //place all the lines behind each other with LINESEPARATOR between them diff --git a/src/timeinfo.c b/src/timeinfo.c index 8a7255dd..8adba38d 100644 --- a/src/timeinfo.c +++ b/src/timeinfo.c @@ -310,7 +310,7 @@ void print_format_time(struct text_object *obj, char *p, int p_max_size) { char buf[max_user_text]; - generate_text_internal(buf, max_user_text, *obj->sub, &info); + generate_text_internal(buf, max_user_text, *obj->sub); obj->data.s = buf; do_format_time(obj, p, p_max_size); } diff --git a/src/user.c b/src/user.c index b314ed31..6f472d68 100644 --- a/src/user.c +++ b/src/user.c @@ -40,7 +40,7 @@ void print_uid_name(struct text_object *obj, char *p, int p_max_size) { char* firstinvalid; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); errno = 0; uid = strtol(objbuf, &firstinvalid, 10); @@ -62,7 +62,7 @@ void print_gid_name(struct text_object *obj, char *p, int p_max_size) { char* firstinvalid; char objbuf[max_user_text]; - generate_text_internal(objbuf, max_user_text, *obj->sub, &info); + generate_text_internal(objbuf, max_user_text, *obj->sub); errno = 0; gid = strtol(objbuf, &firstinvalid, 10);