1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-14 11:33:14 +00:00

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
This commit is contained in:
Nikolas Garofil 2009-05-10 12:48:22 +02:00
parent 197c4d5bc3
commit 2afe66ed01

View File

@ -2595,12 +2595,6 @@ static struct text_object *create_plain_text(const char *s)
{ {
struct text_object *obj; struct text_object *obj;
char *esc = strstr(s, "\\#");
if (esc) {
/* remove extra '\' */
strcpy(esc, esc + 1);
}
if (s == NULL || *s == '\0') { if (s == NULL || *s == '\0') {
return NULL; return NULL;
} }
@ -2822,12 +2816,6 @@ static int extract_variable_text_internal(struct text_object *retval, const char
if (*p == '\n') { if (*p == '\n') {
line++; line++;
} }
/* handle comments within the TEXT area */
if (*p == '#' && (p == orig_p || *(p - 1) != '\\')) {
while (*p && *p != '\n') p++;
s = p;
line++;
}
if (*p == '$') { if (*p == '$') {
*p = '\0'; *p = '\0';
obj = create_plain_text(s); obj = create_plain_text(s);
@ -6702,6 +6690,25 @@ static FILE *open_config_file(const char *f)
return fopen(f, "r"); 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) static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
{ {
char *p, *p2; 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) { if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
return CONF_BREAK; return CONF_BREAK;
} }
remove_comments(buf);
p = buf; p = buf;
/* break at comment, unless preceeded by \ */
p2 = strchr(p, '#');
if (p2 && (p2 == p || *(p2 - 1) != '\\')) {
*p2 = '\0';
}
/* skip spaces */ /* skip spaces */
while (*p && isspace((int) *p)) { while (*p && isspace((int) *p)) {
p++; p++;
@ -7332,6 +7334,7 @@ static void load_config_file(const char *f)
if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) { if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
break; break;
} }
remove_comments(buf);
/* Remove \\-\n. */ /* Remove \\-\n. */
bl = strlen(buf); bl = strlen(buf);