Ignore:
Timestamp:
Mar 25, 2007, 12:33:43 PM (18 years ago)
Author:
cinc
Message:

Output file creation and better option parsing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/c/nom-idl-compiler.c

    r266 r267  
    6767  {"emit-ih", 0, 0, G_OPTION_ARG_NONE, &fOptionEmitIH, "Emmit an include header (*.ih)", NULL},
    6868  {"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},
    7070  {NULL}
    7171};
    7272
    73 static char* chrOutputFileName="";
    7473
    7574/* The pointer array holding the interfaces we found */
     
    9190  {"gchar", IDL_SYMBOL_GCHAR, KIND_TYPESPEC},
    9291  {"void", IDL_SYMBOL_VOID, KIND_TYPESPEC},
     92
     93  {"boolean", IDL_SYMBOL_BOOLEAN, KIND_TYPESPEC},
     94  {"String", IDL_SYMBOL_STRING, KIND_TYPESPEC},
     95
    9396  {"in", IDL_SYMBOL_IN, KIND_DIRECTION},
    9497  {"out", IDL_SYMBOL_OUT, KIND_DIRECTION},
     
    110113PARSEINFO parseInfo={0};
    111114
     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 */
    112123PINTERFACE findInterfaceFromName(gchar* chrName)
    113124{
     
    124135}
    125136
    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 */
    127142gchar* getTypeSpecStringFromCurToken(void)
    128143{
     
    159174}
    160175
    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.
    166183
    167184  N:= G_TOKEN_SYMBOL IDENT ';'
     
    229246
    230247/**
    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.
    232254 */
    233255void parseIt(void)
     
    306328}
    307329
    308 /* Show help.
    309    gContext must be valid.
     330/**
     331   Support function to show help for the IDL compiler. gContext must be valid.
    310332*/
    311333static void outputCompilerHelp(GOptionContext *gContext, gchar* chrExeName)
     
    316338  char** argv2=helpCmd;
    317339  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\
     342it will be used unmodified. Otherwise the output name is built from the given\n\
     343name 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\
     350Note that an emitter specific extension will always be appended to the output\n\
     351filename\n\n");
     352
     353  /* This prints the standard option help to screen. */ 
     354  g_option_context_parse (gContext, &argc2, &argv2, &gError);
    320355}
    321356
     
    334369};
    335370
    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 */
     378void funcMsgHandler(GScanner *gScanner, gchar *message, gboolean error)
     379{
    341380  g_printf("In file %s, line %d:\n\t%s\n", parseInfo.chrCurrentSourceFile,
    342381           g_scanner_cur_line(gScanner)-parseInfo.uiLineCorrection, message);
    343382}
    344383
    345 /*
    346 
     384/**
     385   Main entry point for the idl compiler.
    347386 */
    348387int main(int argc, char **argv)
     
    350389  int a;
    351390  int fd;
     391  /* Vars for filename building */
     392  char* chrOutputFileName="";
    352393
    353394  GError *gError = NULL;
     
    382423  }
    383424#endif
     425
     426  if(strlen(chrOutputName)==0)
     427    {
     428      g_printf("No output file name given.\n\n");
     429      outputCompilerHelp(gContext, argv[0]);
     430    }
    384431  g_option_context_free(gContext);
    385432
     
    396443    }
    397444
    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 */
    399463  if(!strcmp(argv[1], "-"))
    400464    fd=0; /* Read from stdin */
     
    408472    }
    409473 
     474  /* Open output */
     475  parseInfo.outFile=fopen(chrOutputFileName, "w");
     476
    410477  g_printf("\n");
    411 
    412 
    413478
    414479  gScanner=g_scanner_new(NULL);
     
    437502      pSymbols++;
    438503    }
    439   //  gScanner->config->symbol_2_token=TRUE;
    440504
    441505  parseIt();
     
    446510  g_scanner_destroy(gScanner);
    447511  close(fd);
    448 
     512  fclose(parseInfo.outFile);
    449513  return 0;
    450514}
Note: See TracChangeset for help on using the changeset viewer.