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

📄 iofun.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ControlStringCheck:  Checks the 2nd parameter which is the format *//*   control string to see if there are enough matching arguments.   *//*********************************************************************/static char *ControlStringCheck(argCount)  int argCount;  {   DATA_OBJECT t_ptr;   char *str_array;   char print_buff[10];   int longFound;   int i,per_count;   if (ArgTypeCheck("format",2,STRING,&t_ptr) == CLIPS_FALSE) return(NULL);   per_count = 0;   str_array = ValueToString(t_ptr.value);   for (i= 0 ; str_array[i] != '\0' ; )     {      if (str_array[i] == '%')        {         i++;         if (FindFormatFlag(str_array,&i,print_buff,&longFound) != ' ')           { per_count++; }        }      else        { i++; }     }   if (per_count != (argCount - 2))     {      ExpectedCountError("format",EXACTLY,per_count+2);      SetEvaluationError(CLIPS_TRUE);      return (NULL);     }   return(str_array);  }/***********************************************//* FindFormatFlag:  This function searches for *//*   a format flag in the format string.       *//***********************************************/static char FindFormatFlag(formatString,a,formatBuffer,longFound)  char *formatString;  int *a;  char *formatBuffer;  int *longFound;  {   char inchar, formatFlagType;   int start_pos, copy_pos = 0;   /*===========================================================*/   /* Set return values to the default value. A blank character */   /* indicates that no format flag was found which requires a  */   /* parameter. The longFound flag indicates whether the       */   /* character 'l' was used with the float or integer flag to  */   /* indicate a double precision float or a long integer.      */   /*===========================================================*/      formatFlagType = ' ';   *longFound = CLIPS_FALSE;   /*=====================================================*/   /* The format flags for carriage returns, line feeds,  */   /* horizontal and vertical tabs, and the percent sign, */   /* do not require a parameter.                         */   /*=====================================================*/      if (formatString[*a] == 'n')     {      sprintf(formatBuffer,"\n");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == 'r')     {      sprintf(formatBuffer,"\r");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == 't')     {      sprintf(formatBuffer,"\t");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == 'v')     {      sprintf(formatBuffer,"\v");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == '%')     {      sprintf(formatBuffer,"%%");      (*a)++;      return(formatFlagType);     }   /*======================================================*/   /* Identify the format flag which requires a parameter. */   /*======================================================*/      start_pos = *a;   formatBuffer[copy_pos] = '\0';   while ((formatString[*a] != '%') &&          (formatString[*a] != '\0') &&          ((*a - start_pos) < FLAG_MAX))     {      inchar = formatString[*a];      formatBuffer[copy_pos++] = inchar;      formatBuffer[copy_pos] = '\0';      if ( (inchar == 'd') ||           (inchar == 'o') ||           (inchar == 'x') ||           (inchar == 'u') ||           (inchar == 'c') ||           (inchar == 's') ||           (inchar == 'e') ||           (inchar == 'f') ||           (inchar == 'g') )         {         formatFlagType = inchar;         if (formatString[(*a) - 1] == 'l')            { *longFound = CLIPS_TRUE; }         (*a)++;         return(formatFlagType);        }      (*a)++;     }   return(formatFlagType);  }/**********************************************************************//* PrintFormatFlag:  Prints out part of the total format string along *//*   with the argument for that part of the format string.            *//**********************************************************************/static char *PrintFormatFlag (formatString,whichArg,formatType,longFound)  char *formatString;  int whichArg;  int formatType;  int longFound;  {   DATA_OBJECT theResult;   char *theString, *printBuffer;   int theLength;   /*=================*/   /* String argument */   /*=================*/   switch (formatType)     {      case 's':         if (ArgTypeCheck("format",whichArg,SYMBOL_OR_STRING,&theResult) == CLIPS_FALSE) return(NULL);        theLength = strlen(formatString) + strlen(ValueToString(theResult.value)) + 200;        printBuffer = (char *) gm2 (((int) sizeof(char) * theLength));        sprintf(printBuffer,formatString,ValueToString(theResult.value));        break;              case 'c':         if (ArgTypeCheck("format",whichArg,SYMBOL_OR_STRING,&theResult) == CLIPS_FALSE) return(NULL);        theLength = strlen(formatString) + 200;        printBuffer = (char *) gm2 (((int) sizeof(char) * theLength));        sprintf(printBuffer,formatString,(ValueToString(theResult.value))[0]);        break;              case 'd':      case 'x':      case 'o':      case 'u':        if (ArgTypeCheck("format",whichArg,INTEGER_OR_FLOAT,&theResult) == CLIPS_FALSE) return(NULL);        theLength = strlen(formatString) + 200;        printBuffer = (char *) gm2 (((int) sizeof(char) * theLength));        if (GetType(theResult) == FLOAT)          {           if (longFound)             { sprintf(printBuffer,formatString,(long) ValueToDouble(theResult.value)); }           else             { sprintf(printBuffer,formatString,(int) ValueToDouble(theResult.value)); }          }        else          {           if (longFound)             { sprintf(printBuffer,formatString,(long) ValueToLong(theResult.value)); }           else             { sprintf(printBuffer,formatString,(int) ValueToLong(theResult.value)); }          }        break;              case 'f':      case 'g':      case 'e':        if (ArgTypeCheck("format",whichArg,INTEGER_OR_FLOAT,&theResult) == CLIPS_FALSE) return(NULL);        theLength = strlen(formatString) + 200;        printBuffer = (char *) gm2 (((int) sizeof(char) * theLength));                if (GetType(theResult) == FLOAT)          { sprintf(printBuffer,formatString,ValueToDouble(theResult.value)); }        else          { sprintf(printBuffer,formatString,(double) ValueToLong(theResult.value)); }        break;              default:         PrintCLIPS (WERROR," Error in format, the conversion character");         PrintCLIPS (WERROR," for formatted output is not valid\n");         return(CLIPS_FALSE);     }   theString = ValueToString(AddSymbol(printBuffer));   rm(printBuffer,(int) sizeof(char) * theLength);   return(theString);  }/******************************************//* ReadlineFunction: CLIPS access routine *//*   for the readline function.           *//******************************************/globle VOID ReadlineFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {   char *buffer;   int line_max = 0;   int numberOfArguments;   char *logicalName;      returnValue->type = STRING;   if ((numberOfArguments = ArgCountCheck("readline",NO_MORE_THAN,1)) == -1)     {      returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");      return;     }   if (numberOfArguments == 0 )     { logicalName = "stdin"; }   else     {      logicalName = GetLogicalName(1,"stdin");      if (logicalName == NULL)        {         IllegalLogicalNameMessage("readline");         SetHaltExecution(CLIPS_TRUE);         SetEvaluationError(CLIPS_TRUE);         returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");         return;        }     }   if (QueryRouters(logicalName) == CLIPS_FALSE)     {      UnrecognizedRouterMessage(logicalName);      SetHaltExecution(CLIPS_TRUE);      SetEvaluationError(CLIPS_TRUE);      returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");      return;     }   CLIPSInputCount = 0;   buffer = FillBuffer(logicalName,&CLIPSInputCount,&line_max);   CLIPSInputCount = -1;   if (GetHaltExecution())     {      returnValue->value = (VOID *) AddSymbol("*** READ ERROR ***");      if (buffer != NULL) rm(buffer,(int) sizeof (char) * line_max);      return;     }   if (buffer == NULL)     {      returnValue->value = (VOID *) AddSymbol("EOF");      returnValue->type = SYMBOL;      return;     }   returnValue->value = (VOID *) AddSymbol(buffer);   rm(buffer,(int) sizeof (char) * line_max);   return;  }/*************************************************************//* FillBuffer: Read characters from a specified logical name *//*   and places them into a buffer until a carriage return   *//*   or end-of-file character is read.                       *//*************************************************************/static char *FillBuffer(logicalName,currentPosition,maximumSize)  char *logicalName;  int *currentPosition, *maximumSize;  {   int c;   char *buf = NULL;   /*================================*/   /* Read until end of line or eof. */   /*================================*/   c = GetcCLIPS(logicalName);   if (c == EOF)     { return(NULL); }   /*==================================*/   /* Grab characters until cr or eof. */   /*==================================*/   while ((c != '\n') && (c != '\r') && (c != EOF) &&          (! GetHaltExecution()))     {      buf = ExpandStringWithChar(c,buf,currentPosition,maximumSize,*maximumSize+80);      c = GetcCLIPS(logicalName);     }   /*==================*/   /* Add closing EOS. */   /*==================*/   buf = ExpandStringWithChar(EOS,buf,currentPosition,maximumSize,*maximumSize+80);   return (buf);  }#endif#if BASIC_IO || EXT_IO   /****************************************************//* IllegalLogicalNameMessage: Generic error message *//*   for illegal logical names.                     *//****************************************************/static VOID IllegalLogicalNameMessage(theFunction)  char *theFunction;  {   PrintErrorID("IOFUN",1,CLIPS_FALSE);   PrintCLIPS(WERROR,"Illegal logical name used for ");   PrintCLIPS(WERROR,theFunction);   PrintCLIPS(WERROR," function.\n");  }#endif

⌨️ 快捷键说明

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