1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: CDDL 1.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
---|
6 | * this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at http://www.sun.com/cddl/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is "NOM" Netlabs Object Model
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2007
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | *
|
---|
23 | * Alternatively, the contents of this file may be used under the terms of
|
---|
24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
---|
25 | * case the provisions of the LGPL are applicable instead of those above. If
|
---|
26 | * you wish to allow use of your version of this file only under the terms of
|
---|
27 | * the LGPL, and not to allow others to use your version of this file under
|
---|
28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
---|
29 | * above and replace them with the notice and other provisions required by the
|
---|
30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
---|
31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
---|
32 | *
|
---|
33 | * ***** END LICENSE BLOCK ***** */
|
---|
34 | #define INCL_DOSPROCESS
|
---|
35 | #define INCL_DOS
|
---|
36 | #define INCL_DOSPROFILE
|
---|
37 | #define INCL_DOSERRORS
|
---|
38 |
|
---|
39 | #include <os2.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <string.h>
|
---|
43 |
|
---|
44 | #include <io.h>
|
---|
45 | #include <fcntl.h>
|
---|
46 | #include <sys\stat.h>
|
---|
47 |
|
---|
48 | #include <glib.h>
|
---|
49 | #include <glib/gprintf.h>
|
---|
50 |
|
---|
51 | #include "nom.h"
|
---|
52 | #include "nomtk.h"
|
---|
53 |
|
---|
54 | #include "parser.h"
|
---|
55 |
|
---|
56 | /* The pointer array holding the interfaces we found */
|
---|
57 | GPtrArray* pInterfaceArray;
|
---|
58 |
|
---|
59 | /* Symbols defined for our IDL language.
|
---|
60 | Keep this in synch with the defined enums! */
|
---|
61 | const SYMBOL idlSymbols[]={
|
---|
62 | {"interface", IDL_SYMBOL_INTERFACE, KIND_UNKNOWN}, /* 71 */
|
---|
63 | {"NOMCLASSVERSION", IDL_SYMBOL_CLSVERSION, KIND_UNKNOWN},
|
---|
64 | {"NOMINSTANCEVAR", IDL_SYMBOL_INSTANCEVAR, KIND_UNKNOWN},
|
---|
65 | {"NOMOVERRIDE", IDL_SYMBOL_OVERRIDE, KIND_UNKNOWN},
|
---|
66 | {"gulong", IDL_SYMBOL_GULONG, KIND_TYPESPEC},
|
---|
67 | {"gint", IDL_SYMBOL_GINT, KIND_TYPESPEC},
|
---|
68 | {"gpointer", IDL_SYMBOL_GPOINTER, KIND_TYPESPEC},
|
---|
69 | {"gboolean", IDL_SYMBOL_GBOOLEAN, KIND_TYPESPEC},
|
---|
70 | {"in", IDL_SYMBOL_IN, KIND_DIRECTION},
|
---|
71 | {"out", IDL_SYMBOL_OUT, KIND_DIRECTION},
|
---|
72 | {"inout", IDL_SYMBOL_INOUT, KIND_DIRECTION},
|
---|
73 | {"define", IDL_SYMBOL_DEFINE, KIND_UNKNOWN},
|
---|
74 | {"ifdef", IDL_SYMBOL_IFDEF, KIND_UNKNOWN},
|
---|
75 | {"endif", IDL_SYMBOL_ENDIF, KIND_UNKNOWN},
|
---|
76 | {NULL, 0, KIND_UNKNOWN}
|
---|
77 | },*pSymbols=idlSymbols;
|
---|
78 |
|
---|
79 | GScanner *gScanner;
|
---|
80 | GTokenType curToken=G_TOKEN_EOF;
|
---|
81 | PINTERFACE pCurInterface=NULL;
|
---|
82 |
|
---|
83 | /* Holding info about current token. Referenced by gScanner. */
|
---|
84 | SYMBOLINFO curSymbol;
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | /*
|
---|
90 | Parse the class version. Note that the identifier is the current symbol..
|
---|
91 |
|
---|
92 | OM:= IDL_SYMBOL_OVERRIDE '(' IDENT ')' ';'
|
---|
93 | */
|
---|
94 | void parseOverrideMethod(void)
|
---|
95 | {
|
---|
96 | GTokenValue value;
|
---|
97 | POVERMETHOD pOMethod=g_malloc0(sizeof(OVERMETHOD));
|
---|
98 |
|
---|
99 | if(!matchNext('('))
|
---|
100 | {
|
---|
101 | getNextToken(); /* Make sure error references the correct token */
|
---|
102 | g_scanner_unexp_token(gScanner,
|
---|
103 | '(',
|
---|
104 | NULL,
|
---|
105 | NULL,
|
---|
106 | NULL,
|
---|
107 | "Error in NOMOVERRIDE()",
|
---|
108 | TRUE); /* is_error */
|
---|
109 | exit(1);
|
---|
110 | }
|
---|
111 |
|
---|
112 | if(!matchNext(G_TOKEN_IDENTIFIER))
|
---|
113 | {
|
---|
114 | getNextToken(); /* Make sure error references the correct token */
|
---|
115 | g_scanner_unexp_token(gScanner,
|
---|
116 | G_TOKEN_IDENTIFIER,
|
---|
117 | NULL,
|
---|
118 | NULL,
|
---|
119 | NULL,
|
---|
120 | "Error in NOMOVERRIDE()",
|
---|
121 | TRUE); /* is_error */
|
---|
122 | exit(1);
|
---|
123 | }
|
---|
124 | value=gScanner->value;
|
---|
125 | pOMethod->chrName=g_strdup(value.v_identifier);
|
---|
126 |
|
---|
127 | if(!matchNext(')'))
|
---|
128 | {
|
---|
129 | getNextToken(); /* Make sure error references the correct token */
|
---|
130 | g_scanner_unexp_token(gScanner,
|
---|
131 | ')',
|
---|
132 | NULL,
|
---|
133 | NULL,
|
---|
134 | NULL,
|
---|
135 | "Error in NOMOVERRIDE()",
|
---|
136 | TRUE); /* is_error */
|
---|
137 | exit(1);
|
---|
138 | }
|
---|
139 | if(!matchNext(';'))
|
---|
140 | {
|
---|
141 | getNextToken(); /* Make sure error references the correct token */
|
---|
142 | g_scanner_unexp_token(gScanner,
|
---|
143 | ';',
|
---|
144 | NULL,
|
---|
145 | NULL,
|
---|
146 | NULL,
|
---|
147 | "Error in NOMOVERRIDE()",
|
---|
148 | TRUE); /* is_error */
|
---|
149 | exit(1);
|
---|
150 | }
|
---|
151 | g_ptr_array_add(pCurInterface->pOverrideArray, (gpointer) pOMethod);
|
---|
152 | }
|
---|
153 |
|
---|
154 | gchar* getTypeSpecStringFromCurToken(void)
|
---|
155 | {
|
---|
156 | GTokenValue value;
|
---|
157 |
|
---|
158 | if(G_TOKEN_IDENTIFIER==curToken)
|
---|
159 | return g_strdup(value.v_identifier);
|
---|
160 | else
|
---|
161 | {
|
---|
162 | /* It's one of our symbols. */
|
---|
163 | PSYMBOLINFO psi;
|
---|
164 |
|
---|
165 | if(curToken<=G_TOKEN_LAST)
|
---|
166 | g_scanner_unexp_token(gScanner,
|
---|
167 | G_TOKEN_SYMBOL,
|
---|
168 | NULL,
|
---|
169 | NULL,
|
---|
170 | NULL,
|
---|
171 | "Error in NOMINSTANCEVAR()",
|
---|
172 | TRUE); /* is_error */
|
---|
173 |
|
---|
174 | psi=(PSYMBOLINFO)gScanner->user_data;
|
---|
175 | return psi->pSymbols[curToken-G_TOKEN_LAST-1].chrSymbolName;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 |
|
---|
184 | /*
|
---|
185 | Main entry point. This function is called from the EMX wrapper. Be aware that gtk_init()
|
---|
186 | is already called in the wrapper.
|
---|
187 | */
|
---|
188 | int main(int argc, char **argv)
|
---|
189 | {
|
---|
190 | int a;
|
---|
191 | int fd;
|
---|
192 |
|
---|
193 | int idScope=0;
|
---|
194 |
|
---|
195 | if(argc<2)
|
---|
196 | return 1;
|
---|
197 |
|
---|
198 | for(a=0; a<argc; a++)
|
---|
199 | {
|
---|
200 | g_message("arg %d: %s", a, argv[a]);
|
---|
201 | }
|
---|
202 |
|
---|
203 | fd=open(argv[1], O_RDONLY);
|
---|
204 |
|
---|
205 | if(-1==fd)
|
---|
206 | {
|
---|
207 | g_message("Can't open input file %s", argv[1]);
|
---|
208 | exit(1);
|
---|
209 | }
|
---|
210 |
|
---|
211 | g_printf("\n");
|
---|
212 |
|
---|
213 | gScanner=g_scanner_new(NULL);
|
---|
214 | gScanner->user_data=(gpointer)&curSymbol;
|
---|
215 | curSymbol.pSymbols=idlSymbols;
|
---|
216 |
|
---|
217 | pInterfaceArray=g_ptr_array_new();
|
---|
218 |
|
---|
219 | g_scanner_input_file(gScanner, fd);
|
---|
220 | /* No single line comments */
|
---|
221 | gScanner->config->skip_comment_single=FALSE;
|
---|
222 | gScanner->config->cpair_comment_single="";
|
---|
223 | gScanner->input_name=IDL_COMPILER_STRING;
|
---|
224 |
|
---|
225 | g_scanner_set_scope(gScanner, idScope);
|
---|
226 | /* Load our own symbols into the scanner. We use the defualt scope for now. */
|
---|
227 | while(pSymbols->chrSymbolName)
|
---|
228 | {
|
---|
229 | g_scanner_scope_add_symbol(gScanner, idScope, pSymbols->chrSymbolName, GINT_TO_POINTER(pSymbols->uiSymbolToken));
|
---|
230 | pSymbols++;
|
---|
231 | }
|
---|
232 | gScanner->config->symbol_2_token=TRUE;
|
---|
233 |
|
---|
234 | while(g_scanner_peek_next_token(gScanner) != G_TOKEN_EOF) {
|
---|
235 | /* get the next token */
|
---|
236 | GTokenType token;
|
---|
237 | curToken=g_scanner_get_next_token(gScanner);
|
---|
238 | token=curToken;
|
---|
239 | GTokenValue value=gScanner->value;
|
---|
240 |
|
---|
241 | switch(curToken)
|
---|
242 | {
|
---|
243 | case IDL_SYMBOL_INTERFACE:
|
---|
244 | parseInterface(token);
|
---|
245 | break;
|
---|
246 | case G_TOKEN_IDENTIFIER:
|
---|
247 | g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s", token, value.v_identifier);
|
---|
248 | break;
|
---|
249 | case G_TOKEN_STRING:
|
---|
250 | g_message("Token: %d (G_TOKEN_STRING)\t\t\t%s", token, value.v_string);
|
---|
251 | break;
|
---|
252 | case G_TOKEN_LEFT_PAREN:
|
---|
253 | g_message("Token: %d (G_TOKEN_LEFT_PAREN)\t\t(", token);
|
---|
254 | break;
|
---|
255 | case G_TOKEN_RIGHT_PAREN:
|
---|
256 | g_message("Token: %d (G_TOKEN_RIGHT_PAREN)\t\t)", token);
|
---|
257 | break;
|
---|
258 | case ':':
|
---|
259 | g_message("Token: %d (colon)\t\t:", token);
|
---|
260 | break;
|
---|
261 | case ';':
|
---|
262 | g_message("Token: %d (semicolon)\t\t\t;", token);
|
---|
263 | break;
|
---|
264 | case '#':
|
---|
265 | g_message("Token: %d (hash)\t\t\t#", token);
|
---|
266 | break;
|
---|
267 | case '/':
|
---|
268 | g_message("Token: %d (slash)\t\t\t/ %s", token, value.v_comment);
|
---|
269 | break;
|
---|
270 | case G_TOKEN_COMMA:
|
---|
271 | g_message("Token: %d (G_TOKEN_COMMA)\t\t\t,", token);
|
---|
272 | break;
|
---|
273 | case G_TOKEN_INT:
|
---|
274 | g_message("Token: %d (G_TOKEN_INT)\t\t\t%ld", token, value.v_int);
|
---|
275 | break;
|
---|
276 | case IDL_SYMBOL_DEFINE:
|
---|
277 | g_message("Token: %d (IDL_SYMBOL_DEFINE)\t\t\t", token);
|
---|
278 | break;
|
---|
279 | case IDL_SYMBOL_IFDEF:
|
---|
280 | g_message("Token: %d (IDL_SYMBOL_IFDEF)\t\t\t", token);
|
---|
281 | break;
|
---|
282 | case IDL_SYMBOL_ENDIF:
|
---|
283 | g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", token);
|
---|
284 | break;
|
---|
285 | default:
|
---|
286 | g_message("Token: %d (---)\t\t\t%c (LINE %d)", token, token, g_scanner_cur_line(gScanner));
|
---|
287 | break;
|
---|
288 | }
|
---|
289 | }
|
---|
290 | if(pCurInterface)
|
---|
291 | printInterface();
|
---|
292 |
|
---|
293 | g_scanner_destroy(gScanner);
|
---|
294 | close(fd);
|
---|
295 |
|
---|
296 | return 0;
|
---|
297 | }
|
---|
298 |
|
---|
299 | #if 0
|
---|
300 | /* We are a folder somwhere in the chain */
|
---|
301 | nomRetval=WPFileSystem_wpQueryFileName((WPFileSystem*)wpParent, bFullPath, NULLHANDLE);
|
---|
302 |
|
---|
303 | nomRetval=wpParent.wpQueryFileName(bFullPath, NULLHANDLE);
|
---|
304 |
|
---|
305 | nomPath=NOMPathNew();
|
---|
306 | nomPath= (PNOMPath) NOMPath_assignCString(nomPath, _pszFullPath, ev);
|
---|
307 |
|
---|
308 | return (PNOMPath)NOMPath_appendPath(nomRetval, nomPath, NULLHANDLE);
|
---|
309 |
|
---|
310 | #endif
|
---|