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

📄 multifld.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                  MULTIFIELD MODULE                  */   /*******************************************************//*************************************************************//* Purpose:                                                  *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _MULTIFLD_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include "setup.h"#include "constant.h"#include "clipsmem.h"#include "evaluatn.h"#include "scanner.h"#include "router.h"#include "strngrtr.h"#include "utility.h"#include "multifld.h"/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/   static struct multifield  *ListOfMultifields = NULL;  /***********************************************************//* CreateMultifield2:       *//***********************************************************/globle VOID *CreateMultifield2(size)  long size; /* 6.04 Bug Fix */  {   struct multifield *theSegment;   long newSize = size;  /* 6.04 Bug Fix */   if (size <= 0) newSize = 1;      theSegment = get_var_struct2(multifield,(long) sizeof(struct field) * (newSize - 1L));         theSegment->multifieldLength = size;   theSegment->depth = (short) CurrentEvaluationDepth;   theSegment->busyCount = 0;   theSegment->next = NULL;   return((VOID *) theSegment);  }/*****************************************************************//* ReturnMultifield:                                             *//*****************************************************************/globle VOID ReturnMultifield(theSegment)  struct multifield *theSegment;  {   long newSize; /* 6.04 Bug Fix */      if (theSegment == NULL) return;      if (theSegment->multifieldLength == 0) newSize = 1;   else newSize = theSegment->multifieldLength;      rtn_var_struct2(multifield,sizeof(struct field) * (newSize - 1),theSegment);  }/******************************//* MultifieldInstall:            *//******************************/globle VOID MultifieldInstall(theSegment)  struct multifield *theSegment;  {   long length, i; /* 6.04 Bug Fix */   struct field HUGE_ADDR *theFields;   if (theSegment == NULL) return;      length = theSegment->multifieldLength;      theSegment->busyCount++;   theFields = theSegment->theFields;   for (i = 0 ; i < length ; i++)     { AtomInstall(theFields[i].type,theFields[i].value); }  }/******************************//* MultifieldDeinstall:       *//******************************/globle VOID MultifieldDeinstall(theSegment)  struct multifield *theSegment;  {   long length, i; /* 6.04 Bug Fix */   struct field HUGE_ADDR *theFields;   if (theSegment == NULL) return;      length = theSegment->multifieldLength;   theSegment->busyCount--;   theFields = theSegment->theFields;   for (i = 0 ; i < length ; i++)     { AtomDeinstall(theFields[i].type,theFields[i].value); }  }/*******************************************************//* StringToMultifield:  Returns a multifield structure *//*    that represents the string sent as the argument. *//*******************************************************/globle struct multifield *StringToMultifield(theString)  char *theString;  {   struct token theToken;   struct multifield *theSegment;   struct field HUGE_ADDR *theFields;   long numberOfFields = 0; /* 6.04 Bug Fix */   struct expr *topAtom = NULL, *lastAtom = NULL, *theAtom;   /*====================================================*/   /* Open the string as an input source and read in the */   /* list of values to be stored in the multifield.     */   /*====================================================*/      OpenStringSource("multifield-str",theString,0);   GetToken("multifield-str",&theToken);   while (theToken.type != STOP)     {      if ((theToken.type == SYMBOL) || (theToken.type == STRING) ||          (theToken.type == FLOAT) || (theToken.type == INTEGER) ||          (theToken.type == INSTANCE_NAME))        { theAtom = GenConstant(theToken.type,theToken.value); }      else        { theAtom = GenConstant(STRING,AddSymbol(theToken.printForm)); }      numberOfFields++;      if (topAtom == NULL) topAtom = theAtom;      else lastAtom->nextArg = theAtom;      lastAtom = theAtom;      GetToken("multifield-str",&theToken);     }   CloseStringSource("multifield-str");   /*====================================================================*/   /* Create a multifield of the appropriate size for the values parsed. */   /*====================================================================*/      theSegment = (struct multifield *) CreateMultifield(numberOfFields);   theFields = theSegment->theFields;   /*====================================*/   /* Copy the values to the multifield. */   /*====================================*/      theAtom = topAtom;   numberOfFields = 0;   while (theAtom != NULL)     {      theFields[numberOfFields].type = theAtom->type;      theFields[numberOfFields].value = theAtom->value;      numberOfFields++;      theAtom = theAtom->nextArg;     }   /*===========================*/   /* Return the parsed values. */   /*===========================*/      ReturnExpression(topAtom);   /*============================*/   /* Return the new multifield. */   /*============================*/      return(theSegment);  }/***********************************************************//* CreateMultifield: Creates a multifield of the specified *//*   size and adds it to the list of segments.             *//***********************************************************/globle VOID *CreateMultifield(size)  long size; /* 6.04 Bug Fix */  {   struct multifield *theSegment;   long newSize; /* 6.04 Bug Fix */   if (size <= 0) newSize = 1;   else newSize = size;   theSegment = get_var_struct2(multifield,(long) sizeof(struct field) * (newSize - 1L));         theSegment->multifieldLength = size;   theSegment->depth = (short) CurrentEvaluationDepth;   theSegment->busyCount = 0;   theSegment->next = NULL;        theSegment->next = ListOfMultifields;   ListOfMultifields = theSegment;   EphemeralItemCount++;   EphemeralItemSize += sizeof(struct multifield) + (sizeof(struct field) * newSize);   return((VOID *) theSegment);  }  /*********************************************************************//* DOToMultifield:    *//*********************************************************************/globle VOID *DOToMultifield(theValue)  DATA_OBJECT *theValue;  {   struct multifield *dst, *src;      if (theValue->type != MULTIFIELD) return(NULL);      dst = (struct multifield *) CreateMultifield2(GetpDOLength(theValue));      src = (struct multifield *) theValue->value;   CopyMemory(struct field,dst->multifieldLength,              &(dst->theFields[0]),&(src->theFields[GetpDOBegin(theValue) - 1]));   return((VOID *) dst);  }  /***********************************************************//* AddToMultifieldList:                                       *//***********************************************************/globle VOID AddToMultifieldList(theSegment)  struct multifield *theSegment;  {   theSegment->depth = (short) CurrentEvaluationDepth;   theSegment->next = ListOfMultifields;   ListOfMultifields = theSegment;   EphemeralItemCount++;   EphemeralItemSize += sizeof(struct multifield) + (sizeof(struct field) * theSegment->multifieldLength);  }/***********************************************************//* FlushMultifields:                                         *//***********************************************************/globle VOID FlushMultifields()  {   struct multifield *theSegment, *nextPtr, *lastPtr = NULL;   long newSize; /* 6.04 Bug Fix */   theSegment = ListOfMultifields;   while (theSegment != NULL)     {      nextPtr = theSegment->next;      if ((theSegment->depth > CurrentEvaluationDepth) && (theSegment->busyCount == 0))

⌨️ 快捷键说明

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