Changed: #142 Replace atoi and sscanf by fromString when it's possible

This commit is contained in:
kervala 2010-10-16 19:58:05 +02:00
parent c3d577eb0e
commit eff593fcf3
13 changed files with 31 additions and 17 deletions

View file

@ -56,7 +56,8 @@ NLMISC_COMMAND(square,"display the square of the parameter","<value>")
// check args, if there is not the right number of parameters, return bad status. // check args, if there is not the right number of parameters, return bad status.
if (args.size() != 1) return false; if (args.size() != 1) return false;
uint32 val = atoi(args[0].c_str()); uint32 val;
NLMISC::fromString(args[0], val);
// display the result. // display the result.
log.displayNL("The square of %d is %d", val, val*val); log.displayNL("The square of %d is %d", val, val*val);

View file

@ -215,8 +215,9 @@ void cbInfo (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
string token = "MeanPongTime "; string token = "MeanPongTime ";
string::size_type pos=line.find (token); string::size_type pos=line.find (token);
string::size_type pos2=line.find (" ", pos+token.size()); string::size_type pos2=line.find (" ", pos+token.size());
uint32 val = atoi(line.substr (pos+token.size(), pos2-pos-token.size()).c_str()); float val;
LagGraph.addOneValue ((float)val); NLMISC::fromString(line.substr (pos+token.size(), pos2-pos-token.size()), val);
LagGraph.addOneValue (val);
#endif #endif
} }

View file

@ -381,7 +381,7 @@ void CLogicCounter::read (xmlNodePtr node)
_Name = getXMLProp (node, "Name"); _Name = getXMLProp (node, "Name");
_Value = atoiInt64 (getXMLProp (node, "Value").c_str()); _Value = atoiInt64 (getXMLProp (node, "Value").c_str());
_Verbose = atoi(getXMLProp (node, "Verbose").c_str()) == 1; NLMISC::fromString(getXMLProp (node, "Verbose"), _Verbose);
Period.setValue(atoiInt64(getXMLProp (node, "Period").c_str())); Period.setValue(atoiInt64(getXMLProp (node, "Period").c_str()));
Phase.setValue(atoiInt64(getXMLProp (node, "Phase").c_str())); Phase.setValue(atoiInt64(getXMLProp (node, "Phase").c_str()));
Step.setValue(atoiInt64(getXMLProp (node, "Step").c_str())); Step.setValue(atoiInt64(getXMLProp (node, "Step").c_str()));

View file

@ -56,8 +56,12 @@ int CConfigFile::CVar::asInt (int index) const
switch (Type) switch (Type)
{ {
case T_STRING: case T_STRING:
{
if (index >= (int)StrValues.size () || index < 0) throw EBadSize (Name, (int)StrValues.size (), index); if (index >= (int)StrValues.size () || index < 0) throw EBadSize (Name, (int)StrValues.size (), index);
return atoi(StrValues[index].c_str()); int ret = 0;
NLMISC::fromString(StrValues[index], ret);
return ret;
}
case T_REAL: case T_REAL:
if (index >= (int)RealValues.size () || index < 0) throw EBadSize (Name, (int)RealValues.size (), index); if (index >= (int)RealValues.size () || index < 0) throw EBadSize (Name, (int)RealValues.size (), index);
return (int)RealValues[index]; return (int)RealValues[index];

View file

@ -314,9 +314,9 @@ int main(int argc, char *argv[])
sint percentageFace= 100; sint percentageFace= 100;
sint maxFace= INT_MAX; sint maxFace= INT_MAX;
if(argc>=4) if(argc>=4)
percentageFace= atoi(argv[3]); NLMISC::fromString(argv[3], percentageFace);
if(argc>=5) if(argc>=5)
maxFace= atoi(argv[4]); NLMISC::fromString(argv[4], maxFace);
// **** Load the Mesh In. // **** Load the Mesh In.
IShape *pResult = NULL; IShape *pResult = NULL;

View file

@ -52,13 +52,17 @@ void CEditEx::OnSetFocus(CWnd* pOldWnd)
sint CEditEx::getSInt() const sint CEditEx::getSInt() const
{ {
nlassert(_Type == SIntType); nlassert(_Type == SIntType);
return (sint) ::atoi(getString().c_str()); sint ret = 0;
NLMISC::fromString(getString(), ret);
return ret;
} }
uint CEditEx::getUInt() const uint CEditEx::getUInt() const
{ {
nlassert(_Type == UIntType); nlassert(_Type == UIntType);
return (uint) ::atoi(getString().c_str()); uint ret = 0;
NLMISC::fromString(getString(), ret);
return ret;
} }
float CEditEx::getFloat() const float CEditEx::getFloat() const
{ {

View file

@ -880,7 +880,8 @@ bool ShapesExporter::createThumbnail(const string &filename, const string &path)
if (!fgets(str, 100, fp)) if (!fgets(str, 100, fp))
strcpy(str, "0"); strcpy(str, "0");
fclose(fp); fclose(fp);
selectedFrame = atoi(str)/2; NLMISC::fromString(std::string(str), selectedFrame);
selectedFrame /= 2;
} }
} }

