summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2009-10-11 22:11:09 +0200
committerMichael Stapelberg <michael@stapelberg.de>2009-10-11 22:14:29 +0200
commitf947d0a446b1b99020722cbc71127fc0c06086b2 (patch)
tree87b75e70a7e2c0d162685221c66beed5f6b6a9e6 /src/config.c
parent1d122f32e6d2b0ae1f964dd755d769885c7bf1c2 (diff)
Breaks configfiles! Major refactoring of i3status, see below
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.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c153
1 files changed, 0 insertions, 153 deletions
diff --git a/src/config.c b/src/config.c
deleted file mode 100644
index e39c19b..0000000
--- a/src/config.c
+++ /dev/null
@@ -1,153 +0,0 @@
-// vim:ts=8:expandtab
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <glob.h>
-
-#include "i3status.h"
-
-int highest_order = 0;
-
-/*
- * Reads the configuration from the given file
- *
- */
-int load_configuration(const char *configfile) {
- #define OPT(x) else if (strcasecmp(dest_name, x) == 0)
-
- /* check if the file exists */
- struct stat buf;
- if (stat(configfile, &buf) < 0)
- return -1;
-
- int result = 0;
- FILE *handle = fopen(configfile, "r");
- if (handle == NULL)
- die("Could not open configfile\n");
- char dest_name[512], dest_value[512], whole_buffer[1026];
-
- while (!feof(handle)) {
- char *ret;
- if ((ret = fgets(whole_buffer, 1024, handle)) == whole_buffer) {
- /* sscanf implicitly strips whitespace */
- if (sscanf(whole_buffer, "%s %[^\n]", dest_name, dest_value) < 1)
- continue;
- } else if (ret != NULL)
- die("Could not read line in configuration file\n");
-
- /* skip comments and empty lines */
- if (dest_name[0] == '#' || strlen(dest_name) < 3)
- continue;
-
- OPT("wlan")
- wlan_interface = strdup(dest_value);
- OPT("eth")
- eth_interface = strdup(dest_value);
- OPT("time_format")
- time_format = strdup(dest_value);
- OPT("battery") {
- struct battery *new = calloc(1, sizeof(struct battery));
- if (new == NULL)
- die("Could not allocate memory\n");
- if (asprintf(&(new->path), "/sys/class/power_supply/BAT%d/uevent", atoi(dest_value)) == -1)
- die("Could not build battery path\n");
-
- /* check if flags were specified for this battery */
- if (strstr(dest_value, ",") != NULL) {
- char *flags = strstr(dest_value, ",");
- flags++;
- if (*flags == 'f')
- new->use_last_full = true;
- }
- 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") {
- get_cpu_temperature = true;
- int zone = 0;
- if (strlen(dest_value) > 0)
- zone = atoi(dest_value);
- if (asprintf(&thermal_zone, THERMAL_ZONE, zone) == -1)
- die("Could not build thermal_zone path\n");
- } OPT("normcolors")
- wmii_normcolors = strdup(dest_value);
- OPT("interval")
- interval = atoi(dest_value);
- OPT("wmii_path")
- {
-#if !defined(DZEN) && !defined(XMOBAR)
- static glob_t globbuf;
- struct stat stbuf;
- if (glob(dest_value, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
- die("glob() failed\n");
- wmii_path = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : dest_value);
- globfree(&globbuf);
-
- if ((stat(wmii_path, &stbuf)) == -1) {
- fprintf(stderr, "Warning: wmii_path contains an invalid path\n");
- free(wmii_path);
- wmii_path = strdup(dest_value);
- }
- if (wmii_path[strlen(wmii_path)-1] != '/')
- die("wmii_path is not terminated by /\n");
-#endif
- }
- OPT("run_watch")
- {
- char *name = strdup(dest_value);
- char *path = name;
- while (*path != ' ')
- path++;
- *(path++) = '\0';
- num_run_watches += 2;
- run_watches = realloc(run_watches, sizeof(char*) * num_run_watches);
- run_watches[num_run_watches-2] = name;
- run_watches[num_run_watches-1] = path;
- }
- OPT("order")
- {
-
- for (int c = 0; c < MAX_ORDER; c++)
- order[c] = -1;
-
- #define SET_ORDER(opt, idx) { if (strcasecmp(token, opt) == 0) order[idx] = highest_order++; }
- char *walk, *token;
- walk = token = dest_value;
- while (*walk != '\0') {
- while ((*walk != ',') && (*walk != '\0'))
- 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);
- SET_ORDER("cpu_temperature", ORDER_CPU_TEMPERATURE);
- SET_ORDER("load", ORDER_LOAD);
- SET_ORDER("time", ORDER_TIME);
- token = walk;
- while (isspace((int)(*token)))
- token++;
- }
- }
- else
- {
- result = -2;
- die("Unknown configfile option: %s\n", dest_name);
- }
- }
- fclose(handle);
-
-#if !defined(DZEN) && !defined(XMOBAR)
- if (wmii_path == NULL)
- exit(EXIT_FAILURE);
-#endif
-
- return result;
-}