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

text_object: use field i instead of cpu_index

This commit is contained in:
Phil Sutter 2009-10-17 16:55:12 +02:00
parent 3a365bcd33
commit ac99833646
4 changed files with 35 additions and 36 deletions

View File

@ -811,18 +811,18 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(freq) { OBJ(freq) {
if (obj->a) { if (obj->a) {
obj->a = get_freq(p, p_max_size, "%.0f", 1, obj->a = get_freq(p, p_max_size, "%.0f", 1,
obj->data.cpu_index); obj->data.i);
} }
} }
OBJ(freq_g) { OBJ(freq_g) {
if (obj->a) { if (obj->a) {
#ifndef __OpenBSD__ #ifndef __OpenBSD__
obj->a = get_freq(p, p_max_size, "%'.2f", 1000, obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
obj->data.cpu_index); obj->data.i);
#else #else
/* OpenBSD has no such flag (SUSv2) */ /* OpenBSD has no such flag (SUSv2) */
obj->a = get_freq(p, p_max_size, "%.2f", 1000, obj->a = get_freq(p, p_max_size, "%.2f", 1000,
obj->data.cpu_index); obj->data.i);
#endif /* __OpenBSD */ #endif /* __OpenBSD */
} }
} }
@ -830,13 +830,13 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(voltage_mv) { OBJ(voltage_mv) {
if (obj->a) { if (obj->a) {
obj->a = get_voltage(p, p_max_size, "%.0f", 1, obj->a = get_voltage(p, p_max_size, "%.0f", 1,
obj->data.cpu_index); obj->data.i);
} }
} }
OBJ(voltage_v) { OBJ(voltage_v) {
if (obj->a) { if (obj->a) {
obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
obj->data.cpu_index); obj->data.i);
} }
} }
@ -915,28 +915,28 @@ void generate_text_internal(char *p, int p_max_size,
human_readable(cur->cached * 1024, p, 255); human_readable(cur->cached * 1024, p, 255);
} }
OBJ(cpu) { OBJ(cpu) {
if (obj->data.cpu_index > info.cpu_count) { if (obj->data.i > info.cpu_count) {
NORM_ERR("obj->data.cpu_index %i info.cpu_count %i", NORM_ERR("obj->data.i %i info.cpu_count %i",
obj->data.cpu_index, info.cpu_count); obj->data.i, info.cpu_count);
CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!"); CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!");
} }
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.i] * 100.0));
} }
#ifdef X11 #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.i] * 255.0));
#endif /* X11 */ #endif /* X11 */
OBJ(cpubar) { OBJ(cpubar) {
#ifdef X11 #ifdef X11
if(output_methods & TO_X) { if(output_methods & TO_X) {
new_bar(p, obj->a, obj->b, new_bar(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.i] * 255.0));
}else{ }else{
#endif /* X11 */ #endif /* X11 */
if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X; if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), obj->a); new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100), obj->a);
#ifdef X11 #ifdef X11
} }
#endif /* X11 */ #endif /* X11 */
@ -944,7 +944,7 @@ void generate_text_internal(char *p, int p_max_size,
#ifdef X11 #ifdef X11
OBJ(cpugraph) { OBJ(cpugraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), round_to_int(cur->cpu_usage[obj->data.i] * 100),
100, 1, obj->char_a, obj->char_b); 100, 1, obj->char_a, obj->char_b);
} }
OBJ(loadgraph) { OBJ(loadgraph) {

View File

@ -234,7 +234,7 @@ struct information {
float *cpu_usage; float *cpu_usage;
/* struct cpu_stat cpu_summed; what the hell is this? */ /* struct cpu_stat cpu_summed; what the hell is this? */
unsigned int cpu_count; int cpu_count;
int cpu_avg_samples; int cpu_avg_samples;
int net_avg_samples; int net_avg_samples;

View File

@ -163,23 +163,23 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
#endif /* !__OpenBSD__ */ #endif /* !__OpenBSD__ */
get_cpu_count(); get_cpu_count();
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) { || atoi(&arg[0]) > info.cpu_count) {
obj->data.cpu_index = 1; obj->data.i = 1;
/* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! " /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
"Displaying the clock for CPU 1."); */ "Displaying the clock for CPU 1."); */
} else { } else {
obj->data.cpu_index = atoi(&arg[0]); obj->data.i = atoi(&arg[0]);
} }
obj->a = 1; obj->a = 1;
END OBJ(freq_g, 0) END OBJ(freq_g, 0)
get_cpu_count(); get_cpu_count();
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) { || atoi(&arg[0]) > info.cpu_count) {
obj->data.cpu_index = 1; obj->data.i = 1;
/* NORM_ERR("freq_g: Invalid CPU number or you don't have that many " /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
"CPUs! Displaying the clock for CPU 1."); */ "CPUs! Displaying the clock for CPU 1."); */
} else { } else {
obj->data.cpu_index = atoi(&arg[0]); obj->data.i = atoi(&arg[0]);
} }
obj->a = 1; obj->a = 1;
END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)") END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
@ -188,23 +188,23 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
END OBJ(voltage_mv, 0) END OBJ(voltage_mv, 0)
get_cpu_count(); get_cpu_count();
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) { || atoi(&arg[0]) > info.cpu_count) {
obj->data.cpu_index = 1; obj->data.i = 1;
/* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many " /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
"CPUs! Displaying voltage for CPU 1."); */ "CPUs! Displaying voltage for CPU 1."); */
} else { } else {
obj->data.cpu_index = atoi(&arg[0]); obj->data.i = atoi(&arg[0]);
} }
obj->a = 1; obj->a = 1;
END OBJ(voltage_v, 0) END OBJ(voltage_v, 0)
get_cpu_count(); get_cpu_count();
if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
|| (unsigned int) atoi(&arg[0]) > info.cpu_count) { || atoi(&arg[0]) > info.cpu_count) {
obj->data.cpu_index = 1; obj->data.i = 1;
/* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many " /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
"CPUs! Displaying voltage for CPU 1."); */ "CPUs! Displaying voltage for CPU 1."); */
} else { } else {
obj->data.cpu_index = atoi(&arg[0]); obj->data.i = atoi(&arg[0]);
} }
obj->a = 1; obj->a = 1;
@ -337,34 +337,34 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
END OBJ(cached, &update_meminfo) END OBJ(cached, &update_meminfo)
#define SCAN_CPU(__arg, __var) { \ #define SCAN_CPU(__arg, __var) { \
int __offset = 0; \ int __offset = 0; \
if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \ if (__arg && sscanf(__arg, " cpu%d %n", &__var, &__offset) > 0) \
__arg += __offset; \ __arg += __offset; \
else \ else \
__var = 0; \ __var = 0; \
} }
END OBJ(cpu, &update_cpu_usage) END OBJ(cpu, &update_cpu_usage)
SCAN_CPU(arg, obj->data.cpu_index); SCAN_CPU(arg, obj->data.i);
DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index); DBGP2("Adding $cpu for CPU %d", obj->data.i);
#ifdef X11 #ifdef X11
END OBJ(cpugauge, &update_cpu_usage) END OBJ(cpugauge, &update_cpu_usage)
SIZE_DEFAULTS(gauge); SIZE_DEFAULTS(gauge);
SCAN_CPU(arg, obj->data.cpu_index); SCAN_CPU(arg, obj->data.i);
scan_gauge(arg, &obj->a, &obj->b); scan_gauge(arg, &obj->a, &obj->b);
DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index); DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
#endif /* X11 */ #endif /* X11 */
END OBJ(cpubar, &update_cpu_usage) END OBJ(cpubar, &update_cpu_usage)
SIZE_DEFAULTS(bar); SIZE_DEFAULTS(bar);
SCAN_CPU(arg, obj->data.cpu_index); SCAN_CPU(arg, obj->data.i);
scan_bar(arg, &obj->a, &obj->b); scan_bar(arg, &obj->a, &obj->b);
DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index); DBGP2("Adding $cpubar for CPU %d", obj->data.i);
#ifdef X11 #ifdef X11
END OBJ(cpugraph, &update_cpu_usage) END OBJ(cpugraph, &update_cpu_usage)
char *buf = 0; char *buf = 0;
SIZE_DEFAULTS(graph); SIZE_DEFAULTS(graph);
SCAN_CPU(arg, obj->data.cpu_index); SCAN_CPU(arg, obj->data.i);
buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->char_a, &obj->char_b); &obj->e, &obj->char_a, &obj->char_b);
DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index); DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
if (buf) free(buf); if (buf) free(buf);
END OBJ(loadgraph, &update_load_average) END OBJ(loadgraph, &update_load_average)
char *buf = 0; char *buf = 0;

View File

@ -443,7 +443,6 @@ struct text_object {
int i; /* some integer */ int i; /* some integer */
long l; /* some other integer */ long l; /* some other integer */
unsigned char loadavg[3]; unsigned char loadavg[3];
unsigned int cpu_index;
struct mail_s *mail; struct mail_s *mail;
struct { struct {