1 /*
2  * Copyright 2002 Red Hat Inc., Durham, North Carolina.
3  *
4  * All Rights Reserved.
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 on the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial
16  * portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 /*
29  * Authors:
30  *   Rickard E. (Rik) Faith <faith@redhat.com>
31  *
32  */
33 
34 /** \file
35  * Interface to DMX configuration file parser.  \see dmxparse.c */
36 
37 #ifndef _DMXPARSE_H_
38 #define _DMXPARSE_H_
39 
40 #include <stdio.h>              /* For FILE */
41 #include <X11/Xfuncproto.h>     /* For _X_ATTRIBUTE_PRINTF */
42 
43 /** Stores tokens not stored in other structures (e.g., keywords and ;) */
44 typedef struct _DMXConfigToken {
45     int token;
46     int line;
47     const char *comment;
48 } DMXConfigToken, *DMXConfigTokenPtr;
49 
50 /** Stores parsed strings. */
51 typedef struct _DMXConfigString {
52     int token;
53     int line;
54     const char *comment;
55     const char *string;
56     struct _DMXConfigString *next;
57 } DMXConfigString, *DMXConfigStringPtr;
58 
59 /** Stores parsed numbers. */
60 typedef struct _DMXConfigNumber {
61     int token;
62     int line;
63     const char *comment;
64     int number;
65 } DMXConfigNumber, *DMXConfigNumberPtr;
66 
67 /** Stores parsed pairs (e.g., x y) */
68 typedef struct _DMXConfigPair {
69     int token;
70     int line;
71     const char *comment;
72     int x;
73     int y;
74     int xsign;
75     int ysign;
76 } DMXConfigPair, *DMXConfigPairPtr;
77 
78 /** Stores parsed comments not stored with a token. */
79 typedef struct _DMXConfigComment {
80     int token;
81     int line;
82     const char *comment;
83 } DMXConfigComment, *DMXConfigCommentPtr;
84 
85 typedef enum {
86     dmxConfigComment,
87     dmxConfigVirtual,
88     dmxConfigDisplay,
89     dmxConfigWall,
90     dmxConfigOption,
91     dmxConfigParam
92 } DMXConfigType;
93 
94 /** Stores a geometry specification. */
95 typedef struct _DMXConfigPartDim {
96     DMXConfigPairPtr dim;
97     DMXConfigPairPtr offset;
98 } DMXConfigPartDim, *DMXConfigPartDimPtr;
99 
100 /** Stores a pair of geometry specifications. */
101 typedef struct _DMXConfigFullDim {
102     DMXConfigPartDimPtr scrn;
103     DMXConfigPartDimPtr root;
104 } DMXConfigFullDim, *DMXConfigFullDimPtr;
105 
106 /** Stores parsed display information. */
107 typedef struct _DMXConfigDisplay {
108     /* Summary information */
109     const char *name;
110     /* Screen Window Geometry */
111     int scrnWidth, scrnHeight;
112     int scrnX, scrnY;
113     int scrnXSign, scrnYSign;
114     /* Root Window Geometry */
115     int rootWidth, rootHeight;
116     int rootX, rootY;
117     int rootXSign, rootYSign;
118     /* Origin in global space */
119     int rootXOrigin, rootYOrigin;
120 
121     /* Raw configuration information */
122     DMXConfigTokenPtr start;
123     DMXConfigStringPtr dname;
124     DMXConfigFullDimPtr dim;
125     DMXConfigPairPtr origin;
126     DMXConfigTokenPtr end;
127 } DMXConfigDisplay, *DMXConfigDisplayPtr;
128 
129 /** Stores parsed wall information. */
130 typedef struct _DMXConfigWall {
131     /* Summary information */
132     int width, height;          /* dimensions of displays */
133     int xwall, ywall;           /* dimensions of wall, in tiles */
134 
135     /* Raw configuration informaiton */
136     DMXConfigTokenPtr start;
137     DMXConfigPairPtr wallDim;
138     DMXConfigPairPtr displayDim;
139     DMXConfigStringPtr nameList;
140     DMXConfigTokenPtr end;
141 } DMXConfigWall, *DMXConfigWallPtr;
142 
143 /** Stores parsed option information. */
144 typedef struct _DMXConfigOption {
145     /* Summary information */
146     char *string;
147 
148     /* Raw configuration informaiton */
149     DMXConfigTokenPtr start;
150     DMXConfigStringPtr option;
151     DMXConfigTokenPtr end;
152 } DMXConfigOption, *DMXConfigOptionPtr;
153 
154 /** Stores parsed param information. */
155 typedef struct _DMXConfigParam {
156     int argc;
157     const char **argv;
158 
159     DMXConfigTokenPtr start;
160     DMXConfigTokenPtr open;
161     DMXConfigStringPtr param;
162     DMXConfigTokenPtr close;
163     DMXConfigTokenPtr end;      /* Either open/close OR end */
164     struct _DMXConfigParam *next;
165 } DMXConfigParam, *DMXConfigParamPtr;
166 
167 /** Stores options under an entry (subentry). */
168 typedef struct _DMXConfigSub {
169     DMXConfigType type;
170     DMXConfigCommentPtr comment;
171     DMXConfigDisplayPtr display;
172     DMXConfigWallPtr wall;
173     DMXConfigOptionPtr option;
174     DMXConfigParamPtr param;
175     struct _DMXConfigSub *next;
176 } DMXConfigSub, *DMXConfigSubPtr;
177 
178 /** Stores parsed virtual information. */
179 typedef struct _DMXConfigVirtual {
180     /* Summary information */
181     const char *name;
182     int width, height;
183 
184     /* Raw configuration information */
185     DMXConfigTokenPtr start;
186     DMXConfigStringPtr vname;
187     DMXConfigPairPtr dim;
188     DMXConfigTokenPtr open;
189     DMXConfigSubPtr subentry;
190     DMXConfigTokenPtr close;
191 } DMXConfigVirtual, *DMXConfigVirtualPtr;
192 
193 /** Heads entry storage. */
194 typedef struct _DMXConfigEntry {
195     DMXConfigType type;
196     DMXConfigCommentPtr comment;
197     DMXConfigVirtualPtr virtual;
198     struct _DMXConfigEntry *next;
199 } DMXConfigEntry, *DMXConfigEntryPtr;
200 
201 extern DMXConfigEntryPtr dmxConfigEntry;
202 
203 extern void yyerror(const char *message);
204 
205 extern void dmxConfigLog(const char *format, ...) _X_ATTRIBUTE_PRINTF(1,0);
206 extern void *dmxConfigAlloc(unsigned long bytes);
207 extern void *dmxConfigRealloc(void *orig,
208                               unsigned long orig_bytes, unsigned long bytes);
209 extern const char *dmxConfigCopyString(const char *string, int length);
210 extern void dmxConfigFree(void *area);
211 extern DMXConfigTokenPtr dmxConfigCreateToken(int token, int line,
212                                               const char *comment);
213 extern void dmxConfigFreeToken(DMXConfigTokenPtr p);
214 extern DMXConfigStringPtr dmxConfigCreateString(int token, int line,
215                                                 const char *comment,
216                                                 const char *string);
217 extern void dmxConfigFreeString(DMXConfigStringPtr p);
218 extern DMXConfigNumberPtr dmxConfigCreateNumber(int token, int line,
219                                                 const char *comment,
220                                                 int number);
221 extern void dmxConfigFreeNumber(DMXConfigNumberPtr p);
222 extern DMXConfigPairPtr dmxConfigCreatePair(int token, int line,
223                                             const char *comment,
224                                             int x, int y, int xsign, int ysign);
225 extern void dmxConfigFreePair(DMXConfigPairPtr p);
226 extern DMXConfigCommentPtr dmxConfigCreateComment(int token, int line,
227                                                   const char *comment);
228 extern void dmxConfigFreeComment(DMXConfigCommentPtr p);
229 extern DMXConfigPartDimPtr dmxConfigCreatePartDim(DMXConfigPairPtr pDim,
230                                                   DMXConfigPairPtr pOffset);
231 extern void dmxConfigFreePartDim(DMXConfigPartDimPtr p);
232 extern DMXConfigFullDimPtr dmxConfigCreateFullDim(DMXConfigPartDimPtr pScrn,
233                                                   DMXConfigPartDimPtr pRoot);
234 extern void dmxConfigFreeFullDim(DMXConfigFullDimPtr p);
235 extern DMXConfigDisplayPtr dmxConfigCreateDisplay(DMXConfigTokenPtr pStart,
236                                                   DMXConfigStringPtr pName,
237                                                   DMXConfigFullDimPtr pDim,
238                                                   DMXConfigPairPtr pOrigin,
239                                                   DMXConfigTokenPtr pEnd);
240 extern void dmxConfigFreeDisplay(DMXConfigDisplayPtr p);
241 extern DMXConfigWallPtr dmxConfigCreateWall(DMXConfigTokenPtr pStart,
242                                             DMXConfigPairPtr pWallDim,
243                                             DMXConfigPairPtr pDisplayDim,
244                                             DMXConfigStringPtr pNameList,
245                                             DMXConfigTokenPtr pEnd);
246 extern void dmxConfigFreeWall(DMXConfigWallPtr p);
247 extern DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart,
248                                                 DMXConfigStringPtr pOption,
249                                                 DMXConfigTokenPtr pEnd);
250 extern void dmxConfigFreeOption(DMXConfigOptionPtr p);
251 extern DMXConfigParamPtr dmxConfigCreateParam(DMXConfigTokenPtr pStart,
252                                               DMXConfigTokenPtr pOpen,
253                                               DMXConfigStringPtr pParam,
254                                               DMXConfigTokenPtr pClose,
255                                               DMXConfigTokenPtr pEnd);
256 extern void dmxConfigFreeParam(DMXConfigParamPtr p);
257 extern const char **dmxConfigLookupParam(DMXConfigParamPtr p,
258                                          const char *key, int *argc);
259 extern DMXConfigSubPtr dmxConfigCreateSub(DMXConfigType type,
260                                           DMXConfigCommentPtr comment,
261                                           DMXConfigDisplayPtr display,
262                                           DMXConfigWallPtr wall,
263                                           DMXConfigOptionPtr option,
264                                           DMXConfigParamPtr param);
265 extern void dmxConfigFreeSub(DMXConfigSubPtr sub);
266 extern DMXConfigSubPtr dmxConfigSubComment(DMXConfigCommentPtr comment);
267 extern DMXConfigSubPtr dmxConfigSubDisplay(DMXConfigDisplayPtr display);
268 extern DMXConfigSubPtr dmxConfigSubWall(DMXConfigWallPtr wall);
269 extern DMXConfigSubPtr dmxConfigSubOption(DMXConfigOptionPtr option);
270 extern DMXConfigSubPtr dmxConfigSubParam(DMXConfigParamPtr param);
271 extern DMXConfigSubPtr dmxConfigAddSub(DMXConfigSubPtr head,
272                                        DMXConfigSubPtr sub);
273 extern DMXConfigVirtualPtr dmxConfigCreateVirtual(DMXConfigTokenPtr pStart,
274                                                   DMXConfigStringPtr pName,
275                                                   DMXConfigPairPtr pDim,
276                                                   DMXConfigTokenPtr pOpen,
277                                                   DMXConfigSubPtr pSubentry,
278                                                   DMXConfigTokenPtr pClose);
279 extern void dmxConfigFreeVirtual(DMXConfigVirtualPtr virtual);
280 extern DMXConfigEntryPtr dmxConfigCreateEntry(DMXConfigType type,
281                                               DMXConfigCommentPtr comment,
282                                               DMXConfigVirtualPtr virtual);
283 extern void dmxConfigFreeEntry(DMXConfigEntryPtr entry);
284 extern DMXConfigEntryPtr dmxConfigAddEntry(DMXConfigEntryPtr head,
285                                            DMXConfigType type,
286                                            DMXConfigCommentPtr comment,
287                                            DMXConfigVirtualPtr virtual);
288 extern DMXConfigEntryPtr dmxConfigEntryComment(DMXConfigCommentPtr comment);
289 extern DMXConfigEntryPtr dmxConfigEntryVirtual(DMXConfigVirtualPtr virtual);
290 
291 #endif
292