site: add a screenshot by Thibault Moriau
[adesklets.git] / src / cfg_parser.y
blob1dee37e342eab03a9981c4de476707bbf74e474a
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
14 used.
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
30 routines */
32 int cfglex(void); /* Scanner exports */
33 extern int cfg_lineno;
35 void cfgerror(char * str) /* Error message */
37 fprintf(stderr,
38 "Configuration file parsing error `%s', stopped at line %d.\n",
39 str, cfg_lineno);
42 int cfgparse_alloc(void); /* Space allocation */
43 cfgfile_item * cfg_item; /* Item reference
44 to be pushed back
45 on vector */
46 vector * cfg_vec; /* Callback vector */
48 #define CFG_ITEM_ALLOC \
49 if(!cfg_item) if (!cfgparse_alloc()) {\
50 cfgerror("memory allocation problem"); \
51 YYABORT; \
56 /*----------------------------------------------------------------------------*/
57 %union {
58 int cfg_int;
59 char cfg_char[256];
62 %token <cfg_int> INTEGER
63 %token <cfg_char> APPLET
64 %token ID SCREEN X Y UNKNOWN
66 /*----------------------------------------------------------------------------*/
69 cfgfile: /* empty */ |
70 cfgfile item
73 item: APPLET body
75 strncpy(cfg_item->applet,$1,CFGFILE_NAME_SIZE-1);
76 if (!vector_push(cfg_vec,cfg_item))
77 YYABORT;
78 cfg_item=NULL;
80 | UNKNOWN { cfgerror("unknown token encountered"); YYABORT; }
83 body: body_elem |
84 body body_elem
87 body_elem:
88 id_elem |
89 screen_elem |
90 x_elem |
91 y_elem
94 id_elem: ID INTEGER
95 {CFG_ITEM_ALLOC; cfg_item->id=$2;}
97 screen_elem: SCREEN INTEGER
98 {CFG_ITEM_ALLOC; cfg_item->scr=$2;}
101 x_elem: X INTEGER
102 {CFG_ITEM_ALLOC; cfg_item->x=$2;}
105 y_elem: Y INTEGER
106 {CFG_ITEM_ALLOC; cfg_item->y=$2;}
110 /*----------------------------------------------------------------------------*/
111 /* Instanciate a new item space
114 cfgparse_alloc()
116 TRY_CATCH(cfg_item = malloc(sizeof(cfgfile_item)));
117 cfg_item->applet[0]=0;
118 cfg_item->id=0;
119 cfg_item->scr=0;
120 cfg_item->x=0;
121 cfg_item->y=0;
122 cfg_item->no_update=0;
123 return 1;
126 /*----------------------------------------------------------------------------*/
127 /* Initialise external variables used by the parser
129 int
130 cfgparse_init(vector * vec)
132 if (vec)
133 cfg_vec=vec;
134 cfg_item=NULL;
135 return vec!=NULL;