summaryrefslogtreecommitdiff
blob: c1a2af8d8072e8e10cf26070f6d7b66e22ffc9c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- a/keynav-20091108/keynav.c	2009-11-08 16:03:15.000000000 -0500
+++ b/keynav-20091108/keynav.c	2009-11-26 10:31:41.813671575 -0500
@@ -285,22 +285,11 @@
   }
 }
 
-void parse_config() {
-  char *homedir;
-
-  keybindings = malloc(keybindings_size * sizeof(struct keybinding));
-
-  defaults();
-
-  homedir = getenv("HOME");
-
-  if (homedir != NULL) {
-    char *rcfile = NULL;
+void parse_config_file(const char* file) {
     FILE *fp = NULL;
 #define LINEBUF_SIZE 512
     char line[LINEBUF_SIZE];
-    asprintf(&rcfile, "%s/.keynavrc", homedir);
-    fp = fopen(rcfile, "r");
+    fp = fopen(file, "r");
     if (fp != NULL) {
       /* fopen succeeded */
       while (fgets(line, LINEBUF_SIZE, fp) != NULL) {
@@ -308,11 +297,27 @@
         *(line + strlen(line) - 1) = '\0';
         parse_config_line(line);
       }
-      free(rcfile);
+      fclose(fp);
       return;
     }
+}
+
+void parse_config() {
+  char *homedir;
+
+  keybindings = malloc(keybindings_size * sizeof(struct keybinding));
+
+  defaults();
+
+  parse_config_file("/etc/keynavrc");
+  homedir = getenv("HOME");
+
+  if (homedir != NULL) {
+    char *rcfile = NULL;
+    asprintf(&rcfile, "%s/.keynavrc", homedir);
+    parse_config_file(rcfile);
+    free(rcfile);
   }
-  fprintf(stderr, "No ~/.keynavrc found.\n");
 }
 
 void defaults() {