From 9e79881b5f70ecdee635dca6f6e2d43213949668 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Wed, 13 May 2009 12:28:53 -0600 Subject: [PATCH] Fix remove_comments()? --- src/conky.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/conky.c b/src/conky.c index 78f1b25c..49ee87de 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2897,28 +2897,36 @@ static int text_contains_templates(const char *text) return 0; } +static void strfold(char *start, int count) +{ + char *curplace; + for (curplace = start + count; *curplace != 0; curplace++) { + *(curplace - count) = *curplace; + } + *(curplace - count) = 0; +} + static void remove_comments(char *string) { char *curplace, *curplace2; - char *newend = NULL; - for(curplace = string; *curplace != 0; curplace++) { - if(*curplace == '\\' && *(curplace + 1) == '#') { - //strcpy can't be used for overlapping strings - for (curplace2 = curplace+1; *curplace2 != 0; curplace2++) { - *(curplace2 - 1) = *curplace2; + for (curplace = string; *curplace != 0; curplace++) { + if (*curplace == '\\' && *(curplace + 1) == '#') { + // strcpy can't be used for overlapping strings + strfold(curplace, 1); + } else if (*curplace == '#') { + // remove everything until we hit a '\n' + curplace2 = curplace; + while (*curplace2 && *curplace2 != '\n') { + curplace2++; + } + if (*curplace2) { + strfold(curplace, curplace2 - curplace); + } else { + *curplace = 0; } - *(curplace2 - 1) = 0; - } else if(*curplace == '#' && !newend) { - newend = curplace; - } else if(*curplace == '\n' && newend) { - *newend = '\n'; - newend++; } } - if(newend) { - *newend = 0; - } } static int extract_variable_text_internal(struct text_object *retval, const char *const_p, char allow_threaded)