View file

@ -116,7 +116,8 @@ bool getZoneCoordByName(const char * name, uint16& x, uint16& y)
return false; return false;
} }
} }
y = atoi(ystr.c_str());
NLMISC::fromString(ystr, y);
// x // x
x = 0; x = 0;

View file

@ -962,7 +962,7 @@ int main(int /* argc */, char ** /* argv */)
NLMISC::CApplicationContext myApplicationContext; NLMISC::CApplicationContext myApplicationContext;
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
NLMISC::CPath::addSearchPath(NLMISC::CFile::getApplicationDirectory("NeL")); NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
#endif // NL_OS_UNIX #endif // NL_OS_UNIX
NLMISC::CPath::addSearchPath(NL_ZVIEWER_CFG); NLMISC::CPath::addSearchPath(NL_ZVIEWER_CFG);

View file

@ -59,7 +59,8 @@ afx_msg void CLAEdit::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
int start, end; int start, end;
GetSel( start, end ); GetSel( start, end );
str = str.Mid( start, end-start ); str = str.Mid( start, end-start );
int lineNum = atoi( str ); sint lineNum;
NLMISC::fromString(str, lineNum);
if ( ! ((lineNum != 0) || (str == "0")) ) if ( ! ((lineNum != 0) || (str == "0")) )
break; break;
@ -713,7 +714,8 @@ void CLog_analyserDlg::insertTraceLine( int index, char *traceLine )
char *line = strchr( traceLine, ':' ); char *line = strchr( traceLine, ':' );
char scycle [10]; char scycle [10];
strncpy( scycle, traceLine, line-traceLine ); strncpy( scycle, traceLine, line-traceLine );
int cycle = atoi(scycle); sint cycle;
NLMISC::fromString(scycle, cycle);
TStampedLine stampedLine; TStampedLine stampedLine;
stampedLine.Index = index; stampedLine.Index = index;
stampedLine.Line = CString(traceLine); stampedLine.Line = CString(traceLine);

View file

@ -424,7 +424,7 @@ int main( int argc, char ** argv )
NLMISC::CApplicationContext appContext; NLMISC::CApplicationContext appContext;
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
NLMISC::CPath::addSearchPath(NLMISC::CFile::getApplicationDirectory("NeL")); NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
#endif // NL_OS_UNIX #endif // NL_OS_UNIX
NLMISC::CPath::addSearchPath(NL_MK_SH_ID_CFG); NLMISC::CPath::addSearchPath(NL_MK_SH_ID_CFG);

View file

@ -86,7 +86,7 @@ void init()
try try
{ {
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
NLMISC::CPath::addSearchPath(NLMISC::CFile::getApplicationDirectory("NeL")); NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
#endif // NL_OS_UNIX #endif // NL_OS_UNIX
NLMISC::CPath::addSearchPath(NL_BIB_CFG); NLMISC::CPath::addSearchPath(NL_BIB_CFG);

View file

@ -122,7 +122,7 @@ void initConfig()
try try
{ {
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
NLMISC::CPath::addSearchPath(NLMISC::CFile::getApplicationDirectory("NeL")); NLMISC::CPath::addSearchPath(NLMISC::CPath::getApplicationDirectory("NeL"));
#endif // NL_OS_UNIX #endif // NL_OS_UNIX
NLMISC::CPath::addSearchPath(NL_BIRB_CFG); NLMISC::CPath::addSearchPath(NL_BIRB_CFG);