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

📄 iofun.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
         while ((formatString[form_pos] != '%') &&                (formatString[form_pos] != '\0'))           { form_pos++; }         fstr = AppendNToString(theEnv,&formatString[start_pos],fstr,form_pos-start_pos,&fpos,&fmaxm);        }      else        {         start_pos = form_pos;         form_pos++;         formatFlagType = FindFormatFlag(formatString,&form_pos,percentBuffer,FLAG_MAX);         if (formatFlagType != ' ')           {            if ((theString = PrintFormatFlag(theEnv,percentBuffer,f_cur_arg,formatFlagType)) == NULL)              {               if (fstr != NULL) rm(theEnv,fstr,fmaxm);               return (hptr);              }            fstr = AppendToString(theEnv,theString,fstr,&fpos,&fmaxm);            if (fstr == NULL) return(hptr);            f_cur_arg++;           }         else           {            fstr = AppendToString(theEnv,percentBuffer,fstr,&fpos,&fmaxm);            if (fstr == NULL) return(hptr);           }        }     }   if (fstr != NULL)     {      hptr = EnvAddSymbol(theEnv,fstr);      if (strcmp(logicalName,"nil") != 0) EnvPrintRouter(theEnv,logicalName,fstr);      rm(theEnv,fstr,fmaxm);     }   else     { hptr = EnvAddSymbol(theEnv,""); }   return(hptr);  }/*********************************************************************//* ControlStringCheck:  Checks the 2nd parameter which is the format *//*   control string to see if there are enough matching arguments.   *//*********************************************************************/static char *ControlStringCheck(  void *theEnv,  int argCount)  {   DATA_OBJECT t_ptr;   char *str_array;   char print_buff[FLAG_MAX];   size_t i;   int per_count;   char formatFlag;   if (EnvArgTypeCheck(theEnv,"format",2,STRING,&t_ptr) == FALSE) return(NULL);   per_count = 0;   str_array = ValueToString(t_ptr.value);   for (i= 0 ; str_array[i] != '\0' ; )     {      if (str_array[i] == '%')        {         i++;         formatFlag = FindFormatFlag(str_array,&i,print_buff,FLAG_MAX);         if (formatFlag == '-')           {             PrintErrorID(theEnv,"IOFUN",3,FALSE);            EnvPrintRouter(theEnv,WERROR,"Invalid format flag \"");            EnvPrintRouter(theEnv,WERROR,print_buff);            EnvPrintRouter(theEnv,WERROR,"\" specified in format function.\n");            SetEvaluationError(theEnv,TRUE);            return (NULL);           }         else if (formatFlag != ' ')           { per_count++; }        }      else        { i++; }     }   if (per_count != (argCount - 2))     {      ExpectedCountError(theEnv,"format",EXACTLY,per_count+2);      SetEvaluationError(theEnv,TRUE);      return (NULL);     }   return(str_array);  }/***********************************************//* FindFormatFlag:  This function searches for *//*   a format flag in the format string.       *//***********************************************/static char FindFormatFlag(  char *formatString,  size_t *a,  char *formatBuffer,  size_t bufferMax)  {   char inchar, formatFlagType;   size_t start_pos;   size_t copy_pos = 0;   /*====================================================*/   /* Set return values to the default value. A blank    */   /* character indicates that no format flag was found  */   /* which requires a parameter.                        */   /*====================================================*/   formatFlagType = ' ';   /*=====================================================*/   /* 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')     {      gensprintf(formatBuffer,"\n");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == 'r')     {      gensprintf(formatBuffer,"\r");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == 't')     {      gensprintf(formatBuffer,"\t");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == 'v')     {      gensprintf(formatBuffer,"\v");      (*a)++;      return(formatFlagType);     }   else if (formatString[*a] == '%')     {      gensprintf(formatBuffer,"%%");      (*a)++;      return(formatFlagType);     }   /*======================================================*/   /* Identify the format flag which requires a parameter. */   /*======================================================*/   start_pos = *a;   formatBuffer[copy_pos++] = '%';   formatBuffer[copy_pos] = '\0';   while ((formatString[*a] != '%') &&          (formatString[*a] != '\0') &&          (copy_pos < (bufferMax - 5)))     {      inchar = formatString[*a];      (*a)++;      if ( (inchar == 'd') ||           (inchar == 'o') ||           (inchar == 'x') ||           (inchar == 'u'))        {         formatFlagType = inchar;         formatBuffer[copy_pos++] = 'l';         formatBuffer[copy_pos++] = 'l';         formatBuffer[copy_pos++] = inchar;         formatBuffer[copy_pos] = '\0';         return(formatFlagType);        }      else if ( (inchar == 'c') ||                (inchar == 's') ||                (inchar == 'e') ||                (inchar == 'f') ||                (inchar == 'g') )        {         formatBuffer[copy_pos++] = inchar;         formatBuffer[copy_pos] = '\0';         formatFlagType = inchar;         return(formatFlagType);        }            /*=======================================================*/      /* If the type hasn't been read, then this should be the */      /* -M.N part of the format specification (where M and N  */      /* are integers).                                        */      /*=======================================================*/            if ( (! isdigit(inchar)) &&           (inchar != '.') &&           (inchar != '-') )        {          formatBuffer[copy_pos++] = inchar;         formatBuffer[copy_pos] = '\0';         return('-');         }      formatBuffer[copy_pos++] = inchar;      formatBuffer[copy_pos] = '\0';     }   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(  void *theEnv,  char *formatString,  int whichArg,  int formatType)  {   DATA_OBJECT theResult;   char *theString, *printBuffer;   size_t theLength;   void *oldLocale;         /*=================*/   /* String argument */   /*=================*/   switch (formatType)     {      case 's':        if (EnvArgTypeCheck(theEnv,"format",whichArg,SYMBOL_OR_STRING,&theResult) == FALSE) return(NULL);        theLength = strlen(formatString) + strlen(ValueToString(theResult.value)) + 200;        printBuffer = (char *) gm2(theEnv,(sizeof(char) * theLength));        gensprintf(printBuffer,formatString,ValueToString(theResult.value));        break;      case 'c':        EnvRtnUnknown(theEnv,whichArg,&theResult);        if ((GetType(theResult) == STRING) ||            (GetType(theResult) == SYMBOL))          {           theLength = strlen(formatString) + 200;           printBuffer = (char *) gm2(theEnv,(sizeof(char) * theLength));           gensprintf(printBuffer,formatString,(ValueToString(theResult.value))[0]);          }        else if (GetType(theResult) == INTEGER)          {           theLength = strlen(formatString) + 200;           printBuffer = (char *) gm2(theEnv,(sizeof(char) * theLength));           gensprintf(printBuffer,formatString,(char) DOToLong(theResult));          }        else          {           ExpectedTypeError1(theEnv,"format",whichArg,"symbol, string, or integer");           return(NULL);          }        break;      case 'd':      case 'x':      case 'o':      case 'u':        if (EnvArgTypeCheck(theEnv,"format",whichArg,INTEGER_OR_FLOAT,&theResult) == FALSE) return(NULL);        theLength = strlen(formatString) + 200;        printBuffer = (char *) gm2(theEnv,(sizeof(char) * theLength));                oldLocale = EnvAddSymbol(theEnv,setlocale(LC_NUMERIC,NULL));        setlocale(LC_NUMERIC,ValueToString(IOFunctionData(theEnv)->locale));        if (GetType(theResult) == FLOAT)          { gensprintf(printBuffer,formatString,(long long) ValueToDouble(theResult.value)); }        else          { gensprintf(printBuffer,formatString,(long long) ValueToLong(theResult.value)); }                  setlocale(LC_NUMERIC,ValueToString(oldLocale));        break;      case 'f':      case 'g':      case 'e':        if (EnvArgTypeCheck(theEnv,"format",whichArg,INTEGER_OR_FLOAT,&theResult) == FALSE) return(NULL);        theLength = strlen(formatString) + 200;        printBuffer = (char *) gm2(theEnv,(sizeof(char) * theLength));        oldLocale = EnvAddSymbol(theEnv,setlocale(LC_NUMERIC,NULL));                setlocale(LC_NUMERIC,ValueToString(IOFunctionData(theEnv)->locale));        if (GetType(theResult) == FLOAT)          { gensprintf(printBuffer,formatString,ValueToDouble(theResult.value)); }        else          { gensprintf(printBuffer,formatString,(double) ValueToLong(theResult.value)); }                setlocale(LC_NUMERIC,ValueToString(oldLocale));                break;      default:         EnvPrintRouter(theEnv,WERROR," Error in format, the conversion character");         EnvPrintRouter(theEnv,WERROR," for formatted output is not valid\n");         return(FALSE);     }   theString = ValueToString(EnvAddSymbol(theEnv,printBuffer));   rm(theEnv,printBuffer,sizeof(char) * theLength);   return(theString);  }/******************************************//* ReadlineFunction: H/L access routine   *//*   for the readline function.           *//******************************************/globle void ReadlineFunction(  void *theEnv,  DATA_OBJECT_PTR returnValue)  {   char *buffer;   size_t line_max = 0;   int numberOfArguments;   char *logicalName;   returnValue->type = STRING;   if ((numberOfArguments = EnvArgCountCheck(theEnv,"readline",NO_MORE_THAN,1)) == -1)     {      returnValue->value = (void *) EnvAddSymbol(theEnv,"*** READ ERROR ***");      return;     }   if (numberOfArguments == 0 )     { logicalName = "stdin"; }   else     {      logicalName = GetLogicalName(theEnv,1,"stdin");      if (logicalName == NULL)        {         IllegalLogicalNameMessage(theEnv,"readline");         SetHaltExecution(theEnv,TRUE);         SetEvaluationError(theEnv,TRUE);         returnValue->value = (void *) EnvAddSymbol(theEnv,"*** READ ERROR ***");         return;        }     }   if (QueryRouters(theEnv,logicalName) == FALSE)     {      UnrecognizedRouterMessage(theEnv,logicalName);      SetHaltExecution(theEnv,TRUE);      SetEvaluationError(theEnv,TRUE);      returnValue->value = (void *) EnvAddSymbol(theEnv,"*** READ ERROR ***");      return;     }   RouterData(theEnv)->CommandBufferInputCount = 0;   buffer = FillBuffer(theEnv,logicalName,&RouterData(theEnv)->CommandBufferInputCount,&line_max);   RouterData(theEnv)->CommandBufferInputCount = -1;   if (GetHaltExecution(theEnv))     {      returnValue->value = (void *) EnvAddSymbol(theEnv,"*** READ ERROR ***");      if (buffer != NULL) rm(theEnv,buffer,(int) sizeof (char) * line_max);      return;     }

⌨️ 快捷键说明

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