📄 factmngr.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* FACT MANAGER MODULE */ /*******************************************************//*************************************************************//* Purpose: Provides core routines for maintaining the fact *//* list including assert/retract operations, data *//* structure creation/deletion, printing, slot access, *//* and other utility functions. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* *//* Revision History: *//* *//*************************************************************/#define _FACTMNGR_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT#include "constant.h"#include "symbol.h"#include "clipsmem.h"#include "exprnpsr.h"#include "argacces.h"#include "scanner.h"#include "router.h"#include "strngrtr.h"#include "match.h"#include "factbld.h"#include "reteutil.h"#include "retract.h"#include "filecom.h"#include "factfun.h"#include "constrct.h"#include "factrhs.h"#include "factmch.h"#include "watch.h"#include "utility.h"#include "factbin.h"#include "factmngr.h"#include "facthsh.h"#include "default.h"#include "commline.h"#include "engine.h"#include "lgcldpnd.h"#include "drive.h"#include "ruledlt.h"#include "tmpltbsc.h"#include "tmpltdef.h"#include "tmpltutl.h"#include "tmpltfun.h"/****************************************//* GLOBAL EXTERNAL FUNCTION DEFINITIONS *//****************************************/#if ANSI_COMPILER extern VOID FactCommandDefinitions(void); extern VOID FactPatternsCompilerSetup(void);#else extern VOID FactCommandDefinitions(); extern VOID FactPatternsCompilerSetup();#endif/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER static VOID ResetFacts(void); static int ClearFactsReady(void); static VOID RemoveGarbageFacts(void);#else static VOID ResetFacts(); static int ClearFactsReady(); static VOID RemoveGarbageFacts();#endif/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle int ChangeToFactList = CLIPS_FALSE; globle struct fact DummyFact = { { &FactInfo }, NULL, NULL, -1L, 0, 1, NULL, NULL, { 1, 0, 0 } };#if DEBUGGING_FUNCTIONS globle int WatchFacts = OFF;#endif/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static struct fact *GarbageFacts = NULL; static struct fact *LastFact = NULL; static struct fact *FactList = NULL; static long int NextFactIndex = 0L; static long int NumberOfFacts = 0;/**************************************************************//* InitializeFacts: Initializes the fact data representation. *//* Facts are only available when both the defrule and *//* deftemplate constructs are available. *//**************************************************************/globle VOID InitializeFacts() { /*=========================================*/ /* Initialize the fact hash table (used to */ /* quickly determine if a fact exists). */ /*=========================================*/ InitializeFactHashTable(); /*============================================*/ /* Initialize the fact callback functions for */ /* use with the reset and clear commands. */ /*============================================*/ AddResetFunction("facts",ResetFacts,60); AddClearReadyFunction("facts",ClearFactsReady,0); /*=============================*/ /* Initialize periodic garbage */ /* collection for facts. */ /*=============================*/ AddCleanupFunction("facts",RemoveGarbageFacts,0); /*===================================*/ /* Initialize fact pattern matching. */ /*===================================*/ InitializeFactPatterns(); /*==================================*/ /* Initialize the facts keyword for */ /* use with the watch command. */ /*==================================*/ #if DEBUGGING_FUNCTIONS AddWatchItem("facts",0,&WatchFacts,80,DeftemplateWatchAccess,DeftemplateWatchPrint);#endif /*=========================================*/ /* Initialize fact commands and functions. */ /*=========================================*/ FactCommandDefinitions(); FactFunctionDefinitions(); /*==================================*/ /* Initialize fact patterns for use */ /* with the bload/bsave commands. */ /*==================================*/#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) FactBinarySetup();#endif /*===================================*/ /* Initialize fact patterns for use */ /* with the constructs-to-c command. */ /*===================================*/ #if CONSTRUCT_COMPILER && (! RUN_TIME) FactPatternsCompilerSetup();#endif } /**********************************************//* PrintFactWithIdentifier: Displays a single *//* fact preceded by its fact identifier. *//**********************************************/globle VOID PrintFactWithIdentifier(logicalName,factPtr) char *logicalName; struct fact *factPtr; { char printSpace[20]; sprintf(printSpace,"f-%-5ld ",factPtr->factIndex); PrintCLIPS(logicalName,printSpace); PrintFact(logicalName,factPtr); } /****************************************************//* PrintFactIdentifier: Displays a fact identifier. *//****************************************************/globle VOID PrintFactIdentifier(logicalName,factPtr) char *logicalName; VOID *factPtr; { char printSpace[20]; sprintf(printSpace,"f-%ld",((struct fact *) factPtr)->factIndex); PrintCLIPS(logicalName,printSpace); } /********************************************//* PrintFactIdentifierInLongForm: Display a *//* fact identifier in a longer format. *//********************************************/globle VOID PrintFactIdentifierInLongForm(logicalName,factPtr) char *logicalName; VOID *factPtr; { if (AddressesToStrings) PrintCLIPS(logicalName,"\""); if (factPtr != (VOID *) &DummyFact) { PrintCLIPS(logicalName,"<Fact-"); PrintLongInteger(logicalName,((struct fact *) factPtr)->factIndex); PrintCLIPS(logicalName,">"); } else { PrintCLIPS(logicalName,"<Dummy Fact>"); } if (AddressesToStrings) PrintCLIPS(logicalName,"\""); } /*******************************************//* DecrementFactBasisCount: Decrements the *//* partial match busy count of a fact *//*******************************************/globle VOID DecrementFactBasisCount(vFactPtr) VOID *vFactPtr; { struct fact *factPtr = (struct fact *) vFactPtr; struct multifield *theSegment; int i; DecrementFactCount(factPtr); theSegment = &factPtr->theProposition; for (i = 0 ; i < (int) theSegment->multifieldLength ; i++) { AtomDeinstall(theSegment->theFields[i].type,theSegment->theFields[i].value); } } /*******************************************//* IncrementFactBasisCount: Increments the *//* partial match busy count of a fact. *//*******************************************/globle VOID IncrementFactBasisCount(vFactPtr) VOID *vFactPtr; { struct fact *factPtr = (struct fact *) vFactPtr; struct multifield *theSegment; int i; IncrementFactCount(factPtr); theSegment = &factPtr->theProposition; for (i = 0 ; i < (int) theSegment->multifieldLength ; i++) { AtomInstall(theSegment->theFields[i].type,theSegment->theFields[i].value); } } /**************************************************//* PrintFact: Displays the printed representation *//* of a fact containing the relation name and *//* all of the fact's slots or fields. *//**************************************************/globle VOID PrintFact(logicalName,factPtr) char *logicalName; struct fact *factPtr; { struct multifield *theMultifield; /*=========================================*/ /* Print a deftemplate (non-ordered) fact. */ /*=========================================*/ if (factPtr->whichDeftemplate->implied == CLIPS_FALSE) { PrintTemplateFact(logicalName,factPtr); return; } /*==============================*/ /* Print an ordered fact (which */ /* has an implied deftemplate). */ /*==============================*/ PrintCLIPS(logicalName,"("); PrintCLIPS(logicalName,factPtr->whichDeftemplate->header.name->contents); theMultifield = (struct multifield *) factPtr->theProposition.theFields[0].value; if (theMultifield->multifieldLength != 0) { PrintCLIPS(logicalName," "); PrintMultifield(logicalName,theMultifield,0, theMultifield->multifieldLength - 1, CLIPS_FALSE); } PrintCLIPS(logicalName,")"); } /*********************************************//* MatchFactFunction: Filters a fact through *//* the appropriate fact pattern network. *//*********************************************/globle VOID MatchFactFunction(vTheFact) VOID *vTheFact; { struct fact *theFact = (struct fact *) vTheFact; FactPatternMatch(theFact,theFact->whichDeftemplate->patternNetwork,0,NULL,NULL); }/******************************************************//* Retract: C access routine for the retract command. *//******************************************************/globle BOOLEAN Retract(vTheFact) VOID *vTheFact; { struct fact *theFact = (struct fact *) vTheFact; /*===========================================*/ /* A fact can not be retracted while another */ /* fact is being asserted or retracted. */ /*===========================================*/ if (JoinOperationInProgress) { PrintErrorID("FACTMNGR",1,CLIPS_TRUE); PrintCLIPS(WERROR,"Facts may not be retracted during pattern-matching\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -