Changeset 277 for trunk/idl-compiler


Ignore:
Timestamp:
Mar 27, 2007, 7:58:40 PM (18 years ago)
Author:
cinc
Message:

IDL compiler: improved outfile handling.

Location:
trunk/idl-compiler
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/Makefile

    r276 r277  
    2828PGOBJECTS       =       $(OBJDIR)/nom-idl-compiler.o \
    2929                        $(OBJDIR)/token.o \
     30                        $(OBJDIR)/open_outfile.o \
    3031                        $(OBJDIR)/typespec_parser.o \
    3132                        $(OBJDIR)/method_parser.o \
  • trunk/idl-compiler/c/nom-idl-compiler.c

    r276 r277  
    5555
    5656static gchar* chrOutputDir="";
    57 static gchar* chrOutputName="";
    5857static gboolean fOptionEmitH=FALSE;
    5958static gboolean fOptionEmitIH=FALSE;
     
    6766  {"emit-ih", 0, 0, G_OPTION_ARG_NONE, &fOptionEmitIH, "Emmit an include header (*.ih)", NULL},
    6867  {"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. Must not be omitted.", NULL},
    7068  {NULL}
    7169};
     
    480478  helpCmd[0]=chrExeName;
    481479
    482   g_printf("An output filename must always be specified. If the name is an absolute path\n\
    483 it will be used unmodified. Otherwise the output name is built from the given\n\
    484 name and the directory specification.\n\n\
     480  g_printf("The output filename is specified in the IDL file using the 'filestem' keyword.\n\
    485481-If no directory is specified the output name is built from the current directory\n\
    486482 path and the given filename.\n\
     
    533529  /* Vars for filename building */
    534530  char* chrOutputFileName="";
    535   char* chrTemp;
    536531
    537532  GError *gError = NULL;
     
    565560  }
    566561
    567   if(strlen(chrOutputName)==0)
    568     {
    569       g_printf("No output file name given.\n\n");
    570       outputCompilerHelp(gContext, argv[0]);
    571     }
    572562  g_option_context_free(gContext);
    573563
     
    585575
    586576 
    587   /*** Create output file name ****/
    588   if(!g_path_is_absolute(chrOutputName))
    589     {
    590       if(g_path_is_absolute(chrOutputDir))
    591         chrOutputFileName=g_build_filename(chrOutputDir, chrOutputName, NULL);
    592       else
    593         {
    594           /* Yes this is a memory leak but I don't care */
    595           chrOutputFileName=g_build_filename(g_get_current_dir(), chrOutputDir, chrOutputName, NULL);
    596         }
    597     }
     577  /*** Create output path name ****/
     578  if(g_path_is_absolute(chrOutputDir))
     579    chrOutputFileName=chrOutputDir;
    598580  else
    599     chrOutputFileName=chrOutputName;
    600 
    601   /* Add emitter extension */
    602   if(fOptionEmitH)
    603     chrTemp=g_strconcat(chrOutputFileName, ".h", NULL);
    604   else if(fOptionEmitIH)
    605     chrTemp=g_strconcat(chrOutputFileName, ".ih", NULL);
    606   else if(fOptionEmitC)
    607     chrTemp=g_strconcat(chrOutputFileName, ".c", NULL);
    608   g_free(chrOutputFileName);
    609   chrOutputFileName=chrTemp;
    610 
    611   g_message("Output file: %s", chrOutputFileName);
     581    {
     582      /* Yes this is a memory leak but I don't care */
     583      chrOutputFileName=g_build_filename(g_get_current_dir(), chrOutputDir, NULL);
     584    }
     585
     586  g_message("Output path: %s", chrOutputFileName);
     587  parseInfo.chrOutfilePath=chrOutputFileName;
    612588
    613589  /* Open input */
     
    622598      exit(1);
    623599    }
    624  
    625   /* Open output */
    626   parseInfo.outFile=fopen(chrOutputFileName, "w");
    627600
    628601  g_printf("\n");
     
    663636
    664637#if 0
    665   else if(fOptionEmitIH)
    666 
    667638  else if(fOptionEmitC)
    668639    a++;
  • trunk/idl-compiler/h-emitter_c/h_file_emitter.c

    r274 r277  
    3838#include <glib.h>
    3939#include <glib/gprintf.h>
     40
     41#define INCL_FILE
    4042#include "parser.h"
    4143
     
    340342    {
    341343      PINTERFACE pif=g_ptr_array_index(pLocalPI->pInterfaceArray, a);
     344      /* Only interfaces from the file given on the command line */
    342345      if(!strcmp(pif->chrSourceFileName, pLocalPI->chrRootSourceFile))
    343346        {
     347          gchar*  chrTemp;
     348         
     349          chrTemp=g_strconcat(pif->chrFileStem, ".h", NULL);
     350
    344351          printInterface(pif);
    345 
    346           emitHFileHeader(pLocalPI, pif);
    347           emitParentHeader(pLocalPI, pif);
    348           emitClassVersion(pLocalPI, pif);
    349           emitClassDataStructs(pLocalPI, pif);
    350           emitNewMacro(pLocalPI, pif);
    351           emitObjectCheckFunction(pLocalPI, pif);
    352           emitNewMethods(pLocalPI, pif);
    353           emitParentClassMethods(pLocalPI, pif);
    354           emitHFileFooter(pLocalPI, pif);
     352          if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULLHANDLE)
     353            {
     354              emitHFileHeader(pLocalPI, pif);
     355              emitParentHeader(pLocalPI, pif);
     356              emitClassVersion(pLocalPI, pif);
     357              emitClassDataStructs(pLocalPI, pif);
     358              emitNewMacro(pLocalPI, pif);
     359              emitObjectCheckFunction(pLocalPI, pif);
     360              emitNewMethods(pLocalPI, pif);
     361              emitParentClassMethods(pLocalPI, pif);
     362              emitHFileFooter(pLocalPI, pif);
     363              closeOutfile(pLocalPI->outFile);
     364            }
     365          g_free(chrTemp);
    355366        }
    356367    }
  • trunk/idl-compiler/ih-emitter_c/ih_file_emitter.c

    r276 r277  
    5151  /* Protective #ifndef for whole file */
    5252  fprintf(fh, "#ifndef %s_IH\n#define %s_IH\n\n", pif->chrName, pif->chrName);
    53 
     53  /* The *.h of this class conatins some declarations we need */
    5454  fprintf(fh, "#include \"%s.h\"\n", pif->chrName);
    5555
     
    6262  FILE* fh=pLocalPI->outFile;
    6363
    64   fprintf(fh, "#ifdef __cplusplus\n");
    65   fprintf(fh, "}\n");
    66   fprintf(fh, "#endif /* __cplusplus */\n\n");
    6764
    6865  fprintf(fh, "\n#endif /* %s_IH */\n", pif->chrName);
  • trunk/idl-compiler/include/parser.h

    r276 r277  
    8383  gboolean fIsInRootFile;
    8484  gchar* chrMetaClass; /* Pointer to metaclass name or NULL*/
     85  char*  chrFileStem;  /* Holding output filestem */
    8586  char*  chrSourceFileName; /* The preprocessor includes files for us. This is the info
    8687                               about the file this interface is defined in. */
    87   char*  chrFileStem;  /* Holding output filestem */
    8888  GPtrArray *pMethodArray;
    8989  GPtrArray *pOverrideArray;
     
    111111  char*     chrCurrentSourceFile;/* The preprocessor includes files for us. This is the info
    112112                                    about their name. */
     113  char*  chrOutfilePath;         /* This is only the path, no filename */
    113114  FILE*     outFile;             /* Output file handle */
    114115}PARSEINFO, *PPARSEINFO;
     
    182183void printInterface(PINTERFACE pif);
    183184void printAllInterfacec(void);
     185
     186#ifdef INCL_FILE
     187FILE* openOutfile(GScanner *gScanner, gchar* chrOutName);
     188void closeOutfile(FILE* pFile);
     189#endif
Note: See TracChangeset for help on using the changeset viewer.