コード例 #1
0
ファイル: conscomp.c プロジェクト: OS2World/DEV-LISP-Clips
globle int ExpressionToCode(
  FILE *fp,
  struct expr *exprPtr)
  {
   /*========================================*/
   /* Print the reference to the expression. */
   /*========================================*/

   if (exprPtr == NULL)
     {
      if (fp != NULL) fprintf(fp,"NULL");
      return(FALSE);
     }
   else if (fp != NULL)
     { fprintf(fp,"&E%d_%d[%ld]",ImageID,ExpressionVersion,ExpressionCount); }

   /*==================================================*/
   /* Create a new expression code file, if necessary. */
   /*==================================================*/

   if (ExpressionHeader == TRUE)
     {
      if ((ExpressionFP = NewCFile(FilePrefix,3,ExpressionVersion,FALSE)) == NULL)
        { return(-1); }

      fprintf(ExpressionFP,"struct expr E%d_%d[] = {\n",ImageID,ExpressionVersion);
      fprintf(HeaderFP,"extern struct expr E%d_%d[];\n",ImageID,ExpressionVersion);
      ExpressionHeader = FALSE;
     }
   else
     { fprintf(ExpressionFP,",\n"); }

   /*===========================*/
   /* Dump the expression code. */
   /*===========================*/

   DumpExpression(exprPtr);

   /*=========================================*/
   /* Close the expression file if necessary. */
   /*=========================================*/

   if (ExpressionCount >= MaxIndices)
     {
      ExpressionCount = 0;
      ExpressionVersion++;
      fprintf(ExpressionFP,"};\n");
      fclose(ExpressionFP);
      ExpressionFP = NULL;
      ExpressionHeader = TRUE;
     }

   /*==========================================*/
   /* Return TRUE to indicate the expression   */
   /* reference and expression data structures */
   /* were succcessfully written to the file.  */
   /*==========================================*/

   return(TRUE);
  }
コード例 #2
0
globle int ConstraintsToCode(
  void *theEnv,
  char *fileName,
  int fileID,
  FILE *headerFP,
  int imageID,
  int maxIndices)
  {
   int i, j, count;
   int newHeader = TRUE;
   FILE *fp;
   int version = 1;
   int arrayVersion = 1;
   unsigned short numberOfConstraints = 0;
   CONSTRAINT_RECORD *tmpPtr;

   /*===============================================*/
   /* Count the total number of constraint records. */
   /*===============================================*/

   for (i = 0 ; i < SIZE_CONSTRAINT_HASH; i++)
     {
      for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
           tmpPtr != NULL;
           tmpPtr = tmpPtr->next)
        { tmpPtr->bsaveIndex = numberOfConstraints++; }
     }

   /*=====================================================*/
   /* If dynamic constraint checking is disabled, then    */
   /* contraints won't be saved. If there are constraints */
   /* which could be saved, then issue a warning message. */
   /*=====================================================*/

   if ((! EnvGetDynamicConstraintChecking(theEnv)) && (numberOfConstraints != 0))
     {
      numberOfConstraints = 0;
      PrintWarningID(theEnv,"CSTRNCMP",1,FALSE);
      EnvPrintRouter(theEnv,WWARNING,"Constraints are not saved with a constructs-to-c image\n");
      EnvPrintRouter(theEnv,WWARNING,"  when dynamic constraint checking is disabled.\n");
     }

   if (numberOfConstraints == 0) return(-1);

   /*=================================================*/
   /* Print the extern definition in the header file. */
   /*=================================================*/

   for (i = 1; i <= (numberOfConstraints / maxIndices) + 1 ; i++)
     { fprintf(headerFP,"extern CONSTRAINT_RECORD C%d_%d[];\n",imageID,i); }

   /*==================*/
   /* Create the file. */
   /*==================*/

   if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL) return(-1);

   /*===================*/
   /* List the entries. */
   /*===================*/

   j = 0;
   count = 0;

   for (i = 0; i < SIZE_CONSTRAINT_HASH; i++)
     {
      for (tmpPtr = ConstraintData(theEnv)->ConstraintHashtable[i];
           tmpPtr != NULL;
           tmpPtr = tmpPtr->next)
        {
         if (newHeader)
           {
            fprintf(fp,"CONSTRAINT_RECORD C%d_%d[] = {\n",imageID,arrayVersion);
            newHeader = FALSE;
           }

         fprintf(fp,"{%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
                 tmpPtr->anyAllowed,
                 tmpPtr->symbolsAllowed,
                 tmpPtr->stringsAllowed,
                 tmpPtr->floatsAllowed,
                 tmpPtr->integersAllowed,
                 tmpPtr->instanceNamesAllowed,
                 tmpPtr->instanceAddressesAllowed,
                 tmpPtr->externalAddressesAllowed,
                 tmpPtr->factAddressesAllowed,
                 0, /* void allowed */
                 tmpPtr->anyRestriction,
                 tmpPtr->symbolRestriction,
                 tmpPtr->stringRestriction,
                 tmpPtr->floatRestriction,
                 tmpPtr->integerRestriction,
                 tmpPtr->instanceNameRestriction,
                 tmpPtr->multifieldsAllowed,
                 tmpPtr->singlefieldsAllowed);

         fprintf(fp,",0,"); /* bsaveIndex */

         PrintHashedExpressionReference(theEnv,fp,tmpPtr->restrictionList,imageID,maxIndices);
         fprintf(fp,",");
         PrintHashedExpressionReference(theEnv,fp,tmpPtr->minValue,imageID,maxIndices);
         fprintf(fp,",");
         PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxValue,imageID,maxIndices);
         fprintf(fp,",");
         PrintHashedExpressionReference(theEnv,fp,tmpPtr->minFields,imageID,maxIndices);
         fprintf(fp,",");
         PrintHashedExpressionReference(theEnv,fp,tmpPtr->maxFields,imageID,maxIndices);

         /* multifield slot */

         fprintf(fp,",NULL");

         /* next slot */

         if (tmpPtr->next == NULL)
           { fprintf(fp,",NULL,"); }
         else
           {
            if ((j + 1) >= maxIndices)
              { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion + 1,0); }
            else
              { fprintf(fp,",&C%d_%d[%d],",imageID,arrayVersion,j + 1); }
           }

         fprintf(fp,"%d,%d",tmpPtr->bucket,tmpPtr->count + 1);

         count++;
         j++;

         if ((count == numberOfConstraints) || (j >= maxIndices))
           {
            fprintf(fp,"}};\n");
            GenClose(fp);
            j = 0;
            version++;
            arrayVersion++;
            if (count < numberOfConstraints)
              {
               if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0);
               newHeader = TRUE;
              }
           }
         else
           { fprintf(fp,"},\n"); }
        }
     }

   return(version);
  }
