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

📄 classexm.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*               CLIPS Version 6.05  04/09/97          */   /*                                                     */   /*                 CLASS EXAMINATION MODULE            */   /*******************************************************//**************************************************************//* Purpose: Class browsing and examination commands           *//*                                                            *//* Principal Programmer(s):                                   *//*      Brian L. Donnell                                      *//*                                                            *//* Contributing Programmer(s):                                *//*                                                            *//* Revision History:                                          *//*                                                            *//**************************************************************/   /* =========================================   *****************************************               EXTERNAL DEFINITIONS   =========================================   ***************************************** */#include "setup.h"#if OBJECT_SYSTEM#if ANSI_COMPILER#include <string.h>#endif#include "argacces.h"#include "classcom.h"#include "classfun.h"#include "classini.h"#include "clipsmem.h"#include "insfun.h"#include "msgcom.h"#include "msgfun.h"#include "router.h"#include "strngrtr.h"#define _CLASSEXM_SOURCE_#include "classexm.h"/* =========================================   *****************************************                   CONSTANTS   =========================================   ***************************************** */   /* =========================================   *****************************************                MACROS AND TYPES   =========================================   ***************************************** *//* =========================================   *****************************************      INTERNALLY VISIBLE FUNCTION HEADERS   =========================================   ***************************************** */#if ANSI_COMPILERstatic int CheckTwoClasses(char *,DEFCLASS **,DEFCLASS **);static SLOT_DESC *CheckSlotExists(char *,DEFCLASS **,BOOLEAN,BOOLEAN);static SLOT_DESC *LookupSlot(DEFCLASS *,char *,BOOLEAN);#if DEBUGGING_FUNCTIONSstatic DEFCLASS *CheckClass(char *,char *);static char *GetClassNameArgument(char *);static VOID PrintClassBrowse(char *,DEFCLASS *,int);static VOID DisplaySeparator(char *,char *,int,int);static VOID DisplaySlotBasicInfo(char *,char *,char *,char *,DEFCLASS *);static BOOLEAN PrintSlotSources(char *,SYMBOL_HN *,PACKED_CLASS_LINKS *,unsigned,int);static VOID DisplaySlotConstraintInfo(char *,char *,char *,int,DEFCLASS *);static char *ConstraintCode(CONSTRAINT_RECORD *,unsigned,unsigned);#endif#elsestatic int CheckTwoClasses();static SLOT_DESC *CheckSlotExists();static SLOT_DESC *LookupSlot();#if DEBUGGING_FUNCTIONSstatic DEFCLASS *CheckClass();static char *GetClassNameArgument();static VOID PrintClassBrowse();static VOID DisplaySeparator();static VOID DisplaySlotBasicInfo();static BOOLEAN PrintSlotSources();static VOID DisplaySlotConstraintInfo();static char *ConstraintCode();#endif#endif/* =========================================   *****************************************      EXTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */   /* =========================================   *****************************************      INTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** *//* =========================================   *****************************************          EXTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */   #if DEBUGGING_FUNCTIONS/****************************************************************  NAME         : BrowseClassesCommand  DESCRIPTION  : Displays a "graph" of the class hierarchy  INPUTS       : None  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : Syntax : CLIPS> (browse-classes [<class>]) ****************************************************************/globle VOID BrowseClassesCommand()  {   register DEFCLASS *cls;      if (RtnArgCount() == 0)      /* ================================================         Find the OBJECT root class (has no superclasses)         ================================================ */      cls = LookupDefclassByMdlOrScope(OBJECT_TYPE_NAME);   else     {      DATA_OBJECT tmp;            if (ArgTypeCheck("browse-classes",1,SYMBOL,&tmp) == CLIPS_FALSE)        return;      cls = LookupDefclassByMdlOrScope(DOToString(tmp));      if (cls == NULL)        {         ClassExistError("browse-classes",DOToString(tmp));         return;        }     }   BrowseClasses(WDISPLAY,(VOID *) cls);  }  /****************************************************************  NAME         : BrowseClasses  DESCRIPTION  : Displays a "graph" of the class hierarchy  INPUTS       : 1) The logical name of the output                 2) Class pointer  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : None ****************************************************************/globle VOID BrowseClasses(logicalName,clsptr)  char *logicalName;  VOID *clsptr;  {   PrintClassBrowse(logicalName,(DEFCLASS *) clsptr,0);  }/****************************************************************  NAME         : DescribeClassCommand  DESCRIPTION  : Displays direct superclasses and                   subclasses and the entire precedence                   list for a class  INPUTS       : None  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : Syntax : CLIPS> (describe-class <class-name>) ****************************************************************/globle VOID DescribeClassCommand()  {   char *cname;   DEFCLASS *cls;   cname = GetClassNameArgument("describe-class");      if (cname == NULL)     return;   cls = CheckClass("describe-class",cname);   if (cls == NULL)     return;   DescribeClass(WDISPLAY,(VOID *) cls);  }  /******************************************************  NAME         : DescribeClass  DESCRIPTION  : Displays direct superclasses and                   subclasses and the entire precedence                   list for a class  INPUTS       : 1) The logical name of the output                 2) Class pointer  RETURNS      : Nothing useful  SIDE EFFECTS : None  NOTES        : None ******************************************************/globle VOID DescribeClass(logicalName,clsptr)  char *logicalName;  VOID *clsptr;  {   DEFCLASS *cls;   char buf[83],        slotNamePrintFormat[12],        overrideMessagePrintFormat[12];   int i,messageBanner,       slotNameLength,overrideMessageLength,       maxSlotNameLength,maxOverrideMessageLength;      cls = (DEFCLASS *) clsptr;      DisplaySeparator(logicalName,buf,82,'=');   DisplaySeparator(logicalName,buf,82,'*');   if (cls->abstract)     PrintCLIPS(logicalName,"Abstract: direct instances of this class cannot be created.\n\n");   else     {      PrintCLIPS(logicalName,"Concrete: direct instances of this class can be created.\n");#if INSTANCE_PATTERN_MATCHING      if (cls->reactive)        PrintCLIPS(logicalName,"Reactive: direct instances of this class can match defrule patterns.\n\n");      else        PrintCLIPS(logicalName,"Non-reactive: direct instances of this class cannot match defrule patterns.\n\n");#else      PrintCLIPS(logicalName,"\n");#endif     }   PrintPackedClassLinks(logicalName,"Direct Superclasses:",&cls->directSuperclasses);   PrintPackedClassLinks(logicalName,"Inheritance Precedence:",&cls->allSuperclasses);   PrintPackedClassLinks(logicalName,"Direct Subclasses:",&cls->directSubclasses);   if (cls->instanceTemplate != NULL)     {      DisplaySeparator(logicalName,buf,82,'-');      maxSlotNameLength = 5;      maxOverrideMessageLength = 8;      for (i = 0 ; i < cls->instanceSlotCount ; i++)        {         slotNameLength = strlen(ValueToString(cls->instanceTemplate[i]->slotName->name));         if (slotNameLength > maxSlotNameLength)           maxSlotNameLength = slotNameLength;         if (cls->instanceTemplate[i]->noWrite == 0)           {            overrideMessageLength =               strlen(ValueToString(cls->instanceTemplate[i]->overrideMessage));            if (overrideMessageLength > maxOverrideMessageLength)              maxOverrideMessageLength = overrideMessageLength;           }        }      if (maxSlotNameLength > 16)        maxSlotNameLength = 16;      if (maxOverrideMessageLength > 12)        maxOverrideMessageLength = 12;      sprintf(slotNamePrintFormat,"%%-%d.%ds : ",maxSlotNameLength,maxSlotNameLength);      sprintf(overrideMessagePrintFormat,"%%-%d.%ds ",maxOverrideMessageLength,                                              maxOverrideMessageLength);      DisplaySlotBasicInfo(logicalName,slotNamePrintFormat,overrideMessagePrintFormat,buf,cls);      PrintCLIPS(logicalName,"\nConstraint information for slots:\n\n");      DisplaySlotConstraintInfo(logicalName,slotNamePrintFormat,buf,82,cls);     }   if (cls->handlerCount > 0)     messageBanner = CLIPS_TRUE;   else     {      messageBanner = CLIPS_FALSE;      for (i = 1 ; i < cls->allSuperclasses.classCount ; i++)        if (cls->allSuperclasses.classArray[i]->handlerCount > 0)          {           messageBanner = CLIPS_TRUE;           break;          }     }   if (messageBanner)     {      DisplaySeparator(logicalName,buf,82,'-');      PrintCLIPS(logicalName,"Recognized message-handlers:\n");      DisplayHandlersInLinks(logicalName,&cls->allSuperclasses,0);     }   DisplaySeparator(logicalName,buf,82,'*');   DisplaySeparator(logicalName,buf,82,'=');  }#endif/**********************************************************  NAME         : GetCreateAccessorString  DESCRIPTION  : Gets a string describing which                 accessors are implicitly created                 for a slot: R, W, RW or NIL  INPUTS       : The slot descriptor  RETURNS      : The string description  SIDE EFFECTS : None  NOTES        : Used by (describe-class) and (slot-facets) **********************************************************/globle char *GetCreateAccessorString(vsd)  VOID *vsd;  {   SLOT_DESC *sd = (SLOT_DESC *) vsd;     if (sd->createReadAccessor && sd->createWriteAccessor)     return("RW");   if ((sd->createReadAccessor == 0) && (sd->createWriteAccessor == 0))     return("NIL");   else     return(sd->createReadAccessor ? "R" : "W");  }  /************************************************************  NAME         : GetDefclassModuleCommand  DESCRIPTION  : Determines to which module a class belongs  INPUTS       : None  RETURNS      : The symbolic name of the module  SIDE EFFECTS : None  NOTES        : CLIPS Syntax: (defclass-module <class-name>) ************************************************************/globle SYMBOL_HN *GetDefclassModuleCommand()  {   return(GetConstructModuleCommand("defclass-module",DefclassConstruct));  }  /*********************************************************************  NAME         : SuperclassPCommand  DESCRIPTION  : Determines if a class is a superclass of another  INPUTS       : None  RETURNS      : CLIPS_TRUE if class-1 is a superclass of class-2  SIDE EFFECTS : None  NOTES        : CLIPS Syntax : (superclassp <class-1> <class-2>) *********************************************************************/globle BOOLEAN SuperclassPCommand()  {   DEFCLASS *c1,*c2;      if (CheckTwoClasses("superclassp",&c1,&c2) == CLIPS_FALSE)     return(CLIPS_FALSE);   return(SuperclassP((VOID *) c1,(VOID *) c2));  }  /***************************************************  NAME         : SuperclassP  DESCRIPTION  : Determines if the first class is                 a superclass of the other  INPUTS       : 1) First class                 2) Second class  RETURNS      : CLIPS_TRUE if first class is a                 superclass of the first,                 CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None ***************************************************/globle BOOLEAN SuperclassP(firstClass,secondClass)  VOID *firstClass,*secondClass;  {   return(HasSuperclass((DEFCLASS *) secondClass,(DEFCLASS *) firstClass));  }/*********************************************************************  NAME         : SubclassPCommand  DESCRIPTION  : Determines if a class is a subclass of another  INPUTS       : None  RETURNS      : CLIPS_TRUE if class-1 is a subclass of class-2  SIDE EFFECTS : None  NOTES        : CLIPS Syntax : (subclassp <class-1> <class-2>) *********************************************************************/globle BOOLEAN SubclassPCommand()  {   DEFCLASS *c1,*c2;      if (CheckTwoClasses("subclassp",&c1,&c2) == CLIPS_FALSE)     return(CLIPS_FALSE);   return(SubclassP((VOID *) c1,(VOID *) c2));  }/***************************************************  NAME         : SubclassP  DESCRIPTION  : Determines if the first class is                 a subclass of the other  INPUTS       : 1) First class                 2) Second class  RETURNS      : CLIPS_TRUE if first class is a                 subclass of the first,                 CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None ***************************************************/globle BOOLEAN SubclassP(firstClass,secondClass)  VOID *firstClass,*secondClass;  {   return(HasSuperclass((DEFCLASS *) firstClass,(DEFCLASS *) secondClass));  }/*********************************************************************  NAME         : SlotExistPCommand  DESCRIPTION  : Determines if a slot is present in a class  INPUTS       : None  RETURNS      : CLIPS_TRUE if the slot exists, CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : CLIPS Syntax : (slot-existp <class> <slot> [inherit]) *********************************************************************/globle int SlotExistPCommand()  {

⌨️ 快捷键说明

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