1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

Fix comments in TEXT section

When a '#' is found in TEXT, section remove_comments() is called.  However, that function doesn't
limit itself to removing that particular comment. Instead, it greedily removes all "comments" from
the string, including those in ${color $abcdef} constructs. This, obviously, makes a mess of
things.

Solution: I added a new function, remove_comment(), that only removes the current comment.

Note: Atm, the function doesn't delete the newline, since that was the current behavior, and is
the natural one for the config section. However, for the TEXT it seems better to delete the \n
too, to avoid blank lines.

Note2: this also fixes the bug in strfold(), which incorectly copied the string, truncating it by
one byte.

Signed-off-by: Brenden Matthews <brenden@rty.ca>
This commit is contained in:
Pavel Labath 2009-06-09 17:21:40 +02:00 committed by Brenden Matthews
parent f3aa025872
commit 6586d47813

View File

@ -3166,12 +3166,26 @@ static void strfold(char *start, int count)
for (curplace = start + count; *curplace != 0; curplace++) {
*(curplace - count) = *curplace;
}
*(curplace - count - 1) = 0;
*(curplace - count) = 0;
}
/*
* - assumes that *string is '#'
* - removes the part from '#' to the end of line ('\n' or '\0')
* - BUT, it leaves the '\n'
*/
static size_t remove_comment(char *string)
{
char *end = string;
while(*end != '\0' && *end != '\n')
++end;
strfold(string, end - string);
return end - string;
}
static size_t remove_comments(char *string)
{
char *curplace, *curplace2;
char *curplace;
size_t folded = 0;
for (curplace = string; *curplace != 0; curplace++) {
if (*curplace == '\\' && *(curplace + 1) == '#') {
@ -3179,19 +3193,7 @@ static size_t remove_comments(char *string)
strfold(curplace, 1);
folded += 1;
} else if (*curplace == '#') {
// remove everything until we hit a '\n'
curplace2 = curplace;
while (*curplace2) {
curplace2++;
if (*curplace2 == '\n' &&
*(curplace2 + 1) != '#') break;
}
if (*curplace2) {
strfold(curplace, curplace2 - curplace);
folded += curplace2 - curplace;
} else {
*curplace = 0;
}
folded += remove_comment(curplace);
}
}
return folded;
@ -3330,11 +3332,10 @@ static int extract_variable_text_internal(struct text_object *retval, const char
}
}
} else if (*p == '#') {
remove_comments(p);
remove_comment(p);
}
p++;
}
remove_comments(s);
obj = create_plain_text(s);
if (obj != NULL) {
append_object(retval, obj);