mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-11 10:38:12 +00:00
review load* code
This commit is contained in:
parent
42dfb7ac69
commit
0bed05997b
@ -1,3 +1,7 @@
|
||||
2009-10-25
|
||||
* Fixed loadavg and loadgraph argument parsing and corrected it's
|
||||
documentation.
|
||||
|
||||
2009-09-11
|
||||
* Fixed configure test failure. Tolua test program couldn't find lua
|
||||
libraries (even though they existed) and failed to compile.
|
||||
|
@ -1787,7 +1787,8 @@
|
||||
<option>(1|2|3)</option>
|
||||
</term>
|
||||
<listitem>System load average, 1 is for past 1 minute, 2
|
||||
for past 5 minutes and 3 for past 15 minutes.
|
||||
for past 5 minutes and 3 for past 15 minutes. Without argument, prints
|
||||
all three values separated by whitespace.
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
@ -1795,7 +1796,7 @@
|
||||
<command>
|
||||
<option>loadgraph</option>
|
||||
</command>
|
||||
<option>(1|2|3) (height),(width) (gradient colour 1)
|
||||
<option>(height),(width) (gradient colour 1)
|
||||
(gradient colour 2) (scale) (-t) (-l)</option>
|
||||
</term>
|
||||
<listitem>Load1 average graph, similar to xload, with
|
||||
|
48
src/common.c
48
src/common.c
@ -420,41 +420,26 @@ unsigned int round_to_int(float f)
|
||||
|
||||
void scan_loadavg_arg(struct text_object *obj, const char *arg)
|
||||
{
|
||||
int a = 1, b = 2, c = 3, r = 3;
|
||||
|
||||
if (arg) {
|
||||
r = sscanf(arg, "%d %d %d", &a, &b, &c);
|
||||
if (r >= 3 && (c < 1 || c > 3)) {
|
||||
r--;
|
||||
}
|
||||
if (r >= 2 && (b < 1 || b > 3)) {
|
||||
r--, b = c;
|
||||
}
|
||||
if (r >= 1 && (a < 1 || a > 3)) {
|
||||
r--, a = b, b = c;
|
||||
obj->data.i = 0;
|
||||
if (arg && !arg[1] && isdigit(arg[0])) {
|
||||
obj->data.i = atoi(arg);
|
||||
if (obj->data.i > 3 || obj->data.i < 1) {
|
||||
NORM_ERR("loadavg arg needs to be in range (1,3)");
|
||||
obj->data.i = 0;
|
||||
}
|
||||
}
|
||||
obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
|
||||
obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
|
||||
obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
|
||||
/* convert to array index (or the default (-1)) */
|
||||
obj->data.i--;
|
||||
}
|
||||
|
||||
void print_loadavg(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
float *v = info.loadavg;
|
||||
|
||||
if (obj->data.loadavg[2]) {
|
||||
snprintf(p, p_max_size, "%.2f %.2f %.2f",
|
||||
v[obj->data.loadavg[0] - 1],
|
||||
v[obj->data.loadavg[1] - 1],
|
||||
v[obj->data.loadavg[2] - 1]);
|
||||
} else if (obj->data.loadavg[1]) {
|
||||
snprintf(p, p_max_size, "%.2f %.2f",
|
||||
v[obj->data.loadavg[0] - 1],
|
||||
v[obj->data.loadavg[1] - 1]);
|
||||
} else if (obj->data.loadavg[0]) {
|
||||
snprintf(p, p_max_size, "%.2f",
|
||||
v[obj->data.loadavg[0] - 1]);
|
||||
if (obj->data.i < 0) {
|
||||
snprintf(p, p_max_size, "%.2f %.2f %.2f", v[0], v[1], v[2]);
|
||||
} else {
|
||||
snprintf(p, p_max_size, "%.2f", v[obj->data.i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -462,17 +447,12 @@ void print_loadavg(struct text_object *obj, char *p, int p_max_size)
|
||||
void scan_loadgraph_arg(struct text_object *obj, const char *arg)
|
||||
{
|
||||
char *buf = 0;
|
||||
|
||||
SIZE_DEFAULTS(graph);
|
||||
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
|
||||
&obj->e, &obj->char_a, &obj->char_b);
|
||||
if (buf) {
|
||||
int a = 1, r = 3;
|
||||
if (arg) {
|
||||
r = sscanf(arg, "%d", &a);
|
||||
}
|
||||
obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
|
||||
if (buf)
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void print_loadgraph(struct text_object *obj, char *p)
|
||||
|
@ -434,7 +434,6 @@ struct text_object {
|
||||
char *s; /* some string */
|
||||
int i; /* some integer */
|
||||
long l; /* some other integer */
|
||||
unsigned char loadavg[3];
|
||||
|
||||
struct {
|
||||
void *opaque; /* temporary workaround to not blow stuff */
|
||||
|
Loading…
Reference in New Issue
Block a user