📄 cstrccom.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.24 07/01/05 */ /* */ /* CONSTRUCT COMMANDS MODULE */ /*******************************************************//*************************************************************//* Purpose: Contains generic routines for deleting, pretty *//* printing, finding, obtaining module information, *//* obtaining lists of constructs, listing constructs, and *//* manipulation routines. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* 6.23: Modified GetConstructList to remove buffer *//* overflow problem with large construct/module *//* names. DR0858 *//* *//* Changed name of variable log to logName *//* because of Unix compiler warnings of shadowed *//* definitions. *//* *//* Correction for FalseSymbol/TrueSymbol. DR0859 *//* *//* 6.24: Corrected an error when compiling as a C++ *//* file. DR0868 *//* *//* Renamed BOOLEAN macro type to intBool. *//* *//* Added ConstructsDeletable function. *//* *//*************************************************************/#define _CSTRCCOM_SOURCE_#include <string.h>#include "setup.h"#include "constant.h"#include "envrnmnt.h"#include "memalloc.h"#include "moduldef.h"#include "argacces.h"#include "multifld.h"#include "modulutl.h"#include "router.h"#include "utility.h"#include "commline.h"#include "sysdep.h"#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bload.h"#endif#if (! BLOAD_ONLY) && (! RUN_TIME)#include "cstrcpsr.h"#endif#include "cstrccom.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if DEBUGGING_FUNCTIONS static void ConstructPrintWatch(void *,char *,struct construct *,void *, unsigned (*)(void *,void *)); static unsigned ConstructWatchSupport(void *,struct construct *,char *, char *,EXPRESSION *,intBool, unsigned,unsigned (*)(void *,void *), void (*)(void *,unsigned,void *));#endif#if (! RUN_TIME)/************************************//* AddConstructToModule: Adds a *//* construct to the current module. *//************************************/globle void AddConstructToModule( struct constructHeader *theConstruct) { if (theConstruct->whichModule->lastItem == NULL) { theConstruct->whichModule->firstItem = theConstruct; } else { theConstruct->whichModule->lastItem->next = theConstruct; } theConstruct->whichModule->lastItem = theConstruct; theConstruct->next = NULL; }#endif /* (! RUN_TIME) *//****************************************************//* DeleteNamedConstruct: Generic driver routine for *//* deleting a specific construct from a module. *//****************************************************/globle intBool DeleteNamedConstruct( void *theEnv, char *constructName, struct construct *constructClass) {#if (! BLOAD_ONLY) void *constructPtr; /*=============================*/ /* Constructs can't be deleted */ /* while a bload is in effect. */ /*=============================*/#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE if (Bloaded(theEnv) == TRUE) return(FALSE);#endif /*===============================*/ /* Look for the named construct. */ /*===============================*/ constructPtr = (*constructClass->findFunction)(theEnv,constructName); /*========================================*/ /* If the construct was found, delete it. */ /*========================================*/ if (constructPtr != NULL) { return((*constructClass->deleteFunction)(theEnv,constructPtr)); } /*========================================*/ /* If the construct wasn't found, but the */ /* special symbol * was used, then delete */ /* all constructs of the specified type. */ /*========================================*/ if (strcmp("*",constructName) == 0) { (*constructClass->deleteFunction)(theEnv,NULL); return(TRUE); } /*===============================*/ /* Otherwise, return FALSE to */ /* indicate no deletion occured. */ /*===============================*/ return(FALSE);#else#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(theEnv,constructName,constructClass)#endif return(FALSE);#endif }/*******************************************//* FindNamedConstruct: Generic routine for *//* searching for a specified construct. *//*******************************************/globle void *FindNamedConstruct( void *theEnv, char *constructName, struct construct *constructClass) { void *theConstruct; SYMBOL_HN *findValue; /*==========================*/ /* Save the current module. */ /*==========================*/ SaveCurrentModule(theEnv); /*=========================================================*/ /* Extract the construct name. If a module was specified, */ /* then ExtractModuleAndConstructName will set the current */ /* module to the module specified in the name. */ /*=========================================================*/ constructName = ExtractModuleAndConstructName(theEnv,constructName); /*=================================================*/ /* If a valid construct name couldn't be extracted */ /* or the construct name isn't in the symbol table */ /* (which means the construct doesn't exist), then */ /* return NULL to indicate the specified construct */ /* couldn't be found. */ /*=================================================*/ if ((constructName == NULL) ? TRUE : ((findValue = (SYMBOL_HN *) FindSymbolHN(theEnv,constructName)) == NULL)) { RestoreCurrentModule(theEnv); return(NULL); } /*===============================================*/ /* Loop through every construct of the specified */ /* class in the current module checking to see */ /* if the construct's name matches the construct */ /* being sought. If found, restore the current */ /* module and return a pointer to the construct. */ /*===============================================*/ for (theConstruct = (*constructClass->getNextItemFunction)(theEnv,NULL); theConstruct != NULL; theConstruct = (*constructClass->getNextItemFunction)(theEnv,theConstruct)) { if (findValue == (*constructClass->getConstructNameFunction)((struct constructHeader *) theConstruct)) { RestoreCurrentModule(theEnv); return (theConstruct); } } /*=============================*/ /* Restore the current module. */ /*=============================*/ RestoreCurrentModule(theEnv); /*====================================*/ /* Return NULL to indicated the named */ /* construct was not found. */ /*====================================*/ return(NULL); }/*****************************************//* UndefconstructCommand: Driver routine *//* for the undef<construct> commands. *//*****************************************/globle void UndefconstructCommand( void *theEnv, char *command, struct construct *constructClass) { char *constructName; char buffer[80]; /*==============================================*/ /* Get the name of the construct to be deleted. */ /*==============================================*/ gensprintf(buffer,"%s name",constructClass->constructName); constructName = GetConstructName(theEnv,command,buffer); if (constructName == NULL) return;#if (! RUN_TIME) && (! BLOAD_ONLY) /*=============================================*/ /* Check to see if the named construct exists. */ /*=============================================*/ if (((*constructClass->findFunction)(theEnv,constructName) == NULL) && (strcmp("*",constructName) != 0)) { CantFindItemErrorMessage(theEnv,constructClass->constructName,constructName); return; } /*===============================================*/ /* If the construct does exist, try deleting it. */ /*===============================================*/ else if (DeleteNamedConstruct(theEnv,constructName,constructClass) == FALSE) { CantDeleteItemErrorMessage(theEnv,constructClass->constructName,constructName); return; } return;#else /*=====================================*/ /* Constructs can't be deleted in a */ /* run-time or bload only environment. */ /*=====================================*/ CantDeleteItemErrorMessage(theEnv,constructClass->constructName,constructName); return;#endif }/******************************************//* PPConstructCommand: Driver routine for *//* the ppdef<construct> commands. *//******************************************/globle void PPConstructCommand( void *theEnv, char *command, struct construct *constructClass) { char *constructName; char buffer[80]; /*===============================*/ /* Get the name of the construct */ /* to be "pretty printed." */ /*===============================*/ gensprintf(buffer,"%s name",constructClass->constructName); constructName = GetConstructName(theEnv,command,buffer); if (constructName == NULL) return; /*================================*/ /* Call the driver routine for */ /* pretty printing the construct. */ /*================================*/ if (PPConstruct(theEnv,constructName,WDISPLAY,constructClass) == FALSE) { CantFindItemErrorMessage(theEnv,constructClass->constructName,constructName); } }/***********************************//* PPConstruct: Driver routine for *//* pretty printing a construct. *//***********************************/globle int PPConstruct( void *theEnv, char *constructName, char *logicalName, struct construct *constructClass) { void *constructPtr; /*==================================*/ /* Use the construct's name to find */ /* a pointer to actual construct. */ /*==================================*/ constructPtr = (*constructClass->findFunction)(theEnv,constructName); if (constructPtr == NULL) return(FALSE); /*==============================================*/ /* If the pretty print form is NULL (because of */ /* conserve-mem), return TRUE (which indicates */ /* the construct was found). */ /*==============================================*/ if ((*constructClass->getPPFormFunction)(theEnv,(struct constructHeader *) constructPtr) == NULL) { return(TRUE); } /*============================================*/ /* Print the pretty print string in smaller */ /* chunks. (VMS had a bug that didn't allow */ /* printing a string greater than 512 bytes.) */ /*============================================*/ PrintInChunks(theEnv,logicalName,(*constructClass->getPPFormFunction)(theEnv,(struct constructHeader *) constructPtr)); /*=======================================*/ /* Return TRUE to indicate the construct */ /* was found and pretty printed. */ /*=======================================*/ return(TRUE); }/*********************************************//* GetConstructModuleCommand: Driver routine *//* for def<construct>-module routines *//*********************************************/globle SYMBOL_HN *GetConstructModuleCommand( void *theEnv, char *command, struct construct *constructClass) { char *constructName; char buffer[80]; struct defmodule *constructModule; /*=========================================*/ /* Get the name of the construct for which */ /* we want to determine its module. */ /*=========================================*/ gensprintf(buffer,"%s name",constructClass->constructName); constructName = GetConstructName(theEnv,command,buffer); if (constructName == NULL) return((SYMBOL_HN *) EnvFalseSymbol(theEnv)); /*==========================================*/ /* Get a pointer to the construct's module. */ /*==========================================*/ constructModule = GetConstructModule(theEnv,constructName,constructClass); if (constructModule == NULL) { CantFindItemErrorMessage(theEnv,constructClass->constructName,constructName); return((SYMBOL_HN *) EnvFalseSymbol(theEnv)); } /*============================================*/ /* Return the name of the construct's module. */ /*============================================*/ return(constructModule->name); }/******************************************//* GetConstructModule: Driver routine for *//* getting the module for a construct *//******************************************/globle struct defmodule *GetConstructModule(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -