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

Merge branch 'master' of git.omp.am:/home/omp/git/conky

This commit is contained in:
Brenden Matthews 2009-05-10 11:52:32 -06:00
commit d224810235
2 changed files with 61 additions and 42 deletions

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);
@ -3263,9 +3251,11 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(battery_percent) { OBJ(battery_percent) {
percent_print(p, p_max_size, get_battery_perct(obj->data.s)); percent_print(p, p_max_size, get_battery_perct(obj->data.s));
} }
#ifdef X11
OBJ(battery_bar) { OBJ(battery_bar) {
new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s)); new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
} }
#endif
OBJ(battery_short) { OBJ(battery_short) {
get_battery_short_status(p, p_max_size, obj->data.s); get_battery_short_status(p, p_max_size, obj->data.s);
} }
@ -3286,6 +3276,7 @@ static void generate_text_internal(char *p, int p_max_size,
percent_print(p, p_max_size, percent_print(p, p_max_size,
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0)); round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
} }
#ifdef X11
OBJ(cpugauge) OBJ(cpugauge)
new_gauge(p, obj->a, obj->b, new_gauge(p, obj->a, obj->b,
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0)); round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
@ -3335,6 +3326,7 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(color9) { OBJ(color9) {
new_fg(p, color9); new_fg(p, color9);
} }
#endif
OBJ(conky_version) { OBJ(conky_version) {
snprintf(p, p_max_size, "%s", VERSION); snprintf(p, p_max_size, "%s", VERSION);
} }
@ -3489,10 +3481,11 @@ static void generate_text_internal(char *p, int p_max_size,
get_obsd_product(p, p_max_size); get_obsd_product(p, p_max_size);
} }
#endif /* __OpenBSD__ */ #endif /* __OpenBSD__ */
#ifdef X11
OBJ(font) { OBJ(font) {
new_font(p, obj->data.s); new_font(p, obj->data.s);
} }
#endif
/* TODO: move this correction from kB to kB/s elsewhere /* TODO: move this correction from kB to kB/s elsewhere
* (or get rid of it??) */ * (or get rid of it??) */
OBJ(diskio) { OBJ(diskio) {
@ -3507,6 +3500,7 @@ static void generate_text_internal(char *p, int p_max_size,
human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, human_readable((obj->data.diskio->current_read / update_interval) * 1024LL,
p, p_max_size); p, p_max_size);
} }
#ifdef X11
OBJ(diskiograph) { OBJ(diskiograph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current, obj->e, 1, obj->showaslog); obj->data.diskio->current, obj->e, 1, obj->showaslog);
@ -3519,6 +3513,7 @@ static void generate_text_internal(char *p, int p_max_size,
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current_write, obj->e, 1, obj->showaslog); obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
} }
#endif
OBJ(downspeed) { OBJ(downspeed) {
human_readable(obj->data.net->recv_speed, p, 255); human_readable(obj->data.net->recv_speed, p, 255);
} }
@ -3526,10 +3521,12 @@ static void generate_text_internal(char *p, int p_max_size,
spaced_print(p, p_max_size, "%.1f", 8, spaced_print(p, p_max_size, "%.1f", 8,
obj->data.net->recv_speed / 1024.0); obj->data.net->recv_speed / 1024.0);
} }
#ifdef X11
OBJ(downspeedgraph) { OBJ(downspeedgraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog); obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog);
} }
#endif
OBJ(else) { OBJ(else) {
/* Since we see you, you're if has not jumped. /* Since we see you, you're if has not jumped.
* Do Ninja jump here: without leaving traces. * Do Ninja jump here: without leaving traces.
@ -3633,6 +3630,7 @@ static void generate_text_internal(char *p, int p_max_size,
free_text_objects(&subroot); free_text_objects(&subroot);
free(tmp_info); free(tmp_info);
} }
#ifdef X11
OBJ(execgauge) { OBJ(execgauge) {
double barnum; double barnum;
@ -3719,6 +3717,7 @@ static void generate_text_internal(char *p, int p_max_size,
} }
new_gauge(p, obj->a, obj->b, round_to_int(obj->f)); new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
} }
#endif
OBJ(execi) { OBJ(execi) {
if (current_update_time - obj->data.execi.last_update if (current_update_time - obj->data.execi.last_update
>= obj->data.execi.interval >= obj->data.execi.interval
@ -3814,6 +3813,7 @@ static void generate_text_internal(char *p, int p_max_size,
timed_thread_unlock(mail->p_timed_thread); timed_thread_unlock(mail->p_timed_thread);
} }
} }
#ifdef X11
OBJ(fs_bar) { OBJ(fs_bar) {
if (obj->data.fs != NULL) { if (obj->data.fs != NULL) {
if (obj->data.fs->size == 0) { if (obj->data.fs->size == 0) {
@ -3825,6 +3825,7 @@ static void generate_text_internal(char *p, int p_max_size,
} }
} }
} }
#endif
OBJ(fs_free) { OBJ(fs_free) {
if (obj->data.fs != NULL) { if (obj->data.fs != NULL) {
human_readable( (obj->data.fs->free ? obj->data.fs->free : human_readable( (obj->data.fs->free ? obj->data.fs->free :
@ -3859,6 +3860,7 @@ static void generate_text_internal(char *p, int p_max_size,
? obj->data.fs->free : obj->data.fs->avail), p, 255); ? obj->data.fs->free : obj->data.fs->avail), p, 255);
} }
} }
#ifdef X11
OBJ(fs_bar_free) { OBJ(fs_bar_free) {
if (obj->data.fs != NULL) { if (obj->data.fs != NULL) {
if (obj->data.fs->size == 0) { if (obj->data.fs->size == 0) {
@ -3870,6 +3872,7 @@ static void generate_text_internal(char *p, int p_max_size,
} }
} }
} }
#endif
OBJ(fs_used_perc) { OBJ(fs_used_perc) {
if (obj->data.fs != NULL) { if (obj->data.fs != NULL) {
int val = 0; int val = 0;
@ -3906,9 +3909,11 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(tab) { OBJ(tab) {
new_tab(p, obj->data.pair.a, obj->data.pair.b); new_tab(p, obj->data.pair.a, obj->data.pair.b);
} }
#ifdef X11
OBJ(hr) { OBJ(hr) {
new_hr(p, obj->data.i); new_hr(p, obj->data.i);
} }
#endif
OBJ(nameserver) { OBJ(nameserver) {
if (cur->nameserver_info.nscount > obj->data.i) if (cur->nameserver_info.nscount > obj->data.i)
snprintf(p, p_max_size, "%s", snprintf(p, p_max_size, "%s",
@ -4162,6 +4167,7 @@ static void generate_text_internal(char *p, int p_max_size,
if (cur->memmax) if (cur->memmax)
percent_print(p, p_max_size, cur->mem * 100 / cur->memmax); percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
} }
#ifdef X11
OBJ(memgauge){ OBJ(memgauge){
new_gauge(p, obj->data.pair.a, obj->data.pair.b, new_gauge(p, obj->data.pair.a, obj->data.pair.b,
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
@ -4175,7 +4181,7 @@ static void generate_text_internal(char *p, int p_max_size,
cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
100, 1, obj->showaslog); 100, 1, obj->showaslog);
} }
#endif
/* mixer stuff */ /* mixer stuff */
OBJ(mixer) { OBJ(mixer) {
percent_print(p, p_max_size, mixer_get_avg(obj->data.l)); percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
@ -4186,6 +4192,7 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(mixerr) { OBJ(mixerr) {
percent_print(p, p_max_size, mixer_get_right(obj->data.l)); percent_print(p, p_max_size, mixer_get_right(obj->data.l));
} }
#ifdef X11
OBJ(mixerbar) { OBJ(mixerbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h, new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l))); mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
@ -4198,6 +4205,7 @@ static void generate_text_internal(char *p, int p_max_size,
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h, new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l))); mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
} }
#endif
OBJ(if_mixer_mute) { OBJ(if_mixer_mute) {
if (!mixer_is_mute(obj->data.ifblock.i)) { if (!mixer_is_mute(obj->data.ifblock.i)) {
DO_JUMP; DO_JUMP;
@ -4292,12 +4300,14 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(text) { OBJ(text) {
snprintf(p, p_max_size, "%s", obj->data.s); snprintf(p, p_max_size, "%s", obj->data.s);
} }
#ifdef X11
OBJ(shadecolor) { OBJ(shadecolor) {
new_bg(p, obj->data.l); new_bg(p, obj->data.l);
} }
OBJ(stippled_hr) { OBJ(stippled_hr) {
new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b); new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
} }
#endif
OBJ(swap) { OBJ(swap) {
human_readable(cur->swap * 1024, p, 255); human_readable(cur->swap * 1024, p, 255);
} }
@ -4311,10 +4321,12 @@ static void generate_text_internal(char *p, int p_max_size,
percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax); percent_print(p, p_max_size, cur->swap * 100 / cur->swapmax);
} }
} }
#ifdef X11
OBJ(swapbar) { OBJ(swapbar) {
new_bar(p, obj->data.pair.a, obj->data.pair.b, new_bar(p, obj->data.pair.a, obj->data.pair.b,
cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0); cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
} }
#endif
OBJ(sysname) { OBJ(sysname) {
snprintf(p, p_max_size, "%s", cur->uname_s.sysname); snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
} }
@ -4375,10 +4387,12 @@ static void generate_text_internal(char *p, int p_max_size,
spaced_print(p, p_max_size, "%.1f", 8, spaced_print(p, p_max_size, "%.1f", 8,
obj->data.net->trans_speed / 1024.0); obj->data.net->trans_speed / 1024.0);
} }
#ifdef X11
OBJ(upspeedgraph) { OBJ(upspeedgraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog); obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog);
} }
#endif
OBJ(uptime_short) { OBJ(uptime_short) {
format_seconds_short(p, p_max_size, (int) cur->uptime); format_seconds_short(p, p_max_size, (int) cur->uptime);
} }
@ -4462,10 +4476,12 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(mpd_percent) { OBJ(mpd_percent) {
percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100)); percent_print(p, p_max_size, (int)(mpd_get_info()->progress * 100));
} }
#ifdef X11
OBJ(mpd_bar) { OBJ(mpd_bar) {
new_bar(p, obj->data.pair.a, obj->data.pair.b, new_bar(p, obj->data.pair.a, obj->data.pair.b,
(int) (mpd_get_info()->progress * 255.0f)); (int) (mpd_get_info()->progress * 255.0f));
} }
#endif
OBJ(mpd_smart) { OBJ(mpd_smart) {
struct mpd_s *mpd = mpd_get_info(); struct mpd_s *mpd = mpd_get_info();
int len = obj->data.i; int len = obj->data.i;
@ -4824,6 +4840,7 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(entropy_poolsize) { OBJ(entropy_poolsize) {
snprintf(p, p_max_size, "%d", cur->entropy.poolsize); snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
} }
#ifdef X11
OBJ(entropy_bar) { OBJ(entropy_bar) {
double entropy_perc; double entropy_perc;
@ -4831,6 +4848,7 @@ static void generate_text_internal(char *p, int p_max_size,
(double) cur->entropy.poolsize; (double) cur->entropy.poolsize;
new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f)); new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
} }
#endif
#ifdef IBM #ifdef IBM
OBJ(smapi) { OBJ(smapi) {
char *s; char *s;
@ -6702,6 +6720,29 @@ static FILE *open_config_file(const char *f)
return fopen(f, "r"); return fopen(f, "r");
} }
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;
}
*(curplace2 - 1) = 0;
} 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 +6750,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 +7368,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);

