📄 int_variable.c
字号:
if (value->ts == NULL) return((*(value->sendMessage))(value,GetFieldMsge,arg)); while(value != NULL && IsVariable(value)) value = ((VARIABLE) value)->content; if (value == NULL) return(NULL); if (GetTrueTypeValue(value) == arrayType) return(GetFieldArray(value,arg)); fi = FindField(value->ts->fields,arg[0]); if (fi==NULL) { SetErrorf("Bad field name '%s' for variable of type '%s'",arg[0],GetTypeValue(value)); return(NULL); } return(GetFieldValue(*fi,value,arg));}/* * Send a NumExtract message to the content 'value' with the number 'f' and the flagDot and put the result * in f,str or val * It returns what the message returned */static char *NumExtract(VALUE value, LWFLOAT f, char flagDot, LWFLOAT *f1,char **str1, VALUE *vc1){ void *arg[5]; arg[0] = &f; arg[1] = &flagDot; arg[2] = f1; arg[3] = str1; *str1 = NULL; arg[4] = vc1; *vc1 = NULL; InitError(); return(NumExtractValue(value,arg));}/* * Basic function to extract from a content a field using the . syntax * or some values using the () syntax. * * The parameters are : * * - level : the current level * - theCont : the content to extract/getfield from * (the nref should include the pointer handled here which is supposed to be temporary) * * - begin : the string (starting by '.' or '[') corresponding to the command line * - left : a pointer in which will be returned the first character of the command line which was not read * - resFlt : the returned LWFLOAT if the result is LWFLOAT (which do not correspond to a string) * - resVC : the returned content if not a "pure" LWFLOAT (if this result is not used its content is deleted) * - defParam : information for extraction (such as (1:)) * * It returns the type of the corresponding value * */unsigned char TGetFieldOrExtractContentExpr(LEVEL level, VALUE theCont, char *begin, char **left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, ExprDefParam *defParam, char flagDollar){ static STRVALUE sc = NULL; static NUMVALUE nc = NULL; VALUE value; char *end,*name,*tempStr; LWFLOAT tempFlt; char *type,*type1; unsigned char answer; FSIList *list; ExtractInfo *ei,extractInfo; char **options; unsigned long optionFlag; char string[MaxNameLength]; VALUE tempCont; void *arg[7]; char flagNull; char oldFlagSpace; /* Allocation */ if (sc == NULL) sc = NewNullStrValue(); else sc->str = NULL; if (nc == NULL) nc = NewNumValue(); /* Get the level the variable must be looked at */ while (level->levelVar != level) level = level->levelVar; /* Init */ value = theCont; type1 = NULL; type = GetTypeValue(theCont); /* * Main Loop */ end = begin; name = NULL; oldFlagSpace = defParam->flagSpace; while (1) { defParam->flagSpace = oldFlagSpace; /* Are we done ? */ if (*end != '[' && *end != '.') break; /* we are not in the case of a field extraction that has to be handled by an object */ if (name == NULL) { /* Get type */ type1 = type; type = GetTypeValue(value); } /**************************** * * Case of extraction * ****************************/ if (*end == '[') { defParam->flagSpace = YES; end++; ParamSkipSpace(end); if (name == NULL) { arg[0] = NULL; options = GetExtractOptionsValue(value,arg); if (options == NULL) { Clean(*resVC); if (!IsErrorMsge()) SetErrorf("No extraction possible"); return(0); } } /* Get the extraction options if any */ if (*end == '*') { if (options[0] == '\0') { Clean(*resVC); if (!IsErrorMsge()) SetErrorf("No option available for extraction"); return(0); } if (FSIReadExtractOption(end,left,options,&optionFlag) == NO) { Clean(*resVC); return(0); } end = *left; } else optionFlag = 0; arg[0] = name; arg[1] = &optionFlag; ei = GetExtractInfoValue(value,arg); if (ei == NULL) { Clean(*resVC); if (!IsErrorMsge()) SetErrorf("No extraction possible"); return(0); } /* Copy the info */ extractInfo = *ei; /* Extract list */ ParamSkipSpace(end); flagNull = NO; if (*end != ']') { list = SFIListExpr(end, left, &extractInfo,defParam); if (list != NULL && list->nx == 0) flagNull = YES; } else list = SFIListExpr(end, left, &extractInfo,defParam); if (list==NULL) { Clean(*resVC); return(0); } if (!flagNull && list->nx==0) { DeleteFSIList(list); SetErrorf("Expecting [:] instead of []"); *left = end-1; Clean(*resVC); return(0); } list->options = optionFlag; if ((**left)!=']') { DeleteFSIList(list); SetErrorf("Cannot find the matching bracket"); Clean(*resVC); DeleteFSIList(list); *left = end; return(0); } (*left)=(*left)+1; end = *left; /* if (flagNull) { value = nullValue; continue; } */ /* Send an extract message and get the new VALUE */ type = GetField(value,name,list,&tempFlt,&tempStr,&tempCont); if (tempCont) value = tempCont; else if (tempStr) { sc->str = NULL; SetStrValue(sc,tempStr); value = (VALUE) sc; } else if (type == numType) { SetNumValue(nc,tempFlt); value = (VALUE) nc; } else value = NULL; /* Delete the list */ DeleteFSIList(list); /* Error if nothing */ if (value == NULL) { *left = end; Clean(*resVC); return(0); } name = NULL; } /**************************** * * Case of a field * ****************************/ else { /* Begin is pointing to the first character of the field */ begin = end+1; end = begin; /* * Get the name of the field * Substitution case */ if (*end == '$' && defParam->flagSubst) { answer = TGetVariableContentLevelExpr(level,end,left,resFlt,resVC,StringType | FloatType,NO,defParam); if (answer == 0) return(0); end = *left; if (answer == FloatType) { Flt2Str(*resFlt,tempStr); name = tempStr; } else name = GetStrFromStrValue((STRVALUE) *resVC); *resVC = NULL; if (*name == '\0') { SetErrorf("Missing field name"); return(0); } } /* * Get the name of the field * No Substitution case */ else { if (IsValidSymbolChar(*end)) { end++; while (*end != '\0' && IsValidSymbolChar(*end) && *end != '.') end++; } /* If we didn't get anything --> error */ if (end == begin) { *left = begin; Clean(*resVC); SetErrorf("Missing field name"); return(0); } /* Get the name of the field */ if (MaxNameLength +2 < end-begin) Errorf("TGetFieldOrExtractContentExpr() : Weird Error : MaxNameLength is too short"); strncpy(string,begin,end-begin); string[end-begin] = '\0'; name = string; } /* * If there is an extraction right after we must send an GetExtractInfoSignal message first * to check whether the field extraction will be handled by the object itself or by the * object associated to the field */ if (*end == '[') { arg[0] = name; options = GetExtractOptionsValue(value,arg); if (options != NULL) continue; } /* * Let's get the field object */ type = GetField(value,name,NULL,&tempFlt,&tempStr,&tempCont); if (tempCont) value = tempCont; else if (tempStr) { sc->str = NULL; SetStrValue(sc,tempStr); value = (VALUE) sc; } else if (type == numType) { SetNumValue(nc,tempFlt); value = (VALUE) nc; } else value = NULL; /* Error if nothing */ if (value == NULL) { *left = begin; Clean(*resVC); return(0); } name = NULL; } } /* * End of loop * Now we must check the type */ Clean(*resVC); *left = end; defParam->flagSpace = oldFlagSpace; /* Set the returned values */ if (type == signalType || type == signaliType) {answer = SignalType; *resVC = value;} else if (type == imageType || type == imageiType) {answer = ImageType; *resVC = value;} else if (type == listvType) {answer = ListvType; *resVC = value;} else if (type == rangeType) {answer = RangeType; *resVC = value;} else if (type == numType) { *resFlt = ((NUMVALUE) value)->f; if (value != (VALUE) nc) *resVC = value; else *resVC = NULL; answer = FloatType; } else if (type == strType) { if (sc == (STRVALUE) value) { *resVC = (VALUE) NewStrValue(); SetStrValue((STRVALUE) *resVC, sc->str); TempValue(*resVC); } else *resVC = value; answer = StringType; } else if (type == nullType) { *resVC = value; answer = NullType; } else { *resVC = value; answer = OtherType; } sc->str = NULL; ParamSkipSpace(*left); /* Then just return */ return(answer); }/* * Function to read 0a like syntax * begin[0] must be either '.' or a digit * The result is in resVC and is made temporary */static unsigned char GetNumberExtraction(char *begin, char **left, LWFLOAT *resFlt, VALUE *resVC, ExprDefParam *defParam){ char flagDot; LWFLOAT f,tempFlt; char *end; unsigned char answer; VALUE value,tempCont; char *tempStr; char *type; if (begin[0] == '.') {begin++; flagDot = 1;} else flagDot = 0; f = strtol(begin,&end,10); if (end != begin) { /* case of 10a */ if (IsValidSymbolChar1(*end)) { begin = end; answer = TGetVariableContentLevelExpr(DefaultLevel(defParam),begin,left,resFlt,resVC,AnyType,YES,defParam); end = *left; if (answer == 0) { Clean(*resVC); return(0); } if (*resVC == NULL) { SetErrorf("Cannot perform number extraction on a LWFLOAT variable"); *left = begin; return(0); } } /* case of 10 */ else { *resVC = (VALUE) GetVariableLevel_(DefaultLevel(defParam),"objCur"); if (*resVC != NULL) *resVC = ValueOf((VALUE) *resVC); if (*resVC == NULL) { SetErrorf("Variable ObjCur expected to be defined"); *left = begin; Clean(*resVC); return(0); } } value = *resVC; type = NumExtract(value,f, flagDot, &tempFlt,&tempStr,&tempCont); if (type == NULL) { Clean(*resVC); if (!IsErrorMsge()) SetErrorf("Bad syntax"); *left = begin; return(0); } if (tempCont != NULL) { AddRefValue(tempCont); TempValue(tempCont); *resVC = tempCont; *left = end; return(1); } else if (tempStr != NULL) { tempCont = (VALUE) NewNullStrValue(); TempValue(tempCont); SetStrValue((STRVALUE) tempCont, tempStr); *resVC = tempCont; *left = end; return(1); } else { tempCont = (VALUE) NewNumValue(); TempValue(tempCont); SetNumValue((NUMVALUE) tempCont, tempFlt); *resVC = tempCont; *left = end; return(1); } } else { SetErrorf("Do not expect a number"); *left = begin; Clean(*resVC); return(0); }} /* * Function to get the content of a variable * * 'level' : the level it looks the variable at * 'begin', 'left' : the usual parsing strings * 'resFlt', 'resVC' : the results (if resVC is NULL then the result is a LWFLOAT in resFlt, if not and if the result is a LWFLOAT * the result is in both variable) * 'flagType' : we are looking for this type * 'flagSimple' : we just look for a simple variable (not a.dx or a[1]) * 'defParam' : the current extraction parameter (could be NULL) * */extern char ParseCompiledScript_(char **theScript, SCRIPT *pScript, char flagSubst, char flagBrace, char *flagErr);extern char * LookForBracketList(char *theLine, char *line);extern SPROC SetProc(char *name, char **list, char **help, SCRIPT script);unsigned char TGetVariableContentLevelExpr(LEVEL level, char *begin, char **left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, unsigned char flagSimple, ExprDefParam *defParam){extern void EvalScriptLevel(LEVEL level, SCRIPT script,char flagStoreResult); static NUMVALUE nc = NULL; STRVALUE sc; VARIABLE var; VALUE value,*pcont;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -