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

📄 msgcom.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*               CLIPS Version 6.05  04/09/97          */   /*                                                     */   /*                OBJECT MESSAGE COMMANDS              */   /*******************************************************//*************************************************************//* Purpose:                                                  *//*                                                           *//* 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 "classinf.h"#include "insfun.h"#include "insmoddp.h"#include "msgfun.h"#include "prccode.h"#include "router.h"#if BLOAD || BLOAD_AND_BSAVE#include "bload.h"#endif#if ! RUN_TIME#include "extnfunc.h"#endif#if (! BLOAD_ONLY) && (! RUN_TIME)#include "constrct.h"#include "msgpsr.h"#endif#if DEBUGGING_FUNCTIONS#include "watch.h"#endif#define _MSGCOM_SOURCE_#include "msgcom.h"/* =========================================   *****************************************                   CONSTANTS   =========================================   ***************************************** *//* =========================================   *****************************************               MACROS AND TYPES   =========================================   ***************************************** *//* =========================================   *****************************************      INTERNALLY VISIBLE FUNCTION HEADERS   =========================================   ***************************************** */#if ANSI_COMPILER#if ! RUN_TIMEstatic VOID CreateSystemHandlers(void);#endif#if (! BLOAD_ONLY) && (! RUN_TIME)static int WildDeleteHandler(DEFCLASS *,SYMBOL_HN *,char *);#endif#if DEBUGGING_FUNCTIONSstatic BOOLEAN DefmessageHandlerWatchAccess(int,int,EXPRESSION *);static BOOLEAN DefmessageHandlerWatchPrint(char *,int,EXPRESSION *);static BOOLEAN DefmessageHandlerWatchSupport(char *,char *,int,                                             VOID (*)(char *,VOID *,unsigned),                                             VOID (*)(int,VOID *,unsigned),EXPRESSION *);static BOOLEAN WatchClassHandlers(VOID *,char *,int,char *,int,int,                                  VOID (*)(char *,VOID *,unsigned),                                  VOID (*)(int,VOID *,unsigned));static VOID PrintHandlerWatchFlag(char *,VOID *,unsigned);#endif#else#if ! RUN_TIMEstatic VOID CreateSystemHandlers();#endif#if (! BLOAD_ONLY) && (! RUN_TIME)static int WildDeleteHandler();#endif#if DEBUGGING_FUNCTIONSstatic BOOLEAN DefmessageHandlerWatchAccess();static BOOLEAN DefmessageHandlerWatchPrint();static BOOLEAN DefmessageHandlerWatchSupport();static BOOLEAN WatchClassHandlers();static VOID PrintHandlerWatchFlag();#endif#endif      /* =========================================   *****************************************      EXTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** *//* =========================================   *****************************************      INTERNALLY VISIBLE GLOBAL VARIABLES   =========================================   ***************************************** */   static ENTITY_RECORD HandlerGetInfo = { HANDLER_GET,0,1,1,                                        PrintHandlerSlotGetFunction,                                        PrintHandlerSlotGetFunction,NULL,                                        HandlerSlotGetFunction,                                        NULL,NULL,NULL,NULL,NULL,NULL },                                                             HandlerPutInfo = { HANDLER_PUT,0,1,1,                                        PrintHandlerSlotPutFunction,                                        PrintHandlerSlotPutFunction,NULL,                                        HandlerSlotPutFunction,                                        NULL,NULL,NULL,NULL,NULL,NULL };/* =========================================   *****************************************          EXTERNALLY VISIBLE FUNCTIONS   =========================================   ***************************************** */   /***************************************************  NAME         : SetupMessageHandlers  DESCRIPTION  : Sets up internal symbols and                 fucntion definitions pertaining to                 message-handlers.  Also creates                 system handlers  INPUTS       : None  RETURNS      : Nothing useful  SIDE EFFECTS : Functions and data structures                 initialized  NOTES        : Should be called before                 SetupInstanceModDupCommands() in                 INSMODDP.C ***************************************************/globle VOID SetupMessageHandlers()  {   InstallPrimitive(&HandlerGetInfo,HANDLER_GET);   InstallPrimitive(&HandlerPutInfo,HANDLER_PUT);#if ! RUN_TIME     INIT_SYMBOL = (SYMBOL_HN *) AddSymbol(INIT_STRING);   IncrementSymbolCount(INIT_SYMBOL);      DELETE_SYMBOL = (SYMBOL_HN *) AddSymbol(DELETE_STRING);   IncrementSymbolCount(DELETE_SYMBOL);   AddClearFunction("defclass",CreateSystemHandlers,-100);   #if ! BLOAD_ONLY   SELF_SYMBOL = (SYMBOL_HN *) AddSymbol(SELF_STRING);   IncrementSymbolCount(SELF_SYMBOL);     AddConstruct("defmessage-handler","defmessage-handlers",                ParseDefmessageHandler,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);   DefineFunction2("undefmessage-handler",'v',PTIF UndefmessageHandlerCommand,                  "UndefmessageHandlerCommand","23w");#endif   DefineFunction2("send",'u',PTIF SendCommand,"SendCommand","2*uuw");   #if DEBUGGING_FUNCTIONS   DefineFunction2("preview-send",'v',PTIF PreviewSendCommand,"PreviewSendCommand","22w");      DefineFunction2("ppdefmessage-handler",'v',PTIF PPDefmessageHandlerCommand,                  "PPDefmessageHandlerCommand","23w");   DefineFunction2("list-defmessage-handlers",'v',PTIF ListDefmessageHandlersCommand,                  "ListDefmessageHandlersCommand","02w");#endif#if IMPERATIVE_MESSAGE_HANDLERS   DefineFunction2("next-handlerp",'b',PTIF NextHandlerAvailable,"NextHandlerAvailable","00");   FuncSeqOvlFlags("next-handlerp",CLIPS_TRUE,CLIPS_FALSE);   DefineFunction2("call-next-handler",'u',                  PTIF CallNextHandler,"CallNextHandler","00");   FuncSeqOvlFlags("call-next-handler",CLIPS_TRUE,CLIPS_FALSE);   DefineFunction2("override-next-handler",'u',                  PTIF CallNextHandler,"CallNextHandler",NULL);   FuncSeqOvlFlags("override-next-handler",CLIPS_TRUE,CLIPS_FALSE);#endif      DefineFunction2("dynamic-get",'u',PTIF DynamicHandlerGetSlot,"DynamicHandlerGetSlot","11w");   DefineFunction2("dynamic-put",'u',PTIF DynamicHandlerPutSlot,"DynamicHandlerPutSlot","1**w");   DefineFunction2("get",'u',PTIF DynamicHandlerGetSlot,"DynamicHandlerGetSlot","11w");   DefineFunction2("put",'u',PTIF DynamicHandlerPutSlot,"DynamicHandlerPutSlot","1**w");#endif   #if DEBUGGING_FUNCTIONS   AddWatchItem("messages",0,&WatchMessages,36,NULL,NULL);   AddWatchItem("message-handlers",0,&WatchHandlers,35,                DefmessageHandlerWatchAccess,DefmessageHandlerWatchPrint);#endif  }/*****************************************************  NAME         : GetDefmessageHandlerName  DESCRIPTION  : Gets the name of a message-handler  INPUTS       : 1) Pointer to a class                 2) Array index of handler in class's                    message-handler array (+1)  RETURNS      : Name-string of message-handler  SIDE EFFECTS : None  NOTES        : None *****************************************************/char *GetDefmessageHandlerName(ptr,index)  VOID *ptr;  unsigned index;  {   return(ValueToString(((DEFCLASS *) ptr)->handlers[index-1].name));  }  /*****************************************************  NAME         : GetDefmessageHandlerType  DESCRIPTION  : Gets the type of a message-handler  INPUTS       : 1) Pointer to a class                 2) Array index of handler in class's                    message-handler array (+1)  RETURNS      : Type-string of message-handler  SIDE EFFECTS : None  NOTES        : None *****************************************************/globle char *GetDefmessageHandlerType(ptr,index)  VOID *ptr;  unsigned index;  {   return(hndquals[((DEFCLASS *) ptr)->handlers[index-1].type]);  }  /**************************************************************  NAME         : GetNextDefmessageHandler  DESCRIPTION  : Finds first or next handler for a class  INPUTS       : 1) The address of the handler's class                 2) The array index of the current handler (+1)  RETURNS      : The array index (+1) of the next handler, or 0                   if there is none  SIDE EFFECTS : None  NOTES        : If index == 0, the first handler array index                 (i.e. 1) returned **************************************************************/globle unsigned GetNextDefmessageHandler(ptr,index)  VOID *ptr;  unsigned index;  {   DEFCLASS *cls;      cls = (DEFCLASS *) ptr;   if (index == 0)     return((cls->handlers != NULL) ? 1 : 0);   if (index == cls->handlerCount)     return(0);    return(index+1);  }#if DEBUGGING_FUNCTIONS /*********************************************************  NAME         : GetDefmessageHandlerWatch  DESCRIPTION  : Determines if trace messages for calls                 to this handler will be generated or not  INPUTS       : 1) A pointer to the class                 2) The index of the handler  RETURNS      : CLIPS_TRUE if a trace is active,                 CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None *********************************************************/globle BOOLEAN GetDefmessageHandlerWatch(theClass,theIndex)  VOID *theClass;  unsigned theIndex;  {   return(((DEFCLASS *) theClass)->handlers[theIndex-1].trace);  }  /*********************************************************  NAME         : SetDefmessageHandlerWatch  DESCRIPTION  : Sets the trace to ON/OFF for the                 calling of the handler  INPUTS       : 1) CLIPS_TRUE to set the trace on,                    CLIPS_FALSE to set it off                 2) A pointer to the class                 3) The index of the handler  RETURNS      : Nothing useful  SIDE EFFECTS : Watch flag for the handler set  NOTES        : None *********************************************************/globle VOID SetDefmessageHandlerWatch(newState,theClass,theIndex)  int newState;  VOID *theClass;  unsigned theIndex;  {   ((DEFCLASS *) theClass)->handlers[theIndex-1].trace = newState;  }#endif/***************************************************  NAME         : FindDefmessageHandler  DESCRIPTION  : Determines the index of a specfied                  message-handler  INPUTS       : 1) A pointer to the class                 2) Name-string of the handler                 3) Handler-type: "around","before",                    "primary", or "after"  RETURNS      : The index of the handler                   (0 if not found)  SIDE EFFECTS : None  NOTES        : None ***************************************************/globle unsigned FindDefmessageHandler(ptr,hname,htypestr)  VOID *ptr;  char *hname,*htypestr;  {   int htype;   SYMBOL_HN *hsym;   DEFCLASS *cls;   int index;      htype = HandlerType("handler-lookup",htypestr);   if (htype == MERROR)     return(0);   hsym = FindSymbol(hname);   if (hsym == NULL)     return(0);   cls = (DEFCLASS *) ptr;   index = FindHandlerByIndex(cls,hsym,(unsigned) htype);   return((unsigned) (index+1));  }/***************************************************  NAME         : IsDefmessageHandlerDeletable  DESCRIPTION  : Determines if a message-handler                   can be deleted  INPUTS       : 1) Address of the handler's class                 2) Index of the handler  RETURNS      : CLIPS_TRUE if deletable, CLIPS_FALSE otherwise  SIDE EFFECTS : None

⌨️ 快捷键说明

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