factfun.c

来自「一套美国国家宇航局人工智能中心NASA的专家系统工具源代码」· C语言 代码 · 共 510 行 · 第 1/2 页

C
510
字号
   /*=====================*/   /* Get the slot names. */   /*=====================*/      FactSlotNames(theFact,returnValue);  }/***************************************//* FactSlotNames: C access routine for *//*   the fact-slot-names function.     *//***************************************/globle VOID FactSlotNames(vTheFact,returnValue)  VOID *vTheFact;  DATA_OBJECT *returnValue;  {   struct fact *theFact = (struct fact *) vTheFact;   struct multifield *theList;   struct templateSlot *theSlot;   int count;   /*===============================================*/   /* If we're dealing with an implied deftemplate, */   /* then the only slot names is "implied."        */   /*===============================================*/      if (theFact->whichDeftemplate->implied)     {       SetpType(returnValue,MULTIFIELD);      SetpDOBegin(returnValue,1);      SetpDOEnd(returnValue,1);      theList = (struct multifield *) CreateMultifield((int) 1);      SetMFType(theList,1,SYMBOL);      SetMFValue(theList,1,AddSymbol("implied"));      SetpValue(returnValue,(VOID *) theList);       return;     }        /*=================================*/   /* Count the number of slot names. */   /*=================================*/      for (count = 0, theSlot = theFact->whichDeftemplate->slotList;        theSlot != NULL;        count++, theSlot = theSlot->next)     { /* Do Nothing */ }      /*=============================================================*/   /* Create a multifield value in which to store the slot names. */   /*=============================================================*/   SetpType(returnValue,MULTIFIELD);   SetpDOBegin(returnValue,1);   SetpDOEnd(returnValue,count);   theList = (struct multifield *) CreateMultifield(count);   SetpValue(returnValue,(VOID *) theList);       /*===============================================*/   /* Store the slot names in the multifield value. */   /*===============================================*/      for (count = 1, theSlot = theFact->whichDeftemplate->slotList;        theSlot != NULL;        count++, theSlot = theSlot->next)     {       SetMFType(theList,count,SYMBOL);      SetMFValue(theList,count,theSlot->slotName);     }   }/*********************************************//* GetFactListFunction: CLIPS access routine *//*   for the get-fact-list function.         *//*********************************************/globle VOID GetFactListFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {   struct defmodule *theModule;   DATA_OBJECT result;   int numArgs;      /*===========================================*/   /* Determine if a module name was specified. */   /*===========================================*/      if ((numArgs = ArgCountCheck("get-fact-list",NO_MORE_THAN,1)) == -1)     {            SetMultifieldErrorValue(returnValue);      return;     }   if (numArgs == 1)     {      RtnUnknown(1,&result);      if (GetType(result) != SYMBOL)        {         SetMultifieldErrorValue(returnValue);         ExpectedTypeError1("get-fact-list",1,"defmodule name");         return;        }              if ((theModule = (struct defmodule *) FindDefmodule(DOToString(result))) == NULL)        {         if (strcmp("*",DOToString(result)) != 0)            {            SetMultifieldErrorValue(returnValue);            ExpectedTypeError1("get-fact-list",1,"defmodule name");            return;           }                    theModule = NULL;        }     }   else     { theModule = ((struct defmodule *) GetCurrentModule()); }     /*=====================*/   /* Get the constructs. */   /*=====================*/      GetFactList(returnValue,theModule);  }  /*************************************//* GetFactList: C access routine for *//*   the get-fact-list function.     *//*************************************/globle VOID GetFactList(returnValue,vTheModule)  DATA_OBJECT_PTR returnValue;  VOID *vTheModule;  {    struct fact *theFact;   long count;   struct multifield *theList;   struct defmodule *theModule = (struct defmodule *) vTheModule;   /*==========================*/   /* Save the current module. */   /*==========================*/      SaveCurrentModule();      /*============================================*/   /* Count the number of facts to be retrieved. */   /*============================================*/      if (theModule == NULL)     {      for (theFact = (struct fact *) GetNextFact(NULL), count = 0;           theFact != NULL;           theFact = (struct fact *) GetNextFact(theFact), count++)        { /* Do Nothing */ }     }   else     {            SetCurrentModule((VOID *) theModule);      UpdateDeftemplateScope();      for (theFact = (struct fact *) GetNextFactInScope(NULL), count = 0;           theFact != NULL;           theFact = (struct fact *) GetNextFactInScope(theFact), count++)        { /* Do Nothing */ }     }      /*===========================================================*/   /* Create the multifield value to store the construct names. */   /*===========================================================*/      SetpType(returnValue,MULTIFIELD);   SetpDOBegin(returnValue,1);   SetpDOEnd(returnValue,count);   theList = (struct multifield *) CreateMultifield(count);   SetpValue(returnValue,(VOID *) theList);   /*==================================================*/   /* Store the fact pointers in the multifield value. */   /*==================================================*/      if (theModule == NULL)     {      for (theFact = (struct fact *) GetNextFact(NULL), count = 1;           theFact != NULL;           theFact = (struct fact *) GetNextFact(theFact), count++)        {          SetMFType(theList,count,FACT_ADDRESS);         SetMFValue(theList,count,(VOID *) theFact);        }     }   else     {            for (theFact = (struct fact *) GetNextFactInScope(NULL), count = 1;           theFact != NULL;           theFact = (struct fact *) GetNextFactInScope(theFact), count++)        {          SetMFType(theList,count,FACT_ADDRESS);         SetMFValue(theList,count,(VOID *) theFact);        }     }   /*=============================*/   /* Restore the current module. */   /*=============================*/      RestoreCurrentModule();   UpdateDeftemplateScope();  }   /**************************************************************//* GetFactAddressOrIndexArgument: Retrieves an argument for a *//*   function which should be a reference to a valid fact.    *//**************************************************************/globle struct fact *GetFactAddressOrIndexArgument(theFunction,position,noFactError)  char *theFunction;  int position;  int noFactError;  {   DATA_OBJECT item;   long factIndex;   struct fact *theFact;   char tempBuffer[20];   RtnUnknown(position,&item);   if (GetType(item) == FACT_ADDRESS)     {       if (((struct fact *) GetValue(item))->garbage) return(NULL);      else return (((struct fact *) GetValue(item)));      }   else if (GetType(item) == INTEGER)     {      factIndex = ValueToLong(item.value);      if (factIndex < 0)        {         ExpectedTypeError1(theFunction,position,"fact-address or fact-index");         return(NULL);        }            theFact = FindIndexedFact(factIndex);      if ((theFact == NULL) && noFactError)        {         sprintf(tempBuffer,"f-%ld",factIndex);         CantFindItemErrorMessage("fact",tempBuffer);         return(NULL);        }      return(theFact);     }      ExpectedTypeError1(theFunction,position,"fact-address or fact-index");   return(NULL);  }  #endif /* DEFTEMPLATE_CONSTRUCT */

⌨️ 快捷键说明

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