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

📄 watch.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                    WATCH MODULE                     */   /*******************************************************/                                      /*************************************************************//* Purpose: Support functions for the watch and unwatch      *//*   commands.                                               *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian Donnell                                        *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _WATCH_SOURCE_#include "setup.h"#if DEBUGGING_FUNCTIONS#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "constant.h"#include "clipsmem.h"#include "router.h"#include "argacces.h"#include "extnfunc.h"#include "watch.h"/*************************//* STRUCTURE DEFINITIONS *//*************************/struct watchItem  {   char *name;   int *flag;   int code,priority;#if ANSI_COMPILER   BOOLEAN (*accessFunc)(int,int,struct expr *);   BOOLEAN (*printFunc)(char *,int,struct expr *);#else   BOOLEAN (*accessFunc)();   BOOLEAN (*printFunc)();#endif   struct watchItem *next;  };/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER   static struct watchItem       *ValidWatchItem(char *,int *);   static BOOLEAN                 RecognizeWatchRouters(char *);   static int                     CaptureWatchPrints(char *,char *);#else   static struct watchItem       *ValidWatchItem();   static BOOLEAN                 RecognizeWatchRouters();   static int                     CaptureWatchPrints();#endif/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/   static struct watchItem      *ListOfWatchItems = NULL;/*************************************************************//* AddWatchItem: Adds an item to the list of watchable items *//*   that can be set using the watch and unwatch commands.   *//*   Returns FALSE if the item is already in the list,       *//*   otherwise returns TRUE.                                 *//*************************************************************/globle BOOLEAN AddWatchItem(name,code,flag,priority,accessFunc,printFunc)  char *name;  int *flag;  int code,priority;#if ANSI_COMPILER  BOOLEAN (*accessFunc)(int,int,struct expr *);  BOOLEAN (*printFunc)(char *,int,struct expr *);#else  BOOLEAN (*accessFunc)();  BOOLEAN (*printFunc)();#endif  {   struct watchItem *newPtr, *currentPtr, *lastPtr;   /*================================================================*/   /* Find the insertion point in the watchable items list to place  */   /* the new item. If the item is already in the list return FALSE. */   /*================================================================*/      for (currentPtr = ListOfWatchItems, lastPtr = NULL;         currentPtr != NULL;         currentPtr = currentPtr->next)     {      if (strcmp(currentPtr->name,name) == 0) return(CLIPS_FALSE);      if (priority < currentPtr->priority) lastPtr = currentPtr;     }        /*============================*/   /* Create the new watch item. */   /*============================*/      newPtr = get_struct(watchItem);   newPtr->name = name;   newPtr->flag = flag;   newPtr->code = code;   newPtr->priority = priority;   newPtr->accessFunc = accessFunc;   newPtr->printFunc = printFunc;      /*=================================================*/   /* Insert the new item in the list of watch items. */   /*=================================================*/      if (lastPtr == NULL)     {      newPtr->next = ListOfWatchItems;      ListOfWatchItems = newPtr;     }   else     {      newPtr->next = lastPtr->next;      lastPtr->next = newPtr;     }   /*==================================================*/   /* Return TRUE to indicate the item has been added. */   /*==================================================*/      return(CLIPS_TRUE);  }/**************************************************//* Watch: C access routine for the watch command. *//**************************************************/globle BOOLEAN Watch(itemName)  char *itemName;  {   return(SetWatchItem(itemName,ON,NULL));  }  /******************************************************//* Unwatch: C access routine for the unwatch command. *//******************************************************/globle BOOLEAN Unwatch(itemName)  char *itemName;  {   return(SetWatchItem(itemName,OFF,NULL));  }   /********************************************************************//* SetWatchItem: Sets the state of a specified watch item to either *//*   on or off. Returns TRUE if the item was set, otherwise FALSE.  *//********************************************************************/globle BOOLEAN SetWatchItem(itemName,newState,argExprs)  char *itemName;  int newState;  struct expr *argExprs;  {   struct watchItem *wPtr;   /*======================================================*/   /* If the new state isn't on or off, then return FALSE. */   /*======================================================*/      if ((newState != ON) && (newState != OFF)) return(CLIPS_FALSE);   /*===================================================*/   /* If the name of the watch item to set is all, then */   /* all watch items are set to the new state and TRUE */   /* is returned.                                      */   /*===================================================*/      if (strcmp(itemName,"all") == 0)     {      for (wPtr = ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)        {         /*==============================================*/         /* If no specific arguments are specified, then */         /* set the global flag for the watch item.      */         /*==============================================*/                            if (argExprs == NULL) *(wPtr->flag) = newState;                  /*=======================================*/         /* Set flags for individual watch items. */         /*=======================================*/                  if ((wPtr->accessFunc == NULL) ? CLIPS_FALSE :             ((*wPtr->accessFunc)(wPtr->code,newState,argExprs) == CLIPS_FALSE))           {            SetEvaluationError(CLIPS_TRUE);            return(CLIPS_FALSE);           }        }      return(CLIPS_TRUE);     }   /*=================================================*/   /* Search for the watch item to be set in the list */   /* of watch items. If found, set the watch item to */   /* its new state and return TRUE.                  */   /*=================================================*/      for (wPtr = ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)     {      if (strcmp(itemName,wPtr->name) == 0)        {         /*==============================================*/         /* If no specific arguments are specified, then */         /* set the global flag for the watch item.      */         /*==============================================*/                  if (argExprs == NULL) *(wPtr->flag) = newState;                  /*=======================================*/         /* Set flags for individual watch items. */         /*=======================================*/                  if ((wPtr->accessFunc == NULL) ? CLIPS_FALSE :             ((*wPtr->accessFunc)(wPtr->code,newState,argExprs) == CLIPS_FALSE))           {            SetEvaluationError(CLIPS_TRUE);            return(CLIPS_FALSE);           }                    return(CLIPS_TRUE);        }     }   /*=================================================*/   /* If the specified item was not found in the list */   /* of watchable items then return FALSE.           */   /*=================================================*/   return(CLIPS_FALSE);  }/*********************************************************************//* GetWatchItem: Gets the current state of the specified watch item. *//*   Returns the state of the watch item (0 for off and 1 for on) if *//*   the watch item is found in the list of watch items, otherwise   *//*   -1 is returned.                                                 */               /*********************************************************************/globle int GetWatchItem(itemName)  char *itemName;  {   struct watchItem *wPtr;      for (wPtr = ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next)     { if (strcmp(itemName,wPtr->name) == 0) return(*(wPtr->flag)); }   return(-1);  }

⌨️ 快捷键说明

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