View File

@ -204,9 +204,9 @@ static struct special_t *new_special(char *buf, enum special_types t)
return &specials[special_count++]; return &specials[special_count++];
} }
#ifdef X11
void new_gauge(char *buf, int w, int h, int usage) void new_gauge(char *buf, int w, int h, int usage)
{ {
#ifdef X11
struct special_t *s = 0; struct special_t *s = 0;
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
return; return;
@ -216,12 +216,10 @@ void new_gauge(char *buf, int w, int h, int usage)
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage); s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
s->width = w; s->width = w;
s->height = h; s->height = h;
#endif
} }
void new_bar(char *buf, int w, int h, int usage) void new_bar(char *buf, int w, int h, int usage)
{ {
#ifdef X11
struct special_t *s = 0; struct special_t *s = 0;
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
@ -232,12 +230,10 @@ void new_bar(char *buf, int w, int h, int usage)
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage); s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
s->width = w; s->width = w;
s->height = h; s->height = h;
#endif
} }
void new_font(char *buf, char *args) void new_font(char *buf, char *args)
{ {
#ifdef X11
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
return; return;
@ -258,11 +254,6 @@ void new_font(char *buf, char *args)
selected_font = s->font_added = 0; selected_font = s->font_added = 0;
selected_font = tmp; selected_font = tmp;
} }
#else
(void)buf;
(void)args;
return;
#endif
} }
static void graph_append(struct special_t *graph, double f, char showaslog) static void graph_append(struct special_t *graph, double f, char showaslog)
@ -298,7 +289,6 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
void new_graph(char *buf, int w, int h, unsigned int first_colour, void new_graph(char *buf, int w, int h, unsigned int first_colour,
unsigned int second_colour, double i, int scale, int append, char showaslog) unsigned int second_colour, double i, int scale, int append, char showaslog)
{ {
#ifdef X11
struct special_t *s = 0; struct special_t *s = 0;
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
@ -341,22 +331,18 @@ void new_graph(char *buf, int w, int h, unsigned int first_colour,
if (append) { if (append) {
graph_append(s, i, showaslog); graph_append(s, i, showaslog);
} }
#endif
} }
void new_hr(char *buf, int a) void new_hr(char *buf, int a)
{ {
#ifdef X11
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
return; return;
new_special(buf, HORIZONTAL_LINE)->height = a; new_special(buf, HORIZONTAL_LINE)->height = a;
#endif
} }
void new_stippled_hr(char *buf, int a, int b) void new_stippled_hr(char *buf, int a, int b)
{ {
#ifdef X11
struct special_t *s = 0; struct special_t *s = 0;
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
@ -366,28 +352,24 @@ void new_stippled_hr(char *buf, int a, int b)
s->height = b; s->height = b;
s->arg = a; s->arg = a;
#endif
} }
void new_fg(char *buf, long c) void new_fg(char *buf, long c)
{ {
#ifdef X11
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
return; return;
new_special(buf, FG)->arg = c; new_special(buf, FG)->arg = c;
#endif
} }
void new_bg(char *buf, long c) void new_bg(char *buf, long c)
{ {
#ifdef X11
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)
return; return;
new_special(buf, BG)->arg = c; new_special(buf, BG)->arg = c;
#endif
} }
#endif
void new_outline(char *buf, long c) void new_outline(char *buf, long c)
{ {