Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xwin / winprefsyacc.y
CommitLineData
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 */
52WINPREFS pref;
53
54/* The working menu */
55static MENUPARSED menu;
56
57/* Functions for parsing the tokens into out structure */
58/* Defined at the end section of this file */
59
60static void SetIconDirectory (char *path);
61static void SetDefaultIcon (char *fname);
62static void SetRootMenu (char *menu);
63static void SetDefaultSysMenu (char *menu, int pos);
64static void SetTrayIcon (char *fname);
65
66static void OpenMenu(char *menuname);
67static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param);
68static void CloseMenu(void);
69
70static void OpenIcons(void);
71static void AddIconLine(char *matchstr, char *iconfile);
72static void CloseIcons(void);
73
74static void OpenStyles(void);
75static void AddStyleLine(char *matchstr, unsigned long style);
76static void CloseStyles(void);
77
78static void OpenSysMenu(void);
79static void AddSysMenuLine(char *matchstr, char *menuname, int pos);
80static void CloseSysMenu(void);
81
82static int yyerror (char *s);
83
84extern char *yytext;
85extern 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
132input: /* empty */
133 | input line
134 ;
135
136line: NEWLINE
137 | command
138 ;
139
140
141newline_or_nada:
142 | NEWLINE newline_or_nada
143 ;
144
145command: 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
159trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); }
160 ;
161
162rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); }
163 ;
164
165defaultsysmenu: DEFAULTSYSMENU STRING atspot NEWLINE { SetDefaultSysMenu($2, $3); free($2); }
166 ;
167
168defaulticon: DEFAULTICON STRING NEWLINE { SetDefaultIcon($2); free($2); }
169 ;
170
171icondirectory: ICONDIRECTORY STRING NEWLINE { SetIconDirectory($2); free($2); }
172 ;
173
174menuline: 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
181menulist: menuline
182 | menuline menulist
183 ;
184
185menu: MENU STRING LB { OpenMenu($2); free($2); } newline_or_nada menulist RB {CloseMenu();}
186 ;
187
188iconline: STRING STRING NEWLINE newline_or_nada { AddIconLine($1, $2); free($1); free($2); }
189 ;
190
191iconlist: iconline
192 | iconline iconlist
193 ;
194
195icons: ICONS LB {OpenIcons();} newline_or_nada iconlist RB {CloseIcons();}
196 ;
197
198group1: TOPMOST { $$=STYLE_TOPMOST; }
199 | MAXIMIZE { $$=STYLE_MAXIMIZE; }
200 | MINIMIZE { $$=STYLE_MINIMIZE; }
201 | BOTTOM { $$=STYLE_BOTTOM; }
202 ;
203
204group2: NOTITLE { $$=STYLE_NOTITLE; }
205 | OUTLINE { $$=STYLE_OUTLINE; }
206 | NOFRAME { $$=STYLE_NOFRAME; }
207 ;
208
209stylecombo: group1 { $$=$1; }
210 | group2 { $$=$1; }
211 | group1 group2 { $$=$1|$2; }
212 | group2 group1 { $$=$1|$2; }
213 ;
214
215styleline: STRING stylecombo NEWLINE newline_or_nada { AddStyleLine($1, $2); free($1); }
216 ;
217
218stylelist: styleline
219 | styleline stylelist
220 ;
221
222styles: STYLES LB {OpenStyles();} newline_or_nada stylelist RB {CloseStyles();}
223 ;
224
225atspot: { $$=AT_END; }
226 | ATSTART { $$=AT_START; }
227 | ATEND { $$=AT_END; }
228 ;
229
230sysmenuline: STRING STRING atspot NEWLINE newline_or_nada { AddSysMenuLine($1, $2, $3); free($1); free($2); }
231 ;
232
233sysmenulist: sysmenuline
234 | sysmenuline sysmenulist
235 ;
236
237sysmenu: SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();}
238 ;
239
240forceexit: FORCEEXIT NEWLINE { pref.fForceExit = TRUE; }
241 ;
242
243silentexit: SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; }
244 ;
245
246debug: 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 */
254static int
255yyerror (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 */
264static void
265SetIconDirectory (char *path)
266{
267 strncpy (pref.iconDirectory, path, PATH_MAX);
268 pref.iconDirectory[PATH_MAX] = 0;
269}
270
271static void
272SetDefaultIcon (char *fname)
273{
274 strncpy (pref.defaultIconName, fname, NAME_MAX);
275 pref.defaultIconName[NAME_MAX] = 0;
276}
277
278static void
279SetTrayIcon (char *fname)
280{
281 strncpy (pref.trayIconName, fname, NAME_MAX);
282 pref.trayIconName[NAME_MAX] = 0;
283}
284
285static void
286SetRootMenu (char *menuname)
287{
288 strncpy (pref.rootMenuName, menuname, MENU_MAX);
289 pref.rootMenuName[MENU_MAX] = 0;
290}
291
292static void
293SetDefaultSysMenu (char *menuname, int pos)
294{
295 strncpy (pref.defaultSysMenuName, menuname, MENU_MAX);
296 pref.defaultSysMenuName[MENU_MAX] = 0;
297 pref.defaultSysMenuPos = pos;
298}
299
300static void
301OpenMenu (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
310static void
311AddMenuLine (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
332static void
333CloseMenu (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
353static void
354OpenIcons (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
364static void
365AddIconLine (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
384static void
385CloseIcons (void)
386{
387}
388
389static void
390OpenStyles (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
400static void
401AddStyleLine (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
417static void
418CloseStyles (void)
419{
420}
421
422static void
423OpenSysMenu (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
433static void
434AddSysMenuLine (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
453static void
454CloseSysMenu (void)
455{
456}
457