]> Dogcows Code - chaz/openbox/blob - plugins/keyboard/keysrc.yacc
load keybindings from keysrc
[chaz/openbox] / plugins / keyboard / keysrc.yacc
1 %{
2 #include "keyboard.h"
3 #include "../../kernel/action.h"
4 #include <glib.h>
5 #ifdef HAVE_STDIO_H
6 # include <stdio.h>
7 #endif
8
9 extern int kparselex();
10 extern int kparselineno;
11 extern FILE *kparsein; /* lexer input */
12
13 void kparseerror(char *s);
14 static void addbinding(GList *keylist, char *action, char *path, int num);
15
16 static char *path;
17 %}
18
19 %union {
20 char *string;
21 int integer;
22 GList *list;
23 }
24
25 %token <integer> INTEGER;
26 %token <string> STRING
27 %token <string> FIELD
28 %token <string> EXECUTE
29 %token <string> RESTART
30 %token <string> DESKTOP
31
32 %type <list> fields
33
34 %%
35
36 config:
37 | config '\n'
38 | config fields FIELD '\n' { addbinding($2, $3, NULL, 0); }
39 | config fields DESKTOP INTEGER '\n' { addbinding($2, $3, NULL, $4); }
40 | config fields RESTART '\n' { addbinding($2, $3, NULL, 0); }
41 | config fields EXECUTE STRING '\n' { addbinding($2, $3, $4, 0); }
42 | config fields RESTART STRING '\n' { addbinding($2, $3, $4, 0); }
43 ;
44
45 fields:
46 FIELD { $$ = g_list_prepend(NULL, $1); }
47 | fields FIELD { $$ = g_list_prepend($1, $2); }
48 ;
49
50 %%
51
52 void kparseerror(char *s) {
53 g_warning("Parser error in '%s' on line %d", path, kparselineno);
54 }
55
56 void keysrc_parse()
57 {
58 path = g_build_filename(g_get_home_dir(), ".openbox", "keysrc", NULL);
59 if ((kparsein = fopen(path, "r")) == NULL) {
60 g_free(path);
61 path = g_build_filename(RCDIR, "keysrc", NULL);
62 if ((kparsein = fopen(path, "r")) == NULL) {
63 g_warning("No keysrc file found!");
64 g_free(path);
65 return;
66 }
67 }
68
69 kparselineno = 1;
70
71 kparseparse();
72 }
73
74 static void addbinding(GList *keylist, char *action, char *apath, int num)
75 {
76 Action *a;
77
78 a = action_from_string(action);
79
80 /* no move/resize with the keyboard */
81 if (a && (a->func == action_move || a->func == action_resize)) {
82 action_free(a);
83 a = NULL;
84 }
85 if (a == NULL) {
86 g_warning("Invalid action '%s' in '%s' on line %d", action, apath,
87 kparselineno - 1);
88 return;
89 }
90 /* these have extra data! */
91 if (a->func == action_execute || a->func == action_restart)
92 a->data.execute.path = apath;
93 if (a->func == action_desktop)
94 a->data.desktop.desk = (unsigned) num + 1;
95
96 if (!kbind(keylist, a)) {
97 action_free(a);
98 g_warning("Unable to add binding in '%s' on line %d", path,
99 kparselineno - 1);
100 }
101 }
This page took 0.042384 seconds and 5 git commands to generate.