16 const char *wlan_interface;
17 const char *eth_interface;
19 const char *time_format;
20 const char *battery_path;
23 const char *wmii_normcolors = "#222222 #333333";
24 char order[MAX_ORDER][2];
25 const char **run_watches;
26 unsigned int num_run_watches;
27 unsigned int interval = 1;
29 void die(const char *fmt, ...);
32 * Reads the configuration from the given file
35 int load_configuration(const char *configfile) {
36 #define OPT(x) else if (strcasecmp(dest_name, x) == 0)
38 /* check if the file exists */
40 if (stat(configfile, &buf) < 0)
44 FILE *handle = fopen(configfile, "r");
46 die("Could not open configfile");
47 char dest_name[512], dest_value[512], whole_buffer[1026];
49 while (!feof(handle)) {
51 if ((ret = fgets(whole_buffer, 1024, handle)) == whole_buffer) {
52 /* sscanf implicitly strips whitespace */
53 if (sscanf(whole_buffer, "%s %[^\n]", dest_name, dest_value) < 1)
55 } else if (ret != NULL)
56 die("Could not read line in configuration file");
58 /* skip comments and empty lines */
59 if (dest_name[0] == '#' || strlen(dest_name) < 3)
63 wlan_interface = strdup(dest_value);
65 eth_interface = strdup(dest_value);
67 time_format = strdup(dest_value);
69 battery_path = strdup(dest_value);
75 wmii_normcolors = strdup(dest_value);
77 interval = atoi(dest_value);
80 static glob_t globbuf;
81 if (glob(dest_value, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
83 wmii_path = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : dest_value);
86 if ((stat(wmii_path, &stbuf)) == -1) {
87 fprintf(stderr, "Warning: wmii_path contains an invalid path\n");
89 wmii_path = strdup(dest_value);
91 if (wmii_path[strlen(wmii_path)-1] != '/')
92 die("wmii_path is not terminated by /");
96 char *name = strdup(dest_value);
101 num_run_watches += 2;
102 run_watches = realloc(run_watches, sizeof(char*) * num_run_watches);
103 run_watches[num_run_watches-2] = name;
104 run_watches[num_run_watches-1] = path;
108 #define SET_ORDER(opt, idx) { if (strcasecmp(token, opt) == 0) sprintf(order[idx], "%d", c++); }
111 walk = token = dest_value;
112 while (*walk != '\0') {
113 while ((*walk != ',') && (*walk != '\0'))
116 SET_ORDER("run", ORDER_RUN);
117 SET_ORDER("wlan", ORDER_WLAN);
118 SET_ORDER("eth", ORDER_ETH);
119 SET_ORDER("battery", ORDER_BATTERY);
120 SET_ORDER("load", ORDER_LOAD);
121 SET_ORDER("time", ORDER_TIME);
123 while (isspace((int)(*token)))
130 die("Unknown configfile option: %s\n", dest_name);
135 if (wmii_path == NULL)