⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constrct.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                  CONSTRUCT MODULE                   */   /*******************************************************//*************************************************************//* Purpose: Provides basic functionality for creating new    *//*   types of constructs, saving constructs to a file, and   *//*   adding new functionality to the clear and reset         *//*   commands.                                               *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _CONSTRCT_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "setup.h"#include "constant.h"#include "clipsmem.h"#include "router.h"#include "scanner.h"#include "watch.h"#include "prcdrfun.h"#include "prcdrpsr.h"#include "argacces.h"#include "exprnpsr.h"#include "multifld.h"#include "moduldef.h"#include "utility.h"#include "commline.h"#include "constrct.h"/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/   globle int                   ClearInProgress = CLIPS_FALSE;   globle int                   ResetInProgress = CLIPS_FALSE;/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/#if (! RUN_TIME) && (! BLOAD_ONLY)   static struct callFunctionItem   *ListOfSaveFunctions = NULL;   static BOOLEAN                    PrintWhileLoading = CLIPS_FALSE;   static BOOLEAN                    WatchCompilations = ON;#endif   static struct construct          *ListOfConstructs = NULL;   static struct callFunctionItem   *ListOfResetFunctions = NULL;   static struct callFunctionItem   *ListOfClearFunctions = NULL;   static struct callFunctionItem   *ListOfClearReadyFunctions = NULL;   static int                        Executing = CLIPS_FALSE;#if ANSI_COMPILER   static int                      (*BeforeResetFunction)(void) = NULL;#else   static int                      (*BeforeResetFunction)() = NULL;#endif#if (! RUN_TIME) && (! BLOAD_ONLY)/*************************************************//* FindConstruct: Determines whether a construct *//*   type is in the ListOfConstructs.            *//*************************************************/globle struct construct *FindConstruct(name)  char *name;  {   struct construct *currentPtr;   for (currentPtr = ListOfConstructs;        currentPtr != NULL;        currentPtr = currentPtr->next)     {      if (strcmp(name,currentPtr->constructName) == 0)        { return(currentPtr); }     }   return(NULL);  }/***********************************************************//* RemoveConstruct: Removes a construct and its associated *//*   parsing function from the ListOfConstructs. Returns   *//*   TRUE if the construct type was removed, otherwise     *//*   FALSE.                                                *//***********************************************************/globle int RemoveConstruct(name)  char *name;  {   struct construct *currentPtr, *lastPtr = NULL;      for (currentPtr = ListOfConstructs;        currentPtr != NULL;        currentPtr = currentPtr->next)     {      if (strcmp(name,currentPtr->constructName) == 0)        {         if (lastPtr == NULL)           { ListOfConstructs = currentPtr->next; }         else           { lastPtr->next = currentPtr->next; }         rtn_struct(construct,currentPtr);         return(CLIPS_TRUE);        }              lastPtr = currentPtr;     }   return(CLIPS_FALSE);  }/************************************************//* Save: C access routine for the save command. *//************************************************/globle int Save(fileName)  char *fileName;  {   struct callFunctionItem *saveFunction;   FILE *filePtr;   /*=====================*/   /* Open the save file. */   /*=====================*/      if ((filePtr = fopen(fileName,"w")) == NULL)     { return(CLIPS_FALSE); }        /*===========================*/   /* Bypass the router system. */   /*===========================*/      SetFastSave(filePtr);   /*======================*/   /* Save the constructs. */   /*======================*/   for (saveFunction = ListOfSaveFunctions;        saveFunction != NULL;        saveFunction = saveFunction->next)     {#if ANSI_COMPILER      ((* (VOID (*)(char *)) saveFunction->func))((char *) filePtr);#else      (*saveFunction->func)((char *) filePtr);#endif     }   /*======================*/   /* Close the save file. */   /*======================*/      fclose(filePtr);      /*===========================*/   /* Remove the router bypass. */   /*===========================*/      SetFastSave(NULL);   /*=========================*/   /* Return TRUE to indicate */   /* successful completion.  */   /*=========================*/      return(CLIPS_TRUE);  }/*******************************************************//* RemoveSaveFunction: Removes a function from the     *//*   ListOfSaveFunctions. Returns TRUE if the function *//*   was successfully removed, otherwise FALSE.        *//*******************************************************/globle BOOLEAN RemoveSaveFunction(name)  char *name;  {   int found;   ListOfSaveFunctions =      RemoveFunctionFromCallList(name,ListOfSaveFunctions,&found);   if (found) return(CLIPS_TRUE);      return(CLIPS_FALSE);  }/**********************************//* SetCompilationsWatch: Sets the *//*   value of WatchCompilations.  *//**********************************/globle VOID SetCompilationsWatch(value)  int value;  {   WatchCompilations = value;  }/*************************************//* GetCompilationsWatch: Returns the *//*   value of WatchCompilations.     *//*************************************/globle BOOLEAN GetCompilationsWatch()  { return(WatchCompilations); }/**********************************//* SetPrintWhileLoading: Sets the *//*   value of PrintWhileLoading.  *//**********************************/globle VOID SetPrintWhileLoading(value)  BOOLEAN value;  {   PrintWhileLoading = value;  }/*************************************//* GetPrintWhileLoading: Returns the *//*   value of PrintWhileLoading.     *//*************************************/globle BOOLEAN GetPrintWhileLoading()  {   return(PrintWhileLoading);  }#endif/*************************************//* InitializeConstructs: Initializes *//*   the Construct Manager.          *//*************************************/globle VOID InitializeConstructs()  {#if (! RUN_TIME)   DefineFunction2("clear",   'v', PTIF ClearCommand,   "ClearCommand", "00");   DefineFunction2("reset",   'v', PTIF ResetCommand,   "ResetCommand", "00");#endif#if DEBUGGING_FUNCTIONS && (! RUN_TIME) && (! BLOAD_ONLY)   AddWatchItem("compilations",0,&WatchCompilations,30,NULL,NULL);#endif  }  /**************************************//* ClearCommand: CLIPS access routine *//*   for the clear command.           *//**************************************/globle VOID ClearCommand()  {   if (ArgCountCheck("clear",EXACTLY,0) == -1) return;   Clear();   return;  }/**************************************//* ResetCommand: CLIPS access routine *//*   for the reset command.           *//**************************************/globle VOID ResetCommand()  {   if (ArgCountCheck("reset",EXACTLY,0) == -1) return;   Reset();   return;  }/****************************//* Reset: C access routine  *//*   for the reset command. *//****************************/globle VOID Reset()  {   struct callFunctionItem *resetPtr;   /*=====================================*/   /* The reset command can't be executed */   /* while a reset is in progress.       */   /*=====================================*/      if (ResetInProgress) return;   ResetInProgress = CLIPS_TRUE;      /*================================================*/   /* If the reset is performed from the top level   */   /* command prompt, reset the halt execution flag. */   /*================================================*/      if (CurrentEvaluationDepth == 0) SetHaltExecution(CLIPS_FALSE);   /*=======================================================*/   /* Call the before reset function to determine if the    */   /* reset should continue. [Used by the some of the       */   /* windowed interfaces to query the user whether a       */   /* reset should proceed with activations on the agenda.] */   /*=======================================================*/      if ((BeforeResetFunction != NULL) ? ((*BeforeResetFunction)() == CLIPS_FALSE) :                                        CLIPS_FALSE)     {      ResetInProgress = CLIPS_FALSE;      return;     }      /*===========================*/   /* Call each reset function. */   /*===========================*/      for (resetPtr = ListOfResetFunctions;        (resetPtr != NULL) && (GetHaltExecution() == CLIPS_FALSE);        resetPtr = resetPtr->next)     { (*resetPtr->func)(); }   /*============================================*/   /* Set the current module to the MAIN module. */   /*============================================*/      SetCurrentModule((VOID *) FindDefmodule("MAIN"));      /*===========================================*/   /* Perform periodic cleanup if the reset was */   /* issued from an embedded controller.       */   /*===========================================*/      if ((CurrentEvaluationDepth == 0) && (! EvaluatingTopLevelCommand) &&       (CurrentExpression == NULL))     { PeriodicCleanup(CLIPS_TRUE,CLIPS_FALSE); }   /*===================================*/   /* A reset is no longer in progress. */   /*===================================*/      ResetInProgress = CLIPS_FALSE;  }/************************************//* SetBeforeResetFunction: Sets the *//*  value of BeforeResetFunction.   *//************************************/#if ! MAC_MCWgloble int (*SetBeforeResetFunction(theFunction))(VOID_ARG)  int (*theFunction)(VOID_ARG);#elsegloble int (*SetBeforeResetFunction(theFunction))()  int (*theFunction)(VOID_ARG);#endif  {   int (*tempFunction)(VOID_ARG);   tempFunction = BeforeResetFunction;   BeforeResetFunction = theFunction;   return(tempFunction);  }/*************************************//* AddResetFunction: Adds a function *//*   to ListOfResetFunctions.        *//*************************************/globle BOOLEAN AddResetFunction(name,functionPtr,priority)  char *name;#if ANSI_COMPILER  VOID (*functionPtr)(void);#else  VOID (*functionPtr)();#endif  int priority;  {   ListOfResetFunctions = AddFunctionToCallList(name,priority,                                                functionPtr,                                                ListOfResetFunctions);   return(CLIPS_TRUE);  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -