mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-05 21:07:52 +00:00
Allow the use of '#' for comments within text area (can be escaped with '\#'.
Also refactored some code relating to the config file loading (since there was some duplication of code).
This commit is contained in:
parent
9dc5411681
commit
24f97c45c6
@ -1,3 +1,7 @@
|
||||
2009-05-09
|
||||
* Allow the use of '#' for comments within text area (can be escaped with
|
||||
'\#'
|
||||
|
||||
2009-05-07
|
||||
* Fix occasional cpubar segfaults
|
||||
* Added top_name_width config option
|
||||
|
162
src/conky.c
162
src/conky.c
@ -2595,6 +2595,12 @@ 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;
|
||||
}
|
||||
@ -2816,6 +2822,12 @@ 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);
|
||||
@ -6668,41 +6680,41 @@ static void X11_initialisation(void)
|
||||
}
|
||||
#endif /* X11 */
|
||||
|
||||
static void load_config_file(const char *f)
|
||||
{
|
||||
#define CONF_ERR ERR("%s: %d: config file error", f, line)
|
||||
#define CONF_ERR2(a) ERR("%s: %d: config file error: %s", f, line, a)
|
||||
int line = 0;
|
||||
FILE *fp;
|
||||
#define CONF2(a) if (strcasecmp(name, a) == 0)
|
||||
#define CONF(a) else CONF2(a)
|
||||
#define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
|
||||
|| strcasecmp(name, b) == 0)
|
||||
#define CONF_CONTINUE 1
|
||||
#define CONF_BREAK 2
|
||||
#define CONF_BUFF_SIZE 512
|
||||
|
||||
set_default_configurations();
|
||||
static FILE *open_config_file(const char *f)
|
||||
{
|
||||
#ifdef CONFIG_OUTPUT
|
||||
if (!strcmp(f, "==builtin==")) {
|
||||
#ifdef HAVE_FOPENCOOKIE
|
||||
fp = fopencookie(NULL, "r", conf_cookie);
|
||||
#endif
|
||||
return fopencookie(NULL, "r", conf_cookie);
|
||||
#endif /* HAVE_FOPENCOOKIE */
|
||||
} else
|
||||
#endif /* CONFIG_OUTPUT */
|
||||
fp = fopen(f, "r");
|
||||
|
||||
if (!fp) {
|
||||
return;
|
||||
return fopen(f, "r");
|
||||
}
|
||||
DBGP("reading contents from config file '%s'", f);
|
||||
|
||||
while (!feof(fp)) {
|
||||
char buf[256], *p, *p2, *name, *value;
|
||||
|
||||
line++;
|
||||
if (fgets(buf, 256, fp) == NULL) {
|
||||
break;
|
||||
static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **value)
|
||||
{
|
||||
char *p, *p2;
|
||||
(*line)++;
|
||||
if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
|
||||
return CONF_BREAK;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
|
||||
/* break at comment */
|
||||
/* break at comment, unless preceeded by \ */
|
||||
p2 = strchr(p, '#');
|
||||
if (p2) {
|
||||
if (p2 && (p2 == p || *(p2 - 1) != '\\')) {
|
||||
*p2 = '\0';
|
||||
}
|
||||
|
||||
@ -6711,10 +6723,10 @@ static void load_config_file(const char *f)
|
||||
p++;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
continue; /* empty line */
|
||||
return CONF_CONTINUE; /* empty line */
|
||||
}
|
||||
|
||||
name = p;
|
||||
*name = p;
|
||||
|
||||
/* skip name */
|
||||
p2 = p;
|
||||
@ -6733,20 +6745,38 @@ static void load_config_file(const char *f)
|
||||
p++;
|
||||
}
|
||||
|
||||
value = p;
|
||||
*value = p;
|
||||
|
||||
p2 = value + strlen(value);
|
||||
p2 = *value + strlen(*value);
|
||||
while (isspace((int) *(p2 - 1))) {
|
||||
*--p2 = '\0';
|
||||
}
|
||||
} else {
|
||||
value = 0;
|
||||
*value = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define CONF2(a) if (strcasecmp(name, a) == 0)
|
||||
#define CONF(a) else CONF2(a)
|
||||
#define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
|
||||
|| strcasecmp(name, b) == 0)
|
||||
static void load_config_file(const char *f)
|
||||
{
|
||||
int line = 0;
|
||||
FILE *fp;
|
||||
|
||||
set_default_configurations();
|
||||
fp = open_config_file(f);
|
||||
if (!fp) {
|
||||
return;
|
||||
}
|
||||
DBGP("reading contents from config file '%s'", f);
|
||||
|
||||
while (!feof(fp)) {
|
||||
char buff[CONF_BUFF_SIZE], *name, *value;
|
||||
int ret = do_config_step(&line, fp, buff, &name, &value);
|
||||
if (ret == CONF_BREAK) {
|
||||
break;
|
||||
} else if (ret == CONF_CONTINUE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef X11
|
||||
CONF2("out_to_x") {
|
||||
@ -7305,8 +7335,9 @@ static void load_config_file(const char *f)
|
||||
while (!feof(fp)) {
|
||||
unsigned int l = strlen(global_text);
|
||||
unsigned int bl;
|
||||
char buf[CONF_BUFF_SIZE];
|
||||
|
||||
if (fgets(buf, 256, fp) == NULL) {
|
||||
if (fgets(buf, CONF_BUFF_SIZE, fp) == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -7435,71 +7466,19 @@ static void load_config_file_x11(const char *f)
|
||||
int line = 0;
|
||||
FILE *fp;
|
||||
|
||||
#ifdef CONFIG_OUTPUT
|
||||
if (!strcmp(f, "==builtin==")) {
|
||||
#ifdef HAVE_FOPENCOOKIE
|
||||
fp = fopencookie(NULL, "r", conf_cookie);
|
||||
#endif
|
||||
} else
|
||||
#endif /* CONFIG_OUTPUT */
|
||||
fp = fopen(f, "r");
|
||||
|
||||
fp = open_config_file(f);
|
||||
if (!fp) {
|
||||
return;
|
||||
}
|
||||
DBGP("reading contents from config file '%s'", f);
|
||||
|
||||
while (!feof(fp)) {
|
||||
char buf[256], *p, *p2, *name, *value;
|
||||
|
||||
line++;
|
||||
if (fgets(buf, 256, fp) == NULL) {
|
||||
char buff[CONF_BUFF_SIZE], *name, *value;
|
||||
int ret = do_config_step(&line, fp, buff, &name, &value);
|
||||
if (ret == CONF_BREAK) {
|
||||
break;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
|
||||
/* break at comment */
|
||||
p2 = strchr(p, '#');
|
||||
if (p2) {
|
||||
*p2 = '\0';
|
||||
}
|
||||
|
||||
/* skip spaces */
|
||||
while (*p && isspace((int) *p)) {
|
||||
p++;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
continue; /* empty line */
|
||||
}
|
||||
|
||||
name = p;
|
||||
|
||||
/* skip name */
|
||||
p2 = p;
|
||||
while (*p2 && !isspace((int) *p2)) {
|
||||
p2++;
|
||||
}
|
||||
if (*p2 != '\0') {
|
||||
*p2 = '\0'; /* break at name's end */
|
||||
p2++;
|
||||
}
|
||||
|
||||
/* get value */
|
||||
if (*p2) {
|
||||
p = p2;
|
||||
while (*p && isspace((int) *p)) {
|
||||
p++;
|
||||
}
|
||||
|
||||
value = p;
|
||||
|
||||
p2 = value + strlen(value);
|
||||
while (isspace((int) *(p2 - 1))) {
|
||||
*--p2 = '\0';
|
||||
}
|
||||
} else {
|
||||
value = 0;
|
||||
} else if (ret == CONF_CONTINUE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef X11
|
||||
@ -7655,11 +7634,16 @@ static void load_config_file_x11(const char *f)
|
||||
#endif /* X11 */
|
||||
#undef CONF
|
||||
#undef CONF2
|
||||
#undef CONF3
|
||||
#undef CONF_ERR
|
||||
#undef CONF_ERR2
|
||||
#undef CONF_BREAK
|
||||
#undef CONF_CONTINUE
|
||||
#undef CONF_BUFF_SIZE
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
#undef CONF_ERR
|
||||
}
|
||||
|
||||
static void print_help(const char *prog_name) {
|
||||
|
Loading…
Reference in New Issue
Block a user