📄 moduldef.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* DEFMODULE MODULE */ /*******************************************************//*************************************************************//* Purpose: Defines basic defmodule primitive functions such *//* as allocating and deallocating, traversing, and finding *//* defmodule data structures. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* *//* Revision History: *//* *//*************************************************************/#define _MODULDEF_SOURCE_#include "setup.h"#include <stdio.h>#include <string.h>#define _CLIPS_STDIO_#include "clipsmem.h"#include "constant.h"#include "router.h"#include "extnfunc.h"#include "argacces.h"#include "constrct.h"#include "modulpsr.h"#include "modulcmp.h"#include "modulbsc.h"#include "utility.h"#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bload.h"#include "modulbin.h"#endif#include "moduldef.h"/*******************//* DATA STRUCTURES *//*******************/typedef struct moduleStackItem { BOOLEAN changeFlag; struct defmodule *theModule; struct moduleStackItem *next; } MODULE_STACK_ITEM;/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static struct moduleItem *LastModuleItem = NULL; static struct callFunctionItem *AfterModuleChangeFunctions = NULL; static MODULE_STACK_ITEM *ModuleStack = NULL; static BOOLEAN CallModuleChangeFunctions = CLIPS_TRUE;/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle struct defmodule *ListOfDefmodules = NULL; globle struct defmodule *CurrentModule = NULL; globle struct defmodule *LastDefmodule = NULL; globle int NumberOfModuleItems = 0; globle struct moduleItem *ListOfModuleItems = NULL; globle long ModuleChangeIndex = 0; globle int MainModuleRedefinable = CLIPS_TRUE;/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER#if (! RUN_TIME) static VOID ReturnDefmodule(struct defmodule *);#endif#else#if (! RUN_TIME) static VOID ReturnDefmodule();#endif#endif/**************************************************************//* InitializeDefmodules: Initializes the defmodule construct. *//**************************************************************/globle VOID InitializeDefmodules() { DefmoduleBasicCommands(); #if (! RUN_TIME) CreateMainModule();#endif#if DEFMODULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY) AddConstruct("defmodule","defmodules",ParseDefmodule,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL);#endif#if (! RUN_TIME) && DEFMODULE_CONSTRUCT DefineFunction2("get-current-module", 'w', PTIF GetCurrentModuleCommand, "GetCurrentModuleCommand", "00"); DefineFunction2("set-current-module", 'w', PTIF SetCurrentModuleCommand, "SetCurrentModuleCommand", "11w");#endif } /******************************************************//* RegisterModuleItem: Called to register a construct *//* which can be placed within a module. *//******************************************************/globle int RegisterModuleItem(theItem,allocateFunction,freeFunction, bloadModuleReference,constructsToCModuleReference, findFunction) char *theItem;#if ANSI_COMPILER VOID *(*allocateFunction)(void); VOID (*freeFunction)(VOID *); VOID *(*bloadModuleReference)(int); VOID (*constructsToCModuleReference)(FILE *,int,int,int); VOID *(*findFunction)(char *);#else VOID *(*allocateFunction)(); VOID (*freeFunction)(); VOID *(*bloadModuleReference)(); VOID (*constructsToCModuleReference)(); VOID *(*findFunction)();#endif { struct moduleItem *newModuleItem; newModuleItem = get_struct(moduleItem); newModuleItem->name = theItem; newModuleItem->allocateFunction = allocateFunction; newModuleItem->freeFunction = freeFunction; newModuleItem->bloadModuleReference = bloadModuleReference; newModuleItem->constructsToCModuleReference = constructsToCModuleReference; newModuleItem->findFunction = findFunction; newModuleItem->moduleIndex = NumberOfModuleItems++; newModuleItem->next = NULL; if (LastModuleItem == NULL) { ListOfModuleItems = newModuleItem; LastModuleItem = newModuleItem; } else { LastModuleItem->next = newModuleItem; LastModuleItem = newModuleItem; } return(newModuleItem->moduleIndex); } /***********************************************************//* GetListOfModuleItems: Returns the list of module items. *//***********************************************************/globle struct moduleItem *GetListOfModuleItems() { return (ListOfModuleItems); } /***************************************************************//* GetNumberOfModuleItems: Returns the number of module items. *//***************************************************************/globle int GetNumberOfModuleItems() { return (NumberOfModuleItems); } /********************************************************//* FindModuleItem: Finds the module item data structure *//* corresponding to the specified name. *//********************************************************/globle struct moduleItem *FindModuleItem(theName) char *theName; { struct moduleItem *theModuleItem; for (theModuleItem = ListOfModuleItems; theModuleItem != NULL; theModuleItem = theModuleItem->next) { if (strcmp(theModuleItem->name,theName) == 0) return(theModuleItem); } return(NULL); } /**************************************************************//* GetCurrentModule: Returns a pointer to the current module. *//**************************************************************/globle VOID *GetCurrentModule() { return ((VOID *) CurrentModule); }/***********************************************************//* SetCurrentModule: Sets the value of the current module. *//***********************************************************/globle VOID *SetCurrentModule(xNewValue) VOID *xNewValue; { struct defmodule *newValue = (struct defmodule *) xNewValue; struct callFunctionItem *changeFunctions; VOID *rv; /*=============================================*/ /* Change the current module to the specified */ /* module and save the previous current module */ /* for the return value. */ /*=============================================*/ rv = (VOID *) CurrentModule; CurrentModule = newValue; /*==========================================================*/ /* Call the list of registered functions that need to know */ /* when the module has changed. The module change functions */ /* should only be called if this is a "real" module change. */ /* Many routines temporarily change the module to look for */ /* constructs, etc. The SaveCurrentModule function will */ /* disable the change functions from being called. */ /*==========================================================*/ if (CallModuleChangeFunctions) { ModuleChangeIndex++; changeFunctions = AfterModuleChangeFunctions; while (changeFunctions != NULL) { (* (VOID (*)(VOID_ARG)) changeFunctions->func)(); changeFunctions = changeFunctions->next; } } /*=====================================*/ /* Return the previous current module. */ /*=====================================*/ return(rv); } /********************************************************//* SaveCurrentModule: Saves current module on stack and *//* prevents SetCurrentModule() from calling change *//* functions *//********************************************************/globle VOID SaveCurrentModule() { MODULE_STACK_ITEM *tmp; tmp = get_struct(moduleStackItem); tmp->changeFlag = CallModuleChangeFunctions; CallModuleChangeFunctions = CLIPS_FALSE; tmp->theModule = CurrentModule; tmp->next = ModuleStack; ModuleStack = tmp; } /**********************************************************//* RestoreCurrentModule: Restores saved module and resets *//* ability of SetCurrentModule() to call changed *//* functions to previous state *//**********************************************************/globle VOID RestoreCurrentModule() { MODULE_STACK_ITEM *tmp; tmp = ModuleStack; ModuleStack = tmp->next; CallModuleChangeFunctions = tmp->changeFlag; CurrentModule = tmp->theModule; rtn_struct(moduleStackItem,tmp); } /*************************************************************//* GetModuleItem: Returns the data pointer for the specified *//* module item in the specified module. If no module is *//* indicated, then the module item for the current module *//* is returned. *//*************************************************************/globle VOID *GetModuleItem(theModule,moduleItemIndex) struct defmodule *theModule; int moduleItemIndex; { if (theModule == NULL) { if (CurrentModule == NULL) return(NULL); theModule = CurrentModule; } if (theModule->itemsArray == NULL) return (NULL); return ((VOID *) theModule->itemsArray[moduleItemIndex]); } /************************************************************//* SetModuleItem: Sets the data pointer for the specified *//* module item in the specified module. If no module is *//* indicated, then the module item for the current module *//* is returned. *//************************************************************/globle VOID SetModuleItem(theModule,moduleItemIndex,newValue) struct defmodule *theModule; int moduleItemIndex; VOID *newValue; { if (theModule == NULL) { if (CurrentModule == NULL) return; theModule = CurrentModule; } if (theModule->itemsArray == NULL) return; theModule->itemsArray[moduleItemIndex] = (struct defmoduleItemHeader *) newValue; } /******************************************************//* CreateMainModule: Creates the default MAIN module. *//******************************************************/globle VOID CreateMainModule()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -