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

📄 cstrnutl.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*             CONSTRAINT UTILITY MODULE               */   /*******************************************************//*************************************************************//* Purpose: Utility routines for manipulating, initializing, *//*   creating, copying, and comparing constraint records.    *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian Donnell                                        *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _CSTRNUTL_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#if ANSI_COMPILER#include <stdlib.h>#endif#include "setup.h"#include "constant.h"#include "clipsmem.h"#include "router.h"#include "extnfunc.h"#include "scanner.h"#include "multifld.h"#include "argacces.h"#include "cstrnutl.h"   /************************************************//* GetConstraintRecord: Creates and initializes *//*   the values of a constraint record.         *//************************************************/globle struct constraintRecord *GetConstraintRecord()  {      CONSTRAINT_RECORD *constraints;   unsigned i;   constraints = get_struct(constraintRecord);     /* 6.05 bug fix - bit fields must be      initialized to null bytes before access */   for (i = 0 ; i < sizeof(CONSTRAINT_RECORD) ; i++)     ((char *) constraints)[i] = '\0';   SetAnyAllowedFlags(constraints,CLIPS_TRUE);      constraints->multifieldsAllowed = CLIPS_FALSE;   constraints->singlefieldsAllowed = CLIPS_TRUE;         constraints->anyRestriction = CLIPS_FALSE;   constraints->symbolRestriction = CLIPS_FALSE;   constraints->stringRestriction = CLIPS_FALSE;   constraints->floatRestriction = CLIPS_FALSE;   constraints->integerRestriction = CLIPS_FALSE;   constraints->instanceNameRestriction = CLIPS_FALSE;    constraints->restrictionList = NULL;   constraints->minValue = GenConstant(SYMBOL,NegativeInfinity);   constraints->maxValue = GenConstant(SYMBOL,PositiveInfinity);   constraints->minFields = GenConstant(INTEGER,Zero);   constraints->maxFields = GenConstant(SYMBOL,PositiveInfinity);   constraints->bucket = -1;   constraints->count = 0;   constraints->multifield = NULL;    constraints->next = NULL;      return(constraints);  }/********************************************************//* SetAnyAllowedFlags: Sets the allowed type flags of a *//*   constraint record to allow all types. If passed an *//*   argument of TRUE, just the "any allowed" flag is   *//*   set to TRUE. If passed an argument of FALSE, then  *//*   all of the individual type flags are set to TRUE.  *//********************************************************/globle VOID SetAnyAllowedFlags(theConstraint,justOne)  CONSTRAINT_RECORD *theConstraint;  int justOne;  {   int flag1, flag2;      if (justOne)      {      flag1 = CLIPS_TRUE;      flag2 = CLIPS_FALSE;     }   else     {      flag1 = CLIPS_FALSE;      flag2 = CLIPS_TRUE;     }   theConstraint->anyAllowed = flag1;   theConstraint->symbolsAllowed = flag2;   theConstraint->stringsAllowed = flag2;   theConstraint->floatsAllowed = flag2;   theConstraint->integersAllowed = flag2;   theConstraint->instanceNamesAllowed = flag2;   theConstraint->instanceAddressesAllowed = flag2;   theConstraint->externalAddressesAllowed = flag2;    theConstraint->factAddressesAllowed = flag2;   }/*****************************************************//* CopyConstraintRecord: Copies a constraint record. *//*****************************************************/globle struct constraintRecord *CopyConstraintRecord(sourceConstraint)  CONSTRAINT_RECORD *sourceConstraint;  {      CONSTRAINT_RECORD *theConstraint;      if (sourceConstraint == NULL) return(NULL);      theConstraint = get_struct(constraintRecord);     theConstraint->anyAllowed = sourceConstraint->anyAllowed;   theConstraint->symbolsAllowed = sourceConstraint->symbolsAllowed;   theConstraint->stringsAllowed = sourceConstraint->stringsAllowed;   theConstraint->floatsAllowed = sourceConstraint->floatsAllowed;   theConstraint->integersAllowed = sourceConstraint->integersAllowed;   theConstraint->instanceNamesAllowed = sourceConstraint->instanceNamesAllowed;   theConstraint->instanceAddressesAllowed = sourceConstraint->instanceAddressesAllowed;   theConstraint->externalAddressesAllowed = sourceConstraint->externalAddressesAllowed;    theConstraint->multifieldsAllowed = sourceConstraint->multifieldsAllowed;    theConstraint->singlefieldsAllowed = sourceConstraint->singlefieldsAllowed;   theConstraint->factAddressesAllowed = sourceConstraint->factAddressesAllowed;     theConstraint->anyRestriction = sourceConstraint->anyRestriction;   theConstraint->symbolRestriction = sourceConstraint->symbolRestriction;   theConstraint->stringRestriction = sourceConstraint->stringRestriction;   theConstraint->floatRestriction = sourceConstraint->floatRestriction;   theConstraint->integerRestriction = sourceConstraint->integerRestriction;   theConstraint->instanceNameRestriction = sourceConstraint->instanceNameRestriction;    theConstraint->restrictionList = CopyExpression(sourceConstraint->restrictionList);   theConstraint->minValue = CopyExpression(sourceConstraint->minValue);   theConstraint->maxValue = CopyExpression(sourceConstraint->maxValue);   theConstraint->minFields = CopyExpression(sourceConstraint->minFields);   theConstraint->maxFields = CopyExpression(sourceConstraint->maxFields);   theConstraint->bucket = -1;   theConstraint->count = 0;   theConstraint->multifield = CopyConstraintRecord(sourceConstraint->multifield);   theConstraint->next = NULL;      return(theConstraint);  }#if (! RUN_TIME) && (! BLOAD_ONLY)/**************************************************************//* SetAnyRestrictionFlags: Sets the restriction type flags of *//*   a constraint record to indicate there are restriction on *//*   all types. If passed an argument of TRUE, just the       *//*   "any restriction" flag is set to TRUE. If passed an      *//*   argument of FALSE, then all of the individual type       *//*   restriction flags are set to TRUE.                       *//**************************************************************/globle VOID SetAnyRestrictionFlags(theConstraint,justOne)  CONSTRAINT_RECORD *theConstraint;  int justOne;  {   int flag1, flag2;      if (justOne)      {      flag1 = CLIPS_TRUE;      flag2 = CLIPS_FALSE;     }   else     {      flag1 = CLIPS_FALSE;      flag2 = CLIPS_TRUE;     }      theConstraint->anyRestriction = flag1;   theConstraint->symbolRestriction = flag2;   theConstraint->stringRestriction = flag2;   theConstraint->floatRestriction = flag2;   theConstraint->integerRestriction = flag2;   theConstraint->instanceNameRestriction = flag2;  }  /*****************************************************//* SetConstraintType: Given a constraint type and a  *//*   constraint, sets the allowed type flags for the *//*   specified type in the constraint to TRUE.       *//*****************************************************/globle int SetConstraintType(theType,constraints)  int theType;  CONSTRAINT_RECORD *constraints;  {   int rv = CLIPS_TRUE;      switch(theType)     {      case UNKNOWN_VALUE:         rv = constraints->anyAllowed;         constraints->anyAllowed = CLIPS_TRUE;         break;               case SYMBOL:         rv = constraints->symbolsAllowed;         constraints->symbolsAllowed = CLIPS_TRUE;         break;               case STRING:         rv = constraints->stringsAllowed;         constraints->stringsAllowed = CLIPS_TRUE;         break;               case SYMBOL_OR_STRING:         rv = (constraints->stringsAllowed | constraints->symbolsAllowed);         constraints->symbolsAllowed = CLIPS_TRUE;         constraints->stringsAllowed = CLIPS_TRUE;         break;               case INTEGER:         rv = constraints->integersAllowed;         constraints->integersAllowed = CLIPS_TRUE;         break;               case FLOAT:         rv = constraints->floatsAllowed;         constraints->floatsAllowed = CLIPS_TRUE;         break;               case INTEGER_OR_FLOAT:         rv = (constraints->integersAllowed | constraints->floatsAllowed);         constraints->integersAllowed = CLIPS_TRUE;         constraints->floatsAllowed = CLIPS_TRUE;          break;                   case INSTANCE_ADDRESS:         rv = constraints->instanceAddressesAllowed;         constraints->instanceAddressesAllowed = CLIPS_TRUE;         break;               case INSTANCE_NAME:         rv = constraints->instanceNamesAllowed;         constraints->instanceNamesAllowed = CLIPS_TRUE;         break;               case INSTANCE_OR_INSTANCE_NAME:         rv = (constraints->instanceNamesAllowed | constraints->instanceAddressesAllowed);         constraints->instanceNamesAllowed = CLIPS_TRUE;         constraints->instanceAddressesAllowed = CLIPS_TRUE;          break;                   case EXTERNAL_ADDRESS:         rv = constraints->externalAddressesAllowed;         constraints->externalAddressesAllowed = CLIPS_TRUE;         break;                 case FACT_ADDRESS:         rv = constraints->factAddressesAllowed;         constraints->factAddressesAllowed = CLIPS_TRUE;         break;               case MULTIFIELD:         rv = constraints->multifieldsAllowed;         constraints->multifieldsAllowed = CLIPS_TRUE;         break;     }        if (theType != UNKNOWN_VALUE) constraints->anyAllowed = CLIPS_FALSE;   return(rv);  }    #endif /* (! RUN_TIME) && (! BLOAD_ONLY) *//*************************************************************//* CompareNumbers: Given two numbers (which can be integers, *//*   floats, or the symbols for positive/negative infinity)  *//*   returns the relationship between the numbers (greater   *//*   than, less than or equal).                              *//*************************************************************/globle int CompareNumbers(type1,vptr1,type2,vptr2)  int type1;  VOID *vptr1;  int type2;  VOID *vptr2;  {    /*============================================*/   /* Handle the situation in which the values   */   /* are exactly equal (same type, same value). */   /*============================================*/      if (vptr1 == vptr2) return(EQUAL);      /*=======================================*/   /* Handle the special cases for positive */   /* and negative infinity.                */   /*=======================================*/      if (vptr1 == PositiveInfinity) return(GREATER_THAN);      if (vptr1 == NegativeInfinity) return(LESS_THAN);      if (vptr2 == PositiveInfinity) return(LESS_THAN);      if (vptr2 == NegativeInfinity) return(GREATER_THAN);      /*=======================*/   /* Compare two integers. */   /*=======================*/      if ((type1 == INTEGER) && (type2 == INTEGER))     {      if (ValueToLong(vptr1) < ValueToLong(vptr2))        { return(LESS_THAN); }      else if (ValueToLong(vptr1) > ValueToLong(vptr2))        { return(GREATER_THAN); }              return(EQUAL);     }        /*=====================*/   /* Compare two floats. */   /*=====================*/      if ((type1 == FLOAT) && (type2 == FLOAT))

⌨️ 快捷键说明

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