📄 cstrcpsr.c
字号:
{ struct construct *currentPtr; int rv, ov; /*=================================*/ /* Look for a valid construct name */ /* (e.g. defrule, deffacts). */ /*=================================*/ currentPtr = FindConstruct(name); if (currentPtr == NULL) return(-1); /*==================================*/ /* Prepare the parsing environment. */ /*==================================*/ ov = GetHaltExecution(); SetEvaluationError(CLIPS_FALSE); SetHaltExecution(CLIPS_FALSE); ClearParsedBindNames(); PushRtnBrkContexts(); ReturnContext = CLIPS_FALSE; BreakContext = CLIPS_FALSE; CurrentEvaluationDepth++; /*=======================================*/ /* Call the construct's parsing routine. */ /*=======================================*/ rv = (*currentPtr->parseFunction)(logicalName); /*===============================*/ /* Restore environment settings. */ /*===============================*/ CurrentEvaluationDepth--; PopRtnBrkContexts(); ClearParsedBindNames(); SetPPBufferStatus(OFF); SetHaltExecution(ov); /*==============================*/ /* Return the status of parsing */ /* the construct. */ /*==============================*/ return(rv); } /*********************************************************//* GetConstructNameAndComment: Get the name and comment *//* field of a construct. Returns name of the construct *//* if no errors are detected, otherwise returns NULL. *//*********************************************************/globle SYMBOL_HN *GetConstructNameAndComment(readSource,inputToken,constructName, findFunction,deleteFunction, constructSymbol,fullMessageCR,getComment, moduleNameAllowed) char *readSource; struct token *inputToken; char *constructName;#if ANSI_COMPILER VOID *(*findFunction)(char *); int (*deleteFunction)(VOID *);#else VOID *(*findFunction)(); int (*deleteFunction)();#endif char *constructSymbol; int fullMessageCR, getComment; int moduleNameAllowed; { SYMBOL_HN *name, *moduleName; int redefining = CLIPS_FALSE; VOID *theConstruct; int separatorPosition; struct defmodule *theModule; /*==========================*/ /* Next token should be the */ /* name of the construct. */ /*==========================*/ GetToken(readSource,inputToken); if (inputToken->type != SYMBOL) { PrintErrorID("CSTRCPSR",2,CLIPS_TRUE); PrintCLIPS(WERROR,"Missing name for "); PrintCLIPS(WERROR,constructName); PrintCLIPS(WERROR," construct\n"); return(NULL); } name = (SYMBOL_HN *) inputToken->value; /*===============================*/ /* Determine the current module. */ /*===============================*/ separatorPosition = FindModuleSeparator(ValueToString(name)); if (separatorPosition) { if (moduleNameAllowed == CLIPS_FALSE) { SyntaxErrorMessage("module specifier"); return(NULL); } moduleName = ExtractModuleName(separatorPosition,ValueToString(name)); if (moduleName == NULL) { SyntaxErrorMessage("construct name"); return(NULL); } theModule = (struct defmodule *) FindDefmodule(ValueToString(moduleName)); if (theModule == NULL) { CantFindItemErrorMessage("defmodule",ValueToString(moduleName)); return(NULL); } SetCurrentModule((VOID *) theModule); name = ExtractConstructName(separatorPosition,ValueToString(name)); if (name == NULL) { SyntaxErrorMessage("construct name"); return(NULL); } } /*=====================================================*/ /* If the module was not specified, record the current */ /* module name as part of the pretty-print form. */ /*=====================================================*/ else { theModule = ((struct defmodule *) GetCurrentModule()); if (moduleNameAllowed) { PPBackup(); SavePPBuffer(GetDefmoduleName(theModule)); SavePPBuffer("::"); SavePPBuffer(ValueToString(name)); } } /*==================================================================*/ /* Check for import/export conflicts from the construct definition. */ /*==================================================================*/#if DEFMODULE_CONSTRUCT if (FindImportExportConflict(constructName,theModule,ValueToString(name))) { ImportExportConflictMessage(constructName,ValueToString(name),NULL,NULL); return(NULL); }#endif /*==============================================================*/ /* Remove the construct if it is already in the knowledge base. */ /*==============================================================*/ if (findFunction != NULL) { theConstruct = (*findFunction)(ValueToString(name)); if (theConstruct != NULL) { redefining = CLIPS_TRUE; if (deleteFunction != NULL) { if ((*deleteFunction)(theConstruct) == CLIPS_FALSE) { PrintErrorID("CSTRCPSR",4,CLIPS_TRUE); PrintCLIPS(WERROR,"Cannot redefine "); PrintCLIPS(WERROR,constructName); PrintCLIPS(WERROR," "); PrintCLIPS(WERROR,ValueToString(name)); PrintCLIPS(WERROR," while it is in use.\n"); return(NULL); } } } } /*=============================================*/ /* If compilations are being watched, indicate */ /* that a construct is being compiled. */ /*=============================================*/#if DEBUGGING_FUNCTIONS if ((GetWatchItem("compilations") == CLIPS_TRUE) && GetPrintWhileLoading()) { if (redefining) PrintCLIPS(WDIALOG,"Redefining "); else PrintCLIPS(WDIALOG,"Defining "); PrintCLIPS(WDIALOG,constructName); PrintCLIPS(WDIALOG,": "); PrintCLIPS(WDIALOG,ValueToString(name)); if (fullMessageCR) PrintCLIPS(WDIALOG,"\n"); else PrintCLIPS(WDIALOG," "); } else #endif { if (GetPrintWhileLoading()) PrintCLIPS(WDIALOG,constructSymbol); } /*===============================*/ /* Get the comment if it exists. */ /*===============================*/ GetToken(readSource,inputToken); if ((inputToken->type == STRING) && getComment) { PPBackup(); SavePPBuffer(" "); SavePPBuffer(inputToken->printForm); GetToken(readSource,inputToken); if (inputToken->type != RPAREN) { PPBackup(); SavePPBuffer("\n "); SavePPBuffer(inputToken->printForm); } } else if (inputToken->type != RPAREN) { PPBackup(); SavePPBuffer("\n "); SavePPBuffer(inputToken->printForm); } /*===================================*/ /* Return the name of the construct. */ /*===================================*/ return(name); } /****************************************//* RemoveConstructFromModule: Removes a *//* construct from its module's list *//****************************************/globle VOID RemoveConstructFromModule(theConstruct) struct constructHeader *theConstruct; { struct constructHeader *lastConstruct,*currentConstruct; /*==============================*/ /* Find the specified construct */ /* in the module's list. */ /*==============================*/ lastConstruct = NULL; currentConstruct = theConstruct->whichModule->firstItem; while (currentConstruct != theConstruct) { lastConstruct = currentConstruct; currentConstruct = currentConstruct->next; } /*========================================*/ /* If it wasn't there, something's wrong. */ /*========================================*/ if (currentConstruct == NULL) { CLIPSSystemError("CSTRCPSR",1); ExitCLIPS(2); } /*==========================*/ /* Remove it from the list. */ /*==========================*/ if (lastConstruct == NULL) { theConstruct->whichModule->firstItem = theConstruct->next; } else { lastConstruct->next = theConstruct->next; } /*=================================================*/ /* Update the pointer to the last item in the list */ /* if the construct just deleted was at the end. */ /*=================================================*/ if (theConstruct == theConstruct->whichModule->lastItem) { theConstruct->whichModule->lastItem = lastConstruct; } } /******************************************************//* ImportExportConflictMessage: Generic error message *//* for an import/export module conflict detected *//* when a construct is being defined. *//******************************************************/globle VOID ImportExportConflictMessage(constructName,itemName, causedByConstruct,causedByName) char *constructName, *itemName; char *causedByConstruct, *causedByName; { PrintErrorID("CSTRCPSR",3,CLIPS_TRUE); PrintCLIPS(WERROR,"Cannot define "); PrintCLIPS(WERROR,constructName); PrintCLIPS(WERROR," "); PrintCLIPS(WERROR,itemName); PrintCLIPS(WERROR," because of an import/export conflict"); if (causedByConstruct == NULL) PrintCLIPS(WERROR,".\n"); else { PrintCLIPS(WERROR," caused by the "); PrintCLIPS(WERROR,causedByConstruct); PrintCLIPS(WERROR," "); PrintCLIPS(WERROR,causedByName); PrintCLIPS(WERROR,".\n"); } } #endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -