📄 defins.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* DEFINSTANCES MODULE */ /*******************************************************//*************************************************************//* Purpose: CLIPS Kernel definstances interface commands *//* and routines *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* *//* Revision History: *//* *//*************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFINSTANCES_CONSTRUCT#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bload.h"#include "dfinsbin.h"#endif#if CONSTRUCT_COMPILER && (! RUN_TIME)#include "dfinscmp.h"#endif#include "argacces.h"#include "classcom.h"#include "classfun.h"#include "clipsmem.h"#include "cstrccom.h"#include "cstrcpsr.h"#include "constant.h"#include "constrct.h"#include "evaluatn.h"#include "extnfunc.h"#include "insfun.h"#include "inspsr.h"#include "modulpsr.h"#include "router.h"#include "scanner.h"#include "symbol.h"#include "utility.h"#define _DEFINS_SOURCE_#include "defins.h"#if (! BLOAD_ONLY) && (! RUN_TIME)extern struct token ObjectParseToken;#endif/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */#define ACTIVE_RLN "active"/* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** *//* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILER#if (! BLOAD_ONLY) && (! RUN_TIME)static int ParseDefinstances(char *);static SYMBOL_HN *ParseDefinstancesName(char *,int *);static VOID RemoveDefinstances(VOID *);static VOID SaveDefinstances(char *);static BOOLEAN RemoveAllDefinstances(void);static VOID DefinstancesDeleteError(char *);#if INSTANCE_PATTERN_MATCHINGstatic VOID CreateInitialDefinstances(void);#endif#endif#if ! RUN_TIMEstatic VOID *AllocateModule(void);static VOID FreeModule(VOID *);static BOOLEAN ClearDefinstancesReady(void);static VOID CheckDefinstancesBusy(struct constructHeader *,VOID *);#endifstatic VOID ResetDefinstances(void);static VOID ResetDefinstancesAction(struct constructHeader *,VOID *);#else#if (! BLOAD_ONLY) && (! RUN_TIME)static int ParseDefinstances();static SYMBOL_HN *ParseDefinstancesName();static VOID RemoveDefinstances();static VOID SaveDefinstances();static BOOLEAN RemoveAllDefinstances();static VOID DefinstancesDeleteError();#if INSTANCE_PATTERN_MATCHINGstatic VOID CreateInitialDefinstances();#endif#endif#if ! RUN_TIMEstatic VOID *AllocateModule();static VOID FreeModule();static BOOLEAN ClearDefinstancesReady();static VOID CheckDefinstancesBusy();#endifstatic VOID ResetDefinstances();static VOID ResetDefinstancesAction();#endif/* ========================================= ***************************************** EXTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */globle int DefinstancesModuleIndex;/* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static struct construct *DefinstancesConstruct;/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*************************************************** NAME : SetupDefinstances DESCRIPTION : Adds the definstance support routines to the CLIPS Kernel INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Appropriate function lists modified NOTES : None ***************************************************/globle VOID SetupDefinstances() { DefinstancesModuleIndex = RegisterModuleItem("definstances",#if (! RUN_TIME) AllocateModule,FreeModule,#else NULL,NULL,#endif#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY BloadDefinstancesModuleRef,#else NULL,#endif#if CONSTRUCT_COMPILER && (! RUN_TIME) DefinstancesCModuleReference,#else NULL,#endif FindDefinstances); DefinstancesConstruct = AddConstruct("definstances","definstances",#if (! BLOAD_ONLY) && (! RUN_TIME) ParseDefinstances,#else NULL,#endif FindDefinstances, GetConstructNamePointer,GetConstructPPForm, GetConstructModuleItem,GetNextDefinstances,SetNextConstruct, IsDefinstancesDeletable,Undefinstances,#if (! BLOAD_ONLY) && (! RUN_TIME) RemoveDefinstances#else NULL#endif );#if ! RUN_TIME AddClearReadyFunction("definstances",ClearDefinstancesReady,0);#if ! BLOAD_ONLY DefineFunction2("undefinstances",'v',PTIF UndefinstancesCommand,"UndefinstancesCommand","11w"); AddSaveFunction("definstances",SaveDefinstances,0);#if INSTANCE_PATTERN_MATCHING AddClearFunction("definstances",CreateInitialDefinstances,-1000);#endif#endif#if DEBUGGING_FUNCTIONS DefineFunction2("ppdefinstances",'v',PTIF PPDefinstancesCommand ,"PPDefinstancesCommand","11w"); DefineFunction2("list-definstances",'v',PTIF ListDefinstancesCommand,"ListDefinstancesCommand","01");#endif DefineFunction2("get-definstances-list",'m',PTIF GetDefinstancesListFunction, "GetDefinstancesListFunction","01"); DefineFunction2("definstances-module",'w',PTIF GetDefinstancesModuleCommand, "GetDefinstancesModuleCommand","11w");#endif AddResetFunction("definstances",(VOID (*)(VOID_ARG)) ResetDefinstances,0); #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE SetupDefinstancesBload();#endif#if CONSTRUCT_COMPILER && (! RUN_TIME) SetupDefinstancesCompiler();#endif } /*********************************************************** NAME : GetNextDefinstances DESCRIPTION : Finds first or next definstances INPUTS : The address of the current definstances RETURNS : The address of the next definstances (NULL if none) SIDE EFFECTS : None NOTES : If ptr == NULL, the first definstances is returned. ***********************************************************/globle VOID *GetNextDefinstances(ptr) VOID *ptr; { return((VOID *) GetNextConstructItem((struct constructHeader *) ptr, DefinstancesModuleIndex)); } /*************************************************** NAME : FindDefinstances DESCRIPTION : Looks up a definstance construct by name-string INPUTS : The symbolic name RETURNS : The definstance address, or NULL if not found SIDE EFFECTS : None NOTES : None ***************************************************/globle VOID *FindDefinstances(name) char *name; { return(FindNamedConstruct(name,DefinstancesConstruct)); } /*************************************************** NAME : IsDefinstancesDeletable DESCRIPTION : Determines if a definstances can be deleted INPUTS : Address of the definstances RETURNS : CLIPS_TRUE if deletable, CLIPS_FALSE otherwise SIDE EFFECTS : None NOTES : None ***************************************************/globle int IsDefinstancesDeletable(ptr) VOID *ptr; {#if (MAC_MPW || MAC_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(ptr)#endif#if BLOAD_ONLY || RUN_TIME return(CLIPS_FALSE);#else#if BLOAD || BLOAD_AND_BSAVE if (Bloaded()) return(CLIPS_FALSE);#endif return((((DEFINSTANCES *) ptr)->busy == 0) ? CLIPS_TRUE : CLIPS_FALSE);#endif }/*********************************************************** NAME : UndefinstancesCommand DESCRIPTION : Removes a definstance INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Definstance deallocated NOTES : CLIPS Syntax : (undefinstances <name> | *) ***********************************************************/globle VOID UndefinstancesCommand() { UndefconstructCommand("undefinstances",DefinstancesConstruct); }/***************************************************************** NAME : GetDefinstancesModuleCommand DESCRIPTION : Determines to which module a definstances belongs INPUTS : None RETURNS : The symbolic name of the module SIDE EFFECTS : None NOTES : CLIPS Syntax: (definstances-module <defins-name>) *****************************************************************/globle SYMBOL_HN *GetDefinstancesModuleCommand() { return(GetConstructModuleCommand("definstances-module",DefinstancesConstruct)); } /*********************************************************** NAME : Undefinstances DESCRIPTION : Removes a definstance INPUTS : Address of definstances to remove RETURNS : CLIPS_TRUE if successful, CLIPS_FALSE otherwise SIDE EFFECTS : Definstance deallocated NOTES : None ***********************************************************/globle BOOLEAN Undefinstances(vptr) VOID *vptr; { DEFINSTANCES *dptr; dptr = (DEFINSTANCES *) vptr;#if RUN_TIME || BLOAD_ONLY return(CLIPS_FALSE);#else#if BLOAD || BLOAD_AND_BSAVE if (Bloaded()) return(CLIPS_FALSE);#endif if (dptr == NULL) return(RemoveAllDefinstances()); if (IsDefinstancesDeletable(vptr) == CLIPS_FALSE) return(CLIPS_FALSE); RemoveConstructFromModule((struct constructHeader *) vptr); RemoveDefinstances((VOID *) dptr); return(CLIPS_TRUE);#endif } #if DEBUGGING_FUNCTIONS/*************************************************************** NAME : PPDefinstancesCommand DESCRIPTION : Prints out the pretty-print form of a definstance INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : None NOTES : CLIPS Syntax : (ppdefinstances <name>) ***************************************************************/globle VOID PPDefinstancesCommand() { PPConstructCommand("ppdefinstances",DefinstancesConstruct); }/*************************************************** NAME : ListDefinstancesCommand DESCRIPTION : Displays all definstances names INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Definstances name sprinted NOTES : CLIPS Interface ***************************************************/globle VOID ListDefinstancesCommand() { ListConstructCommand("list-definstances",DefinstancesConstruct); }/*************************************************** NAME : ListDefinstances DESCRIPTION : Displays all definstances names INPUTS : 1) The logical name of the output 2) The module RETURNS : Nothing useful SIDE EFFECTS : Definstances names printed NOTES : C Interface ***************************************************/globle VOID ListDefinstances(logicalName,theModule) char *logicalName; struct defmodule *theModule; { ListConstruct(DefinstancesConstruct,logicalName,theModule); }#endif /**************************************************************** NAME : GetDefinstancesListFunction DESCRIPTION : Groups all definstances names into a multifield list INPUTS : A data object buffer to hold the multifield result RETURNS : Nothing useful SIDE EFFECTS : Multifield allocated and filled NOTES : CLIPS Syntax: (get-definstances-list [<module>]) ****************************************************************/globle VOID GetDefinstancesListFunction(returnValue) DATA_OBJECT*returnValue; { GetConstructListFunction("get-definstances-list",returnValue,DefinstancesConstruct); }/*************************************************************** NAME : GetDefinstancesList DESCRIPTION : Groups all definstances names into a multifield list INPUTS : 1) A data object buffer to hold the multifield result 2) The module from which to obtain definstances RETURNS : Nothing useful SIDE EFFECTS : Multifield allocated and filled NOTES : External C access ***************************************************************/globle VOID GetDefinstancesList(returnValue,theModule) DATA_OBJECT *returnValue; struct defmodule *theModule; { GetConstructList(returnValue,DefinstancesConstruct,theModule); } /* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -