xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

winprefsyacc.y (10722B)


      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(const char *name, MENUCOMMANDTYPE cmd, const 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 (const char *s);
     83 
     84 extern char *yytext;
     85 extern int yylineno;
     86 extern int yylex(void);
     87 
     88 %}
     89 
     90 %union {
     91   char *sVal;
     92   unsigned long uVal;
     93   int iVal;
     94 }
     95 
     96 %token NEWLINE
     97 %token MENU
     98 %token LB
     99 %token RB
    100 %token ICONDIRECTORY
    101 %token DEFAULTICON
    102 %token ICONS
    103 %token STYLES
    104 %token TOPMOST
    105 %token MAXIMIZE
    106 %token MINIMIZE
    107 %token BOTTOM
    108 %token NOTITLE
    109 %token OUTLINE
    110 %token NOFRAME
    111 %token DEFAULTSYSMENU
    112 %token SYSMENU
    113 %token ROOTMENU
    114 %token SEPARATOR
    115 %token ATSTART
    116 %token ATEND
    117 %token EXEC
    118 %token ALWAYSONTOP
    119 %token DEBUGOUTPUT "DEBUG"
    120 %token RELOAD
    121 %token TRAYICON
    122 %token FORCEEXIT
    123 %token SILENTEXIT
    124 
    125 %token <sVal> STRING
    126 %type <uVal>  group1
    127 %type <uVal>  group2
    128 %type <uVal>  stylecombo
    129 %type <iVal>  atspot
    130 
    131 %%
    132 
    133 input:	/* empty */
    134 	| input line
    135 	;
    136 
    137 line:	NEWLINE
    138 	| command
    139 	;
    140 
    141 
    142 newline_or_nada:	
    143 	| NEWLINE newline_or_nada
    144 	;
    145 
    146 command:	defaulticon
    147 	| icondirectory
    148 	| menu
    149 	| icons
    150 	| styles
    151 	| sysmenu
    152 	| rootmenu
    153 	| defaultsysmenu
    154 	| debug
    155 	| trayicon
    156 	| forceexit
    157 	| silentexit
    158 	;
    159 
    160 trayicon:	TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); }
    161 	;
    162 
    163 rootmenu:	ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); }
    164 	;
    165 
    166 defaultsysmenu:	DEFAULTSYSMENU STRING atspot NEWLINE { SetDefaultSysMenu($2, $3); free($2); }
    167 	;
    168 
    169 defaulticon:	DEFAULTICON STRING NEWLINE { SetDefaultIcon($2); free($2); }
    170 	;
    171 
    172 icondirectory:	ICONDIRECTORY STRING NEWLINE { SetIconDirectory($2); free($2); }
    173 	;
    174 
    175 menuline:	SEPARATOR NEWLINE newline_or_nada  { AddMenuLine("-", CMD_SEPARATOR, ""); }
    176 	| STRING ALWAYSONTOP NEWLINE newline_or_nada  { AddMenuLine($1, CMD_ALWAYSONTOP, ""); free($1); }
    177 	| STRING EXEC STRING NEWLINE newline_or_nada  { AddMenuLine($1, CMD_EXEC, $3); free($1); free($3); }
    178 	| STRING MENU STRING NEWLINE newline_or_nada  { AddMenuLine($1, CMD_MENU, $3); free($1); free($3); }
    179 	| STRING RELOAD NEWLINE newline_or_nada  { AddMenuLine($1, CMD_RELOAD, ""); free($1); }
    180 	;
    181 
    182 menulist:	menuline
    183 	| menuline menulist
    184 	;
    185 
    186 menu:	MENU STRING LB { OpenMenu($2); free($2); } newline_or_nada menulist RB {CloseMenu();}
    187 	;
    188 
    189 iconline:	STRING STRING NEWLINE newline_or_nada { AddIconLine($1, $2); free($1); free($2); }
    190 	;
    191 
    192 iconlist:	iconline
    193 	| iconline iconlist
    194 	;
    195 
    196 icons:	ICONS LB {OpenIcons();} newline_or_nada iconlist RB {CloseIcons();}
    197 	;
    198 
    199 group1:	TOPMOST { $$=STYLE_TOPMOST; }
    200 	| MAXIMIZE { $$=STYLE_MAXIMIZE; }
    201 	| MINIMIZE { $$=STYLE_MINIMIZE; }
    202 	| BOTTOM { $$=STYLE_BOTTOM; }
    203 	;
    204 
    205 group2:	NOTITLE { $$=STYLE_NOTITLE; }
    206 	| OUTLINE { $$=STYLE_OUTLINE; }
    207 	| NOFRAME { $$=STYLE_NOFRAME; }
    208 	;
    209 
    210 stylecombo:	group1 { $$=$1; }
    211 	| group2 { $$=$1; }
    212 	| group1 group2 { $$=$1|$2; }
    213 	| group2 group1 { $$=$1|$2; }
    214 	;
    215 
    216 styleline:	STRING stylecombo NEWLINE newline_or_nada { AddStyleLine($1, $2); free($1); }
    217 	;
    218 
    219 stylelist:	styleline
    220 	| styleline stylelist
    221 	;
    222 
    223 styles:	STYLES LB {OpenStyles();} newline_or_nada stylelist RB {CloseStyles();}
    224 	;
    225 
    226 atspot:	{ $$=AT_END; }
    227 	| ATSTART { $$=AT_START; }
    228 	| ATEND { $$=AT_END; }
    229 	;
    230 
    231 sysmenuline:	STRING STRING atspot NEWLINE newline_or_nada { AddSysMenuLine($1, $2, $3); free($1); free($2); }
    232 	;
    233 
    234 sysmenulist:	sysmenuline
    235 	| sysmenuline sysmenulist
    236 	;
    237 
    238 sysmenu:	SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();}
    239 	;
    240 
    241 forceexit:	FORCEEXIT NEWLINE { pref.fForceExit = TRUE; }
    242 	;
    243 
    244 silentexit:	SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; }
    245 	;
    246 
    247 debug: 	DEBUGOUTPUT STRING NEWLINE { ErrorF("LoadPreferences: %s\n", $2); free($2); }
    248 	;
    249 
    250 
    251 %%
    252 /*
    253  * Errors in parsing abort and print log messages
    254  */
    255 static int
    256 yyerror (const char *s)
    257 {
    258   ErrorF("LoadPreferences: %s line %d\n", s, yylineno);
    259   return 1;
    260 }
    261 
    262 /* Miscellaneous functions to store TOKENs into the structure */
    263 static void
    264 SetIconDirectory (char *path)
    265 {
    266   strncpy (pref.iconDirectory, path, PATH_MAX);
    267   pref.iconDirectory[PATH_MAX] = 0;
    268 }
    269 
    270 static void
    271 SetDefaultIcon (char *fname)
    272 {
    273   strncpy (pref.defaultIconName, fname, NAME_MAX);
    274   pref.defaultIconName[NAME_MAX] = 0;
    275 }
    276 
    277 static void
    278 SetTrayIcon (char *fname)
    279 {
    280   strncpy (pref.trayIconName, fname, NAME_MAX);
    281   pref.trayIconName[NAME_MAX] = 0;
    282 }
    283 
    284 static void
    285 SetRootMenu (char *menuname)
    286 {
    287   strncpy (pref.rootMenuName, menuname, MENU_MAX);
    288   pref.rootMenuName[MENU_MAX] = 0;
    289 }
    290 
    291 static void
    292 SetDefaultSysMenu (char *menuname, int pos)
    293 {
    294   strncpy (pref.defaultSysMenuName, menuname, MENU_MAX);
    295   pref.defaultSysMenuName[MENU_MAX] = 0;
    296   pref.defaultSysMenuPos = pos;
    297 }
    298 
    299 static void
    300 OpenMenu (char *menuname)
    301 {
    302   if (menu.menuItem) free(menu.menuItem);
    303   menu.menuItem = NULL;
    304   strncpy(menu.menuName, menuname, MENU_MAX);
    305   menu.menuName[MENU_MAX] = 0;
    306   menu.menuItems = 0;
    307 }
    308 
    309 static void
    310 AddMenuLine (const char *text, MENUCOMMANDTYPE cmd, const char *param)
    311 {
    312   if (menu.menuItem==NULL)
    313     menu.menuItem = malloc(sizeof(MENUITEM));
    314   else
    315     menu.menuItem = realloc(menu.menuItem, sizeof(MENUITEM)*(menu.menuItems+1));
    316 
    317   strncpy (menu.menuItem[menu.menuItems].text, text, MENU_MAX);
    318   menu.menuItem[menu.menuItems].text[MENU_MAX] = 0;
    319 
    320   menu.menuItem[menu.menuItems].cmd = cmd;
    321 
    322   strncpy(menu.menuItem[menu.menuItems].param, param, PARAM_MAX);
    323   menu.menuItem[menu.menuItems].param[PARAM_MAX] = 0;
    324 
    325   menu.menuItem[menu.menuItems].commandID = 0;
    326 
    327   menu.menuItems++;
    328 }
    329 
    330 static void
    331 CloseMenu (void)
    332 {
    333   if (menu.menuItem==NULL || menu.menuItems==0)
    334     {
    335       ErrorF("LoadPreferences: Empty menu detected\n");
    336       return;
    337     }
    338   
    339   if (pref.menuItems)
    340     pref.menu = realloc (pref.menu, (pref.menuItems+1)*sizeof(MENUPARSED));
    341   else
    342     pref.menu = malloc (sizeof(MENUPARSED));
    343   
    344   memcpy (pref.menu+pref.menuItems, &menu, sizeof(MENUPARSED));
    345   pref.menuItems++;
    346 
    347   memset (&menu, 0, sizeof(MENUPARSED));
    348 }
    349 
    350 static void 
    351 OpenIcons (void)
    352 {
    353   if (pref.icon != NULL) {
    354     ErrorF("LoadPreferences: Redefining icon mappings\n");
    355     free(pref.icon);
    356     pref.icon = NULL;
    357   }
    358   pref.iconItems = 0;
    359 }
    360 
    361 static void
    362 AddIconLine (char *matchstr, char *iconfile)
    363 {
    364   if (pref.icon==NULL)
    365     pref.icon = malloc(sizeof(ICONITEM));
    366   else
    367     pref.icon = realloc(pref.icon, sizeof(ICONITEM)*(pref.iconItems+1));
    368 
    369   strncpy(pref.icon[pref.iconItems].match, matchstr, MENU_MAX);
    370   pref.icon[pref.iconItems].match[MENU_MAX] = 0;
    371 
    372   strncpy(pref.icon[pref.iconItems].iconFile, iconfile, PATH_MAX+NAME_MAX+1);
    373   pref.icon[pref.iconItems].iconFile[PATH_MAX+NAME_MAX+1] = 0;
    374 
    375   pref.icon[pref.iconItems].hicon = 0;
    376 
    377   pref.iconItems++;
    378 }
    379 
    380 static void 
    381 CloseIcons (void)
    382 {
    383 }
    384 
    385 static void
    386 OpenStyles (void)
    387 {
    388   if (pref.style != NULL) {
    389     ErrorF("LoadPreferences: Redefining window style\n");
    390     free(pref.style);
    391     pref.style = NULL;
    392   }
    393   pref.styleItems = 0;
    394 }
    395 
    396 static void
    397 AddStyleLine (char *matchstr, unsigned long style)
    398 {
    399   if (pref.style==NULL)
    400     pref.style = malloc(sizeof(STYLEITEM));
    401   else
    402     pref.style = realloc(pref.style, sizeof(STYLEITEM)*(pref.styleItems+1));
    403 
    404   strncpy(pref.style[pref.styleItems].match, matchstr, MENU_MAX);
    405   pref.style[pref.styleItems].match[MENU_MAX] = 0;
    406 
    407   pref.style[pref.styleItems].type = style;
    408 
    409   pref.styleItems++;
    410 }
    411 
    412 static void
    413 CloseStyles (void)
    414 {
    415 }
    416 
    417 static void
    418 OpenSysMenu (void)
    419 {
    420   if (pref.sysMenu != NULL) {
    421     ErrorF("LoadPreferences: Redefining system menu\n");
    422     free(pref.sysMenu);
    423     pref.sysMenu = NULL;
    424   }
    425   pref.sysMenuItems = 0;
    426 }
    427 
    428 static void
    429 AddSysMenuLine (char *matchstr, char *menuname, int pos)
    430 {
    431   if (pref.sysMenu==NULL)
    432     pref.sysMenu = malloc(sizeof(SYSMENUITEM));
    433   else
    434     pref.sysMenu = realloc(pref.sysMenu, sizeof(SYSMENUITEM)*(pref.sysMenuItems+1));
    435 
    436   strncpy (pref.sysMenu[pref.sysMenuItems].match, matchstr, MENU_MAX);
    437   pref.sysMenu[pref.sysMenuItems].match[MENU_MAX] = 0;
    438 
    439   strncpy (pref.sysMenu[pref.sysMenuItems].menuName, menuname, MENU_MAX);
    440   pref.sysMenu[pref.sysMenuItems].menuName[MENU_MAX] = 0;
    441 
    442   pref.sysMenu[pref.sysMenuItems].menuPos = pos;
    443 
    444   pref.sysMenuItems++;
    445 }
    446 
    447 static void
    448 CloseSysMenu (void)
    449 {
    450 }
    451