From f947d0a446b1b99020722cbc71127fc0c06086b2 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 11 Oct 2009 22:11:09 +0200 Subject: Breaks configfiles! Major refactoring of i3status, see below MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We finally switched to libconfuse for a configuration file format which does not require much work for the programmer nor for the user. Plus, it avoids the Not-Invented-Here syndrome of yet another config file format. Furthermore, as a consequence of providing format strings for every "module" (ipv6, wireless, …), we directly print the output and thus we needed to drop support for wmii. This allowed us to get rid of quite some complexity. Documentation about the new configuration file and options will follow. This commit is the beginning of what will be i3status v2.0. --- src/output.c | 154 ++--------------------------------------------------------- 1 file changed, 4 insertions(+), 150 deletions(-) (limited to 'src/output.c') diff --git a/src/output.c b/src/output.c index eee458b..d4d8c2f 100644 --- a/src/output.c +++ b/src/output.c @@ -11,22 +11,12 @@ #include "i3status.h" /* - * Writes an errormessage to statusbar - * - */ -void write_error_to_statusbar(const char *message) { - cleanup_rbar_dir(); - create_file("error"); - write_to_statusbar("error", message, true); -} - -/* - * Returns the correct color format for dzen (^fg(color)) or wmii (color ) + * Returns the correct color format for dzen (^fg(color)) or xmobar () * */ char *color(const char *colorstr) { static char colorbuf[32]; - if (!use_colors) { + if (!cfg_getbool(cfg_general, "colors")) { colorbuf[0] = '\0'; return colorbuf; } @@ -34,8 +24,6 @@ char *color(const char *colorstr) { (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr); #elif XMOBAR (void)snprintf(colorbuf, sizeof(colorbuf), "", colorstr); -#else - (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors); #endif return colorbuf; } @@ -52,142 +40,8 @@ char *endcolor() { #endif } -/* - * Cleans wmii's /rbar directory by deleting all regular files - * - */ -void cleanup_rbar_dir() { -#if defined(DZEN) || defined(XMOBAR) - return; -#endif - struct dirent *ent; - DIR *dir; - char pathbuf[strlen(wmii_path)+256+1]; - - if ((dir = opendir(wmii_path)) == NULL) - exit(EXIT_FAILURE); - - while ((ent = readdir(dir)) != NULL) { - if (ent->d_type == DT_REG) { - (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, ent->d_name); - if (unlink(pathbuf) == -1) - exit(EXIT_FAILURE); - } - } - - (void)closedir(dir); -} - -/* - * Creates the specified file in wmii's /rbar directory with - * correct modes and initializes colors if colormode is enabled - * - */ -void create_file(const char *name) { +void print_seperator() { #if defined(DZEN) || defined(XMOBAR) - return; + printf("%s", BAR); #endif - char pathbuf[strlen(wmii_path)+256+1]; - int fd; - int flags = O_CREAT | O_WRONLY; - struct stat statbuf; - - (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name); - - /* Overwrite file's contents if it exists */ - if (stat(pathbuf, &statbuf) >= 0) - flags |= O_TRUNC; - - if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0) - exit(EXIT_FAILURE); - if (use_colors) { - char *tmp = color("#888888"); - if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp)) - exit(EXIT_FAILURE); - } - (void)close(fd); -} - -/* - * Waits until wmii_path/rbar exists (= the filesystem gets mounted), - * cleans up all files and creates the needed files - * - */ -void setup(void) { - unsigned int i; - char pathbuf[512]; - -#if !defined(DZEN) && !defined(XMOBAR) - struct stat statbuf; - /* 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) - cf(ORDER_WLAN, "wlan"); - if (eth_interface) - cf(ORDER_ETH, "eth"); - if (get_cpu_temperature) - cf(ORDER_CPU_TEMPERATURE, "cpu_temperature"); - cf(ORDER_LOAD, "load"); - if (time_format) - cf(ORDER_TIME, "time"); - for (i = 0; i < num_run_watches; i += 2) { - snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]); - create_file(pathbuf); - } -} - -/* - * Writes the given message in the corresponding file in wmii's /rbar directory - * - */ -void write_to_statusbar(const char *name, const char *message, bool final_entry) { -#ifdef DZEN - if (final_entry) { - if (printf("%s^p(6)\n", message) < 0) { - perror("printf"); - exit(1); - } - - fflush(stdout); - return; - } - if (printf("%s" BAR, message) < 0) { - perror("printf"); - exit(1); - } - return; -#elif XMOBAR - if (final_entry) { - if (printf("%s\n", message) < 0) { - perror("printf"); - exit(1); - } - - fflush(stdout); - return; - } - if (printf("%s" BAR, message) < 0) { - perror("printf"); - exit(1); - } - return; - -#endif - - char pathbuf[strlen(wmii_path)+256+1]; - int fd; - - (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name); - if ((fd = open(pathbuf, O_RDWR)) == -1) { - /* Try to re-setup stuff and just continue */ - setup(); - return; - } - if (write(fd, message, strlen(message)) != (ssize_t)strlen(message)) - exit(EXIT_FAILURE); - (void)close(fd); } -- cgit v1.2.3