From 7db03223fc1c8a2e144f3055dc39c3ffba709b35 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 18 Oct 2010 13:00:39 +0200 Subject: [PATCH] Changed: #142 Replace atoi and sscanf by fromString when it's possible --- code/ryzom/tools/leveldesign/prim_export/main.cpp | 10 ++++++++-- code/ryzom/tools/pd_parser/parser_rules.h | 2 +- code/ryzom/tools/pd_parser/templatizer.h | 4 +++- .../server/build_world_packed_col/zone_util.cpp | 3 ++- code/ryzom/tools/skill_extractor/skill_extractor.cpp | 4 ++-- code/ryzom/tools/stats_scan/char_commands.cpp | 12 +++++++++--- .../tools/translation_tools/extract_bot_names.cpp | 6 ++++-- code/ryzom/tools/translation_tools/main.cpp | 10 +++++++--- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/code/ryzom/tools/leveldesign/prim_export/main.cpp b/code/ryzom/tools/leveldesign/prim_export/main.cpp index 44f377575..b993caea1 100644 --- a/code/ryzom/tools/leveldesign/prim_export/main.cpp +++ b/code/ryzom/tools/leveldesign/prim_export/main.cpp @@ -179,7 +179,9 @@ bool getZoneCoordByName(const char * name, uint16& x, uint16& y) return false; } } - y = -atoi(ystr.c_str()); + + NLMISC::fromString(ystr, y); + y = -y; // x x = 0; @@ -223,7 +225,11 @@ sint getYFromZoneName (const string &ZoneName) { xStr += ZoneName[i]; ++i; } - return -atoi(yStr.c_str()); + + sint y = 0; + NLMISC::fromString(yStr, y); + + return -y; } // *************************************************************************** diff --git a/code/ryzom/tools/pd_parser/parser_rules.h b/code/ryzom/tools/pd_parser/parser_rules.h index ed3f0fec0..a5840504e 100644 --- a/code/ryzom/tools/pd_parser/parser_rules.h +++ b/code/ryzom/tools/pd_parser/parser_rules.h @@ -203,7 +203,7 @@ CParseNode *parse##nodename(CTokenizer &tokenizer) \ { \ if (tokenizer.end() || tokenizer.current() != TokenNumber) \ PARSE_FAIL \ - main->savein = atoi(tokenizer.get(tokenizer.currentToken()).c_str()); \ + NLMISC::fromString(tokenizer.get(tokenizer.currentToken()), main->savein); \ tokenizer.next(); \ } diff --git a/code/ryzom/tools/pd_parser/templatizer.h b/code/ryzom/tools/pd_parser/templatizer.h index 70a98b5a4..2f661c059 100644 --- a/code/ryzom/tools/pd_parser/templatizer.h +++ b/code/ryzom/tools/pd_parser/templatizer.h @@ -865,7 +865,9 @@ public: if (env->envExists(subname)) { - CTemplatizerEnv* subenv = (atoi(evalinsub.c_str()) ? env->getEnv(subname) : env); + sint eval; + NLMISC::fromString(evalinsub, eval); + CTemplatizerEnv* subenv = (eval ? env->getEnv(subname) : env); return ITemplatizerBloc::eval(subenv); } diff --git a/code/ryzom/tools/server/build_world_packed_col/zone_util.cpp b/code/ryzom/tools/server/build_world_packed_col/zone_util.cpp index 64bcf268a..d63e3caf5 100644 --- a/code/ryzom/tools/server/build_world_packed_col/zone_util.cpp +++ b/code/ryzom/tools/server/build_world_packed_col/zone_util.cpp @@ -51,7 +51,8 @@ bool getZonePos(const std::string &name, sint &destX, sint &destY) if (xStr.size() != 2) return false; // compute min corner destX = ((xStr[0] - 'A') * 26 + (xStr[1] - 'A')); - destY = -atoi(yStr.c_str()); + NLMISC::fromString(yStr, destY); + destY = -destY; return true; } diff --git a/code/ryzom/tools/skill_extractor/skill_extractor.cpp b/code/ryzom/tools/skill_extractor/skill_extractor.cpp index 37b3f1020..24500f45d 100644 --- a/code/ryzom/tools/skill_extractor/skill_extractor.cpp +++ b/code/ryzom/tools/skill_extractor/skill_extractor.cpp @@ -317,10 +317,10 @@ sint main( sint argc, char ** argv ) skill.ParentSkill = toUpper(string( ptr )); break; case 3: // max skill value - skill.MaxValue = (uint16)atoi(ptr); + NLMISC::fromString(std::string(ptr), skill.MaxValue); break; case 4: // stage type - skill.StageType = (uint8)atoi(ptr); + NLMISC::fromString(std::string(ptr), skill.StageType); break; case 5: // main category skill.MainCategory = string( ptr ); diff --git a/code/ryzom/tools/stats_scan/char_commands.cpp b/code/ryzom/tools/stats_scan/char_commands.cpp index 4506536af..261e1f2e3 100644 --- a/code/ryzom/tools/stats_scan/char_commands.cpp +++ b/code/ryzom/tools/stats_scan/char_commands.cpp @@ -196,7 +196,9 @@ NLMISC_COMMAND(jobsPromote,"pause execution of jobs","") if (args.size()!=1) return false; - uint32 idx= atoi(args[0].c_str()); + uint32 idx; + NLMISC::fromString(args[0], idx); + if ( (idx==0 && args[0]!="0") ) { nlwarning("Argument is not a valid job id - should be a number"); @@ -216,7 +218,9 @@ NLMISC_COMMAND(JobUpdatesPerUpdate,"set or display the number of job updates per if (args.size()==1) { - uint32 count= atoi(args[0].c_str()); + uint32 count; + NLMISC::fromString(args[0], count); + if ( (count==0 && args[0]!="0") ) { nlwarning("Argument is not a valid number"); @@ -270,7 +274,9 @@ NLMISC_COMMAND(jobsDisplayDetails,"display detailed info for the current job (or case 1: { - uint32 idx= atoi(args[0].c_str()); + uint32 idx; + NLMISC::fromString(args[0], idx); + if ( (idx==0 && args[0]!="0") ) { nlwarning("Argument is not a valid job id - should be a number"); diff --git a/code/ryzom/tools/translation_tools/extract_bot_names.cpp b/code/ryzom/tools/translation_tools/extract_bot_names.cpp index 0bfc6f6dc..5660b1a41 100644 --- a/code/ryzom/tools/translation_tools/extract_bot_names.cpp +++ b/code/ryzom/tools/translation_tools/extract_bot_names.cpp @@ -339,7 +339,8 @@ int extractBotNames(int argc, char *argv[]) result[i]->getPropertyByName("count", countStr); result[i]->getPropertyByName("bot_sheet_look", sheetStr); - uint32 count = atoi(countStr.c_str()); + uint32 count; + NLMISC::fromString(countStr, count); if (count != 0) { @@ -402,7 +403,8 @@ int extractBotNames(int argc, char *argv[]) result[i]->getPropertyByName("count", countStr); result[i]->getPropertyByName("bot_sheet_client", sheetStr); - uint32 count = atoi(countStr.c_str()); + uint32 count; + NLMISC::fromString(countStr, count); if (count > 0 && sheetStr.empty()) { diff --git a/code/ryzom/tools/translation_tools/main.cpp b/code/ryzom/tools/translation_tools/main.cpp index decf4af78..5655442e9 100644 --- a/code/ryzom/tools/translation_tools/main.cpp +++ b/code/ryzom/tools/translation_tools/main.cpp @@ -263,14 +263,16 @@ bool parseDiffCommandFromComment(const ucstring &comments, TDiffInfo &diffInfo) string indexStr; if (!CI18N::parseLabel(it, last, indexStr)) return false; - diffInfo.Index1 = atoi(indexStr.c_str()); + + NLMISC::fromString(indexStr, diffInfo.Index1); if (diffInfo.Command == diff_swap) { CI18N::skipWhiteSpace(it, last); if (!CI18N::parseLabel(it, last, indexStr)) return false; - diffInfo.Index2 = atoi(indexStr.c_str()); + + NLMISC::fromString(indexStr, diffInfo.Index2); } return true; } @@ -3183,7 +3185,9 @@ int main(int argc, char *argv[]) showUsage(argv[0]); return 1; } - uint nbLines = atoi(argv[3]); + + uint nbLines; + NLMISC::fromString(argv[3], nbLines); cropLines(argv[2], nbLines);