📄 constrct.c
字号:
/*******************************************//* RemoveResetFunction: Removes a function *//* from the ListOfResetFunctions. *//*******************************************/globle BOOLEAN RemoveResetFunction(name) char *name; { int found; ListOfResetFunctions = RemoveFunctionFromCallList(name,ListOfResetFunctions,&found); if (found) return(CLIPS_TRUE); return(CLIPS_FALSE); }/**************************************************//* Clear: C access routine for the clear command. *//**************************************************/globle VOID Clear() { struct callFunctionItem *theFunction; /*==========================================*/ /* Activate the watch router which captures */ /* trace output so that it is not displayed */ /* during a clear. */ /*==========================================*/ #if DEBUGGING_FUNCTIONS ActivateRouter(WTRACE);#endif /*===================================*/ /* Determine if a clear is possible. */ /*===================================*/ if (ClearReady() == CLIPS_FALSE) { PrintErrorID("CONSTRCT",1,CLIPS_FALSE); PrintCLIPS(WERROR,"Some constructs are still in use. Clear cannot continue.\n");#if DEBUGGING_FUNCTIONS DeactivateRouter(WTRACE);#endif return; } /*===========================*/ /* Call all clear functions. */ /*===========================*/ ClearInProgress = CLIPS_TRUE; for (theFunction = ListOfClearFunctions; theFunction != NULL; theFunction = theFunction->next) { (*theFunction->func)(); } /*=============================*/ /* Deactivate the watch router */ /* for capturing output. */ /*=============================*/#if DEBUGGING_FUNCTIONS DeactivateRouter(WTRACE);#endif /*===========================================*/ /* Perform periodic cleanup if the clear was */ /* issued from an embedded controller. */ /*===========================================*/ if ((CurrentEvaluationDepth == 0) && (! EvaluatingTopLevelCommand) && (CurrentExpression == NULL)) { PeriodicCleanup(CLIPS_TRUE,CLIPS_FALSE); } /*===========================*/ /* Clear has been completed. */ /*===========================*/ ClearInProgress = CLIPS_FALSE; }/*********************************************************//* ClearReady: Returns TRUE if a clear can be performed, *//* otherwise FALSE. Note that this is destructively *//* determined (e.g. facts will be deleted as part of *//* the determination). */ /*********************************************************/globle BOOLEAN ClearReady() { struct callFunctionItem *theFunction; int (*tempFunction)(VOID_ARG); for (theFunction = ListOfClearReadyFunctions; theFunction != NULL; theFunction = theFunction->next) { tempFunction = (int (*)(VOID_ARG)) theFunction->func; if ((*tempFunction)() == CLIPS_FALSE) { return(CLIPS_FALSE); } } return(CLIPS_TRUE); } /******************************************//* AddClearReadyFunction: Adds a function *//* to ListOfClearReadyFunctions. *//******************************************/globle BOOLEAN AddClearReadyFunction(name,functionPtr,priority) char *name;#if ANSI_COMPILER int (*functionPtr)(void);#else int (*functionPtr)();#endif int priority; { ListOfClearReadyFunctions = AddFunctionToCallList(name,priority,#if ANSI_COMPILER (VOID (*)(void)) functionPtr,#else (VOID (*)()) functionPtr,#endif ListOfClearReadyFunctions); return(1); }/************************************************//* RemoveClearReadyFunction: Removes a function *//* from the ListOfClearReadyFunctions. *//************************************************/globle BOOLEAN RemoveClearReadyFunction(name) char *name; { int found; ListOfClearReadyFunctions = RemoveFunctionFromCallList(name,ListOfClearReadyFunctions,&found); if (found) return(CLIPS_TRUE); return(CLIPS_FALSE); }/*************************************//* AddClearFunction: Adds a function *//* to ListOfClearFunctions. *//*************************************/globle BOOLEAN AddClearFunction(name,functionPtr,priority) char *name;#if ANSI_COMPILER VOID (*functionPtr)(void);#else VOID (*functionPtr)();#endif int priority; { ListOfClearFunctions = AddFunctionToCallList(name,priority,#if ANSI_COMPILER (VOID (*)(void)) functionPtr,#else (VOID (*)()) functionPtr,#endif ListOfClearFunctions); return(1); }/*******************************************//* RemoveClearFunction: Removes a function *//* from the ListOfClearFunctions. *//*******************************************/globle BOOLEAN RemoveClearFunction(name) char *name; { int found; ListOfClearFunctions = RemoveFunctionFromCallList(name,ListOfClearFunctions,&found); if (found) return(CLIPS_TRUE); return(CLIPS_FALSE); }/***********************************************//* ExecutingConstruct: Returns CLIPS_TRUE if a *//* construct is currently being executed, *//* otherwise CLIPS_FALSE. *//***********************************************/globle int ExecutingConstruct() { return(Executing); }/********************************************//* SetExecutingConstruct: Sets the value of *//* the executing variable indicating that *//* actions such as reset, clear, etc *//* should not be performed. *//********************************************/globle VOID SetExecutingConstruct(value) int value; { Executing = value; }/************************************************************//* OldGetConstructList: Returns a list of all the construct *//* names in a multifield value. It doesn't check the *//* number of arguments. It assumes that the restriction *//* string in DefineFunction2 call was "00". *//************************************************************/globle VOID OldGetConstructList(returnValue,nextFunction,nameFunction) DATA_OBJECT_PTR returnValue;#if ANSI_COMPILER VOID *(*nextFunction)(VOID *); char *(*nameFunction)(VOID *);#else VOID *(*nextFunction)(); char *(*nameFunction)();#endif { VOID *theConstruct; long count = 0; struct multifield *theList; /*====================================*/ /* Determine the number of constructs */ /* of the specified type. */ /*====================================*/ for (theConstruct = (*nextFunction)(NULL); theConstruct != NULL; theConstruct = (*nextFunction)(theConstruct)) { count++; } /*===========================*/ /* Create a multifield large */ /* enough to store the list. */ /*===========================*/ SetpType(returnValue,MULTIFIELD); SetpDOBegin(returnValue,1); SetpDOEnd(returnValue,count); theList = (struct multifield *) CreateMultifield((int) count); SetpValue(returnValue,(VOID *) theList); /*====================================*/ /* Store the names in the multifield. */ /*====================================*/ for (theConstruct = (*nextFunction)(NULL), count = 1; theConstruct != NULL; theConstruct = (*nextFunction)(theConstruct), count++) { if (HaltExecution == CLIPS_TRUE) { SetMultifieldErrorValue(returnValue); return; } SetMFType(theList,count,SYMBOL); SetMFValue(theList,count,AddSymbol((*nameFunction)(theConstruct))); } } /*******************************************************//* DeinstallConstructHeader: Decrements the busy count *//* of a construct name and frees its pretty print *//* representation string (both of which are stored *//* in the generic construct header). *//*******************************************************/globle VOID DeinstallConstructHeader(theHeader) struct constructHeader *theHeader; { DecrementSymbolCount(theHeader->name); if (theHeader->ppForm != NULL) { rm(theHeader->ppForm, (int) sizeof(char) * ((int) strlen(theHeader->ppForm) + 1)); theHeader->ppForm = NULL; } }/*****************************************************//* AddConstruct: Adds a construct and its associated *//* parsing function to the ListOfConstructs. *//*****************************************************/globle struct construct *AddConstruct(name,pluralName, parseFunction,findFunction, getConstructNameFunction,getPPFormFunction, getModuleItemFunction,getNextItemFunction, setNextItemFunction,isConstructDeletableFunction, deleteFunction,freeFunction) char *name, *pluralName;#if ANSI_COMPILER int (*parseFunction)(char *); VOID *(*findFunction)(char *); SYMBOL_HN *(*getConstructNameFunction)(struct constructHeader *); char *(*getPPFormFunction)(struct constructHeader *); struct defmoduleItemHeader *(*getModuleItemFunction)(struct constructHeader *); VOID *(*getNextItemFunction)(VOID *); VOID (*setNextItemFunction)(struct constructHeader *,struct constructHeader *); BOOLEAN (*isConstructDeletableFunction)(VOID *); int (*deleteFunction)(VOID *); VOID (*freeFunction)(VOID *);#else int (*parseFunction)(); VOID *(*findFunction)(); SYMBOL_HN *(*getConstructNameFunction)(); char *(*getPPFormFunction)(); struct defmoduleItemHeader *(*getModuleItemFunction)(); VOID *(*getNextItemFunction)(); VOID (*setNextItemFunction)(); BOOLEAN (*isConstructDeletableFunction)(); int (*deleteFunction)(); VOID (*freeFunction)();#endif { struct construct *newPtr; /*=============================*/ /* Allocate and initialize the */ /* construct data structure. */ /*=============================*/ newPtr = get_struct(construct); newPtr->constructName = name; newPtr->pluralName = pluralName; newPtr->parseFunction = parseFunction; newPtr->findFunction = findFunction; newPtr->getConstructNameFunction = getConstructNameFunction; newPtr->getPPFormFunction = getPPFormFunction; newPtr->getModuleItemFunction = getModuleItemFunction; newPtr->getNextItemFunction = getNextItemFunction; newPtr->setNextItemFunction = setNextItemFunction; newPtr->isConstructDeletableFunction = isConstructDeletableFunction; newPtr->deleteFunction = deleteFunction; newPtr->freeFunction = freeFunction; /*===============================*/ /* Add the construct to the list */ /* of constructs and return it. */ /*===============================*/ newPtr->next = ListOfConstructs; ListOfConstructs = newPtr; return(newPtr); } /************************************//* AddSaveFunction: Adds a function *//* to the ListOfSaveFunctions. *//************************************/globle BOOLEAN AddSaveFunction(name,functionPtr,priority) char *name;#if ANSI_COMPILER VOID (*functionPtr)(char *);#else VOID (*functionPtr)();#endif int priority; {#if (MAC_MPW || MAC_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(name)#pragma unused(functionPtr)#pragma unused(priority)#endif#if (! RUN_TIME) && (! BLOAD_ONLY) ListOfSaveFunctions = AddFunctionToCallList(name,priority,#if ANSI_COMPILER (VOID (*)(void)) functionPtr,#else (VOID (*)()) functionPtr,#endif ListOfSaveFunctions);#endif return(1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -