Changeset 267 for trunk/idl-compiler/c/nom-idl-compiler.c
- Timestamp:
- Mar 25, 2007, 12:33:43 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/idl-compiler/c/nom-idl-compiler.c
r266 r267 67 67 {"emit-ih", 0, 0, G_OPTION_ARG_NONE, &fOptionEmitIH, "Emmit an include header (*.ih)", NULL}, 68 68 {"emit-c", 0, 0, G_OPTION_ARG_NONE, &fOptionEmitC, "Emmit an implementation template (*.c)", NULL}, 69 {"output", 'o', 0, G_OPTION_ARG_FILENAME, &chrOutputName, "Output name ", NULL},69 {"output", 'o', 0, G_OPTION_ARG_FILENAME, &chrOutputName, "Output name. Must not be omitted.", NULL}, 70 70 {NULL} 71 71 }; 72 72 73 static char* chrOutputFileName="";74 73 75 74 /* The pointer array holding the interfaces we found */ … … 91 90 {"gchar", IDL_SYMBOL_GCHAR, KIND_TYPESPEC}, 92 91 {"void", IDL_SYMBOL_VOID, KIND_TYPESPEC}, 92 93 {"boolean", IDL_SYMBOL_BOOLEAN, KIND_TYPESPEC}, 94 {"String", IDL_SYMBOL_STRING, KIND_TYPESPEC}, 95 93 96 {"in", IDL_SYMBOL_IN, KIND_DIRECTION}, 94 97 {"out", IDL_SYMBOL_OUT, KIND_DIRECTION}, … … 110 113 PARSEINFO parseInfo={0}; 111 114 115 /** 116 Helper function which scans the array of known interfaces and returns the interface 117 structure for the given name. 118 119 \PARAM chrName Name of the interface. 120 \Returns If no interface with that name can be found NULL is returned otherwise a 121 pointer to the interface structure.. 122 */ 112 123 PINTERFACE findInterfaceFromName(gchar* chrName) 113 124 { … … 124 135 } 125 136 126 137 /** 138 Helper function which returns a copy of the typespec string of the current token. 139 That is e.g. 'gint' or 'gpointer'. Note that this function is only called when the 140 current token is indeed a type specification in the IDL file. 141 */ 127 142 gchar* getTypeSpecStringFromCurToken(void) 128 143 { … … 159 174 } 160 175 161 /* 162 The native keyword is used to introduce new types. That's coming 163 from the Corba spec. Maybe we will change that some time. 164 165 The current token is the 'native' keyword. 176 /** 177 Parse the declaration of a new type using the 'native' keyword. 178 179 The 'native' keyword is used to introduce new types. That's coming 180 from the Corba spec. 181 182 \Remarks The current token is the 'native' keyword. 166 183 167 184 N:= G_TOKEN_SYMBOL IDENT ';' … … 229 246 230 247 /** 231 This is the root parse function. Here starts the fun... 248 This is the root parse function. Here starts the fun. When a token is found in the 249 input stream which matches one of the known token types the respective parsing function 250 is called for further processing. In case of an error the parsing function in question 251 prints an error which describes the problem and exits the application. 252 253 This function scans the input until EOF is hit. 232 254 */ 233 255 void parseIt(void) … … 306 328 } 307 329 308 /* Show help.309 gContext must be valid.330 /** 331 Support function to show help for the IDL compiler. gContext must be valid. 310 332 */ 311 333 static void outputCompilerHelp(GOptionContext *gContext, gchar* chrExeName) … … 316 338 char** argv2=helpCmd; 317 339 helpCmd[0]=chrExeName; 318 319 g_option_context_parse (gContext, &argc2, &argv2, &gError); 340 341 g_printf("An output filename must always be specified. If the name is an absolute path\n\ 342 it will be used unmodified. Otherwise the output name is built from the given\n\ 343 name and the directory specification.\n\n\ 344 -If no directory is specified the output name is built from the current directory\n\ 345 path and the given filename.\n\ 346 -If the directory is a relative path the output name is built from the current\n\ 347 directory path, the given directory name (or path) and the filename.\n\ 348 -If the directory is a full path the output name is built from the directory\n\ 349 path and the given filename.\n\n\ 350 Note that an emitter specific extension will always be appended to the output\n\ 351 filename\n\n"); 352 353 /* This prints the standard option help to screen. */ 354 g_option_context_parse (gContext, &argc2, &argv2, &gError); 320 355 } 321 356 … … 334 369 }; 335 370 336 void funcMsgHandler(GScanner *gScanner, 337 gchar *message, 338 gboolean error) 339 { 340 371 /** 372 Message output handler for the scanner. The default handler isn't used because the preprocessor 373 mangles all include files together and thus the line numbers are not as expected by the user. 374 This function prints the error messages with corrected linenumbers and the source file name 375 in which to find the problem. 376 377 */ 378 void funcMsgHandler(GScanner *gScanner, gchar *message, gboolean error) 379 { 341 380 g_printf("In file %s, line %d:\n\t%s\n", parseInfo.chrCurrentSourceFile, 342 381 g_scanner_cur_line(gScanner)-parseInfo.uiLineCorrection, message); 343 382 } 344 383 345 /* 346 384 /** 385 Main entry point for the idl compiler. 347 386 */ 348 387 int main(int argc, char **argv) … … 350 389 int a; 351 390 int fd; 391 /* Vars for filename building */ 392 char* chrOutputFileName=""; 352 393 353 394 GError *gError = NULL; … … 382 423 } 383 424 #endif 425 426 if(strlen(chrOutputName)==0) 427 { 428 g_printf("No output file name given.\n\n"); 429 outputCompilerHelp(gContext, argv[0]); 430 } 384 431 g_option_context_free(gContext); 385 432 … … 396 443 } 397 444 398 /* Create output file name */ 445 446 /*** Create output file name ****/ 447 if(!g_path_is_absolute(chrOutputName)) 448 { 449 if(g_path_is_absolute(chrOutputDir)) 450 chrOutputFileName=g_build_filename(chrOutputDir, chrOutputName, NULL); 451 else 452 { 453 /* Yes this is a memory leak but I don't care */ 454 chrOutputFileName=g_build_filename(g_get_current_dir(), chrOutputDir, chrOutputName, NULL); 455 } 456 } 457 else 458 chrOutputFileName=chrOutputName; 459 460 //g_message("Output file: %s", chrOutputFileName); 461 462 /* Open input */ 399 463 if(!strcmp(argv[1], "-")) 400 464 fd=0; /* Read from stdin */ … … 408 472 } 409 473 474 /* Open output */ 475 parseInfo.outFile=fopen(chrOutputFileName, "w"); 476 410 477 g_printf("\n"); 411 412 413 478 414 479 gScanner=g_scanner_new(NULL); … … 437 502 pSymbols++; 438 503 } 439 // gScanner->config->symbol_2_token=TRUE;440 504 441 505 parseIt(); … … 446 510 g_scanner_destroy(gScanner); 447 511 close(fd); 448 512 fclose(parseInfo.outFile); 449 513 return 0; 450 514 }
Note:
See TracChangeset
for help on using the changeset viewer.