1 /*--- cfg_parser.y -------------------------------------------------------------
2 Copyright (C) 2004, 2005, 2006 Sylvain Fourmanoit <syfou@users.sourceforge.net>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to
6 deal in the Software without restriction, including without limitation the
7 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies of the Software and its documentation and acknowledgment shall be
13 given in the documentation and software packages that this Software was
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ------------------------------------------------------------------------------*/
23 /* Configuration file parser (bison)
26 /*----------------------------------------------------------------------------*/
29 #include "cfgfile.h" /* Configuration file
32 int cfglex
(void); /* Scanner exports */
33 extern
int cfg_lineno
;
35 void cfgerror
(char * str
) /* Error message */
38 "Configuration file parsing error `%s', stopped at line %d.\n",
42 int cfgparse_alloc
(void); /* Space allocation */
43 cfgfile_item
* cfg_item
; /* Item reference
46 vector
* cfg_vec
; /* Callback vector */
48 #define CFG_ITEM_ALLOC \
49 if
(!cfg_item
) if
(!cfgparse_alloc
()) {\
50 cfgerror
("memory allocation problem"); \
56 /*----------------------------------------------------------------------------*/
62 %token
<cfg_int
> INTEGER
63 %token
<cfg_char
> APPLET
64 %token ID SCREEN X Y UNKNOWN
66 /*----------------------------------------------------------------------------*/
69 cfgfile: /* empty */ |
75 strncpy
(cfg_item
->applet
,$1,CFGFILE_NAME_SIZE
-1);
76 if
(!vector_push
(cfg_vec
,cfg_item
))
80 | UNKNOWN
{ cfgerror
("unknown token encountered"); YYABORT; }
95 {CFG_ITEM_ALLOC
; cfg_item
->id
=$2;}
97 screen_elem: SCREEN INTEGER
98 {CFG_ITEM_ALLOC
; cfg_item
->scr
=$2;}
102 {CFG_ITEM_ALLOC
; cfg_item
->x
=$2;}
106 {CFG_ITEM_ALLOC
; cfg_item
->y
=$2;}
110 /*----------------------------------------------------------------------------*/
111 /* Instanciate a new item space
116 TRY_CATCH
(cfg_item
= malloc
(sizeof
(cfgfile_item
)));
117 cfg_item
->applet
[0]=0;
122 cfg_item
->no_update
=0;
126 /*----------------------------------------------------------------------------*/
127 /* Initialise external variables used by the parser
130 cfgparse_init
(vector
* vec
)