1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-24 15:48:28 +00:00

be consistent when parsing args of cpu objects

The inconsistent naming of the cpu parameter in the docs led me to this,
so I also simplified parsing by introducing the macro SCAN_CPU(). Note
that this introduces a syntactical change to the config: the cpuN
argument now has to be passed at first position to $cpugraph.
This commit is contained in:
Phil Sutter 2009-04-04 01:19:49 +02:00
parent 45ee67ae7e
commit 7001e95186
2 changed files with 17 additions and 36 deletions

View File

@ -421,7 +421,7 @@
<varlistentry>
<term>
<command><option>cpubar</option></command>
<option>(cpu number) (height),(width)</option>
<option>(cpuN) (height),(width)</option>
</term>
<listitem>
Bar that shows CPU usage, height is bar's height in pixels. See $cpu for more info on SMP.
@ -431,7 +431,7 @@
<varlistentry>
<term>
<command><option>cpugauge</option></command>
<option>(cpu number) (height),(width)</option>
<option>(cpuN) (height),(width)</option>
</term>
<listitem>
Elliptical gauge that shows CPU usage, height and width are gauge's vertical and horizontal axis respectively. See $cpu for more info on SMP.
@ -441,7 +441,7 @@
<varlistentry>
<term>
<command><option>cpugraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (cpu number)</option>
<option>(cpuN) ("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option>
</term>
<listitem>
CPU usage graph, with optional colours in hex, minus the #. See $cpu for more info on SMP. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".

View File

@ -1286,47 +1286,28 @@ static struct text_object *construct_text_object(const char *s,
#endif /* __OpenBSD__ */
END OBJ(buffers, INFO_BUFFERS)
END OBJ(cached, INFO_BUFFERS)
#define SCAN_CPU(__arg, __var) { \
int __offset; \
if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset)) \
__arg += __offset; \
else \
__var = 0; \
}
END OBJ(cpu, INFO_CPU)
if (arg) {
if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
obj->data.cpu_index = atoi(&arg[3]);
arg += 4;
} else {
obj->data.cpu_index = 0;
}
DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
} else {
obj->data.cpu_index = 0;
}
SCAN_CPU(arg, obj->data.cpu_index);
DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
END OBJ(cpugauge, INFO_CPU)
SCAN_CPU(arg, obj->data.cpu_index);
scan_gauge(arg, &obj->a, &obj->b);
DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
END OBJ(cpubar, INFO_CPU)
if (arg) {
if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
obj->data.cpu_index = atoi(&arg[3]);
arg += 4;
} else {
obj->data.cpu_index = 0;
}
scan_bar(arg, &obj->a, &obj->b);
} else {
scan_bar(arg, &obj->a, &obj->b);
obj->data.cpu_index = 0;
}
SCAN_CPU(arg, obj->data.cpu_index);
scan_bar(arg, &obj->a, &obj->b);
DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
END OBJ(cpugraph, INFO_CPU)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
SCAN_CPU(arg, obj->data.cpu_index);
scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog);
if (buf) {
if (strncmp(buf, "cpu", 3) == EQUAL && isdigit(buf[3])) {
obj->data.cpu_index = atoi(&buf[3]);
} else {
obj->data.cpu_index = 0;
}
free(buf);
}
DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
END OBJ(loadgraph, INFO_LOADAVG)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,