]> Dogcows Code - chaz/openbox/blob - plugins/mouse/mouserc_parse.l
dont set fields if in a comment
[chaz/openbox] / plugins / mouse / mouserc_parse.l
1 %{
2 #include "mouse.h"
3 #include <glib.h>
4 #ifdef HAVE_STDIO_H
5 # include <stdio.h>
6 #endif
7
8 static int lineno;
9 static char *path;
10 static gboolean comment;
11 static gboolean error;
12
13 static char *context;
14 static char *event;
15 static char *button;
16 static char *action;
17
18 static void endofline();
19 static int mparsewrap();
20 static void gotfield();
21 static void addbinding();
22 %}
23
24 field [A-Za-z0-9][-A-Za-z0-9]*[^-]
25 sep [ \t]+
26 white [ \t]*
27
28 %%
29
30 ^{white}# comment = TRUE;
31 {field} gotfield();
32 \n endofline();
33 [ \t]
34 . error = TRUE;
35
36 %%
37
38 static void gotfield()
39 {
40 if (!comment) {
41 if (context == NULL)
42 context = g_strdup(mparsetext);
43 else if (event == NULL)
44 event = g_strdup(mparsetext);
45 else if (button == NULL)
46 button = g_strdup(mparsetext);
47 else if (action == NULL)
48 action = g_strdup(mparsetext);
49 else
50 error = TRUE;
51 }
52 }
53
54 static void endofline()
55 {
56 if (!comment) {
57 if (!error && context && event && button && action)
58 addbinding();
59 else if (error || context || event || button || action)
60 g_warning("Parser error in '%s' on line %d", path, lineno);
61 }
62
63 comment = error = FALSE;
64 g_free(context); g_free(event); g_free(button); g_free(action);
65 context = event = button = action = NULL;
66
67 ++lineno;
68 }
69
70 static void addbinding()
71 {
72 Action *a;
73 MouseAction mact;
74
75 if (!g_ascii_strcasecmp(event, "press"))
76 mact = MouseAction_Press;
77 else if (!g_ascii_strcasecmp(event, "release"))
78 mact = MouseAction_Release;
79 else if (!g_ascii_strcasecmp(event, "click"))
80 mact = MouseAction_Click;
81 else if (!g_ascii_strcasecmp(event, "doubleclick"))
82 mact = MouseAction_DClick;
83 else if (!g_ascii_strcasecmp(event, "drag"))
84 mact = MouseAction_Motion;
85 else {
86 g_warning("Invalid event '%s' in '%s' on line %d", event, path,
87 lineno);
88 return;
89 }
90
91 if (!g_ascii_strcasecmp(action, "focus")) {
92 a = action_new(action_focus);
93 } else if (!g_ascii_strcasecmp(action, "unfocus")) {
94 a = action_new(action_unfocus);
95 } else if (!g_ascii_strcasecmp(action, "iconify")) {
96 a = action_new(action_iconify);
97 } else if (!g_ascii_strcasecmp(action, "raise")) {
98 a = action_new(action_raise);
99 } else if (!g_ascii_strcasecmp(action, "lower")) {
100 a = action_new(action_lower);
101 } else if (!g_ascii_strcasecmp(action, "focusraise")) {
102 a = action_new(action_focusraise);
103 } else if (!g_ascii_strcasecmp(action, "close")) {
104 a = action_new(action_close);
105 } else if (!g_ascii_strcasecmp(action, "kill")) {
106 a = action_new(action_kill);
107 } else if (!g_ascii_strcasecmp(action, "shade")) {
108 a = action_new(action_shade);
109 } else if (!g_ascii_strcasecmp(action, "unshade")) {
110 a = action_new(action_unshade);
111 } else if (!g_ascii_strcasecmp(action, "toggleshade")) {
112 a = action_new(action_toggle_shade);
113 } else if (!g_ascii_strcasecmp(action, "toggleomnipresent")) {
114 a = action_new(action_toggle_omnipresent);
115 } else if (!g_ascii_strcasecmp(action, "maximizefull")) {
116 a = action_new(action_maximize_full);
117 } else if (!g_ascii_strcasecmp(action, "unmaximizefull")) {
118 a = action_new(action_unmaximize_full);
119 } else if (!g_ascii_strcasecmp(action, "togglemaximizefull")) {
120 a = action_new(action_toggle_maximize_full);
121 } else if (!g_ascii_strcasecmp(action, "maximizehorz")) {
122 a = action_new(action_maximize_horz);
123 } else if (!g_ascii_strcasecmp(action, "unmaximizehorz")) {
124 a = action_new(action_unmaximize_horz);
125 } else if (!g_ascii_strcasecmp(action, "togglemaximizehorz")) {
126 a = action_new(action_toggle_maximize_horz);
127 } else if (!g_ascii_strcasecmp(action, "maximizevert")) {
128 a = action_new(action_maximize_vert);
129 } else if (!g_ascii_strcasecmp(action, "unmaximizevert")) {
130 a = action_new(action_unmaximize_vert);
131 } else if (!g_ascii_strcasecmp(action, "togglemaximizevert")) {
132 a = action_new(action_toggle_maximize_vert);
133 } else if (!g_ascii_strcasecmp(action, "sendtonextdesktop")) {
134 a = action_new(action_send_to_next_desktop);
135 a->data.sendtonextprev.wrap = FALSE;
136 a->data.sendtonextprev.follow = TRUE;
137 } else if (!g_ascii_strcasecmp(action, "sendtonextdesktopwrap")) {
138 a = action_new(action_send_to_next_desktop);
139 a->data.sendtonextprev.wrap = TRUE;
140 a->data.sendtonextprev.follow = TRUE;
141 } else if (!g_ascii_strcasecmp(action, "sendtopreviousdesktop")) {
142 a = action_new(action_send_to_previous_desktop);
143 a->data.sendtonextprev.wrap = FALSE;
144 a->data.sendtonextprev.follow = TRUE;
145 } else if (!g_ascii_strcasecmp(action, "sendtopreviousdesktopwrap")) {
146 a = action_new(action_send_to_previous_desktop);
147 a->data.sendtonextprev.wrap = TRUE;
148 a->data.sendtonextprev.follow = TRUE;
149 } else if (!g_ascii_strcasecmp(action, "nextdesktop")) {
150 a = action_new(action_next_desktop);
151 a->data.nextprevdesktop.wrap = FALSE;
152 } else if (!g_ascii_strcasecmp(action, "nextdesktopwrap")) {
153 a = action_new(action_next_desktop);
154 a->data.nextprevdesktop.wrap = TRUE;
155 } else if (!g_ascii_strcasecmp(action, "previousdesktop")) {
156 a = action_new(action_previous_desktop);
157 a->data.nextprevdesktop.wrap = FALSE;
158 } else if (!g_ascii_strcasecmp(action, "previousdesktopwrap")) {
159 a = action_new(action_previous_desktop);
160 a->data.nextprevdesktop.wrap = TRUE;
161 } else if (!g_ascii_strcasecmp(action, "nextdesktopcolumn")) {
162 a = action_new(action_next_desktop_column);
163 a->data.nextprevdesktop.wrap = FALSE;
164 } else if (!g_ascii_strcasecmp(action, "nextdesktopcolumnwrap")) {
165 a = action_new(action_next_desktop_column);
166 a->data.nextprevdesktop.wrap = TRUE;
167 } else if (!g_ascii_strcasecmp(action, "previousdesktopcolumn")) {
168 a = action_new(action_previous_desktop_column);
169 a->data.nextprevdesktop.wrap = FALSE;
170 } else if (!g_ascii_strcasecmp(action, "previousdesktopcolumnwrap")) {
171 a = action_new(action_previous_desktop_column);
172 a->data.nextprevdesktop.wrap = TRUE;
173 } else if (!g_ascii_strcasecmp(action, "nextdesktoprow")) {
174 a = action_new(action_next_desktop_row);
175 a->data.nextprevdesktop.wrap = FALSE;
176 } else if (!g_ascii_strcasecmp(action, "nextdesktoprowwrap")) {
177 a = action_new(action_next_desktop_row);
178 a->data.nextprevdesktop.wrap = TRUE;
179 } else if (!g_ascii_strcasecmp(action, "previousdesktoprow")) {
180 a = action_new(action_previous_desktop_row);
181 a->data.nextprevdesktop.wrap = FALSE;
182 } else if (!g_ascii_strcasecmp(action, "previousdesktoprowwrap")) {
183 a = action_new(action_previous_desktop_row);
184 a->data.nextprevdesktop.wrap = TRUE;
185 } else if (!g_ascii_strcasecmp(action, "move") &&
186 mact == MouseAction_Motion) {
187 a = action_new(action_move);
188 } else if (!g_ascii_strcasecmp(action, "resize") &&
189 mact == MouseAction_Motion) {
190 a = action_new(action_resize);
191 } else {
192 g_warning("Invalid action '%s' in '%s' on line %d", action, path,
193 lineno);
194 return;
195 }
196
197 if (!mbind(button, context, mact, a)) {
198 action_free(a);
199 g_warning("Unable to add binding '%s %s %s %s'",
200 context, event, button, action);
201 }
202 }
203
204
205 static int mparsewrap()
206 {
207 g_free(context); g_free(event); g_free(button); g_free(action);
208 return 1;
209 }
210
211 void mouserc_parse()
212 {
213 path = g_build_filename(g_get_home_dir(), ".openbox", "mouserc", NULL);
214 if ((mparsein = fopen(path, "r")) == NULL) {
215 g_free(path);
216 path = g_build_filename(RCDIR, "mouserc", NULL);
217 if ((mparsein = fopen(path, "r")) == NULL) {
218 g_warning("No mouserc file found!");
219 g_free(path);
220 return;
221 }
222 }
223
224 lineno = 1;
225 comment = FALSE;
226 error = FALSE;
227 context = event = button = action = NULL;
228
229 mparselex();
230
231 g_free(path);
232 }
This page took 0.042282 seconds and 4 git commands to generate.