3 * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
4 * Copyright (C) Colin Harrison 2005-2008
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:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
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.
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.
30 * Authors: Earle F. Philhower, III
35 #ifdef HAVE_XWIN_CONFIG_H
36 #include <xwin-config.h>
40 #define _STDLIB_H 1 /* bison checks this to know if stdlib has been included */
44 /* The following give better error messages in bison at the cost of a few KB */
45 #define YYERROR_VERBOSE 1
47 /* YYLTYPE_IS_TRIVIAL and YYENABLE_NLS defined to suppress warnings */
48 #define YYLTYPE_IS_TRIVIAL 1
49 #define YYENABLE_NLS 0
51 /* The global pref settings */
54 /* The working menu */
55 static MENUPARSED menu;
57 /* Functions for parsing the tokens into out structure */
58 /* Defined at the end section of this file */
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);
66 static void OpenMenu(char *menuname);
67 static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param);
68 static void CloseMenu(void);
70 static void OpenIcons(void);
71 static void AddIconLine(char *matchstr, char *iconfile);
72 static void CloseIcons(void);
74 static void OpenStyles(void);
75 static void AddStyleLine(char *matchstr, unsigned long style);
76 static void CloseStyles(void);
78 static void OpenSysMenu(void);
79 static void AddSysMenuLine(char *matchstr, char *menuname, int pos);
80 static void CloseSysMenu(void);
82 static int yyerror (char *s);
85 extern int yylex(void);
110 %token DEFAULTSYSMENU
118 %token DEBUGOUTPUT "DEBUG"
127 %type <uVal> stylecombo
142 | NEWLINE newline_or_nada
159 trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); }
162 rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); }
165 defaultsysmenu: DEFAULTSYSMENU STRING atspot NEWLINE { SetDefaultSysMenu($2, $3); free($2); }
168 defaulticon: DEFAULTICON STRING NEWLINE { SetDefaultIcon($2); free($2); }
171 icondirectory: ICONDIRECTORY STRING NEWLINE { SetIconDirectory($2); free($2); }
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); }
185 menu: MENU STRING LB { OpenMenu($2); free($2); } newline_or_nada menulist RB {CloseMenu();}
188 iconline: STRING STRING NEWLINE newline_or_nada { AddIconLine($1, $2); free($1); free($2); }
195 icons: ICONS LB {OpenIcons();} newline_or_nada iconlist RB {CloseIcons();}
198 group1: TOPMOST { $$=STYLE_TOPMOST; }
199 | MAXIMIZE { $$=STYLE_MAXIMIZE; }
200 | MINIMIZE { $$=STYLE_MINIMIZE; }
201 | BOTTOM { $$=STYLE_BOTTOM; }
204 group2: NOTITLE { $$=STYLE_NOTITLE; }
205 | OUTLINE { $$=STYLE_OUTLINE; }
206 | NOFRAME { $$=STYLE_NOFRAME; }
209 stylecombo: group1 { $$=$1; }
211 | group1 group2 { $$=$1|$2; }
212 | group2 group1 { $$=$1|$2; }
215 styleline: STRING stylecombo NEWLINE newline_or_nada { AddStyleLine($1, $2); free($1); }
219 | styleline stylelist
222 styles: STYLES LB {OpenStyles();} newline_or_nada stylelist RB {CloseStyles();}
225 atspot: { $$=AT_END; }
226 | ATSTART { $$=AT_START; }
227 | ATEND { $$=AT_END; }
230 sysmenuline: STRING STRING atspot NEWLINE newline_or_nada { AddSysMenuLine($1, $2, $3); free($1); free($2); }
233 sysmenulist: sysmenuline
234 | sysmenuline sysmenulist
237 sysmenu: SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();}
240 forceexit: FORCEEXIT NEWLINE { pref.fForceExit = TRUE; }
243 silentexit: SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; }
246 debug: DEBUGOUTPUT STRING NEWLINE { ErrorF("LoadPreferences: %s\n", $2); free($2); }
252 * Errors in parsing abort and print log messages
257 extern int yylineno; /* Handled by flex internally */
259 ErrorF("LoadPreferences: %s line %d\n", s, yylineno);
263 /* Miscellaneous functions to store TOKENs into the structure */
265 SetIconDirectory (char *path)
267 strncpy (pref.iconDirectory, path, PATH_MAX);
268 pref.iconDirectory[PATH_MAX] = 0;
272 SetDefaultIcon (char *fname)
274 strncpy (pref.defaultIconName, fname, NAME_MAX);
275 pref.defaultIconName[NAME_MAX] = 0;
279 SetTrayIcon (char *fname)
281 strncpy (pref.trayIconName, fname, NAME_MAX);
282 pref.trayIconName[NAME_MAX] = 0;
286 SetRootMenu (char *menuname)
288 strncpy (pref.rootMenuName, menuname, MENU_MAX);
289 pref.rootMenuName[MENU_MAX] = 0;
293 SetDefaultSysMenu (char *menuname, int pos)
295 strncpy (pref.defaultSysMenuName, menuname, MENU_MAX);
296 pref.defaultSysMenuName[MENU_MAX] = 0;
297 pref.defaultSysMenuPos = pos;
301 OpenMenu (char *menuname)
303 if (menu.menuItem) free(menu.menuItem);
304 menu.menuItem = NULL;
305 strncpy(menu.menuName, menuname, MENU_MAX);
306 menu.menuName[MENU_MAX] = 0;
311 AddMenuLine (char *text, MENUCOMMANDTYPE cmd, char *param)
313 if (menu.menuItem==NULL)
314 menu.menuItem = (MENUITEM*)malloc(sizeof(MENUITEM));
316 menu.menuItem = (MENUITEM*)
317 realloc(menu.menuItem, sizeof(MENUITEM)*(menu.menuItems+1));
319 strncpy (menu.menuItem[menu.menuItems].text, text, MENU_MAX);
320 menu.menuItem[menu.menuItems].text[MENU_MAX] = 0;
322 menu.menuItem[menu.menuItems].cmd = cmd;
324 strncpy(menu.menuItem[menu.menuItems].param, param, PARAM_MAX);
325 menu.menuItem[menu.menuItems].param[PARAM_MAX] = 0;
327 menu.menuItem[menu.menuItems].commandID = 0;
335 if (menu.menuItem==NULL || menu.menuItems==0)
337 ErrorF("LoadPreferences: Empty menu detected\n");
342 pref.menu = (MENUPARSED*)
343 realloc (pref.menu, (pref.menuItems+1)*sizeof(MENUPARSED));
345 pref.menu = (MENUPARSED*)malloc (sizeof(MENUPARSED));
347 memcpy (pref.menu+pref.menuItems, &menu, sizeof(MENUPARSED));
350 memset (&menu, 0, sizeof(MENUPARSED));
356 if (pref.icon != NULL) {
357 ErrorF("LoadPreferences: Redefining icon mappings\n");
365 AddIconLine (char *matchstr, char *iconfile)
368 pref.icon = (ICONITEM*)malloc(sizeof(ICONITEM));
370 pref.icon = (ICONITEM*)
371 realloc(pref.icon, sizeof(ICONITEM)*(pref.iconItems+1));
373 strncpy(pref.icon[pref.iconItems].match, matchstr, MENU_MAX);
374 pref.icon[pref.iconItems].match[MENU_MAX] = 0;
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;
379 pref.icon[pref.iconItems].hicon = 0;
392 if (pref.style != NULL) {
393 ErrorF("LoadPreferences: Redefining window style\n");
401 AddStyleLine (char *matchstr, unsigned long style)
403 if (pref.style==NULL)
404 pref.style = (STYLEITEM*)malloc(sizeof(STYLEITEM));
406 pref.style = (STYLEITEM*)
407 realloc(pref.style, sizeof(STYLEITEM)*(pref.styleItems+1));
409 strncpy(pref.style[pref.styleItems].match, matchstr, MENU_MAX);
410 pref.style[pref.styleItems].match[MENU_MAX] = 0;
412 pref.style[pref.styleItems].type = style;
425 if (pref.sysMenu != NULL) {
426 ErrorF("LoadPreferences: Redefining system menu\n");
430 pref.sysMenuItems = 0;
434 AddSysMenuLine (char *matchstr, char *menuname, int pos)
436 if (pref.sysMenu==NULL)
437 pref.sysMenu = (SYSMENUITEM*)malloc(sizeof(SYSMENUITEM));
439 pref.sysMenu = (SYSMENUITEM*)
440 realloc(pref.sysMenu, sizeof(SYSMENUITEM)*(pref.sysMenuItems+1));
442 strncpy (pref.sysMenu[pref.sysMenuItems].match, matchstr, MENU_MAX);
443 pref.sysMenu[pref.sysMenuItems].match[MENU_MAX] = 0;
445 strncpy (pref.sysMenu[pref.sysMenuItems].menuName, menuname, MENU_MAX);
446 pref.sysMenu[pref.sysMenuItems].menuName[MENU_MAX] = 0;
448 pref.sysMenu[pref.sysMenuItems].menuPos = pos;