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

📄 iofun.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                 I/O FUNCTIONS MODULE                */   /*******************************************************//*************************************************************//* Purpose: Contains the code for several I/O functions      *//*   including printout, read, open, close, remove, rename,  *//*   format, and readline.                                   *//*                                                           *//* Principal Programmer(s):                                  *//*      Brian L. Donnell                                     *//*      Gary D. Riley                                        *//*      Bebe Ly                                              *//*                                                           *//* Contributing Programmer(s):                               *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _IOFUN_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "setup.h"#include "router.h"#include "strngrtr.h"#include "filertr.h"#include "argacces.h"#include "extnfunc.h"#include "scanner.h"#include "constant.h"#include "clipsmem.h"#include "commline.h"#include "sysdep.h"#include "utility.h"#include "iofun.h"/***************//* DEFINITIONS *//***************/#define FORMAT_MAX 512#define FLAG_MAX    80/****************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS  *//****************************************/#if ANSI_COMPILER#if BASIC_IO   static VOID             ReadTokenFromStdin(struct token *);#endif#if BASIC_IO || EXT_IO   static VOID             IllegalLogicalNameMessage(char *);#endif#if EXT_IO   static char            *ControlStringCheck(int);   static char             FindFormatFlag(char *,int *,char *,int *);   static char            *PrintFormatFlag (char *,int,int,int);   static char            *FillBuffer(char *,int *,int *);#endif#else#if BASIC_IO   static VOID             ReadTokenFromStdin();#endif#if BASIC_IO || EXT_IO   static VOID             IllegalLogicalNameMessage();#endif#if EXT_IO   static char            *ControlStringCheck();   static char             FindFormatFlag();   static char            *PrintFormatFlag ();   static char            *FillBuffer();#endif#endif#if ! RUN_TIME/**************************************//* IOFunctionDefinitions: Initializes *//*   the I/O functions.               *//**************************************/globle VOID IOFunctionDefinitions()  {#if BASIC_IO   DefineFunction2("printout", 'v', PTIF PrintoutFunction, "PrintoutFunction", "1*");   DefineFunction2("read",     'u', PTIF ReadFunction,  "ReadFunction", "*1");   DefineFunction2("open",     'b', OpenFunction,  "OpenFunction", "23*k");   DefineFunction2("close",    'b', CloseFunction, "CloseFunction", "*1");#endif#if EXT_IO   DefineFunction2("remove",   'b', RemoveFunction,  "RemoveFunction", "11k");   DefineFunction2("rename",   'b', RenameFunction, "RenameFunction", "22k");   DefineFunction2("format",   's', PTIF FormatFunction, "FormatFunction", "2**us");   DefineFunction2("readline", 'k', PTIF ReadlineFunction, "ReadlineFunction", "*1");#endif  }#endif#if BASIC_IO/******************************************//* PrintoutFunction: CLIPS access routine *//*   for the printout function.           *//******************************************/globle VOID PrintoutFunction()  {   char *dummyid;   int i, argCount;   DATA_OBJECT theArgument;   /*=======================================================*/   /* The printout function requires at least one argument. */   /*=======================================================*/      if ((argCount = ArgCountCheck("printout",AT_LEAST,1)) == -1) return;   /*=====================================================*/   /* Get the logical name to which output is to be sent. */   /*=====================================================*/   dummyid = GetLogicalName(1,"stdout");   if (dummyid == NULL)     {      IllegalLogicalNameMessage("printout");      SetHaltExecution(CLIPS_TRUE);      SetEvaluationError(CLIPS_TRUE);      return;     }   /*============================================================*/   /* Determine if any router recognizes the output destination. */   /*============================================================*/      if (QueryRouters(dummyid) == CLIPS_FALSE)     {      UnrecognizedRouterMessage(dummyid);      return;     }   /*===============================================*/   /* Print each of the arguments sent to printout. */   /*===============================================*/      for (i = 2; i <= argCount; i++)     {      RtnUnknown(i,&theArgument);      if (HaltExecution) break;            switch(GetType(theArgument))        {         case SYMBOL:           if (strcmp(DOToString(theArgument),"crlf") == 0)             { PrintCLIPS(dummyid,"\n"); }           else if (strcmp(DOToString(theArgument),"tab") == 0)             { PrintCLIPS(dummyid,"\t"); }           else if (strcmp(DOToString(theArgument),"vtab") == 0)             { PrintCLIPS(dummyid,"\v"); }           else if (strcmp(DOToString(theArgument),"ff") == 0)             { PrintCLIPS(dummyid,"\f"); }           else if (strcmp(DOToString(theArgument),"t") == 0)             { PrintCLIPS(dummyid,"\n"); }           else             { PrintCLIPS(dummyid,DOToString(theArgument)); }           break;         case STRING:           PrintCLIPS(dummyid,DOToString(theArgument));           break;         default:           PrintDataObject(dummyid,&theArgument);           break;        }     }  }/*************************************************************//* ReadFunction: CLIPS access routine for the read function. *//*************************************************************/globle VOID ReadFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {   struct token theToken;   int numberOfArguments;   char *logicalName = NULL;   /*===============================================*/   /* Check for an appropriate number of arguments. */   /*===============================================*/   if ((numberOfArguments = ArgCountCheck("read",NO_MORE_THAN,1)) == -1)     {      returnValue->type = STRING;      returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");      return;     }   /*======================================================*/   /* Determine the logical name from which input is read. */   /*======================================================*/   if (numberOfArguments == 0)     { logicalName = "stdin"; }   else if (numberOfArguments == 1)     {      logicalName = GetLogicalName(1,"stdin");      if (logicalName == NULL)        {         IllegalLogicalNameMessage("read");         SetHaltExecution(CLIPS_TRUE);         SetEvaluationError(CLIPS_TRUE);         returnValue->type = STRING;         returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");         return;        }     }   /*============================================*/   /* Check to see that the logical name exists. */   /*============================================*/      if (QueryRouters(logicalName) == CLIPS_FALSE)     {      UnrecognizedRouterMessage(logicalName);      SetHaltExecution(CLIPS_TRUE);      SetEvaluationError(CLIPS_TRUE);      returnValue->type = STRING;      returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");      return;     }   /*=======================================*/   /* Collect input into string if the read */   /* source is stdin, else just get token. */   /*=======================================*/   if (strcmp(logicalName,"stdin") == 0)     { ReadTokenFromStdin(&theToken); }   else     { GetToken(logicalName,&theToken); }   CLIPSInputCount = -1;   /*====================================================*/   /* Copy the token to the return value data structure. */   /*====================================================*/   returnValue->type = theToken.type;   if ((theToken.type == FLOAT) || (theToken.type == STRING) ||#if OBJECT_SYSTEM       (theToken.type == INSTANCE_NAME) ||#endif       (theToken.type == SYMBOL) || (theToken.type == INTEGER))     { returnValue->value = theToken.value; }   else if (theToken.type == STOP)     {      returnValue->type = SYMBOL;      returnValue->value = (VOID *) AddSymbol("EOF");     }   else if (theToken.type == UNKNOWN_VALUE)     {      returnValue->type = STRING;      returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");     }   else     {      returnValue->type = STRING;      returnValue->value = (VOID *) AddSymbol(theToken.printForm);     }   return;  }  /********************************************************//* ReadTokenFromStdin: Special routine used by the read *//*   function to read a token from standard input.      *//********************************************************/static VOID ReadTokenFromStdin(theToken)  struct token *theToken;  {   char *inputString;   int inputStringSize;   int inchar;      /*=============================================*/   /* Continue processing until a token is found. */   /*=============================================*/      theToken->type = STOP;   while (theToken->type == STOP)     {      /*===========================================*/      /* Initialize the variables used for storing */      /* the characters retrieved from stdin.      */      /*===========================================*/            inputString = NULL;      inputStringSize = CLIPSInputCount = 0;      inchar = GetcCLIPS("stdin");            /*========================================================*/      /* Continue reading characters until a carriage return is */      /* entered or the user halts execution (usually with      */      /* control-c). Waiting for the carriage return prevents   */      /* the input from being prematurely parsed (such as when  */      /* a space is entered after a symbol has been typed).     */      /*========================================================*/            while ((inchar != '\n') && (inchar != '\r') && (inchar != EOF) &&             (! GetHaltExecution()))        {         inputString = ExpandStringWithChar(inchar,inputString,&CLIPSInputCount,                                            &inputStringSize,inputStringSize + 80);         inchar = GetcCLIPS("stdin");        }      /*==================================================*/      /* Open a string input source using the characters  */      /* retrieved from stdin and extract the first token */      /* contained in the string.                         */      /*==================================================*/            OpenStringSource("read",inputString,0);      GetToken("read",theToken);      CloseStringSource("read");      if (inputStringSize > 0) rm(inputString,inputStringSize);      /*===========================================*/      /* Pressing control-c (or comparable action) */      /* aborts the read function.                 */      /*===========================================*/            if (GetHaltExecution())

⌨️ 快捷键说明

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