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

📄 int_parser.c

📁 LastWave
💻 C
📖 第 1 页 / 共 5 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e   K e r n e l   3 . 0                               *//*                                                                          *//*      Copyright (C) 1998-2002 Emmanuel Bacry.                             *//*      email : lastwave@cmap.polytechnique.fr                              *//*                                                                          *//*..........................................................................*//*                                                                          *//*      This program is a free software, you can redistribute it and/or     *//*      modify it under the terms of the GNU General Public License as      *//*      published by the Free Software Foundation; either version 2 of the  *//*      License, or (at your option) any later version                      *//*                                                                          *//*      This program is distributed in the hope that it will be useful,     *//*      but WITHOUT ANY WARRANTY; without even the implied warranty of      *//*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *//*      GNU General Public License for more details.                        *//*                                                                          *//*      You should have received a copy of the GNU General Public License   *//*      along with this program (in a file named COPYRIGHT);                *//*      if not, write to the Free Software Foundation, Inc.,                *//*      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             *//*                                                                          *//*..........................................................................*/#include "lastwave.h"#include <ctype.h>#include <stdarg.h>#include "signals.h"#include "images.h"#include "int_fsilist.h"#define MaxLengthList 14000       /* Maximum length of a list                 */#define MaxNumWords 1500          /* Maximum number of words in a list        */#define MaxNumCommands 400        /* Maximum number of commands in a script   *//*********************************************************************************** * *  Parsing a number   * * if 'flagSubst' is set then it performs substitution * if 'flagFast', it starts by trying to read a simple number before going into the evaluator * if 'flagTempAlloc' then temporary alocation will be deleted after at the end of the call  * ***********************************************************************************/char ParseNumLevel_(LEVEL level, char *arg, LWFLOAT *f, char flagTempAlloc, char flagSubst, char flagFast){  char *type;  LWFLOAT resFlt;  VALUE resVC;    if (flagTempAlloc) SetTempAlloc();  resVC = NULL;  type = TTEvalExpressionLevel_(level,arg,&resFlt,&resVC,FloatType,flagSubst,flagFast,AnyType,NO);  if (flagTempAlloc) ClearTempAlloc();  if (type == NULL) return(NO);  *f = resFlt;  return(YES);}/*********************************************************************************** * *  Parsing an int   * ***********************************************************************************/char ParseIntLevel_(LEVEL level, char *arg, int defVal, int *i){  long l;  LWFLOAT f;  char *endp;  *i = defVal;  if (arg == NULL) {    SetErrorf("ParseIntLevel_() : NULL string cannot be converted to an int");    return(NO);  }  if (*arg == '\0') {    SetErrorf("ParseIntLevel_() : empty string cannot be converted to an int");    return(NO);  }    l = strtol(arg,&endp,10);    if (*endp != '\0') {      if (!(ParseNumLevel_(level,arg,&f,NO,NO,NO))) return(NO);    if (f != (int) f) {      SetErrorf("ParseInt_() : '%.8g' is not an integer",f);      return(NO);    }    l = (int) f;  }     if (l >= INT_MAX || l <= INT_MIN) {    SetErrorf("ParseInt() : '%s' is out of range",arg);    return(NO);  }    *i = l;  return(YES);}/* Same as above but with current level */char ParseInt_(char *arg, int defVal, int *i){  return(ParseIntLevel_(levelCur,arg,defVal,i));;}/* Same as above but generate an error (no default value) */void ParseIntLevel(LEVEL level, char *arg, int *i){  if (ParseIntLevel_(level,arg,0,i) == NO) Errorf1("");}/* Same as above but with current level */void ParseInt(char *arg, int *i){  if (ParseIntLevel_(levelCur,arg,0,i) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a LWFLOAT   * ***********************************************************************************/char ParseFloatLevel_(LEVEL level, char *arg, LWFLOAT defVal, LWFLOAT *x){  LWFLOAT f;  char *endp;    *x = defVal;  if (arg == NULL) {    SetErrorf("ParseFloatLevel_() : NULL string cannot be converted to a LWFLOAT");    return(NO);  }    if (*arg == '\0') {    SetErrorf("ParseFloatLevel_() : empty string cannot be converted to a LWFLOAT");    return(NO);  }    f = (LWFLOAT) strtod(arg,&endp);    if (*endp != '\0' && !(ParseNumLevel_(level,arg,&f,NO,NO,NO))) return(NO);   /*  merde CW9 if (l >= FLT_MAX || l <= FLT_MIN) {    SetErrorf("ParseFloat() : '%s' is out of range",arg);    return(NO);  }  */    *x = f;  return(YES);}/* Same as above but with current level */char ParseFloat_(char *arg, LWFLOAT defVal, LWFLOAT *i){  return(ParseFloatLevel_(levelCur,arg,defVal,i));}/* Same as above but generate an error (no default value) */void ParseFloatLevel(LEVEL level, char *arg, LWFLOAT *i){  if (ParseFloatLevel_(level,arg,0,i) == NO) Errorf1("");}/* Same as above but with current level */void ParseFloat(char *arg, LWFLOAT *i){  if (ParseFloatLevel_(levelCur,arg,0,i) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a val * ***********************************************************************************//* * Parse the string 'arg' at level 'level' to get a value and puts it  * either in 'f' if it is a LWFLOAT or in 'val' for all other cases. * In the case the result is not a LWFLOAT, 'val' is a temporary object * * 'flagType' is a flag to determine which types are accepted * * It returns either NULL or the type of the read Value. * */  char *ParseFloatValLevel_(LEVEL level, char *arg, LWFLOAT *f, VALUE *val, unsigned char flagType, unsigned char listvElemType, char flagEmptySigIm){  *val = NULL;    /* If arg is NULL --> error */  if (arg == NULL) {    SetErrorf("ParseFloatValLevel_() : NULL string cannot be converted to a value");    return(NULL);  }    /* If arg == '' ---> error */  if (*arg == '\0') {    SetErrorf("ParseFloatValLevel_() : empty string cannot be converted to a value");    return(NULL);  }    /* Eval the expression 'arg' */  *val = NULL;  return(TTEvalExpressionLevel_(level,arg,f,val,flagType,NO,NO,listvElemType,flagEmptySigIm));  }/* * The routines for Parsing Values at a given level *//* The basic routine */char ParseValLevel__(LEVEL level, char *arg, VALUE defVal, VALUE *val, unsigned char flagType, unsigned char listvElemType, char flagEmptySigIm){  char *answer;  LWFLOAT f;  NUMVALUE nc;    answer = ParseFloatValLevel_(level,arg,&f,val,flagType,listvElemType,flagEmptySigIm);    if (answer == NULL) {    *val = defVal;    if (defVal != NULL) {      AddRefValue(defVal);      TempValue(defVal);    }    return(NO);  }    if (*val != NULL) return(YES);  nc = NewNumValue();  SetNumValue(nc,f);  *val = (VALUE) nc;  TempValue(*val);  return(YES);}char ParseTypedValLevel_(LEVEL level, char *arg, VALUE defVal, VALUE *val, char *type){  char flag;    if (type == valobjType) return(ParseValLevel__(level,arg,defVal,val,AnyType-FloatType,AnyType,YES));  if (type == valType) return(ParseValLevel__(level,arg,defVal,val,AnyType,AnyType,YES));  if (type == scriptType) return(ParseScriptLevel_(level,&arg,(SCRIPT) defVal,(SCRIPT *) val));  if (type != numType) flag = ParseValLevel__(level,arg,defVal,val,AnyType-FloatType,AnyType,YES);  else flag = ParseValLevel__(level,arg,defVal,val,FloatType,AnyType,YES);       if (flag == NO) return(NO);    if (GetTypeValue(*val) != type && GetBTypeContent(*val) != type) {    SetErrorf("ParseTypedValLevel_() : value is of type '%s' and not of expected type '%s'",type,GetTypeValue(*val));    if (*val == defVal) return(NO);    *val = defVal;        if (*val == NULL) return(NO);      if (GetTypeValue(*val) != type) {      SetErrorf("ParseTypedValLevel_() : default value is of type '%s' and not of expected type '%s'",type,GetTypeValue(*val));      return(NO);    }    return(NO);  }    return(flag);}char ParseValLevel_(LEVEL level, char *arg, VALUE defVal, VALUE *val){  return(ParseValLevel__(level,arg,defVal,val,AnyType,AnyType,YES));}void ParseValLevel(LEVEL level, char *arg, VALUE *val){  if (!ParseValLevel_(level,arg,NULL,val)) Errorf1("");}/* * The routines for Parsing Values at the current level */char ParseVal_(char *arg, VALUE defVal, VALUE *val){  return(ParseValLevel_(levelCur,arg,defVal,val));}void ParseVal(char *arg, VALUE *val){  if (!ParseVal_(arg,NULL,val)) Errorf1("");}/*********************************************************************************** * *  Parsing a valobj, i.e., parsing a value which is not a number * ***********************************************************************************/char ParseValObjLevel_(LEVEL level, char *arg, VALUE defVal, VALUE *val){  return(ParseValLevel__(level,arg,defVal,val,AnyType-FloatType,AnyType,YES));}void ParseValObjLevel(LEVEL level, char *arg, VALUE *val){  if (!ParseValObjLevel_(level,arg,NULL,val)) Errorf1("");}char ParseValObj_(char *arg, VALUE defVal, VALUE *val){  return(ParseValObjLevel_(levelCur,arg,defVal,val));}void ParseValObj(char *arg, VALUE *val){  if (!ParseValObj_(arg,NULL,val)) Errorf1("");}/*********************************************************************************** * *  Parsing a double   * ***********************************************************************************/char ParseDoubleLevel_(LEVEL level,char *arg, double defVal, double *x){  LWFLOAT f;  char *endp;    *x = defVal;  if (arg == NULL) {    SetErrorf("ParseDoubleLevel_() : NULL string cannot be converted to a double");    return(NO);  }    if (*arg == '\0') {    SetErrorf("ParseDoubleLevel_() : empty string cannot be converted to a double");    return(NO);  }    f = (LWFLOAT) strtod(arg,&endp);    if (*endp != '\0' && !(ParseNumLevel_(level,arg,&f,NO,NO,NO))) return(NO);       *x = f;  return(YES);}/* Same as above but with current level */char ParseDouble_(char *arg, double defVal,double *i){  return(ParseDoubleLevel_(levelCur,arg,defVal,i));}/* Same as above but generate an error (no default value) */void ParseDoubleLevel(LEVEL level, char *arg, double *i){  if (ParseDoubleLevel_(level,arg,0,i) == NO) Errorf1("");}/* Same as above but with current level */void ParseDouble(char *arg, double *i){  if (ParseDoubleLevel_(levelCur,arg,0,i) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a character evaluated * ***********************************************************************************/char ParseCharLevel_(LEVEL level, char *arg, char defVal, char *c){  char *str;    if (ParseStrLevel_(level,arg,NULL,&str) == NO) {    *c = defVal;    return(NO);  }    if (str[1] != '\0') {    SetErrorf("ParseCharLevel_() : cannot convert string %s to a character",str);    *c = defVal;    return(NO);  }    *c = *str;    return(YES);}/* Same as above but generate an error (no default value) */void ParseCharLevel(LEVEL level, char *arg, char *c){  if (ParseCharLevel_(level,arg,'\0',c) == NO) Errorf1("");}char ParseChar_(char *arg, char defVal, char *c){  return(ParseCharLevel_(levelCur, arg,defVal,c));}/* Same as above but generate an error (no default value) */void ParseChar(char *arg, char *i){  if (ParseChar_(arg,'\0',i) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a word  * ***********************************************************************************/char ParseWord_(char *arg, char *defVal, char **str){  *str = defVal;    if (arg == NULL) {    SetErrorf("ParseWord_() : NULL string cannot be converted to a string");    return(NO);  }  *str = arg;  return(YES);}/* Same as above but generate an error (no default value) */void ParseWord(char *arg, char **i){  if (ParseWord_(arg,"",i) == NO) Errorf1("");}/*********************************************************************************** * *  Parsing a word which is a symbol   * ***********************************************************************************//*  * Is it a valid symbol ?  */ char IsValidSymbol(char *name){  if (name == NULL || *name == '\0') return(NO);  if (IsValidSymbolChar1(*name) == NO) return(NO);  

⌨️ 快捷键说明

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