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

📄 int_parser.c

📁 LastWave
💻 C
📖 第 1 页 / 共 5 页
字号:
        /* We expected an escaped characters */      if (flagEscape) {        SyntaxError("You cannot escape a null character",theLine,line);        return(-1);      }          /* We must end the last word if necessary */      if (theBegWords[nWord] != NULL) {        theEndWords[nWord] = newLine-1;        nWord++;      }            break;    }    /*     * We must init the new word if any      */    if (theBegWords[nWord]==NULL) {          if (nWord > MaxNumWords-1) {        SetErrorf("List is too long");        return(-1);      }          theBegWords[nWord] = newLine;      theEndWords[nWord] = NULL;          }    /*      * 'lineError' points toward the current character ('line' will move in the switch).     * It will be used in case of errors.     */    lineError = line;          switch(*line) {                 /************************* {} [] Signs ********************************/                         case '{' : case '[' :                /* Is character escaped ? */         if (flagEscape) {           Parse1Char(line);           flagEscape = 0;           break;         }         /* If surrounding brace --> just skip it */         if (line == braceBeg && *line != '[') {           line++;           break;         }          /* We just need to look for the matching '}' or  and copy all the characters in between */         bracket = LookForBracketList(theLine,line);         if (bracket == NULL) {           if (*line == '[') {             Parse1Char(line);             break;           }           else return(-1);         }                        /* We just copy all the characters */         i = bracket-line+1;         TestAlloc(i);         strncpy(newLine,line,i);         nNewLine += i;         newLine += i;         line = bracket+1;         break;       case '}' :          /* Is character escaped ? */         if (flagEscape) {           Parse1Char(line);           flagEscape = 0;           break;         }                  /* If surrounding brace --> just skip it */         else if (line == braceEnd) {           line++;           break;         }         SyntaxError("Missing the corresponding {",theLine,lineError);         return(-1);       case ']' :          /* Is character escaped ? */         if (flagEscape) {           Parse1Char(line);           flagEscape = 0;           break;         }         SyntaxError("Missing the corresponding [",theLine,lineError);         return(-1);        /************************* ` ********************************/                                case '`' :         /* Is character escaped ? */         if (flagEscape) {           Parse1Char(line);           flagEscape = 0;           break;         }         /* We just need to look for the matching ` or and copy all the characters in between BUT NOT THE ` */         bracket = LookForBracketList(theLine,line);         if (bracket == NULL) return(-1);         line++;         bracket--;                /* We just copy all the characters and replace escaped characters */         i = bracket-line+1;         TestAlloc(i);         while (1) {           str = strchr(line,'\\');           if (str == NULL) {             i = bracket-line+1;             strncpy(newLine,line,i);             nNewLine += i; line += i; newLine += i;             line++;             break;           }           if (str != line) {             i = str-line;             strncpy(newLine,line,i);             nNewLine += i; line += i; newLine += i;           }           line++;           i = GetCharFromEscapeList(*line);           if (i == -1) {             SyntaxError("This character cannot be escaped",theLine,line);             return(-1);           }           *newLine = (char) i;           nNewLine += 1; line += 1; newLine += 1;         }         break;      /************************* " and ' and () ********************************/                                case '"' : case '\'' : case '(' :         /* Is character escaped ? */         if (flagEscape) {           Parse1Char(line);           flagEscape = 0;           break;         }         /* We just need to look for the matching " or ' or and copy all the characters in between */         bracket = LookForBracketList(theLine,line);         if (bracket == NULL) return(-1);                /* We just copy all the characters */         i = bracket-line+1;         TestAlloc(i);         strncpy(newLine,line,i);         nNewLine += i;         newLine += i;         line = bracket+1;         break;       case ')' :          /* If escaped --> just the ) */         if (flagEscape) {           Parse1Char(line);           flagEscape = 0;           break;         }         /* Otherwise --> error */         else {           SyntaxError("Missing the corresponding (",theLine,lineError);           return(-1);         }       /************************* Word separators ********************************/                                            case '\n': case '\r' : /* These are word separators */         if (flagEscape) {           flagEscape = 0;           if (line[0] == '\n' && line[1] == '\r' || line[0] == '\r' && line[1] == '\n') line+=2;           else line++;           break;         }                     case ' ': case '\t' :          if (flagEscape) {            SyntaxError("A space or a tabulation character cannot be escaped",theLine,lineError);            return(-1);         }         /* let's end the word */                flagCreateWord = YES;                  break;      /************************* \ sign ********************************/                    case '\\':        /* Is character escaped ? */        if (flagEscape) {          Parse1Char(line);          flagEscape = 0;          break;        }        /*         * The escape character          */        flagEscape = 1;        line++;                break;                /************************* Everything else ******************************/                    default :        if (flagEscape) {          i = GetCharFromEscapeList(*line);          if (i == -1) {            SyntaxError("This character cannot be escaped",theLine,lineError+1);            return(-1);          }          else {            Parse1Char(line);            *(newLine-1) = i;          }          flagEscape = 0;        }        else  {          Parse1Char(line);        }        break;    }  }       theBegWords[nWord] = theEndWords[nWord] = NULL;    return(nWord);} /* The function for Parsing a list (no subtstitution but no error generated) */char ParseWordList_(char *theLine, char **defList, char ***list){  int n;  char **beg,**end;    *list = defList;  if (theLine == NULL) {    SetErrorf("ParseWordList_() : NULL string cannot be converted to a wordlist");    return(NO);  }  n = ParseListBegEnd(theLine,&beg,&end);  if (n == -1) {    *list = defList;    return(NO);  }    *list = BegEndStr2List(beg,end);  TempList(*list);  return(YES);}/* The function for Parsing a list (no subtstitution and errors generated) */void ParseWordList(char *theLine, char ***list){  int n;    n = ParseWordList_(theLine,NULL,list);  if (n==NO) Errorf1("");}/*********************************************************************************** * *  Parsing a list evaluated (no allocation)   * ***********************************************************************************/char ParseList_(char *arg, char **defVal, char ***list){  char *type;  LWFLOAT resFlt;  VALUE resVC;    *list = defVal;    if (arg == NULL) {    SetErrorf("ParseList_() : NULL string cannot be converted to a list");    return(NO);  }  resVC = NULL;  type = TTEvalExpressionLevel_(levelCur,arg,&resFlt,&resVC,StringType,NO,YES,AnyType,YES);  if (type == NULL) return(NO);    *list = GetListFromStrValue((STRVALUE) resVC);  if (*list == NULL) {    *list = defVal;    SetErrorf("ParseList_() : Cannot read a consistent list (there might be extra '{' or '}')");    return(NO);  }      return(YES);}/* Same as above but generate an error (no default value) */void ParseList(char *arg, char ***list){  if (ParseList_(arg,NULL,list) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a listv  * ***********************************************************************************/char ParseListvLevel_(LEVEL level, char *arg, LISTV defVal, LISTV *lv){  char *type;  LWFLOAT resFlt;  VALUE resVC;    if (arg == NULL) {    *lv = defVal;    if (defVal != NULL) {      AddRefValue( defVal);      TempValue( defVal);    }    SetErrorf("ParseListv_() : NULL string cannot be converted to a listv");    return(NO);  }  resVC = NULL;  type = TTEvalExpressionLevel_(level,arg,&resFlt,&resVC,ListvType,NO,YES,AnyType,YES);    if (type == NULL) {    *lv = defVal;    if (defVal != NULL) {      AddRefValue( defVal);      TempValue( defVal);    }    return(NO);  }    *lv = (LISTV) resVC;   return(YES);}char ParseListv_(char *arg, LISTV defVal, LISTV *lv){  return(ParseListvLevel_(levelCur,arg,defVal,lv));}/* Same as above but generate an error (no default value) */void ParseListvLevel(LEVEL level, char *arg, LISTV *lv){  if (ParseListvLevel_(level, arg,NULL,lv) == NO) Errorf1("");}void ParseListv(char *arg, LISTV *lv){  if (ParseListv_(arg,NULL,lv) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a range  * ***********************************************************************************/char ParseRangeLevel_(LEVEL level, char *arg, RANGE defVal, RANGE *rg){  char *type;  LWFLOAT resFlt;  VALUE resVC;    if (arg == NULL) {    *rg = defVal;    if (defVal != NULL) {      AddRefValue( defVal);      TempValue( defVal);    }    SetErrorf("ParseRangeLevel_() : NULL string cannot be converted to a range");    return(NO);  }  resVC = NULL;  type = TTEvalExpressionLevel_(level,arg,&resFlt,&resVC,RangeType,NO,YES,AnyType,YES);    if (type == NULL) {    *rg = defVal;    if (defVal != NULL) {      AddRefValue( defVal);      TempValue( defVal);    }    return(NO);  }    *rg = (RANGE) resVC;   return(YES);}char ParseRange_(char *arg, RANGE defVal, RANGE *rg){  return(ParseRangeLevel_(levelCur,arg,defVal,rg));}/* Same as above but generate an error (no default value) */void ParseRangeLevel(LEVEL level, char *arg, RANGE *rg){  if (ParseRangeLevel_(level, arg,NULL,rg) == NO) Errorf1("");}void ParseRange(char *arg, RANGE *rg){  if (ParseRange_(arg,NULL,rg) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a listv or a list * ***********************************************************************************/char ParseListOrListv_(char *arg, char ***list, LISTV *lv){  char *type;  LWFLOAT resFlt;  VALUE resVC;    if (arg == NULL) {    SetErrorf("ParseListOrListv_() : NULL string cannot be converted to a listv");    return(NO);  }  resVC = NULL;  type = TTEvalExpressionLevel_(levelCur,arg,&resFlt,&resVC,ListvType | StringType,NO,YES,AnyType,YES);    if (type == NULL) return(NO);  if (type != listvType  && type != strType) Errorf("ParseListOrListv_() : Weird error");  if (type == listvType) {      *lv = (LISTV) resVC;    *list = NULL;  }  else {    *list = GetListFromStrValue((STRVALUE) resVC);    *lv = NULL;  }  return(YES);}/*********************************************************************************** * *  Parsing a proc  * ***********************************************************************************/

⌨️ 快捷键说明

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