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

📄 filecom.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                 FILE COMMANDS MODULE                */   /*******************************************************//*************************************************************//* Purpose: Contains the code for file commands including    *//*   batch, dribble-on, dribble-off, save, load, bsave, and  *//*   bload.                                                  *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*      Brian L. Donnell                                     *//*                                                           *//* Contributing Programmer(s):                               *//*      Bebe Ly                                              *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _FILECOM_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "setup.h"#include "clipsmem.h"#include "argacces.h"#include "router.h"#include "strngrtr.h"#include "constrct.h"#include "extnfunc.h"#include "cstrcpsr.h"#include "utility.h"#include "commline.h"#include "prcdrfun.h"#include "filecom.h"#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bsave.h"#include "bload.h"#endif/***************//* STRUCTURES  *//***************/struct batchEntry  {   int batchType;   VOID *inputSource;   char *theString;   struct batchEntry *next;  };/***************//* DEFINITIONS *//***************/#define FILE_BATCH      0#define STRING_BATCH    1#define BUFFER_SIZE   120          /***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER#if DEBUGGING_FUNCTIONS   static int                     FindDribble(char *);   static int                     GetcDribble(char *);   static int                     UngetcDribble(int,char *);   static int                     ExitDribble(int);   static int                     PrintDribble(char *,char *);   static VOID                    PutcDribbleBuffer(int);#endif   static int                     FindBatch(char *);   static int                     GetcBatch(char *);   static int                     UngetcBatch(int,char *);   static int                     ExitBatch(int);   static VOID                    AddBatch(int,VOID *,int,char *);#else#if DEBUGGING_FUNCTIONS   static int                     PrintDribble();   static VOID                    PutcDribbleBuffer();   static int                     FindDribble();   static int                     GetcDribble();   static int                     UngetcDribble();   static int                     ExitDribble();#endif   static int                     FindBatch();   static int                     GetcBatch();   static int                     UngetcBatch();   static int                     ExitBatch();   static VOID                    AddBatch();#endif/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/#if DEBUGGING_FUNCTIONS   static FILE               *DribbleFP = NULL;   static char               *DribbleBuffer;   static int                 DribbleCurrentPosition = 0;   static int                 DribbleMaximumPosition = 0;#if ANSI_COMPILER   static int               (*DribbleStatusFunction)(int) = NULL;#else   static int               (*DribbleStatusFunction)() = NULL;#endif#endif   static int                 BatchType;   static VOID               *BatchSource = NULL;   static char               *BatchBuffer;   static int                 BatchCurrentPosition = 0;   static int                 BatchMaximumPosition = 0;   static struct batchEntry  *TopOfBatchList = NULL;   static struct batchEntry  *BottomOfBatchList = NULL;/***************************************//* FileCommandDefinitions: Initializes *//*   file commands.                    *//***************************************/#if ! RUN_TIMEgloble VOID FileCommandDefinitions()  {#if DEBUGGING_FUNCTIONS   DefineFunction2("batch",'b',PTIF BatchCommand,"BatchCommand","11k");   DefineFunction2("batch*",'b',PTIF BatchStarCommand,"BatchStarCommand","11k");   DefineFunction2("dribble-on",'b',PTIF DribbleOnCommand,"DribbleOnCommand","11k");   DefineFunction2("dribble-off",'b',PTIF DribbleOffCommand,"DribbleOffCommand","00");   DefineFunction2("save",'b',PTIF SaveCommand,"SaveCommand","11k");#endif   DefineFunction2("load",'b',PTIF LoadCommand,"LoadCommand","11k");   DefineFunction2("load*",'b',PTIF LoadStarCommand,"LoadStarCommand","11k");#if BLOAD_AND_BSAVE   DefineFunction2("bsave",'b', PTIF BsaveCommand,"BsaveCommand","11k");#endif#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE   DefineFunction2("bload",'b',PTIF BloadCommand,"BloadCommand","11k");#endif  }#endif#if DEBUGGING_FUNCTIONS/*****************************************************//* FindDribble: Find routine for the dribble router. *//*****************************************************/static int FindDribble(logicalName)  char *logicalName;  {   if ( (strcmp(logicalName,"stdout") == 0) ||        (strcmp(logicalName,"stdin") == 0) ||        (strcmp(logicalName,WCLIPS) == 0) ||        (strcmp(logicalName,WTRACE) == 0) ||        (strcmp(logicalName,WERROR) == 0) ||        (strcmp(logicalName,WWARNING) == 0) ||        (strcmp(logicalName,WDISPLAY) == 0) ||        (strcmp(logicalName,WDIALOG) == 0) )     { return(CLIPS_TRUE); }    return(CLIPS_FALSE);  }/*******************************************************//* PrintDribble: Print routine for the dribble router. *//*******************************************************/static int PrintDribble(logicalName,str)  char *logicalName, *str;  {   int i;   /*======================================*/   /* Send the output to the dribble file. */   /*======================================*/   for (i = 0 ; str[i] != EOS ; i++)     { PutcDribbleBuffer(str[i]); }   /*===========================================================*/   /* Send the output to any routers interested in printing it. */   /*===========================================================*/   DeactivateRouter("dribble");   PrintCLIPS(logicalName,str);   ActivateRouter("dribble");      return(1);  }/*****************************************************//* GetcDribble: Getc routine for the dribble router. *//*****************************************************/static int GetcDribble(logicalName)  char *logicalName;  {   int rv;   /*===========================================*/   /* Deactivate the dribble router and get the */   /* character from another active router.     */   /*===========================================*/      DeactivateRouter("dribble");   rv = GetcCLIPS(logicalName);   ActivateRouter("dribble");   /*==========================================*/   /* Put the character retrieved from another */   /* router into the dribble buffer.          */   /*==========================================*/      PutcDribbleBuffer(rv);   /*=======================*/   /* Return the character. */   /*=======================*/      return(rv);  }/***********************************************************//* PutcDribbleBuffer: Putc routine for the dribble router. *//***********************************************************/static VOID PutcDribbleBuffer(rv)  int rv;  {   /*===================================================*/   /* Receiving an end-of-file character will cause the */   /* contents of the dribble buffer to be flushed.     */   /*===================================================*/      if (rv == EOF)     {      if (DribbleCurrentPosition > 0)        {         fprintf(DribbleFP,"%s",DribbleBuffer);         DribbleCurrentPosition = 0;         DribbleBuffer[0] = EOS;        }     }      /*===========================================================*/   /* If we aren't receiving command input, then the character  */   /* just received doesn't need to be placed in the dribble    */   /* buffer--It can be written directly to the file. This will */   /* occur for example when the "CLIPS>" prompt is being       */   /* printed (the CLIPSInputCount variable will be -1 because  */   /* command input has not been receivied yet). Before writing */   /* the character to the file, the dribble buffer is flushed. */   /*===========================================================*/        else if (CLIPSInputCount < 0)     {      if (DribbleCurrentPosition > 0)        {         fprintf(DribbleFP,"%s",DribbleBuffer);         DribbleCurrentPosition = 0;         DribbleBuffer[0] = EOS;        }      fputc(rv,DribbleFP);     }      /*=====================================================*/   /* Otherwise, add the character to the dribble buffer. */   /*=====================================================*/      else     {      DribbleBuffer = ExpandStringWithChar(rv,DribbleBuffer,                                           &DribbleCurrentPosition,                                           &DribbleMaximumPosition,                                           DribbleMaximumPosition+BUFFER_SIZE);     }  }/*********************************************************//* UngetcDribble: Ungetc routine for the dribble router. *//*********************************************************/static int UngetcDribble(ch,logicalName)  int ch;  char *logicalName;  {   int rv;   /*===============================================*/   /* Remove the character from the dribble buffer. */   /*===============================================*/      if (DribbleCurrentPosition > 0) DribbleCurrentPosition--;   DribbleBuffer[DribbleCurrentPosition] = EOS;      /*=============================================*/   /* Deactivate the dribble router and pass the  */   /* ungetc request to the other active routers. */   /*=============================================*/      DeactivateRouter("dribble");   rv = UngetcCLIPS(ch,logicalName);   ActivateRouter("dribble");   /*==========================================*/   /* Return the result of the ungetc request. */   /*==========================================*/      return(rv);  }/*****************************************************//* ExitDribble: Exit routine for the dribble router. *//*****************************************************/#if IBM_TBC#pragma argsused#endifstatic int ExitDribble(num)  int num;  {#if MAC_MPW || MAC_MCW#pragma unused(num)#endif   if (DribbleCurrentPosition > 0)     { fprintf(DribbleFP,"%s",DribbleBuffer); }   if (DribbleFP != NULL) fclose(DribbleFP);   return(1);  }/******************************************//* DribbleOnCommand: CLIPS access routine *//*   for the dribble-on command.          *//******************************************/globle int DribbleOnCommand()  {   char *fileName;   if (ArgCountCheck("dribble-on",EXACTLY,1) == -1) return(CLIPS_FALSE);   if ((fileName = GetFileName("dribble-on",1)) == NULL) return(CLIPS_FALSE);   return (DribbleOn(fileName));  }/***********************************//* DribbleOn: C access routine for *//*   the dribble-on command.       *//***********************************/globle BOOLEAN DribbleOn(fileName)  char *fileName;  {   /*==============================*/   /* If a dribble file is already */   /* open, then close it.         */

⌨️ 快捷键说明

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