⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symblcmp.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*           SYMBOL CONSTRUCT COMPILER MODULE          */   /*******************************************************//*************************************************************//* Purpose: Implements the constructs-to-c feature for       *//*   atomic data values: symbols, integers, floats, and      *//*   bit maps.                                               *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*      Barry Cameron                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _SYMBLCMP_SOURCE_#include "setup.h"#if CONSTRUCT_COMPILER && (! RUN_TIME)#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "symbol.h"#include "clipsmem.h"#include "constant.h"#include "exprnpsr.h"#include "cstrccom.h"#include "constrct.h"#include "argacces.h"#include "cstrncmp.h"#include "router.h"#include "conscomp.h"#include "utility.h"#include "symblcmp.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER   static int                         SymbolHashNodesToCode(char *,int);   static int                         BitMapHashNodesToCode(char *,int);   static int                         BitMapValuesToCode(char *,int);   static int                         FloatHashNodesToCode(char *,int);   static int                         IntegerHashNodesToCode(char *,int);   static int                         HashTablesToCode(char *);   static VOID                        PrintCString(FILE *,char *);#else   static int                         SymbolHashNodesToCode();   static int                         BitMapHashNodesToCode();   static int                         BitMapValuesToCode();   static int                         FloatHashNodesToCode();   static int                         IntegerHashNodesToCode();   static int                         HashTablesToCode();   static VOID                        PrintCString();#endif/**************************************************************//* AtomicValuesToCode: Driver routine for generating the code *//*  used by the symbol, integer, float, and bit map tables.   *//**************************************************************/globle VOID AtomicValuesToCode(fileName)  char *fileName;  {   int version;   SetAtomicValueIndices(CLIPS_TRUE);   HashTablesToCode(fileName);   version = SymbolHashNodesToCode(fileName,5);   version = FloatHashNodesToCode(fileName,version);   version = IntegerHashNodesToCode(fileName,version);   version = BitMapHashNodesToCode(fileName,version);   BitMapValuesToCode(fileName,version);  }/*****************************************************//* SymbolHashNodesToCode: Produces the code for the  *//*   symbol hash table entries for a run-time module *//*   created using the constructs-to-c function.     *//*****************************************************/static int SymbolHashNodesToCode(fileName,version)  char *fileName;  int version;  {   int i, j;   struct symbolHashNode *hashPtr;   int count;   int numberOfEntries;   struct symbolHashNode **symbolTable;   int newHeader = CLIPS_TRUE;   int arrayVersion = 1;   FILE *fp;   /*====================================*/   /* Count the total number of entries. */   /*====================================*/   symbolTable = GetSymbolTable();   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 <= (numberOfEntries / MaxIndices) + 1 ; i++)     { fprintf(HeaderFP,"extern struct symbolHashNode S%d_%d[];\n",ImageID,i); }   /*==================*/   /* Create the file. */   /*==================*/   if ((fp = NewCFile(fileName,1,version,CLIPS_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",ImageID,arrayVersion);            newHeader = CLIPS_FALSE;           }         if (hashPtr->next == NULL)           { fprintf(fp,"{NULL,"); }         else           {            if ((j + 1) >= MaxIndices)              { fprintf(fp,"{&S%d_%d[%d],",ImageID,arrayVersion + 1,0); }            else              { fprintf(fp,"{&S%d_%d[%d],",ImageID,arrayVersion,j + 1); }           }         fprintf(fp,"%ld,0,0,0,%d,",hashPtr->count + 1,i);         PrintCString(fp,hashPtr->contents);         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,CLIPS_FALSE)) == NULL) return(0);               newHeader = CLIPS_TRUE;              }           }         else           { fprintf(fp,"},\n"); }        }     }   return(version);  }  /******************************************************//* BitMapHashNodesToCode: Produces the code for the   *//*   bit map hash table entries for a run-time module *//*   created using the constructs-to-c function.      *//******************************************************/static int BitMapHashNodesToCode(fileName,version)  char *fileName;  int version;  {   int i, j;   struct bitMapHashNode *hashPtr;   int count;   int numberOfEntries;   struct bitMapHashNode **bitMapTable;   int newHeader = CLIPS_TRUE;   int arrayVersion = 1;   FILE *fp;   int longsReqdPartition = 1,longsReqdPartitionCount = 0;      /*====================================*/   /* Count the total number of entries. */   /*====================================*/   bitMapTable = GetBitMapTable();   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 / MaxIndices) + 1 ; i++)     { fprintf(HeaderFP,"extern struct bitMapHashNode B%d_%d[];\n",ImageID,i); }        /*==================*/   /* Create the file. */   /*==================*/   if ((fp = NewCFile(fileName,1,version,CLIPS_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",ImageID,arrayVersion);            newHeader = CLIPS_FALSE;           }         if (hashPtr->next == NULL)           { fprintf(fp,"{NULL,"); }         else           {            if ((j + 1) >= MaxIndices)              { fprintf(fp,"{&B%d_%d[%d],",ImageID,arrayVersion + 1,0); }            else              { fprintf(fp,"{&B%d_%d[%d],",ImageID,arrayVersion,j + 1); }           }         fprintf(fp,"%ld,0,0,0,%d,(char *) &L%d_%d[%d],%d",                     hashPtr->count + 1,i,                     ImageID,longsReqdPartition,longsReqdPartitionCount,                     hashPtr->size);                                       longsReqdPartitionCount += (int) (hashPtr->size / sizeof(unsigned long));         if ((hashPtr->size % sizeof(unsigned long)) != 0)           longsReqdPartitionCount++;         if (longsReqdPartitionCount >= MaxIndices)           {            longsReqdPartitionCount = 0;            longsReqdPartition++;           }                             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,CLIPS_FALSE)) == NULL) return(0);               newHeader = CLIPS_TRUE;              }           }         else           { fprintf(fp,"},\n"); }        }     }   return(version);  }/*****************************************************//* BitMapValuesToCode: Produces the code for the bit *//*   map strings for a run-time module created using *//*   the constructs-to-c function.                   *//*****************************************************/static int BitMapValuesToCode(fileName,version)  char *fileName;  int version;  {   int i, j, k, l;   struct bitMapHashNode *hashPtr;   int count;   int numberOfEntries;   struct bitMapHashNode **bitMapTable;   int newHeader = CLIPS_TRUE;   int arrayVersion = 1;   FILE *fp;   unsigned long tmpLong;   int longsReqd;      /*====================================*/   /* Count the total number of entries. */   /*====================================*/   bitMapTable = GetBitMapTable();   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 / MaxIndices) + 1 ; i++)     { fprintf(HeaderFP,"extern unsigned long L%d_%d[];\n",ImageID,i); }   /*==================*/   /* Create the file. */   /*==================*/   if ((fp = NewCFile(fileName,1,version,CLIPS_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",ImageID,arrayVersion);            newHeader = CLIPS_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) < 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 >= MaxIndices))           {            fprintf(fp,"};\n");            fclose(fp);            j = 0;            arrayVersion++;            version++;            if (count < numberOfEntries)              {               if ((fp = NewCFile(fileName,1,version,CLIPS_FALSE)) == NULL) return(0);               newHeader = CLIPS_TRUE;              }           }         else           { fprintf(fp,",\n"); }        }     }   return(version);  }/****************************************************//* FloatHashNodesToCode: Produces the code for the  *//*   float hash table entries for a run-time module *//*   created using the constructs-to-c function.    *//****************************************************/static int FloatHashNodesToCode(fileName,version)  char *fileName;  int version;  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -