Changeset 326 for trunk/idl-compiler


Ignore:
Timestamp:
Apr 9, 2008, 10:22:08 PM (17 years ago)
Author:
cinc
Message:

Portability patches for Windows, Linux, Darwin by Bird.

Location:
trunk/idl-compiler
Files:
6 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/idl-compiler/c-emitter_c/c_file_emitter.c

    r295 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif
    3537#include <stdlib.h>
    3638#include <string.h>
     
    7981
    8082      /* Do return type */
    81       fprintf(fh, "NOM_Scope ");
     83      fprintf(fh, "NOMDLLEXPORT NOM_Scope ");
    8284      emitReturnType(pLocalPI, pif, pm);
    8385
     
    123125        }
    124126
    125       fprintf(fh, "NOM_Scope ");
     127      fprintf(fh, "NOMDLLEXPORT NOM_Scope ");
    126128      emitReturnType(pLocalPI, pif, pm);
    127129      fprintf(fh, " NOMLINK impl_%s_%s(%s* nomSelf,\n", pif->chrName, pom->chrName, pif->chrName);
     
    167169             
    168170              //printInterface(pif);             
    169               if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULLHANDLE)
     171              if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULL)
    170172                {
    171173                  emitCFileHeader(pLocalPI, pif);
     
    173175                  emitOverridenMethods(pLocalPI, pif);
    174176                  closeOutfile(pLocalPI->outFile);
     177                  pLocalPI->outFile = NULL;
    175178                }
    176179              g_free(chrTemp);
  • trunk/idl-compiler/c/emitter.c

    r290 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdlib.h>
    3639#include <string.h>
    3740
    38 #include <glib.h> 
    39 #include <glib/gprintf.h> 
     41#include <glib.h>
     42#include <glib/gprintf.h>
    4043
    4144#define INCL_FILE
     
    8689      for(b=0;b<pm->uiStar;b++)
    8790        fprintf(fh, "*");
    88       fprintf(fh, " %s,\n", pm->chrName);     
     91      fprintf(fh, " %s,\n", pm->chrName);
    8992    }
    9093}
     
    101104    {
    102105      PMETHODPARAM pm=(PMETHODPARAM)g_ptr_array_index(pArray, a);
    103       fprintf(fh, " %s,", pm->chrName);     
     106      fprintf(fh, " %s,", pm->chrName);
    104107    }
    105108}
  • trunk/idl-compiler/c/nom-idl-compiler.c

    r310 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #define INCL_DOSPROCESS
    35 #define INCL_DOS
    36 #define INCL_DOSPROFILE
    37 #define INCL_DOSERRORS
    38 
    39 #include <os2.h>
     34#ifdef __OS2__
     35# define INCL_DOSPROCESS
     36# define INCL_DOS
     37# define INCL_DOSPROFILE
     38# define INCL_DOSERRORS
     39# include <os2.h>
     40#endif /* __OS2__ */
     41
    4042#include <stdio.h>
    4143#include <stdlib.h>
    4244#include <string.h>
    4345
    44 #include <io.h>
     46#ifdef HAVE_IO_H
     47# include <io.h>
     48#endif
     49#ifdef HAVE_UNISTD_H
     50# include <unistd.h>
     51#endif
    4552#include <fcntl.h>
    46 #include <sys\stat.h>
    47 
    48 #include <glib.h> 
     53#include <sys/stat.h>
     54
     55#include <glib.h>
    4956#include <glib/gprintf.h>
    5057
     
    6067
    6168/* Command line options */
    62 static GOptionEntry gOptionEntries[] = 
     69static GOptionEntry gOptionEntries[] =
    6370{
    6471  {"directory", 'd', 0, G_OPTION_ARG_FILENAME, &chrOutputDir, "Output directory", NULL},
     
    361368   This is the root parse function. Here starts the fun. When a token is found in the
    362369   input stream which matches one of the known token types the respective parsing function
    363    is called for further processing. In case of an error the parsing function in question 
     370   is called for further processing. In case of an error the parsing function in question
    364371   prints an error which describes the problem and exits the application.
    365372
     
    370377  while(g_scanner_peek_next_token(gScanner) != G_TOKEN_EOF) {
    371378    GTokenType token;
     379    GTokenValue value;
    372380
    373381    g_scanner_get_next_token(gScanner);
    374382    token=gScanner->token;
    375     GTokenValue value=gScanner->value;
    376    
     383    value=gScanner->value;
     384
    377385    switch(token)
    378386      {
     
    468476filename\n\n");
    469477
    470   /* This prints the standard option help to screen. */ 
     478  /* This prints the standard option help to screen. */
    471479  g_option_context_parse (gContext, &argc2, &argv2, &gError);
    472480}
     
    494502void funcMsgHandler(GScanner *gScanner, gchar *message, gboolean error)
    495503{
    496   g_printf("%s:%d: error: %s (%d %d)\n", parseInfo.chrCurrentSourceFile,
     504  g_printf("%s:%d: error: %s (%d %d)\n",
     505           parseInfo.chrCurrentSourceFile ? parseInfo.chrCurrentSourceFile : "<null>", /* glib doesn't check for NULL like printf. */
    497506           g_scanner_cur_line(gScanner)-parseInfo.uiLineCorrection, message,
    498507           g_scanner_cur_line(gScanner), parseInfo.uiLineCorrection);
     
    554563    }
    555564#endif
    556  
     565
    557566  /*** Create output path name ****/
    558567  if(g_path_is_absolute(chrOutputDir))
     
    572581  else
    573582    fd=open(argv[1], O_RDONLY);
    574  
     583
    575584  if(-1==fd)
    576585    {
     
    600609  while(pSymbols->chrSymbolName)
    601610    {
    602 #warning !!! Create a copy here so it is the same as with new symbols added later.
     611#ifndef _MSC_VER
     612# warning !!! Create a copy here so it is the same as with new symbols added later.
     613#endif
    603614      g_scanner_scope_add_symbol(gScanner, ID_SCOPE, pSymbols->chrSymbolName,
    604615                                 pSymbols);
  • trunk/idl-compiler/c/open_outfile.c

    r319 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdlib.h>
    3639#include <string.h>
  • trunk/idl-compiler/c/printdata.c

    r321 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif
    3537#include <stdio.h>
    3638#include <stdlib.h>
    3739#include <string.h>
    3840
    39 #include <io.h>
     41#ifdef HAVE_IO_H
     42# include <io.h>
     43#endif
     44#ifdef HAVE_UNISTD_H
     45# include <unistd.h>
     46#endif
    4047#include <fcntl.h>
    41 #include <sys\stat.h>
     48#include <sys/stat.h>
    4249
    4350#include <glib/gprintf.h>
  • trunk/idl-compiler/c/token.c

    r321 r326  
    3333* ***** END LICENSE BLOCK ***** */
    3434
    35 #include <os2.h>
     35#ifdef __OS2__
     36# include <os2.h>
     37#endif /* __OS2__ */
     38
    3639#include <stdio.h>
    3740#include "nom.h"
  • trunk/idl-compiler/c/util.c

    r292 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif
    3537#include <stdlib.h>
    3638#include <string.h>
     
    6264    return NULL;
    6365
    64   while((pifParent=getParentInterface(pifParent))!=NULLHANDLE)
     66  while((pifParent=getParentInterface(pifParent))!=NULL)
    6567    {
    6668      int a;
     
    100102    return NULL;
    101103
    102   while((pifParent=getParentInterface(pifParent))!=NULLHANDLE)
     104  while((pifParent=getParentInterface(pifParent))!=NULL)
    103105    {
    104106      int a;
  • trunk/idl-compiler/h-emitter_c/h_file_emitter.c

    r292 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif  /* __OS2__ */
     37
    3538#include <stdlib.h>
    3639#include <string.h>
     
    107110
    108111  fprintf(fh, "/* Class data structure */\n");
     112  fprintf(fh, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n", pif->chrName);
     113  fprintf(fh, "NOMDLLEXPORT\n");
     114  fprintf(fh, "#else\n");
     115  fprintf(fh, "NOMDLLIMPORT\n");
     116  fprintf(fh, "#endif\n");
    109117  fprintf(fh, "NOMEXTERN struct %sClassDataStructure {\n", pif->chrName);
    110118
     
    116124      fprintf(fh, "    nomMToken %s;\n", pm->chrName);
    117125    }
    118   fprintf(fh, "}%sClassData;\n\n", pif->chrName);
    119 
     126  fprintf(fh, "} NOMDLINK %sClassData;\n\n", pif->chrName);
     127
     128  fprintf(fh, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n", pif->chrName);
     129  fprintf(fh, "NOMDLLEXPORT\n");
     130  fprintf(fh, "#else\n");
     131  fprintf(fh, "NOMDLLIMPORT\n");
     132  fprintf(fh, "#endif\n");
    120133  fprintf(fh, "NOMEXTERN struct %sCClassDataStructure {\n", pif->chrName);
    121134  fprintf(fh, "   nomMethodTabs parentMtab;\n");
     
    132145  if(strcmp(pif->chrName , "NOMObject"))
    133146    {
     147/* FIXME: why is this here too? it's already in nomtk.h... */
    134148      fprintf(fh, "/* This function is used to check if a given object is valid and the\n");
    135149      fprintf(fh, "   object supports the method */\n");
     
    181195              pif->chrName, pm->chrName);
    182196      /* Forward declaration of parameter test function */
     197      fprintf(fh, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n", pif->chrName);
     198      fprintf(fh, "NOMDLLEXPORT\n");
     199      fprintf(fh, "#else\n");
     200      fprintf(fh, "NOMDLLIMPORT\n");
     201      fprintf(fh, "#endif\n");
    183202      fprintf(fh, "NOMEXTERN gboolean NOMLINK parmCheckFunc_%s_%s(%s *nomSelf,\n",
    184203              pif->chrName,  pm->chrName, pif->chrName);
     
    266285
    267286  fprintf(fh, "/*\n * Class creation function\n */\n");
     287  fprintf(fh, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n", pif->chrName);
     288  fprintf(fh, "NOMDLLEXPORT\n");
     289  fprintf(fh, "#else\n");
     290  fprintf(fh, "NOMDLLIMPORT\n");
     291  fprintf(fh, "#endif\n");
    268292  fprintf(fh, "NOMEXTERN NOMClass * NOMLINK %sNewClass(gulong clsMajorVersion, gulong clsMinorVersion);\n\n",
    269293          pif->chrName);
     
    291315  PINTERFACE pifParent=pif;
    292316
    293   while((pifParent=getParentInterface(pifParent))!=NULLHANDLE)
     317  while((pifParent=getParentInterface(pifParent))!=NULL)
    294318    {
    295319      GPtrArray *pArray;
     
    345369             
    346370              //printInterface(pif);             
    347               if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULLHANDLE)
     371              if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULL)
    348372                {
    349373                  emitHFileHeader(pLocalPI, pif);
     
    357381                  emitHFileFooter(pLocalPI, pif);
    358382                  closeOutfile(pLocalPI->outFile);
     383                  pLocalPI->outFile = NULL;
    359384                }
    360385              g_free(chrTemp);
  • trunk/idl-compiler/ih-emitter_c/ih_file_emitter.c

    r293 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdlib.h>
    3639#include <string.h>
     
    8083            fprintf(fh, "  %s;\n", piv->chrName);
    8184    }
    82   fprintf(fh, "}%sData;\n\n", pif->chrName);
     85#ifdef _MSC_VER
     86  if(!a)
     87    fprintf(fh, "  int iDummy;\n"); /* HACK ALERT! */
     88#endif
     89  fprintf(fh, "} %sData;\n\n", pif->chrName);
    8390}
    8491
     
    8693{
    8794  FILE* fh=pLocalPI->outFile;
    88   GPtrArray *pArray=pif->pInstanceVarArray;;
     95  GPtrArray *pArray=pif->pInstanceVarArray;
    8996  int a;
    9097
     
    116123
    117124  fprintf(fh, "/*** Class data structures ***/\n");
    118   fprintf(fh, "struct %sClassDataStructure %sClassData = {0};\n", pif->chrName, pif->chrName );
    119   fprintf(fh, "static struct %sCClassDataStructure %sCClassData = {0};\n\n",
     125  fprintf(fh, "NOMDLLEXPORT struct %sClassDataStructure %sClassData = {0};\n", pif->chrName, pif->chrName );
     126  fprintf(fh, "NOMDLLEXPORT struct %sCClassDataStructure %sCClassData = {0};\n\n",
    120127          pif->chrName, pif->chrName);
    121128}
     
    126133NOMEXTERN gboolean NOMLINK objectCheckFunc_WPRootFolder(WPRootFolder *nomSelf, gchar* chrMethodName)
    127134{
    128 if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf , WPRootFolderClassData.classObject, NULLHANDLE))
     135if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf , WPRootFolderClassData.classObject, NULL))
    129136  {
    130137  nomPrintObjectPointerError(nomSelf, "WPRootFolder", chrMethodName);
     
    170177      fprintf(fh, "\",\n");     
    171178    }
     179#ifdef _MSC_VER
     180  if(!a)
     181    fprintf(fh, "  NULL\n");
     182#endif
    172183}
    173184
     
    187198      fprintf(fh, "#if !defined(_decl_impl_%s_%s_)\n", pif->chrName, pm->chrName);
    188199      fprintf(fh, "#define _decl_impl_%s_%s_ 1\n", pif->chrName, pm->chrName);
    189       fprintf(fh, "NOM_Scope ");
     200      fprintf(fh, "NOMDLLEXPORT NOM_Scope ");
    190201      emitReturnType(pLocalPI, pif, pm);
    191202      fprintf(fh, " NOMLINK impl_%s_%s(%s *nomSelf,\n", pif->chrName, pm->chrName, pif->chrName);
     
    238249        }
    239250
    240       fprintf(fh, "NOM_Scope ");
     251      fprintf(fh, "NOMDLLEXPORT NOM_Scope ");
    241252      emitReturnType(pLocalPI, pif, pm);
    242253      fprintf(fh, " NOMLINK impl_%s_%s(%s* nomSelf,\n", pif->chrName, pom->chrName, pif->chrName);
     
    271282  fprintf(fh, "static nomOverridenMethodDesc nomOverridenMethods%s[] = {\n", pif->chrName);
    272283
     284  pArray=pif->pOverrideArray;
     285
    273286  for(a=0;a<pArray->len;a++)
    274287    {
     
    289302      fprintf(fh, "  },\n");
    290303    }
    291     fprintf(fh, "};\n\n");
     304#ifdef _MSC_VER
     305  if(!a)
     306    fprintf(fh, "  { NULL, NULL, NULL }\n");
     307#endif
     308  fprintf(fh, "};\n\n");
    292309}
    293310
     
    316333      fprintf(fh, "},\n");
    317334    }
     335#ifdef _MSC_VER
     336  if(!a)
     337    fprintf(fh, "  { NULL, NULL, NULL, NULL, NULL }\n");
     338#endif
    318339  fprintf(fh, "};\n\n");
    319340}
     
    344365      /* Emit the parents. We have to output them sorted beginning from the
    345366         leftmost parent. */
    346       while(pifParent->chrParent && (pifParent=findInterfaceFromName(pifParent->chrParent))!=NULLHANDLE)
     367      while(pifParent->chrParent && (pifParent=findInterfaceFromName(pifParent->chrParent))!=NULL)
    347368        {
    348369          g_ptr_array_add(pArray, (gpointer) pifParent);
     
    372393  PINTERFACE pifParent=pif;
    373394
    374   while(pifParent->chrParent && (pifParent=findInterfaceFromName(pifParent->chrParent))!=NULLHANDLE)
     395  while(pifParent->chrParent && (pifParent=findInterfaceFromName(pifParent->chrParent))!=NULL)
    375396    ulRet++;
    376397
     
    498519    }
    499520  fprintf(fh, "#include \"nomgc.h\"\n");
     521  fprintf(fh, "#ifdef NOM_%s_IMPLEMENTATION_FILE\n", pif->chrName);
     522  fprintf(fh, "NOMDLLEXPORT\n");
     523  fprintf(fh, "#else\n");
     524  fprintf(fh, "NOMDLLIMPORT\n");
     525  fprintf(fh, "#endif\n");
    500526  fprintf(fh, "NOMClass* NOMLINK %sNewClass(gulong ulMajor, gulong ulMinor)\n", pif->chrName);
    501527  fprintf(fh, "{\n");
     
    516542  fprintf(fh, "    nomEndRegisterDLLWithGC(hReg);\n");
    517543  fprintf(fh, "    }\n");
     544  fprintf(fh, "#elif defined(_WIN32)\n");
     545  fprintf(fh, " /* FIXME: check this up with the GC. */\n");
     546  fprintf(fh, "#elif defined(__APPLE__)\n");
     547  fprintf(fh, "# warning FIXME: Check out GC/dylib.\n");
     548  fprintf(fh, "#elif defined(__linux__)\n");
     549  fprintf(fh, "# warning FIXME: Check out GC/so on linux.\n");
    518550  fprintf(fh, "#else\n");
    519551  fprintf(fh, "#error DLL must be registered with the garbage collector!\n");
     
    562594              //printInterface(pif);
    563595              chrTemp=g_strconcat(pif->chrFileStem, ".ih", NULL);
    564               if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULLHANDLE)
     596              if((pLocalPI->outFile=openOutfile(gScanner, chrTemp))!=NULL)
    565597                {
    566598                  emitIHFileHeader(pLocalPI, pif);
  • trunk/idl-compiler/parser_c/classversion_parser.c

    r271 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdio.h>
    3639#include <stdlib.h>
  • trunk/idl-compiler/parser_c/filestem_parser.c

    r307 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif  /* __OS2__ */
     37
    3538#include <stdio.h>
    3639#include <stdlib.h>
  • trunk/idl-compiler/parser_c/hash_parser.c

    r308 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdio.h>
    3639#include <stdlib.h>
     
    4548  Current token is a '#'.
    4649
    47   H:= '#' INT STRING INT     // Line info from the preprocessor
     50  H:= '#line' INT STRING INT // Line info from the preprocessor
     51  H:= '#' INT STRING INT     // Line info from the preprocessor (gcc short hand)
    4852 */
    4953void parseHash(void)
    5054{
     55  if (g_scanner_peek_next_token(gScanner) == G_TOKEN_IDENTIFIER
     56   && !strcmp(gScanner->next_value.v_identifier, "line"))
     57    getNextToken(); /* skip the line part. */
    5158
    5259  if(matchNext(G_TOKEN_INT))
  • trunk/idl-compiler/parser_c/instancevar_parser.c

    r271 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdio.h>
    3639#include <stdlib.h>
  • trunk/idl-compiler/parser_c/interface_parser.c

    r309 r326  
    3737  a specialized parser function in another source file is called from here.
    3838 */
    39 #include <os2.h>
     39#ifdef __OS2__
     40# include <os2.h>
     41#endif /* __OS2__ */
     42
    4043#include <stdlib.h>
    4144#include <string.h>
     
    292295{
    293296  PSYMBOL pCurSymbol;
     297  GTokenValue value;
    294298
    295299  /* Parent interface */
     
    305309      exit(1);
    306310    }
    307   GTokenValue value=gScanner->value;
     311  value=gScanner->value;
    308312  /* Make sure it's the correct symbol */
    309313  pCurSymbol=value.v_symbol;
  • trunk/idl-compiler/parser_c/lineinfo_parser.c

    r306 r326  
    3939 */
    4040
    41 #include <os2.h>
     41#ifdef __OS2__
     42# include <os2.h>
     43#endif /* __OS2__ */
     44
    4245#include <stdio.h>
    4346#include <stdlib.h>
  • trunk/idl-compiler/parser_c/metaclass_parser.c

    r320 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdio.h>
    3639#include <stdlib.h>
  • trunk/idl-compiler/parser_c/method_parser.c

    r271 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdlib.h>
    3639
  • trunk/idl-compiler/parser_c/override_parser.c

    r309 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdio.h>
    3639#include <stdlib.h>
  • trunk/idl-compiler/parser_c/typespec_parser.c

    r269 r326  
    3232*
    3333* ***** END LICENSE BLOCK ***** */
    34 #include <os2.h>
     34#ifdef __OS2__
     35# include <os2.h>
     36#endif /* __OS2__ */
     37
    3538#include <stdio.h>
    3639
Note: See TracChangeset for help on using the changeset viewer.