From 34ba9fa9083c655e5ba06cecd46da157eb07d980 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 21 Jul 2009 20:23:08 +0200 Subject: Correctly handle the order of items --- src/config.c | 5 ++++- src/general.c | 8 ++++---- src/output.c | 13 +++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index 5904512..da1e5d1 100644 --- a/src/config.c +++ b/src/config.c @@ -60,6 +60,8 @@ int load_configuration(const char *configfile) { SIMPLEQ_INSERT_TAIL(&batteries, new, batteries); } OPT("color") use_colors = true; + OPT("get_ipv6") + get_ipv6 = true; OPT("get_ethspeed") get_ethspeed = true; OPT("get_cpu_temperature") { @@ -108,7 +110,7 @@ int load_configuration(const char *configfile) { } OPT("order") { - #define SET_ORDER(opt, idx) { if (strcasecmp(token, opt) == 0) sprintf(order[idx], "%d", c++); } + #define SET_ORDER(opt, idx) { if (strcasecmp(token, opt) == 0) order[idx] = c++; } char *walk, *token; int c = 0; walk = token = dest_value; @@ -117,6 +119,7 @@ int load_configuration(const char *configfile) { walk++; *(walk++) = '\0'; SET_ORDER("run", ORDER_RUN); + SET_ORDER("ipv6", ORDER_IPV6); SET_ORDER("wlan", ORDER_WLAN); SET_ORDER("eth", ORDER_ETH); SET_ORDER("battery", ORDER_BATTERY); diff --git a/src/general.c b/src/general.c index 4016ecd..4c110e4 100644 --- a/src/general.c +++ b/src/general.c @@ -63,8 +63,8 @@ void die(const char *fmt, ...) { * Otherwise, the buffer size would have to be increased. * */ -char *concat(const char *str1, const char *str2) { - static char concatbuf[32]; - (void)snprintf(concatbuf, sizeof(concatbuf), "%s%s", str1, str2); - return concatbuf; +char *order_to_str(int number, char *name) { + static char buf[32]; + (void)snprintf(buf, sizeof(buf), "%d%s", number, name); + return buf; } diff --git a/src/output.c b/src/output.c index 379710e..7fc24f5 100644 --- a/src/output.c +++ b/src/output.c @@ -103,19 +103,20 @@ void setup(void) { /* Wait until wmii_path/rbar exists */ for (; stat(wmii_path, &statbuf) < 0; sleep(interval)); #endif +#define cf(orderidx, name) create_file(order_to_str(order[orderidx], name)); cleanup_rbar_dir(); if (wlan_interface) - create_file(concat(order[ORDER_WLAN],"wlan")); + cf(ORDER_WLAN, "wlan"); if (eth_interface) - create_file(concat(order[ORDER_ETH],"eth")); + cf(ORDER_ETH, "eth"); if (get_cpu_temperature) - create_file(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature")); - create_file(concat(order[ORDER_LOAD],"load")); + cf(ORDER_CPU_TEMPERATURE, "cpu_temperature"); + cf(ORDER_LOAD, "load"); if (time_format) - create_file(concat(order[ORDER_TIME],"time")); + cf(ORDER_TIME, "time"); for (i = 0; i < num_run_watches; i += 2) { - snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]); + snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]); create_file(pathbuf); } } -- cgit v1.2.3