コード例 #3
0
ファイル: modulcmp.c プロジェクト: chrislong/clipsrules
static int ConstructToCode(
  void *theEnv,
  char *fileName,
  char *pathName,
  char *fileNameBuffer,
  int fileID,
  FILE *headerFP,
  int imageID,
  int maxIndices)
  {
   struct defmodule *theConstruct;
   FILE *moduleFile = NULL, *itemsFile;
   int portItemCount = 0;
   struct portItem *portItemPtr;
   int mihCount = 0, moduleCount = 0;
   int j;
   struct moduleItem *theItem;
   int moduleArrayVersion = 1;
   int fileCount = 2;

   /*================================================*/
   /* Include the appropriate defmodule header file. */
   /*================================================*/

   fprintf(headerFP,"#include \"moduldef.h\"\n");

   /*============================================*/
   /* Open up the items file for the defmodules. */
   /* Only one file of this type is created so   */
   /* the maximum number of indices is ignored.  */
   /*============================================*/

   if ((itemsFile = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,1,FALSE)) == NULL)
     { return(FALSE); }
   fprintf(itemsFile,"struct defmoduleItemHeader *%s%d_%d[] = {\n",ItemPrefix(),imageID,1);
   fprintf(headerFP,"extern struct defmoduleItemHeader *%s%d_%d[];\n",ItemPrefix(),imageID,1);

   /*======================================================*/
   /* Loop through all the defmodules writing their C code */
   /* representation to the file as they are traversed.    */
   /*======================================================*/

   for (theConstruct = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
        theConstruct != NULL;
        theConstruct = (struct defmodule *) EnvGetNextDefmodule(theEnv,theConstruct))
     {
      /*===========================================*/
      /* Open a new file to write to if necessary. */
      /*===========================================*/

      moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,
                                    &fileCount,moduleArrayVersion,headerFP,
                                    "struct defmodule",DefmodulePrefix(),
                                    FALSE,NULL);

      if (moduleFile == NULL)
        {
         moduleCount = maxIndices;
         CloseFileIfNeeded(theEnv,moduleFile,&moduleCount,
                           &moduleArrayVersion,maxIndices,NULL,NULL);
         GenClose(theEnv,itemsFile);
         return(FALSE);
        }

      /*======================================*/
      /* Write the construct name and ppform. */
      /*======================================*/

      fprintf(moduleFile,"{");
      PrintSymbolReference(theEnv,moduleFile,theConstruct->name);
      fprintf(moduleFile,",NULL,");

      /*=====================================================*/
      /* Write the items array pointers to other constructs. */
      /*=====================================================*/

      fprintf(moduleFile,"&%s%d_1[%d],",ItemPrefix(),imageID,mihCount);

      for (j = 0, theItem = GetListOfModuleItems(theEnv);
           (j < GetNumberOfModuleItems(theEnv)) && (theItem != NULL) ;
           j++, theItem = theItem->next)
        {
         mihCount++;
         if (theItem->constructsToCModuleReference == NULL)
           { fprintf(itemsFile,"NULL"); }
         else
           { (*theItem->constructsToCModuleReference)(theEnv,itemsFile,(int) theConstruct->bsaveID,imageID,maxIndices); }

         if ((j + 1) < GetNumberOfModuleItems(theEnv)) fprintf(itemsFile,",");
         else if (theConstruct->next != NULL) fprintf(itemsFile,",\n");
        }

      /*=================================*/
      /* Write the importList reference. */
      /*=================================*/

      if (theConstruct->importList == NULL)
        { fprintf(moduleFile,"NULL,"); }
      else
        {
         fprintf(moduleFile,"&%s%d_%d[%d],",PortPrefix(),imageID,
                                     (portItemCount / maxIndices) + 1,
                                     portItemCount % maxIndices);
         for (portItemPtr = theConstruct->importList;
              portItemPtr != NULL;
              portItemPtr = portItemPtr->next)
           { portItemCount++; }
        }

      /*=================================*/
      /* Write the exportList reference. */
      /*=================================*/

      if (theConstruct->exportList == NULL)
        { fprintf(moduleFile,"NULL,"); }
      else
        {
         fprintf(moduleFile,"&%s%d_%d[%d],",PortPrefix(),imageID,
                                     (portItemCount / maxIndices) + 1,
                                     portItemCount % maxIndices);
         for (portItemPtr = theConstruct->exportList;
              portItemPtr != NULL;
              portItemPtr = portItemPtr->next)
           { portItemCount++; }
        }

      /*=====================*/
      /* Write the bsave id. */
      /*=====================*/

      fprintf(moduleFile,"0,%ld,",theConstruct->bsaveID);

      /*======================*/
      /* Write the user data. */
      /*======================*/

      fprintf(moduleFile,"NULL,");

      /*===========================*/
      /* Write the next reference. */
      /*===========================*/

      if (theConstruct->next == NULL)
        { fprintf(moduleFile,"NULL}"); }
      else
        {
         fprintf(moduleFile,"&%s%d_%d[%d]}",ConstructPrefix(DefmoduleData(theEnv)->DefmoduleCodeItem),imageID,
                            (int) (theConstruct->next->bsaveID / maxIndices) + 1,
                            (int) theConstruct->next->bsaveID % maxIndices);
        }

      /*===================================================*/
      /* Increment the number of defmodule data structures */
      /* written and close the output file if necessary.   */
      /*===================================================*/

      moduleCount++;
      moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleCount,&moduleArrayVersion,
                                        maxIndices,NULL,NULL);

     }

   /*=========================*/
   /* Close the output files. */
   /*=========================*/

   moduleCount = maxIndices;
   CloseFileIfNeeded(theEnv,moduleFile,&moduleCount,
                     &moduleArrayVersion,maxIndices,NULL,NULL);
   fprintf(itemsFile,"};\n");
   GenClose(theEnv,itemsFile);

   /*=========================================*/
   /* Write out the portItem data structures. */
   /*=========================================*/

   if (portItemCount == 0) return(TRUE);
   return(PortItemsToCode(theEnv,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID,maxIndices,&fileCount));
  }
コード例 #4
0
ファイル: symblcmp.c プロジェクト: guitarpoet/php-clips
static int IntegerHashNodesToCode(
  void *theEnv,
  const char *fileName,
  const char *pathName,
  char *fileNameBuffer,
  int version)
  {
   int i, j;
   struct integerHashNode *hashPtr;
   int count;
   int numberOfEntries;
   struct integerHashNode **integerTable;
   bool newHeader = true;
   FILE *fp;
   int arrayVersion = 1;

   /*====================================*/
   /* Count the total number of entries. */
   /*====================================*/

   integerTable = GetIntegerTable(theEnv);
   count = numberOfEntries = 0;

   for (i = 0; i < INTEGER_HASH_SIZE; i++)
     {
      for (hashPtr = integerTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        { numberOfEntries++; }
     }

   if (numberOfEntries == 0) return(version);

   for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++)
     { fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct integerHashNode I%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,i); }

   /*==================*/
   /* Create the file. */
   /*==================*/

   if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,1,version,false)) == NULL) return(-1);

   /*===================*/
   /* List the entries. */
   /*===================*/

   j = 0;

   for (i = 0; i < INTEGER_HASH_SIZE; i++)
     {
      for (hashPtr = integerTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        {
         if (newHeader)
           {
            fprintf(fp,"struct integerHashNode I%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion);
            newHeader = false;
           }

         if (hashPtr->next == NULL)
           { fprintf(fp,"{NULL,"); }
         else
           {
            if ((j + 1) >= ConstructCompilerData(theEnv)->MaxIndices)
              { fprintf(fp,"{&I%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion + 1,0); }
            else
              { fprintf(fp,"{&I%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion,j + 1); }
           }

         fprintf(fp,"%ld,1,0,0,%d,",hashPtr->count + 1,i);
         fprintf(fp,"%lldLL",hashPtr->contents);

         count++;
         j++;

         if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv)->MaxIndices))
           {
            fprintf(fp,"}};\n");
            GenClose(theEnv,fp);
            j = 0;
            version++;
            arrayVersion++;
            if (count < numberOfEntries)
              {
               if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,1,version,false)) == NULL) return(0);
               newHeader = true;
              }
           }
         else
           { fprintf(fp,"},\n"); }
        }
     }

   return(version);
  }
