summaryrefslogtreecommitdiff
blob: 00a32eb1c3b5b2dd03d7d992ce78674b8d6fdb5c (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
58
59
60
61
62
63
64
65
66
67
68
69
70
From 50fb30000ecd172e1748fab9bad7762df4ea2cf0 Mon Sep 17 00:00:00 2001
From: Russell Harmon <russ@eatnumber1.com>
Date: Thu, 31 Dec 2009 11:44:16 -0500
Subject: [PATCH 1/3] Support using a config file located in /etc

---
 keynav.c |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/keynav.c b/keynav.c
index d872805..76fd307 100644
--- a/keynav.c
+++ b/keynav.c
@@ -306,6 +306,22 @@ void addbinding(int keycode, int mods, char *commands) {
   }
 }
 
+void parse_config_file(const char* file) {
+  FILE *fp = NULL;
+#define LINEBUF_SIZE 512
+  char line[LINEBUF_SIZE];
+  fp = fopen(file, "r");
+  if (fp != NULL) {
+    /* fopen succeeded */
+    while (fgets(line, LINEBUF_SIZE, fp) != NULL) {
+      /* Kill the newline */
+      *(line + strlen(line) - 1) = '\0';
+      parse_config_line(line);
+    }
+    fclose(fp);
+  }
+}
+
 void parse_config() {
   char *homedir;
 
@@ -313,28 +329,15 @@ void parse_config() {
 
   defaults();
 
+  parse_config_file("/etc/keynavrc");
   homedir = getenv("HOME");
 
   if (homedir != NULL) {
     char *rcfile = NULL;
-    FILE *fp = NULL;
-#define LINEBUF_SIZE 512
-    char line[LINEBUF_SIZE];
     asprintf(&rcfile, "%s/.keynavrc", homedir);
-    fp = fopen(rcfile, "r");
-    if (fp != NULL) {
-      /* fopen succeeded */
-      while (fgets(line, LINEBUF_SIZE, fp) != NULL) {
-        /* Kill the newline */
-        *(line + strlen(line) - 1) = '\0';
-        parse_config_line(line);
-      }
-      free(rcfile);
-      return;
-    }
+    parse_config_file(rcfile);
     free(rcfile);
   }
-  fprintf(stderr, "No ~/.keynavrc found.\n");
 }
 
 void defaults() {
-- 
1.6.4.4