bool TSsParserMP::GetFlt(const int& FldN, double& Val) const { // parsing format {ws} [+/-] +{d} ([.]{d}) ([E|e] [+/-] +{d}) const char *c = GetFld(FldN); while (TCh::IsWs(*c)) { c++; } if (*c=='+' || *c=='-') { c++; } if (! TCh::IsNum(*c) && *c!='.') { return false; } while (TCh::IsNum(*c)) { c++; } if (*c == '.') { c++; while (TCh::IsNum(*c)) { c++; } } if (*c=='e' || *c == 'E') { c++; if (*c == '+' || *c == '-' ) { c++; } if (! TCh::IsNum(*c)) { return false; } while (TCh::IsNum(*c)) { c++; } } if (*c != 0) { return false; } Val = atof(GetFld(FldN)); return true; }
bool TSsParserMP::GetInt(const int& FldN, int& Val) const { // parsing format {ws} [+/-] +{ddd} int _Val = -1; bool Minus=false; const char *c = GetFld(FldN); while (TCh::IsWs(*c)) { c++; } if (*c=='-') { Minus=true; c++; } if (! TCh::IsNum(*c)) { return false; } _Val = TCh::GetNum(*c); c++; while (TCh::IsNum(*c)){ _Val = 10 * _Val + TCh::GetNum(*c); c++; } if (Minus) { _Val = -_Val; } if (*c != 0) { return false; } Val = _Val; return true; }
int dynamic_LOAD_PARSER_FUNCTIONS_LoadLINE(struct cfg_line *_line) { int nConst, j; char *Line = _line->data; char c = *Line; if (c >= 'A' && c <= 'Z') c ^= 0x20; // lower case. if (c == 't' && !strncasecmp(Line, "Test=", 5)) { char *cp; cp = convert_old_name_if_needed(&Line[5]); cp = GetFld(&(Setup.pPreloads[nPreloadCnt].ciphertext), cp); if (!Setup.pPreloads[nPreloadCnt].ciphertext || strncmp(Setup.pPreloads[nPreloadCnt].ciphertext, SetupName, strlen(SetupName))) return !fprintf(stderr, "Error, invalid test line (wrong generic type): %s\n", Line); cp = GetFld(&(Setup.pPreloads[nPreloadCnt].plaintext), cp); Setup.pPreloads[nPreloadCnt].plaintext = dynamic_Demangle(Setup.pPreloads[nPreloadCnt].plaintext); Setup.pPreloads[nPreloadCnt].flds[1] = str_alloc_copy(Setup.pPreloads[nPreloadCnt].ciphertext); for (j = 0; j < 10; ++j) { if (j==1) continue; cp = GetFld(&(Setup.pPreloads[nPreloadCnt].flds[j]), cp); } ++nPreloadCnt; return 1; } if (c == 't' && !strncasecmp(Line, "TestU=", 6)) { char *cp; if (!options.utf8) return 1; cp = convert_old_name_if_needed(&Line[6]); cp = GetFld(&(Setup.pPreloads[nPreloadCnt].ciphertext), cp); if (!Setup.pPreloads[nPreloadCnt].ciphertext || strncmp(Setup.pPreloads[nPreloadCnt].ciphertext, SetupName, strlen(SetupName))) return !fprintf(stderr, "Error, invalid test line (wrong generic type): %s\n", Line); cp = GetFld(&(Setup.pPreloads[nPreloadCnt].plaintext), cp); Setup.pPreloads[nPreloadCnt].plaintext = dynamic_Demangle(Setup.pPreloads[nPreloadCnt].plaintext); Setup.pPreloads[nPreloadCnt].flds[1] = str_alloc_copy(Setup.pPreloads[nPreloadCnt].ciphertext); for (j = 0; j < 10; ++j) { if (j==1) continue; cp = GetFld(&(Setup.pPreloads[nPreloadCnt].flds[j]), cp); } ++nPreloadCnt; return 1; } if (c == 't' && !strncasecmp(Line, "TestA=", 6)) { char *cp; if (options.utf8) return 1; cp = convert_old_name_if_needed(&Line[6]); cp = GetFld(&(Setup.pPreloads[nPreloadCnt].ciphertext), cp); if (!Setup.pPreloads[nPreloadCnt].ciphertext || strncmp(Setup.pPreloads[nPreloadCnt].ciphertext, SetupName, strlen(SetupName))) return !fprintf(stderr, "Error, invalid test line (wrong generic type): %s\n", Line); cp = GetFld(&(Setup.pPreloads[nPreloadCnt].plaintext), cp); Setup.pPreloads[nPreloadCnt].plaintext = dynamic_Demangle(Setup.pPreloads[nPreloadCnt].plaintext); Setup.pPreloads[nPreloadCnt].flds[1] = str_alloc_copy(Setup.pPreloads[nPreloadCnt].ciphertext); for (j = 0; j < 10; ++j) { if (j==1) continue; cp = GetFld(&(Setup.pPreloads[nPreloadCnt].flds[j]), cp); } ++nPreloadCnt; return 1; } if (c == 'c' && !strncasecmp(Line, "ColonChar=", 10)) { char *tmp = dynamic_Demangle(&Line[10]); if (!tmp) return !fprintf(stderr, "Error, invalid test line: %s\n", Line); options.loader.field_sep_char = *tmp; return 1; } if (c == 'f' && !strncasecmp(Line, "Func=", 5)) { int i; for (i = 0; MD5Gen_Predicate[i].name; ++i) { if (!strcmp(MD5Gen_Predicate[i].name, &Line[5])) { Setup.pFuncs[nFuncCnt++] = MD5Gen_Predicate[i].func; return 1; } } return !fprintf(stderr, "Error, unknown function: %s\n", Line); } if (c == 'f' && !strncasecmp(Line, "Flag=", 5)) { int i; for (i = 0; MD5Gen_Str_Flag[i].name; ++i) { if (!strcmp(MD5Gen_Str_Flag[i].name, &Line[5])) { Setup.flags |= MD5Gen_Str_Flag[i].flag_bit; return 1; } } for (i = 0; MD5Gen_Str_sFlag[i].name; ++i) { if (!strcmp(MD5Gen_Str_sFlag[i].name, &Line[5])) { Setup.startFlags |= MD5Gen_Str_sFlag[i].flag_bit; return 1; } } return !fprintf(stderr, "Error, unknown flag: %s\n", Line); } if (c == 's' && !strncasecmp(Line, "SaltLen=", 8)) { if (sscanf(&Line[7], "=%d", &Setup.SaltLen) == 1) return 1; return !fprintf(stderr, "Error, Invalid SaltLen= line: %s \n", Line); } if (c == 'm' && !strncasecmp(Line, "MaxInputLen=", 12)) { if (sscanf(&Line[11], "=%d", &Setup.MaxInputLen) == 1) return 1; return !fprintf(stderr, "Error, Invalid MaxInputLen= line: %s \n", Line); } if (c == 'e' && !strncasecmp(Line, "Expression=", 11)) { char tmp[256]; sprintf(tmp, "%s %s", SetupNameID, &Line[11]); Setup.szFORMAT_NAME = str_alloc_copy(tmp); return 1; } if (c == 'c' && !strncasecmp(Line, "const", 5)) { if (sscanf(&Line[5], "%d=", &nConst)!=1) return !fprintf(stderr, "Error, invalid const line. Line: %s\n", Line); if (nConst < 1 || nConst > 8) return !fprintf(stderr, "Error, only constants from 1 to 8 are valid. Line: %s\n", Line); if (strlen(Line) == 7) return !fprintf(stderr, "Error, a 'blank' constant is not valid. Line: %s\n", Line); if (Setup.pConstants[nConst-1].Const) return !fprintf(stderr, "Error, this constant has already entered. Line: %s\n", Line); Setup.pConstants[nConst-1].Const = dynamic_Demangle(&Line[7]); return 1; } return !fprintf(stderr, "Error, unknown line: %s\n", Line); }