コード例 #5
0
ファイル: symblcmp.c プロジェクト: rorchard/FuzzyCLIPS
static int HashTablesToCode(
    char *fileName)
{
    int i;
    FILE *fp;
    struct symbolHashNode **symbolTable;
    struct floatHashNode **floatTable;
    struct integerHashNode **integerTable;
    struct bitMapHashNode **bitMapTable;
#if FUZZY_DEFTEMPLATES
    struct fuzzyValueHashNode **fuzzyValueTable;
#endif

    /*======================================*/
    /* Write the code for the symbol table. */
    /*======================================*/

    symbolTable = GetSymbolTable();

    if ((fp = NewCFile(fileName,1,1,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct symbolHashNode *sht%d[];\n",ImageID);
    fprintf(fp,"struct symbolHashNode *sht%d[%d] = {\n",ImageID,SYMBOL_HASH_SIZE);

    for (i = 0; i < SYMBOL_HASH_SIZE; i++)
    {
        PrintSymbolReference(fp,symbolTable[i]);

        if (i + 1 != SYMBOL_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

    /*=====================================*/
    /* Write the code for the float table. */
    /*=====================================*/

    floatTable = GetFloatTable();

    if ((fp = NewCFile(fileName,1,2,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct floatHashNode *fht%d[];\n",ImageID);
    fprintf(fp,"struct floatHashNode *fht%d[%d] = {\n",ImageID,FLOAT_HASH_SIZE);

    for (i = 0; i < FLOAT_HASH_SIZE; i++)
    {
        if (floatTable[i] == NULL) {
            fprintf(fp,"NULL");
        }
        else PrintFloatReference(fp,floatTable[i]);

        if (i + 1 != FLOAT_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

    /*=======================================*/
    /* Write the code for the integer table. */
    /*=======================================*/

    integerTable = GetIntegerTable();

    if ((fp = NewCFile(fileName,1,3,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct integerHashNode *iht%d[];\n",ImageID);
    fprintf(fp,"struct integerHashNode *iht%d[%d] = {\n",ImageID,INTEGER_HASH_SIZE);

    for (i = 0; i < INTEGER_HASH_SIZE; i++)
    {
        if (integerTable[i] == NULL) {
            fprintf(fp,"NULL");
        }
        else PrintIntegerReference(fp,integerTable[i]);

        if (i + 1 != INTEGER_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

    /*======================================*/
    /* Write the code for the bitmap table. */
    /*======================================*/

    bitMapTable = GetBitMapTable();

    if ((fp = NewCFile(fileName,1,4,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct bitMapHashNode *bmht%d[];\n",ImageID);
    fprintf(fp,"struct bitMapHashNode *bmht%d[%d] = {\n",ImageID,BITMAP_HASH_SIZE);

    for (i = 0; i < BITMAP_HASH_SIZE; i++)
    {
        PrintBitMapReference(fp,bitMapTable[i]);

        if (i + 1 != BITMAP_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

#if FUZZY_DEFTEMPLATES

    /*=============================*/
    /* Dump the fuzzy value table. */
    /*=============================*/

    fuzzyValueTable = GetFuzzyValueTable();

    if ((fp = NewCFile(fileName,1,5,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct fuzzyValueHashNode *fvht%d[];\n",ImageID);
    fprintf(fp,"struct fuzzyValueHashNode *fvht%d[%d] = {\n",ImageID,FUZZY_VALUE_HASH_SIZE);

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        PrintFuzzyValueReference(fp,fuzzyValueTable[i]);

        if (i + 1 != FUZZY_VALUE_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

#endif /* FUZZY_DEFTEMPLATES */

    return(1);
}
コード例 #6
0
ファイル: conscomp.c プロジェクト: OS2World/DEV-LISP-Clips
static int FunctionsToCode(
  char *fileName)
  {
   short i = 0;
   FILE *fp;
   int version = 1;
   int newHeader = TRUE;
   struct FunctionDefinition *fctnPtr;

   /*=============================*/
   /* Assign a reference index to */
   /* each of the functions.      */
   /*=============================*/

   for (fctnPtr = GetFunctionList();
        fctnPtr != NULL;
        fctnPtr = fctnPtr->next)
     { fctnPtr->bsaveIndex = i++; }

   /*=======================================*/
   /* Create the file in which to store the */
   /* function definition data structures.  */
   /*=======================================*/

   if ((fp = NewCFile(fileName,2,version,FALSE)) == NULL)
     { return(0); }

   /*===============================================*/
   /* Construct the definition of the function list */
   /* from the definitions of the functions.        */
   /*===============================================*/

   fprintf(fp,"\n\n");
   fprintf(fp,"/************************************/\n");
   fprintf(fp,"/* FUNCTION LIST DEFINITION         */\n");
   fprintf(fp,"/************************************/\n\n");

   i = 1;
   fctnPtr = GetFunctionList();
   while (fctnPtr != NULL)
     {
      if (newHeader)
        {
         fprintf(fp,"struct FunctionDefinition P%d_%d[] = {\n",ImageID,version);
         fprintf(HeaderFP,"extern struct FunctionDefinition P%d_%d[];\n",ImageID,version);
         newHeader = FALSE;
        }

      fprintf(fp,"{");
      PrintSymbolReference(fp,fctnPtr->callFunctionName);
      fprintf(fp,",\"%s\",",fctnPtr->actualFunctionName);
      fprintf(fp,"'%c',",fctnPtr->returnValueType);
      fprintf(fp,"PTIF %s,",fctnPtr->actualFunctionName);
      fprintf(fp,"NULL,");
      if (fctnPtr->restrictions != NULL) fprintf(fp,"\"%s\",",fctnPtr->restrictions);
      else fprintf(fp,"NULL,");
      fprintf(fp,"0,0,0,");

      PrintFunctionReference(fp,fctnPtr->next);

      i++;
      fctnPtr = fctnPtr->next;
      if ((i > MaxIndices) || (fctnPtr == NULL))
        {
         fprintf(fp,"}};\n");
         fclose(fp);
         i = 1;
         version++;
         if (fctnPtr != NULL)
           {
            if ((fp = NewCFile(fileName,2,version,FALSE)) == NULL) return(0);
            newHeader = TRUE;
           }
        }
      else
        { fprintf(fp,"},\n"); }
     }

   return(TRUE);
  }
コード例 #7
0
ファイル: objrtcmp.c プロジェクト: jonathangizmo/pyclips
/***********************************************************
  NAME         : AlphaPatternNodesToCode
  DESCRIPTION  : Writes out data structures for run-time
                 creation of object pattern alpha memories
  INPUTS       : 1) The base image output file name
                 2) The base image file id
                 3) A pointer to the header output file
                 4) The id of constructs-to-c image
                 5) The maximum number of indices
                    allowed in any single array
                    in the image
  RETURNS      : Next version file to open, 0 if error
  SIDE EFFECTS : Object patterns code written to files
  NOTES        : None
 ***********************************************************/
static int AlphaPatternNodesToCode(
  void *theEnv,
  char *fileName,
  int fileID,
  FILE *headerFP,
  int imageID,
  int maxIndices,
  int version)
  {
   FILE *fp;
   int arrayVersion;
   int newHeader;
   int i;
   OBJECT_ALPHA_NODE *thePattern;

   /* ================
      Create the file.
      ================ */
   if (ObjectNetworkTerminalPointer(theEnv) == NULL)
     return(version);

   /* =================================
      Dump the pattern node structures.
      ================================= */
   if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL)
     return(0);
   newHeader = TRUE;

   arrayVersion = 1;
   i = 1;

   thePattern = ObjectNetworkTerminalPointer(theEnv);
   while (thePattern != NULL)
     {
      if (newHeader)
        {
         fprintf(fp,"OBJECT_ALPHA_NODE %s%d_%d[] = {\n",
                    ObjectANPrefix(),imageID,arrayVersion);
         fprintf(headerFP,"extern OBJECT_ALPHA_NODE %s%d_%d[];\n",
                          ObjectANPrefix(),imageID,arrayVersion);
         newHeader = FALSE;
        }

      fprintf(fp,"{");

      PatternNodeHeaderToCode(theEnv,fp,&thePattern->header,imageID,maxIndices);

      fprintf(fp,",0L,");
      PrintBitMapReference(theEnv,fp,thePattern->classbmp);
      fprintf(fp,",");
      PrintBitMapReference(theEnv,fp,thePattern->slotbmp);
      fprintf(fp,",");
      IntermediatePatternNodeReference(theEnv,thePattern->patternNode,fp,imageID,maxIndices);
      fprintf(fp,",");
      ObjectPatternNodeReference(theEnv,thePattern->nxtInGroup,fp,imageID,maxIndices);
      fprintf(fp,",");
      ObjectPatternNodeReference(theEnv,thePattern->nxtTerminal,fp,imageID,maxIndices);
      fprintf(fp,",0L}");

      i++;
      thePattern = thePattern->nxtTerminal;

      if ((i > maxIndices) || (thePattern == NULL))
        {
         fprintf(fp,"};\n");
         GenClose(fp);
         i = 1;
         version++;
         arrayVersion++;
         if (thePattern != NULL)
           {
            if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL)
              return(0);
            newHeader = TRUE;
           }
        }
      else if (thePattern != NULL)
        { fprintf(fp,",\n"); }
     }

   return(version);
  }
コード例 #8
0
ファイル: symblcmp.c プロジェクト: atrniv/CLIPS
static int HashTablesToCode(
  void *theEnv,
  EXEC_STATUS,
  char *fileName,
  char *pathName,
  char *fileNameBuffer)
  {
   unsigned long i;
   FILE *fp;
   struct symbolHashNode **symbolTable;
   struct floatHashNode **floatTable;
   struct integerHashNode **integerTable;
   struct bitMapHashNode **bitMapTable;

   /*======================================*/
   /* Write the code for the symbol table. */
   /*======================================*/

   symbolTable = GetSymbolTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,1,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct symbolHashNode *sht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct symbolHashNode *sht%d[%ld] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,SYMBOL_HASH_SIZE);

   for (i = 0; i < SYMBOL_HASH_SIZE; i++)
      {
       PrintSymbolReference(theEnv,execStatus,fp,symbolTable[i]);

       if (i + 1 != SYMBOL_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

   /*=====================================*/
   /* Write the code for the float table. */
   /*=====================================*/

   floatTable = GetFloatTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,2,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct floatHashNode *fht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct floatHashNode *fht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,FLOAT_HASH_SIZE);

   for (i = 0; i < FLOAT_HASH_SIZE; i++)
      {
       if (floatTable[i] == NULL) { fprintf(fp,"NULL"); }
       else PrintFloatReference(theEnv,execStatus,fp,floatTable[i]);

       if (i + 1 != FLOAT_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

   /*=======================================*/
   /* Write the code for the integer table. */
   /*=======================================*/

   integerTable = GetIntegerTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,3,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct integerHashNode *iht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct integerHashNode *iht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,INTEGER_HASH_SIZE);

   for (i = 0; i < INTEGER_HASH_SIZE; i++)
      {
       if (integerTable[i] == NULL) { fprintf(fp,"NULL"); }
       else PrintIntegerReference(theEnv,execStatus,fp,integerTable[i]);

       if (i + 1 != INTEGER_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

   /*======================================*/
   /* Write the code for the bitmap table. */
   /*======================================*/

   bitMapTable = GetBitMapTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,4,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct bitMapHashNode *bmht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct bitMapHashNode *bmht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,BITMAP_HASH_SIZE);

   for (i = 0; i < BITMAP_HASH_SIZE; i++)
      {
       PrintBitMapReference(theEnv,execStatus,fp,bitMapTable[i]);

       if (i + 1 != BITMAP_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

    return(1);
   }
コード例 #9
0
ファイル: symblcmp.c プロジェクト: rorchard/FuzzyCLIPS
static int IntegerHashNodesToCode(
    char *fileName,
    int version)
{
    int i, j;
    struct integerHashNode *hashPtr;
    int count;
    int numberOfEntries;
    struct integerHashNode **integerTable;
    int newHeader = TRUE;
    FILE *fp;
    int arrayVersion = 1;

    /*====================================*/
    /* Count the total number of entries. */
    /*====================================*/

    integerTable = GetIntegerTable();
    count = numberOfEntries = 0;

    for (i = 0; i < INTEGER_HASH_SIZE; i++)
    {
        for (hashPtr = integerTable[i];
                hashPtr != NULL;
                hashPtr = hashPtr->next)
        {
            numberOfEntries++;
        }
    }

    if (numberOfEntries == 0) return(version);

    for (i = 1; i <= (numberOfEntries / MaxIndices) + 1 ; i++)
    {
        fprintf(HeaderFP,"extern struct integerHashNode I%d_%d[];\n",ImageID,i);
    }

    /*==================*/
    /* Create the file. */
    /*==================*/

    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(-1);

    /*===================*/
    /* List the entries. */
    /*===================*/

    j = 0;

    for (i = 0; i < INTEGER_HASH_SIZE; i++)
    {
        for (hashPtr = integerTable[i];
                hashPtr != NULL;
                hashPtr = hashPtr->next)
        {
            if (newHeader)
            {
                fprintf(fp,"struct integerHashNode I%d_%d[] = {\n",ImageID,arrayVersion);
                newHeader = FALSE;
            }

            if (hashPtr->next == NULL)
            {
                fprintf(fp,"{NULL,");
            }
            else
            {
                if ((j + 1) >= MaxIndices)
                {
                    fprintf(fp,"{&I%d_%d[%d],",ImageID,arrayVersion + 1,0);
                }
                else
                {
                    fprintf(fp,"{&I%d_%d[%d],",ImageID,arrayVersion,j + 1);
                }
            }

            fprintf(fp,"%ld,0,0,0,%d,",hashPtr->count + 1,i);
            fprintf(fp,"%ld",hashPtr->contents);

            count++;
            j++;

            if ((count == numberOfEntries) || (j >= MaxIndices))
            {
                fprintf(fp,"}};\n");
                fclose(fp);
                j = 0;
                version++;
                arrayVersion++;
                if (count < numberOfEntries)
                {
                    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(0);
                    newHeader = TRUE;
                }
            }
            else
            {
                fprintf(fp,"},\n");
            }
        }
    }

    return(version);
}
コード例 #10
0
ファイル: objrtcmp.c プロジェクト: jonathangizmo/pyclips
/*************************************************************
  NAME         : IntermediatePatternNodesToCode
  DESCRIPTION  : Writes out data structures for run-time
                 creation of object pattern intermediate nodes
  INPUTS       : 1) The base image output file name
                 2) The base image file id
                 3) A pointer to the header output file
                 4) The id of constructs-to-c image
                 5) The maximum number of indices
                    allowed in any single array
                    in the image
  RETURNS      : Next version file to open, 0 if error
  SIDE EFFECTS : Object patterns code written to files
  NOTES        : None
 *************************************************************/
static int IntermediatePatternNodesToCode(
  void *theEnv,
  char *fileName,
  int fileID,
  FILE *headerFP,
  int imageID,
  int maxIndices,
   int version)
  {
   FILE *fp;
   int arrayVersion;
   int newHeader;
   int i;
   OBJECT_PATTERN_NODE *thePattern;

   /* ================
      Create the file.
      ================ */
   if (ObjectNetworkPointer(theEnv) == NULL)
     return(1);

   fprintf(headerFP,"#include \"objrtmch.h\"\n");

   /* =================================
      Dump the pattern node structures.
      ================================= */
   if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL)
     return(0);
   newHeader = TRUE;

   arrayVersion = 1;
   i = 1;

   thePattern = ObjectNetworkPointer(theEnv);
   while (thePattern != NULL)
     {
      if (newHeader)
        {
         fprintf(fp,"OBJECT_PATTERN_NODE %s%d_%d[] = {\n",
                     ObjectPNPrefix(),imageID,arrayVersion);
         fprintf(headerFP,"extern OBJECT_PATTERN_NODE %s%d_%d[];\n",
                     ObjectPNPrefix(),imageID,arrayVersion);
         newHeader = FALSE;
        }
      fprintf(fp,"{0,%u,%u,%u,%u,0L,%u,",thePattern->multifieldNode,
                                        thePattern->endSlot,
                                        thePattern->whichField,
                                        thePattern->leaveFields,
                                        thePattern->slotNameID);

      PrintHashedExpressionReference(theEnv,fp,thePattern->networkTest,imageID,maxIndices);
      fprintf(fp,",");
      IntermediatePatternNodeReference(theEnv,thePattern->nextLevel,fp,imageID,maxIndices);
      fprintf(fp,",");
      IntermediatePatternNodeReference(theEnv,thePattern->lastLevel,fp,imageID,maxIndices);
      fprintf(fp,",");
      IntermediatePatternNodeReference(theEnv,thePattern->leftNode,fp,imageID,maxIndices);
      fprintf(fp,",");
      IntermediatePatternNodeReference(theEnv,thePattern->rightNode,fp,imageID,maxIndices);
      fprintf(fp,",");
      ObjectPatternNodeReference(theEnv,(void *) thePattern->alphaNode,fp,imageID,maxIndices);
      fprintf(fp,",0L}");

      i++;
      thePattern = GetNextObjectPatternNode(thePattern);

      if ((i > maxIndices) || (thePattern == NULL))
        {
         fprintf(fp,"};\n");
         GenClose(fp);
         i = 1;
         version++;
         arrayVersion++;
         if (thePattern != NULL)
           {
            if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL)
              return(0);
            newHeader = TRUE;
           }
        }
      else if (thePattern != NULL)
        { fprintf(fp,",\n"); }
     }

   return(version);
  }
コード例 #11
0
ファイル: symblcmp.c プロジェクト: rorchard/FuzzyCLIPS
static int FuzzyValueArraysToCode(
    char *fileName,
    int version)
{
    int i, j, k;
    struct fuzzyValueHashNode *hashPtr;
    int count;
    int numberOfEntries;
    struct fuzzyValueHashNode **fuzzyValueTable;
    int newHeader = TRUE;
    int arrayVersion = 1;
    FILE *fp;
    int arraySize;

    /*====================================*/
    /* Count the total number of entries. */
    /*  i.e. total x and y values to be   */
    /*       written                      */
    /*====================================*/

    fuzzyValueTable = GetFuzzyValueTable();
    count = numberOfEntries = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            arraySize = hashPtr->contents->n;
            numberOfEntries += arraySize + arraySize;
            hashPtr = hashPtr->next;
        }
    }

    if (numberOfEntries == 0) return(version);

    for (i = 1; i <= (numberOfEntries / MaxIndices) + 1 ; i++)
    {
        fprintf(HeaderFP,"extern double X%d_%d[];\n",ImageID,i);
    }

    /*==================*/
    /* Create the file. */
    /*==================*/

    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(-1);

    /*=====================*/
    /* Fillin the entries. */
    /*=====================*/

    j = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            if (newHeader)
            {
                fprintf(fp,"double X%d_%d[] = {\n",ImageID,arrayVersion);
                newHeader = FALSE;
            }

            /* write out the x values then y values for each fuzzy value */

            arraySize = hashPtr->contents->n;
            for (k=0; k<arraySize-1; k++)
                fprintf(fp,"%s,", FloatToString(hashPtr->contents->x[k]));
            fprintf(fp,"%s,\n", FloatToString(hashPtr->contents->x[arraySize-1]));
            for (k=0; k<arraySize-1; k++)
                fprintf(fp,"%s,", FloatToString(hashPtr->contents->y[k]));
            fprintf(fp,"%s", FloatToString(hashPtr->contents->y[arraySize-1]));

            count += arraySize + arraySize;
            j += arraySize + arraySize;

            if ((count == numberOfEntries) || (j >= MaxIndices))
            {
                fprintf(fp,"};\n");
                fclose(fp);
                j = 0;
                arrayVersion++;
                version++;
                if (count < numberOfEntries)
                {
                    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(0);
                    newHeader = TRUE;
                }
            }
            else
            {
                fprintf(fp,",\n");
            }

            hashPtr = hashPtr->next;
        }
    }

    return(version);
}
コード例 #12
0
ファイル: symblcmp.c プロジェクト: rorchard/FuzzyCLIPS
static int FuzzyValuesToCode(
    char *fileName,
    int version)
{
    int i, j;
    struct fuzzyValueHashNode *hashPtr;
    int count;
    int numberOfEntries;
    struct fuzzyValueHashNode **fuzzyValueTable;
    int newHeader = TRUE;
    int arrayVersion = 1;
    FILE *fp;
    int arraySize;
    int xyArrayPartition = 1, xyArrayPartitionCount = 0;

    /*====================================*/
    /* Count the total number of entries. */
    /*====================================*/

    fuzzyValueTable = GetFuzzyValueTable();
    count = numberOfEntries = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            numberOfEntries++;
            hashPtr = hashPtr->next;
        }
    }

    if (numberOfEntries == 0) return(version);

    for (i = 1; i <= (numberOfEntries / MaxIndices) + 1 ; i++)
    {
        fprintf(HeaderFP,"extern struct fuzzy_value W%d_%d[];\n",ImageID,i);
    }

    /*==================*/
    /* Create the file. */
    /*==================*/

    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(-1);

    /*=====================*/
    /* Fillin the entries. */
    /*=====================*/

    j = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            if (newHeader)
            {
                fprintf(fp,"struct fuzzy_value W%d_%d[] = {\n",ImageID,arrayVersion);
                newHeader = FALSE;
            }

            /* fill in the entries of the fuzzy value struct:
                  whichDeftemplate - ptr to deftemplate structure
                  name  - char *
                  maxn  - int
                  n     - int
                  x     - ptr to double (will be index into X array)
                  y     - ptr to double (will be index into X array)
            */

            fprintf(fp,"{");
            DeftemplateCConstructReference(fp, hashPtr->contents->whichDeftemplate,
                                           ImageID, MaxIndices);
            fprintf(fp,",");
            PrintCString(fp,hashPtr->contents->name);
            /* NOTE: arraySize twice in next fprintf line is correct!
                     We don't want to store maxn value since we pack the arrays
                     when writing X array out to c file
            */
            arraySize = hashPtr->contents->n;
            fprintf(fp,",%d,%d", arraySize, arraySize);
            fprintf(fp,",(double *)&X%d_%d[%d], (double *)&X%d_%d[%d]",
                    ImageID, xyArrayPartition, xyArrayPartitionCount,
                    ImageID, xyArrayPartition, xyArrayPartitionCount+arraySize);

            xyArrayPartitionCount += arraySize + arraySize;
            if (xyArrayPartitionCount >= MaxIndices)
            {
                xyArrayPartitionCount = 0;
                xyArrayPartition++;
            }

            count++;
            j++;

            if ((count == numberOfEntries) || (j >= MaxIndices))
            {
                fprintf(fp,"}};\n");
                fclose(fp);
                j = 0;
                arrayVersion++;
                version++;
                if (count < numberOfEntries)
                {
                    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(0);
                    newHeader = TRUE;
                }
            }
            else
            {
                fprintf(fp,"},\n");
            }

            hashPtr = hashPtr->next;
        }
    }

    return(version);
}
コード例 #13
0
ファイル: symblcmp.c プロジェクト: rorchard/FuzzyCLIPS
static int FuzzyValueHashNodesToCode(
    char *fileName,
    int version)
{
    int i, j;
    struct fuzzyValueHashNode *hashPtr;
    int count;
    int numberOfEntries;
    struct fuzzyValueHashNode **fuzzyValueTable;
    int newHeader = TRUE;
    int arrayVersion = 1;
    FILE *fp;

    /*====================================*/
    /* Count the total number of entries. */
    /*====================================*/

    fuzzyValueTable = GetFuzzyValueTable();
    count = numberOfEntries = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            numberOfEntries++;
            hashPtr = hashPtr->next;
        }
    }

    if (numberOfEntries == 0) return(version);

    for (i = 1; i <= (numberOfEntries / MaxIndices) + 1 ; i++)
    {
        fprintf(HeaderFP,"extern struct fuzzyValueHashNode V%d_%d[];\n",ImageID,i);
    }

    /*==================*/
    /* Create the file. */
    /*==================*/
    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(-1);

    /*===================*/
    /* List the entries. */
    /*===================*/

    j = 0;

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        hashPtr = fuzzyValueTable[i];
        while (hashPtr != NULL)
        {
            if (newHeader)
            {
                fprintf(fp,"struct fuzzyValueHashNode V%d_%d[] = {\n",ImageID,arrayVersion);
                newHeader = FALSE;
            }

            /* fill in 'next' slot in fuzzyValueHashNode struct */
            if (hashPtr->next == NULL)
            {
                fprintf(fp,"{NULL,");
            }
            else
            {
                if ((j + 1) >= MaxIndices)
                {
                    fprintf(fp,"{&V%d_%d[%d],",ImageID,arrayVersion + 1,0);
                }
                else
                {
                    fprintf(fp,"{&V%d_%d[%d],",ImageID,arrayVersion,j + 1);
                }
            }

            /* fill in other slots in fuzzyValueHashNode struct */
            fprintf(fp,"%ld,0,0,0,%d,(struct fuzzy_value *) &W%d_%d[%d]",
                    hashPtr->count + 1,i,
                    ImageID,arrayVersion,j);

            count++;
            j++;

            if ((count == numberOfEntries) || (j >= MaxIndices))
            {
                fprintf(fp,"}};\n");
                fclose(fp);
                j = 0;
                arrayVersion++;
                version++;
                if (count < numberOfEntries)
                {
                    if ((fp = NewCFile(fileName,1,version,FALSE)) == NULL) return(0);
                    newHeader = TRUE;
                }
            }
            else
            {
                fprintf(fp,"},\n");
            }
            hashPtr = hashPtr->next;
        }
    }

    return(version);
}
コード例 #14
0
ファイル: symblcmp.c プロジェクト: atrniv/CLIPS
static int BitMapHashNodesToCode(
  void *theEnv,
  EXEC_STATUS,
  char *fileName,
  char *pathName,
  char *fileNameBuffer,
  int version)
  {
   int i, j;
   struct bitMapHashNode *hashPtr;
   int count;
   int numberOfEntries;
   struct bitMapHashNode **bitMapTable;
   int newHeader = TRUE;
   int arrayVersion = 1;
   FILE *fp;
   int longsReqdPartition = 1,longsReqdPartitionCount = 0;

   /*====================================*/
   /* Count the total number of entries. */
   /*====================================*/

   bitMapTable = GetBitMapTable(theEnv,execStatus);
   count = numberOfEntries = 0;

   for (i = 0; i < BITMAP_HASH_SIZE; i++)
     {
      for (hashPtr = bitMapTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        { numberOfEntries++; }
     }

   if (numberOfEntries == 0) return(version);

   for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv,execStatus)->MaxIndices) + 1 ; i++)
     { fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct bitMapHashNode B%d_%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID,i); }

   /*==================*/
   /* Create the file. */
   /*==================*/

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(-1);

   /*===================*/
   /* List the entries. */
   /*===================*/

   j = 0;

   for (i = 0; i < BITMAP_HASH_SIZE; i++)
     {
      for (hashPtr = bitMapTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        {
         if (newHeader)
           {
            fprintf(fp,"struct bitMapHashNode B%d_%d[] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion);
            newHeader = FALSE;
           }

         if (hashPtr->next == NULL)
           { fprintf(fp,"{NULL,"); }
         else
           {
            if ((j + 1) >= ConstructCompilerData(theEnv,execStatus)->MaxIndices)
              { fprintf(fp,"{&B%d_%d[%d],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion + 1,0); }
            else
              { fprintf(fp,"{&B%d_%d[%d],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion,j + 1); }
           }

         fprintf(fp,"%ld,0,1,0,0,%d,(char *) &L%d_%d[%d],%d",
                     hashPtr->count + 1,i,
                     ConstructCompilerData(theEnv,execStatus)->ImageID,longsReqdPartition,longsReqdPartitionCount,
                     hashPtr->size);

         longsReqdPartitionCount += (int) (hashPtr->size / sizeof(unsigned long));
         if ((hashPtr->size % sizeof(unsigned long)) != 0)
           longsReqdPartitionCount++;
         if (longsReqdPartitionCount >= ConstructCompilerData(theEnv,execStatus)->MaxIndices)
           {
            longsReqdPartitionCount = 0;
            longsReqdPartition++;
           }

         count++;
         j++;

         if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv,execStatus)->MaxIndices))
           {
            fprintf(fp,"}};\n");
            GenClose(theEnv,execStatus,fp);
            j = 0;
            arrayVersion++;
            version++;
            if (count < numberOfEntries)
              {
               if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0);
               newHeader = TRUE;
              }
           }
         else
           { fprintf(fp,"},\n"); }
        }
     }

   return(version);
  }
コード例 #15
0
ファイル: conscomp.c プロジェクト: OS2World/DEV-LISP-Clips
globle FILE *CloseFileIfNeeded(
  FILE *theFile,
  int *theCount,
  int *arrayVersion,
  int maxIndices,
  int *canBeReopened,
  struct CodeGeneratorFile *codeFile)
  {
   /*==========================================*/
   /* If the maximum number of entries for the */
   /* file hasn't been exceeded, then...       */
   /*==========================================*/

   if (*theCount < maxIndices)
     {
      /*====================================*/
      /* If the file can be reopened later, */
      /* close it. Otherwise, keep it open. */
      /*====================================*/

      if (canBeReopened != NULL)
        {
         *canBeReopened = TRUE;
         fclose(theFile);
         return(NULL);
        }

      return(theFile);
     }

   /*===========================================*/
   /* Otherwise, the number of entries allowed  */
   /* in a file has been reached. Indicate that */
   /* the file can't be reopened.               */
   /*===========================================*/

   if (canBeReopened != NULL)
     { *canBeReopened = FALSE; }

   /*===============================================*/
   /* If the file is closed, then we need to reopen */
   /* it to print the final closing right brace.    */
   /*===============================================*/

   if (theFile == NULL)
     {
      if ((canBeReopened == NULL) || (codeFile == NULL))
        {
         SystemError("CONSCOMP",3);
         ExitRouter(EXIT_FAILURE);
        }

      if (codeFile->filePrefix == NULL)
        { return(NULL); }

      theFile = NewCFile(codeFile->filePrefix,codeFile->id,codeFile->version,TRUE);
      if (theFile == NULL)
        {
         SystemError("CONSCOMP",4);
         ExitRouter(EXIT_FAILURE);
        }
     }

   /*================================*/
   /* Print the final closing brace. */
   /*================================*/

   fprintf(theFile,"};\n");
   fclose(theFile);

   /*============================================*/
   /* Update index values for subsequent writing */
   /* of data structures to files.               */
   /*============================================*/

   *theCount = 0;
   (*arrayVersion)++;

   /*=========================*/
   /* Return NULL to indicate */
   /* the file is closed.     */
   /*=========================*/

   return(NULL);
  }
コード例 #16
0
ファイル: symblcmp.c プロジェクト: atrniv/CLIPS
static int BitMapValuesToCode(
  void *theEnv,
  EXEC_STATUS,
  char *fileName,
  char *pathName,
  char *fileNameBuffer,
  int version)
  {
   int i, j, k;
   unsigned l;
   struct bitMapHashNode *hashPtr;
   int count;
   int numberOfEntries;
   struct bitMapHashNode **bitMapTable;
   int newHeader = TRUE;
   int arrayVersion = 1;
   FILE *fp;
   unsigned long tmpLong;
   int longsReqd;

   /*====================================*/
   /* Count the total number of entries. */
   /*====================================*/

   bitMapTable = GetBitMapTable(theEnv,execStatus);
   count = numberOfEntries = 0;

   for (i = 0; i < BITMAP_HASH_SIZE; i++)
     {
      for (hashPtr = bitMapTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        {
         numberOfEntries += (int) (hashPtr->size / sizeof(unsigned long));
         if ((hashPtr->size % sizeof(unsigned long)) != 0)
           { numberOfEntries++; }
        }
     }

   if (numberOfEntries == 0) return(version);

   for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv,execStatus)->MaxIndices) + 1 ; i++)
     { fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern unsigned long L%d_%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID,i); }

   /*==================*/
   /* Create the file. */
   /*==================*/

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(-1);

   /*===================*/
   /* List the entries. */
   /*===================*/

   j = 0;

   for (i = 0; i < BITMAP_HASH_SIZE; i++)
     {
      for (hashPtr = bitMapTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        {
         if (newHeader)
           {
            fprintf(fp,"unsigned long L%d_%d[] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion);
            newHeader = FALSE;
           }

         longsReqd = (int) (hashPtr->size / sizeof(unsigned long));
         if ((hashPtr->size % sizeof(unsigned long)) != 0)
           longsReqd++;

         for (k = 0 ; k < longsReqd ; k++)
           {
            if (k > 0)
              fprintf(fp,",");
            tmpLong = 0L;
            for (l = 0 ;
                 ((l < sizeof(unsigned long)) &&
                 (((k * sizeof(unsigned long)) + l) < (size_t) hashPtr->size)) ;
                 l++)
              ((char *) &tmpLong)[l] = hashPtr->contents[(k * sizeof(unsigned long)) + l];
            fprintf(fp,"0x%lxL",tmpLong);
           }

         count += longsReqd;
         j += longsReqd;

         if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv,execStatus)->MaxIndices))
           {
            fprintf(fp,"};\n");
            GenClose(theEnv,execStatus,fp);
            j = 0;
            arrayVersion++;
            version++;
            if (count < numberOfEntries)
              {
               if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0);
               newHeader = TRUE;
              }
           }
         else
           { fprintf(fp,",\n"); }
        }
     }

   return(version);
  }
コード例 #17
0
ファイル: conscomp.c プロジェクト: OS2World/DEV-LISP-Clips
globle FILE *OpenFileIfNeeded(
  FILE *theFile,
  char *fileName,
  int fileID,
  int imageID,
  int *fileCount,
  int arrayVersion,
  FILE *headerFP,
  char *structureName,
  char *structPrefix,
  int reopenOldFile,
  struct CodeGeneratorFile *codeFile)
  {
   char arrayName[80];
   char *newName;
   int newID, newVersion;

   /*===========================================*/
   /* If a file is being reopened, use the same */
   /* version number, name, and ID as before.   */
   /*===========================================*/

   if (reopenOldFile)
     {
      if (codeFile == NULL)
        {
         SystemError("CONSCOMP",5);
         ExitRouter(EXIT_FAILURE);
        }

      newName = codeFile->filePrefix;
      newID = codeFile->id;
      newVersion = codeFile->version;
     }

   /*=====================================================*/
   /* Otherwise, use the specified version number, name,  */
   /* and ID. If the appropriate argument is supplied,    */
   /* remember these values for later reopening the file. */
   /*=====================================================*/

   else
     {
      newName = fileName;
      newVersion = *fileCount;
      newID = fileID;

      if (codeFile != NULL)
        {
         codeFile->version = newVersion;
         codeFile->filePrefix = newName;
         codeFile->id = newID;
        }
     }

   /*=========================================*/
   /* If the file is already open, return it. */
   /*=========================================*/

   if (theFile != NULL)
     {
      fprintf(theFile,",\n");
      return(theFile);
     }

   /*================*/
   /* Open the file. */
   /*================*/

   if ((theFile = NewCFile(newName,newID,newVersion,reopenOldFile)) == NULL)
     { return(NULL); }

   /*=========================================*/
   /* If this is the first time the file has  */
   /* been opened, write out the beginning of */
   /* the array variable definition.          */
   /*=========================================*/

   if (reopenOldFile == FALSE)
     {
      (*fileCount)++;
      sprintf(arrayName,"%s%d_%d",structPrefix,imageID,arrayVersion);

#if SHORT_LINK_NAMES
      if (strlen(arrayName) > 6)
        {
         PrintWarningID("CONSCOMP",2,FALSE);
         PrintRouter(WWARNING,"Array name ");
         PrintRouter(WWARNING,arrayName);
         PrintRouter(WWARNING,"exceeds 6 characters in length.\n");
         PrintRouter(WWARNING,"   This variable may be indistinguishable from another by the linker.\n");
        }
#endif
      fprintf(theFile,"%s %s[] = {\n",structureName,arrayName);
      fprintf(headerFP,"extern %s %s[];\n",structureName,arrayName);
     }
   else
     { fprintf(theFile,",\n"); }

   /*==================*/
   /* Return the file. */
   /*==================*/

   return(theFile);
  }
コード例 #18
0
ファイル: symblcmp.c プロジェクト: atrniv/CLIPS
static int SymbolHashNodesToCode(
  void *theEnv,
  EXEC_STATUS,
  char *fileName,
  char *pathName,
  char *fileNameBuffer,
  int version)
  {
   unsigned long i, j;
   struct symbolHashNode *hashPtr;
   int count;
   int numberOfEntries;
   struct symbolHashNode **symbolTable;
   int newHeader = TRUE;
   int arrayVersion = 1;
   FILE *fp;

   /*====================================*/
   /* Count the total number of entries. */
   /*====================================*/

   symbolTable = GetSymbolTable(theEnv,execStatus);
   count = numberOfEntries = 0;

   for (i = 0; i < SYMBOL_HASH_SIZE; i++)
     {
      for (hashPtr = symbolTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        { numberOfEntries++; }
     }

   if (numberOfEntries == 0) return(version);

   for (i = 1; i <= (unsigned long) (numberOfEntries / ConstructCompilerData(theEnv,execStatus)->MaxIndices) + 1 ; i++)
     { fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct symbolHashNode S%d_%ld[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID,i); }

   /*==================*/
   /* Create the file. */
   /*==================*/

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(-1);

   /*===================*/
   /* List the entries. */
   /*===================*/

   j = 0;

   for (i = 0; i < SYMBOL_HASH_SIZE; i++)
     {
      for (hashPtr = symbolTable[i];
           hashPtr != NULL;
           hashPtr = hashPtr->next)
        {
         if (newHeader)
           {
            fprintf(fp,"struct symbolHashNode S%d_%d[] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion);
            newHeader = FALSE;
           }

         if (hashPtr->next == NULL)
           { fprintf(fp,"{NULL,"); }
         else
           {
            if ((j + 1) >= (unsigned long) ConstructCompilerData(theEnv,execStatus)->MaxIndices)
              { fprintf(fp,"{&S%d_%d[%d],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion + 1,0); }
            else
              { fprintf(fp,"{&S%d_%d[%ld],",ConstructCompilerData(theEnv,execStatus)->ImageID,arrayVersion,j + 1); }
           }

         fprintf(fp,"%ld,0,1,0,0,%ld,",hashPtr->count + 1,i);
         PrintCString(fp,hashPtr->contents);

         count++;
         j++;

         if ((count == numberOfEntries) || (j >= (unsigned) ConstructCompilerData(theEnv,execStatus)->MaxIndices))
           {
            fprintf(fp,"}};\n");
            GenClose(theEnv,execStatus,fp);
            j = 0;
            arrayVersion++;
            version++;
            if (count < numberOfEntries)
              {
               if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,version,FALSE)) == NULL) return(0);
               newHeader = TRUE;
              }
           }
         else
           { fprintf(fp,"},\n"); }
        }
     }

   return(version);
  }
コード例 #19
0
ファイル: objrtcmp.c プロジェクト: garydriley/FuzzyCLIPS631
/***********************************************************
  NAME         : ClassAlphaLinksToCode
  DESCRIPTION  : Writes out data structures for run-time
                 creation of class alpha link
  INPUTS       : 1) The base image output file name
                 2) The base image file id
                 3) A pointer to the header output file
                 4) The id of constructs-to-c image
                 5) The maximum number of indices
                    allowed in any single array
                    in the image
  RETURNS      : Next version file to open, 0 if error
  SIDE EFFECTS : Class alpha links code written to files
  NOTES        : None
 ***********************************************************/
static int ClassAlphaLinksToCode(
  void *theEnv,
  const char *fileName,
  const char *pathName,
  char *fileNameBuffer,
  int fileID,
  FILE *headerFP,
  int imageID,
  int maxIndices,
  int version)
  {
   FILE *fp;
   int arrayVersion;
   int newHeader;
   int i;
   struct defmodule *theModule = NULL;
   DEFCLASS *theDefclass = NULL;
   CLASS_ALPHA_LINK *theLink = NULL;

   /* =================================
      Dump the alpha link structures.
      ================================= */
   if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL)
     return(0);
   newHeader = TRUE;

   arrayVersion = 1;
   i = 1;
 
   theLink = GetNextAlphaLink(theEnv,&theModule,&theDefclass,theLink);
   while (theLink != NULL)
     {
      if (newHeader)
        {
         fprintf(fp,"CLASS_ALPHA_LINK %s%d_%d[] = {\n",
                    ObjectALPrefix(),imageID,arrayVersion);
         fprintf(headerFP,"extern CLASS_ALPHA_LINK %s%d_%d[];\n",
                          ObjectALPrefix(),imageID,arrayVersion);
         newHeader = FALSE;
        }

      fprintf(fp,"{");
      
      ObjectPatternNodeReference(theEnv,theLink->alphaNode,fp,imageID,maxIndices);

      fprintf(fp,",");
            
      ClassAlphaLinkReference(theEnv,theLink->next,fp,imageID,maxIndices);

      fprintf(fp,"}");
      
      theLink = GetNextAlphaLink(theEnv,&theModule,&theDefclass,theLink);
      
      if ((i > maxIndices) || (theLink == NULL))
        {
         fprintf(fp,"};\n");
         GenClose(theEnv,fp);
         i = 1;
         version++;
         arrayVersion++;
         if (theLink != NULL)
           {
            if ((fp = NewCFile(theEnv,fileName,pathName,fileNameBuffer,fileID,version,FALSE)) == NULL)
              return(0);
            newHeader = TRUE;
           }
        }
      else if (theLink != NULL)
        { fprintf(fp,",\n"); }
     }

   return(version);
  }