📄 watch.c
字号:
/****************************************************************//* ValidWatchItem: Returns TRUE if the specified name is found *//* in the list of watch items, otherwise returns FALSE. *//****************************************************************/static struct watchItem *ValidWatchItem(itemName,recognized) char *itemName; int *recognized; { struct watchItem *wPtr; *recognized = CLIPS_TRUE; if (strcmp(itemName,"all") == 0) return(NULL); for (wPtr = ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next) { if (strcmp(itemName,wPtr->name) == 0) return(wPtr); } *recognized = CLIPS_FALSE; return(NULL); } /*************************************************************//* GetNthWatchName: Returns the name associated with the nth *//* item in the list of watchable items. If the nth item *//* does not exist, then NULL is returned. *//*************************************************************/globle char *GetNthWatchName(whichItem) int whichItem; { int i; struct watchItem *wPtr; for (wPtr = ListOfWatchItems, i = 1; wPtr != NULL; wPtr = wPtr->next, i++) { if (i == whichItem) return(wPtr->name); } return(NULL); }/***************************************************************//* GetNthWatchValue: Returns the current state associated with *//* the nth item in the list of watchable items. If the nth *//* item does not exist, then -1 is returned. *//***************************************************************/globle int GetNthWatchValue(whichItem) int whichItem; { int i; struct watchItem *wPtr; for (wPtr = ListOfWatchItems, i = 1; wPtr != NULL; wPtr = wPtr->next, i++) { if (i == whichItem) return(*(wPtr->flag)); } return(-1); } /**************************************//* WatchCommand: CLIPS access routine *//* for the watch command. *//**************************************/globle VOID WatchCommand() { DATA_OBJECT theValue; char *argument; int recognized; struct watchItem *wPtr; /*========================================*/ /* Determine which item is to be watched. */ /*========================================*/ if (ArgTypeCheck("watch",1,SYMBOL,&theValue) == CLIPS_FALSE) return; argument = DOToString(theValue); wPtr = ValidWatchItem(argument,&recognized); if (recognized == CLIPS_FALSE) { SetEvaluationError(CLIPS_TRUE); ExpectedTypeError1("watch",1,"watchable symbol"); return; } /*=================================================*/ /* Check to make sure extra arguments are allowed. */ /*=================================================*/ if (GetNextArgument(GetFirstArgument()) != NULL) { if ((wPtr == NULL) ? CLIPS_TRUE : (wPtr->accessFunc == NULL)) { SetEvaluationError(CLIPS_TRUE); ExpectedCountError("watch",EXACTLY,1); return; } } /*=====================*/ /* Set the watch item. */ /*=====================*/ SetWatchItem(argument,ON,GetNextArgument(GetFirstArgument())); }/****************************************//* UnwatchCommand: CLIPS access routine *//* for the unwatch command. *//****************************************/globle VOID UnwatchCommand() { DATA_OBJECT theValue; char *argument; int recognized; struct watchItem *wPtr; /*==========================================*/ /* Determine which item is to be unwatched. */ /*==========================================*/ if (ArgTypeCheck("unwatch",1,SYMBOL,&theValue) == CLIPS_FALSE) return; argument = DOToString(theValue); wPtr = ValidWatchItem(argument,&recognized); if (recognized == CLIPS_FALSE) { SetEvaluationError(CLIPS_TRUE); ExpectedTypeError1("unwatch",1,"watchable symbol"); return; } /*=================================================*/ /* Check to make sure extra arguments are allowed. */ /*=================================================*/ if (GetNextArgument(GetFirstArgument()) != NULL) { if ((wPtr == NULL) ? CLIPS_TRUE : (wPtr->accessFunc == NULL)) { SetEvaluationError(CLIPS_TRUE); ExpectedCountError("unwatch",EXACTLY,1); return; } } /*=====================*/ /* Set the watch item. */ /*=====================*/ SetWatchItem(argument,OFF,GetNextArgument(GetFirstArgument())); }/************************************************//* ListWatchItemsCommand: CLIPS access routines *//* for the list-watch-items command. *//************************************************/globle VOID ListWatchItemsCommand() { struct watchItem *wPtr; DATA_OBJECT theValue; int recognized; /*=======================*/ /* List the watch items. */ /*=======================*/ if (GetFirstArgument() == NULL) { for (wPtr = ListOfWatchItems; wPtr != NULL; wPtr = wPtr->next) { PrintCLIPS(WDISPLAY,wPtr->name); if (*(wPtr->flag)) PrintCLIPS(WDISPLAY," = on\n"); else PrintCLIPS(WDISPLAY," = off\n"); } return; } /*=======================================*/ /* Determine which item is to be listed. */ /*=======================================*/ if (ArgTypeCheck("list-watch-items",1,SYMBOL,&theValue) == CLIPS_FALSE) return; wPtr = ValidWatchItem(DOToString(theValue),&recognized); if ((recognized == CLIPS_FALSE) || (wPtr == NULL)) { SetEvaluationError(CLIPS_TRUE); ExpectedTypeError1("list-watch-items",1,"watchable symbol"); return; } /*=================================================*/ /* Check to make sure extra arguments are allowed. */ /*=================================================*/ if ((wPtr->printFunc == NULL) && (GetNextArgument(GetFirstArgument()) != NULL)) { SetEvaluationError(CLIPS_TRUE); ExpectedCountError("list-watch-items",EXACTLY,1); return; } /*====================================*/ /* List the status of the watch item. */ /*====================================*/ PrintCLIPS(WDISPLAY,wPtr->name); if (*(wPtr->flag)) PrintCLIPS(WDISPLAY," = on\n"); else PrintCLIPS(WDISPLAY," = off\n"); /*============================================*/ /* List the status of individual watch items. */ /*============================================*/ if (wPtr->printFunc != NULL) { if ((*wPtr->printFunc)(WDISPLAY,wPtr->code, GetNextArgument(GetFirstArgument())) == CLIPS_FALSE) { SetEvaluationError(CLIPS_TRUE); } } } /*************************************************************//* WatchFunctionDefinitions: Initializes the watch commands. *//*************************************************************/globle VOID WatchFunctionDefinitions() { #if ! RUN_TIME DefineFunction2("watch", 'v', PTIF WatchCommand, "WatchCommand", "1**w"); DefineFunction2("unwatch", 'v', PTIF UnwatchCommand, "UnwatchCommand", "1**w"); DefineFunction2("list-watch-items", 'v', PTIF ListWatchItemsCommand, "ListWatchItemsCommand", "0**w");#endif AddRouter(WTRACE,1000,RecognizeWatchRouters,CaptureWatchPrints,NULL,NULL,NULL); DeactivateRouter(WTRACE); }/**************************************************//* RecognizeWatchRouters: Looks for WTRACE prints *//**************************************************/static BOOLEAN RecognizeWatchRouters(log) char *log; { if (strcmp(log,WTRACE) == 0) return(CLIPS_TRUE); return(CLIPS_FALSE); }/**************************************************//* CaptureWatchPrints: Suppresses WTRACE messages *//**************************************************/#if IBM_TBC#pragma argsused#endifstatic int CaptureWatchPrints(log,str) char *log,*str; {#if MAC_MPW || MAC_MCW#pragma unused(log)#pragma unused(str)#endif return(1); } #endif /* DEBUGGING_FUNCTIONS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -