From 2afe66ed01bbf8b0bcbb398c2a0dfb764d28b2b7 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 10 May 2009 12:48:22 +0200 Subject: [PATCH] Bugfix: removing comments worked only partially All lines behind a comment line were also removed, comments should also be able to start in the middle of line, \# shouldn't be replaced if it's in a comment --- src/conky.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/conky.c b/src/conky.c index 9b7e6cd3..30d2ecbf 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2595,12 +2595,6 @@ static struct text_object *create_plain_text(const char *s) { struct text_object *obj; - char *esc = strstr(s, "\\#"); - if (esc) { - /* remove extra '\' */ - strcpy(esc, esc + 1); - } - if (s == NULL || *s == '\0') { return NULL; } @@ -2822,12 +2816,6 @@ static int extract_variable_text_internal(struct text_object *retval, const char if (*p == '\n') { line++; } - /* handle comments within the TEXT area */ - if (*p == '#' && (p == orig_p || *(p - 1) != '\\')) { - while (*p && *p != '\n') p++; - s = p; - line++; - } if (*p == '$') { *p = '\0'; obj = create_plain_text(s); @@ -6702,6 +6690,25 @@ static FILE *open_config_file(const char *f) return fopen(f, "r"); } +void remove_comments(char *string) { + char *curplace; + char *newend = NULL; + + for(curplace = string; *curplace != 0; curplace++) { + if(*curplace == '\\' && *(curplace + 1) == '#') { + strcpy(curplace, curplace + 1); + } else if(*curplace == '#' && !newend) { + newend = curplace; + } else if(*curplace == '\n' && newend) { + *newend = '\n'; + newend++; + } + } + if(newend) { + *newend = 0; + } +} + static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value) { char *p, *p2; @@ -6709,15 +6716,10 @@ static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **va if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) { return CONF_BREAK; } + remove_comments(buf); p = buf; - /* break at comment, unless preceeded by \ */ - p2 = strchr(p, '#'); - if (p2 && (p2 == p || *(p2 - 1) != '\\')) { - *p2 = '\0'; - } - /* skip spaces */ while (*p && isspace((int) *p)) { p++; @@ -7332,6 +7334,7 @@ static void load_config_file(const char *f) if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) { break; } + remove_comments(buf); /* Remove \\-\n. */ bl = strlen(buf);