Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | %{ |
2 | /* | |
3 | * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. | |
4 | * Copyright (C) Colin Harrison 2005-2008 | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining | |
7 | * a copy of this software and associated documentation files (the | |
8 | * "Software"), to deal in the Software without restriction, including | |
9 | * without limitation the rights to use, copy, modify, merge, publish, | |
10 | * distribute, sublicense, and/or sell copies of the Software, and to | |
11 | * permit persons to whom the Software is furnished to do so, subject to | |
12 | * the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be | |
15 | * included in all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR | |
21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
22 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 | * | |
25 | * Except as contained in this notice, the name of the XFree86 Project | |
26 | * shall not be used in advertising or otherwise to promote the sale, use | |
27 | * or other dealings in this Software without prior written authorization | |
28 | * from the XFree86 Project. | |
29 | * | |
30 | * Authors: Earle F. Philhower, III | |
31 | * Colin Harrison | |
32 | */ | |
33 | /* $XFree86: $ */ | |
34 | ||
35 | #ifdef HAVE_XWIN_CONFIG_H | |
36 | #include <xwin-config.h> | |
37 | #endif | |
38 | #include <stdio.h> | |
39 | #include <stdlib.h> | |
40 | #define _STDLIB_H 1 /* bison checks this to know if stdlib has been included */ | |
41 | #include <string.h> | |
42 | #include "winprefs.h" | |
43 | ||
44 | /* The following give better error messages in bison at the cost of a few KB */ | |
45 | #define YYERROR_VERBOSE 1 | |
46 | ||
47 | /* YYLTYPE_IS_TRIVIAL and YYENABLE_NLS defined to suppress warnings */ | |
48 | #define YYLTYPE_IS_TRIVIAL 1 | |
49 | #define YYENABLE_NLS 0 | |
50 | ||
51 | /* The global pref settings */ | |
52 | WINPREFS pref; | |
53 | ||
54 | /* The working menu */ | |
55 | static MENUPARSED menu; | |
56 | ||
57 | /* Functions for parsing the tokens into out structure */ | |
58 | /* Defined at the end section of this file */ | |
59 | ||
60 | static void SetIconDirectory (char *path); | |
61 | static void SetDefaultIcon (char *fname); | |
62 | static void SetRootMenu (char *menu); | |
63 | static void SetDefaultSysMenu (char *menu, int pos); | |
64 | static void SetTrayIcon (char *fname); | |
65 | ||
66 | static void OpenMenu(char *menuname); | |
67 | static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param); | |
68 | static void CloseMenu(void); | |
69 | ||
70 | static void OpenIcons(void); | |
71 | static void AddIconLine(char *matchstr, char *iconfile); | |
72 | static void CloseIcons(void); | |
73 | ||
74 | static void OpenStyles(void); | |
75 | static void AddStyleLine(char *matchstr, unsigned long style); | |
76 | static void CloseStyles(void); | |
77 | ||
78 | static void OpenSysMenu(void); | |
79 | static void AddSysMenuLine(char *matchstr, char *menuname, int pos); | |
80 | static void CloseSysMenu(void); | |
81 | ||
82 | static int yyerror (char *s); | |
83 | ||
84 | extern char *yytext; | |
85 | extern int yylex(void); | |
86 | ||
87 | %} | |
88 | ||
89 | %union { | |
90 | char *sVal; | |
91 | unsigned long uVal; | |
92 | int iVal; | |
93 | } | |
94 | ||
95 | %token NEWLINE | |
96 | %token MENU | |
97 | %token LB | |
98 | %token RB | |
99 | %token ICONDIRECTORY | |
100 | %token DEFAULTICON | |
101 | %token ICONS | |
102 | %token STYLES | |
103 | %token TOPMOST | |
104 | %token MAXIMIZE | |
105 | %token MINIMIZE | |
106 | %token BOTTOM | |
107 | %token NOTITLE | |
108 | %token OUTLINE | |
109 | %token NOFRAME | |
110 | %token DEFAULTSYSMENU | |
111 | %token SYSMENU | |
112 | %token ROOTMENU | |
113 | %token SEPARATOR | |
114 | %token ATSTART | |
115 | %token ATEND | |
116 | %token EXEC | |
117 | %token ALWAYSONTOP | |
118 | %token DEBUGOUTPUT "DEBUG" | |
119 | %token RELOAD | |
120 | %token TRAYICON | |
121 | %token FORCEEXIT | |
122 | %token SILENTEXIT | |
123 | ||
124 | %token <sVal> STRING | |
125 | %type <uVal> group1 | |
126 | %type <uVal> group2 | |
127 | %type <uVal> stylecombo | |
128 | %type <iVal> atspot | |
129 | ||
130 | %% | |
131 | ||
132 | input: /* empty */ | |
133 | | input line | |
134 | ; | |
135 | ||
136 | line: NEWLINE | |
137 | | command | |
138 | ; | |
139 | ||
140 | ||
141 | newline_or_nada: | |
142 | | NEWLINE newline_or_nada | |
143 | ; | |
144 | ||
145 | command: defaulticon | |
146 | | icondirectory | |
147 | | menu | |
148 | | icons | |
149 | | styles | |
150 | | sysmenu | |
151 | | rootmenu | |
152 | | defaultsysmenu | |
153 | | debug | |
154 | | trayicon | |
155 | | forceexit | |
156 | | silentexit | |
157 | ; | |
158 | ||
159 | trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); } | |
160 | ; | |
161 | ||
162 | rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); } | |
163 | ; | |
164 | ||
165 | defaultsysmenu: DEFAULTSYSMENU STRING atspot NEWLINE { SetDefaultSysMenu($2, $3); free($2); } | |
166 | ; | |
167 | ||
168 | defaulticon: DEFAULTICON STRING NEWLINE { SetDefaultIcon($2); free($2); } | |
169 | ; | |
170 | ||
171 | icondirectory: ICONDIRECTORY STRING NEWLINE { SetIconDirectory($2); free($2); } | |
172 | ; | |
173 | ||
174 | menuline: SEPARATOR NEWLINE newline_or_nada { AddMenuLine("-", CMD_SEPARATOR, ""); } | |
175 | | STRING ALWAYSONTOP NEWLINE newline_or_nada { AddMenuLine($1, CMD_ALWAYSONTOP, ""); free($1); } | |
176 | | STRING EXEC STRING NEWLINE newline_or_nada { AddMenuLine($1, CMD_EXEC, $3); free($1); free($3); } | |
177 | | STRING MENU STRING NEWLINE newline_or_nada { AddMenuLine($1, CMD_MENU, $3); free($1); free($3); } | |
178 | | STRING RELOAD NEWLINE newline_or_nada { AddMenuLine($1, CMD_RELOAD, ""); free($1); } | |
179 | ; | |
180 | ||
181 | menulist: menuline | |
182 | | menuline menulist | |
183 | ; | |
184 | ||
185 | menu: MENU STRING LB { OpenMenu($2); free($2); } newline_or_nada menulist RB {CloseMenu();} | |
186 | ; | |
187 | ||
188 | iconline: STRING STRING NEWLINE newline_or_nada { AddIconLine($1, $2); free($1); free($2); } | |
189 | ; | |
190 | ||
191 | iconlist: iconline | |
192 | | iconline iconlist | |
193 | ; | |
194 | ||
195 | icons: ICONS LB {OpenIcons();} newline_or_nada iconlist RB {CloseIcons();} | |
196 | ; | |
197 | ||
198 | group1: TOPMOST { $$=STYLE_TOPMOST; } | |
199 | | MAXIMIZE { $$=STYLE_MAXIMIZE; } | |
200 | | MINIMIZE { $$=STYLE_MINIMIZE; } | |
201 | | BOTTOM { $$=STYLE_BOTTOM; } | |
202 | ; | |
203 | ||
204 | group2: NOTITLE { $$=STYLE_NOTITLE; } | |
205 | | OUTLINE { $$=STYLE_OUTLINE; } | |
206 | | NOFRAME { $$=STYLE_NOFRAME; } | |
207 | ; | |
208 | ||
209 | stylecombo: group1 { $$=$1; } | |
210 | | group2 { $$=$1; } | |
211 | | group1 group2 { $$=$1|$2; } | |
212 | | group2 group1 { $$=$1|$2; } | |
213 | ; | |
214 | ||
215 | styleline: STRING stylecombo NEWLINE newline_or_nada { AddStyleLine($1, $2); free($1); } | |
216 | ; | |
217 | ||
218 | stylelist: styleline | |
219 | | styleline stylelist | |
220 | ; | |
221 | ||
222 | styles: STYLES LB {OpenStyles();} newline_or_nada stylelist RB {CloseStyles();} | |
223 | ; | |
224 | ||
225 | atspot: { $$=AT_END; } | |
226 | | ATSTART { $$=AT_START; } | |
227 | | ATEND { $$=AT_END; } | |
228 | ; | |
229 | ||
230 | sysmenuline: STRING STRING atspot NEWLINE newline_or_nada { AddSysMenuLine($1, $2, $3); free($1); free($2); } | |
231 | ; | |
232 | ||
233 | sysmenulist: sysmenuline | |
234 | | sysmenuline sysmenulist | |
235 | ; | |
236 | ||
237 | sysmenu: SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();} | |
238 | ; | |
239 | ||
240 | forceexit: FORCEEXIT NEWLINE { pref.fForceExit = TRUE; } | |
241 | ; | |
242 | ||
243 | silentexit: SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; } | |
244 | ; | |
245 | ||
246 | debug: DEBUGOUTPUT STRING NEWLINE { ErrorF("LoadPreferences: %s\n", $2); free($2); } | |
247 | ; | |
248 | ||
249 | ||
250 | %% | |
251 | /* | |
252 | * Errors in parsing abort and print log messages | |
253 | */ | |
254 | static int | |
255 | yyerror (char *s) | |
256 | { | |
257 | extern int yylineno; /* Handled by flex internally */ | |
258 | ||
259 | ErrorF("LoadPreferences: %s line %d\n", s, yylineno); | |
260 | return 1; | |
261 | } | |
262 | ||
263 | /* Miscellaneous functions to store TOKENs into the structure */ | |
264 | static void | |
265 | SetIconDirectory (char *path) | |
266 | { | |
267 | strncpy (pref.iconDirectory, path, PATH_MAX); | |
268 | pref.iconDirectory[PATH_MAX] = 0; | |
269 | } | |
270 | ||
271 | static void | |
272 | SetDefaultIcon (char *fname) | |
273 | { | |
274 | strncpy (pref.defaultIconName, fname, NAME_MAX); | |
275 | pref.defaultIconName[NAME_MAX] = 0; | |
276 | } | |
277 | ||
278 | static void | |
279 | SetTrayIcon (char *fname) | |
280 | { | |
281 | strncpy (pref.trayIconName, fname, NAME_MAX); | |
282 | pref.trayIconName[NAME_MAX] = 0; | |
283 | } | |
284 | ||
285 | static void | |
286 | SetRootMenu (char *menuname) | |
287 | { | |
288 | strncpy (pref.rootMenuName, menuname, MENU_MAX); | |
289 | pref.rootMenuName[MENU_MAX] = 0; | |
290 | } | |
291 | ||
292 | static void | |
293 | SetDefaultSysMenu (char *menuname, int pos) | |
294 | { | |
295 | strncpy (pref.defaultSysMenuName, menuname, MENU_MAX); | |
296 | pref.defaultSysMenuName[MENU_MAX] = 0; | |
297 | pref.defaultSysMenuPos = pos; | |
298 | } | |
299 | ||
300 | static void | |
301 | OpenMenu (char *menuname) | |
302 | { | |
303 | if (menu.menuItem) free(menu.menuItem); | |
304 | menu.menuItem = NULL; | |
305 | strncpy(menu.menuName, menuname, MENU_MAX); | |
306 | menu.menuName[MENU_MAX] = 0; | |
307 | menu.menuItems = 0; | |
308 | } | |
309 | ||
310 | static void | |
311 | AddMenuLine (char *text, MENUCOMMANDTYPE cmd, char *param) | |
312 | { | |
313 | if (menu.menuItem==NULL) | |
314 | menu.menuItem = (MENUITEM*)malloc(sizeof(MENUITEM)); | |
315 | else | |
316 | menu.menuItem = (MENUITEM*) | |
317 | realloc(menu.menuItem, sizeof(MENUITEM)*(menu.menuItems+1)); | |
318 | ||
319 | strncpy (menu.menuItem[menu.menuItems].text, text, MENU_MAX); | |
320 | menu.menuItem[menu.menuItems].text[MENU_MAX] = 0; | |
321 | ||
322 | menu.menuItem[menu.menuItems].cmd = cmd; | |
323 | ||
324 | strncpy(menu.menuItem[menu.menuItems].param, param, PARAM_MAX); | |
325 | menu.menuItem[menu.menuItems].param[PARAM_MAX] = 0; | |
326 | ||
327 | menu.menuItem[menu.menuItems].commandID = 0; | |
328 | ||
329 | menu.menuItems++; | |
330 | } | |
331 | ||
332 | static void | |
333 | CloseMenu (void) | |
334 | { | |
335 | if (menu.menuItem==NULL || menu.menuItems==0) | |
336 | { | |
337 | ErrorF("LoadPreferences: Empty menu detected\n"); | |
338 | return; | |
339 | } | |
340 | ||
341 | if (pref.menuItems) | |
342 | pref.menu = (MENUPARSED*) | |
343 | realloc (pref.menu, (pref.menuItems+1)*sizeof(MENUPARSED)); | |
344 | else | |
345 | pref.menu = (MENUPARSED*)malloc (sizeof(MENUPARSED)); | |
346 | ||
347 | memcpy (pref.menu+pref.menuItems, &menu, sizeof(MENUPARSED)); | |
348 | pref.menuItems++; | |
349 | ||
350 | memset (&menu, 0, sizeof(MENUPARSED)); | |
351 | } | |
352 | ||
353 | static void | |
354 | OpenIcons (void) | |
355 | { | |
356 | if (pref.icon != NULL) { | |
357 | ErrorF("LoadPreferences: Redefining icon mappings\n"); | |
358 | free(pref.icon); | |
359 | pref.icon = NULL; | |
360 | } | |
361 | pref.iconItems = 0; | |
362 | } | |
363 | ||
364 | static void | |
365 | AddIconLine (char *matchstr, char *iconfile) | |
366 | { | |
367 | if (pref.icon==NULL) | |
368 | pref.icon = (ICONITEM*)malloc(sizeof(ICONITEM)); | |
369 | else | |
370 | pref.icon = (ICONITEM*) | |
371 | realloc(pref.icon, sizeof(ICONITEM)*(pref.iconItems+1)); | |
372 | ||
373 | strncpy(pref.icon[pref.iconItems].match, matchstr, MENU_MAX); | |
374 | pref.icon[pref.iconItems].match[MENU_MAX] = 0; | |
375 | ||
376 | strncpy(pref.icon[pref.iconItems].iconFile, iconfile, PATH_MAX+NAME_MAX+1); | |
377 | pref.icon[pref.iconItems].iconFile[PATH_MAX+NAME_MAX+1] = 0; | |
378 | ||
379 | pref.icon[pref.iconItems].hicon = 0; | |
380 | ||
381 | pref.iconItems++; | |
382 | } | |
383 | ||
384 | static void | |
385 | CloseIcons (void) | |
386 | { | |
387 | } | |
388 | ||
389 | static void | |
390 | OpenStyles (void) | |
391 | { | |
392 | if (pref.style != NULL) { | |
393 | ErrorF("LoadPreferences: Redefining window style\n"); | |
394 | free(pref.style); | |
395 | pref.style = NULL; | |
396 | } | |
397 | pref.styleItems = 0; | |
398 | } | |
399 | ||
400 | static void | |
401 | AddStyleLine (char *matchstr, unsigned long style) | |
402 | { | |
403 | if (pref.style==NULL) | |
404 | pref.style = (STYLEITEM*)malloc(sizeof(STYLEITEM)); | |
405 | else | |
406 | pref.style = (STYLEITEM*) | |
407 | realloc(pref.style, sizeof(STYLEITEM)*(pref.styleItems+1)); | |
408 | ||
409 | strncpy(pref.style[pref.styleItems].match, matchstr, MENU_MAX); | |
410 | pref.style[pref.styleItems].match[MENU_MAX] = 0; | |
411 | ||
412 | pref.style[pref.styleItems].type = style; | |
413 | ||
414 | pref.styleItems++; | |
415 | } | |
416 | ||
417 | static void | |
418 | CloseStyles (void) | |
419 | { | |
420 | } | |
421 | ||
422 | static void | |
423 | OpenSysMenu (void) | |
424 | { | |
425 | if (pref.sysMenu != NULL) { | |
426 | ErrorF("LoadPreferences: Redefining system menu\n"); | |
427 | free(pref.sysMenu); | |
428 | pref.sysMenu = NULL; | |
429 | } | |
430 | pref.sysMenuItems = 0; | |
431 | } | |
432 | ||
433 | static void | |
434 | AddSysMenuLine (char *matchstr, char *menuname, int pos) | |
435 | { | |
436 | if (pref.sysMenu==NULL) | |
437 | pref.sysMenu = (SYSMENUITEM*)malloc(sizeof(SYSMENUITEM)); | |
438 | else | |
439 | pref.sysMenu = (SYSMENUITEM*) | |
440 | realloc(pref.sysMenu, sizeof(SYSMENUITEM)*(pref.sysMenuItems+1)); | |
441 | ||
442 | strncpy (pref.sysMenu[pref.sysMenuItems].match, matchstr, MENU_MAX); | |
443 | pref.sysMenu[pref.sysMenuItems].match[MENU_MAX] = 0; | |
444 | ||
445 | strncpy (pref.sysMenu[pref.sysMenuItems].menuName, menuname, MENU_MAX); | |
446 | pref.sysMenu[pref.sysMenuItems].menuName[MENU_MAX] = 0; | |
447 | ||
448 | pref.sysMenu[pref.sysMenuItems].menuPos = pos; | |
449 | ||
450 | pref.sysMenuItems++; | |
451 | } | |
452 | ||
453 | static void | |
454 | CloseSysMenu (void) | |
455 | { | |
456 | } | |
457 |