Browse Source

Begin killing off sprintf

Adam Johnson 12 years ago
parent
commit
dd35878465
  1. 8
      Sources/Plasma/CoreLib/HeadSpin.cpp
  2. 6
      Sources/Plasma/CoreLib/hsMemory.cpp
  3. 4
      Sources/Plasma/CoreLib/hsTemplates.cpp
  4. 20
      Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp
  5. 26
      Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
  6. 14
      Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp
  7. 11
      Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp
  8. 20
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  9. 4
      Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp
  10. 18
      Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp
  11. 6
      Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h
  12. 18
      Sources/Tools/MaxConvert/hsConverterUtils.cpp
  13. 2
      Sources/Tools/MaxConvert/hsMaterialConverter.cpp

8
Sources/Plasma/CoreLib/HeadSpin.cpp

@ -232,14 +232,6 @@ char * hsFormatStrV(const char * fmt, va_list args)
return hsStrcpy(buf.c_str());
}
static char hsStrBuf[100];
char *hsScalarToStr(float s)
{
sprintf(hsStrBuf, "%f", s);
return hsStrBuf;
}
class hsMinimizeClientGuard
{
#ifdef CLIENT

6
Sources/Plasma/CoreLib/hsMemory.cpp

@ -717,7 +717,7 @@ void SortNDumpUnfreedMemory(const char *nm, bool full) // file name base, and FU
#endif
char fname[512];
sprintf(fname,"%s_dmp.txt",nm);
snprintf(fname,arrsize(fname),"%s_dmp.txt",nm);
char *errStr = "";
@ -807,7 +807,7 @@ static _CrtMemBlockHeader *cmbh_last; // Remember this header for next increme
CreateDirectory("Reports",NULL); // stick em in a sub directory
char fnm[512];
sprintf(fnm,"Reports\\%s",fname);
snprintf(fnm,arrsize(fnm),"Reports\\%s",fname);
FILE * DumpLogFile = fopen( fnm, "w" );
// long allocs=0;
@ -835,7 +835,7 @@ static _CrtMemBlockHeader *cmbh_last; // Remember this header for next increme
static int first=1;
if (!full) // if this is a partial mem dump, write to the ROOMS.txt file a summary
{
sprintf(fnm,"Reports\\%s","ROOMS.txt");
snprintf(fnm,arrsize(fnm),"Reports\\%s","ROOMS.txt");
if (first)
{ DumpLogFile = fopen( fnm, "w" ); // first time clobber the old

4
Sources/Plasma/CoreLib/hsTemplates.cpp

@ -155,7 +155,7 @@ void TArrayStats()
hsDlistNode * pNode = hsDlistNode::fpFirst;
char fnm[512];
sprintf(fnm,"Reports\\%s.txt","TArray");
snprintf(fnm,arrsize(fnm),"Reports\\%s.txt","TArray");
FILE * DumpLogFile = fopen( fnm, "w" );
if (!DumpLogFile) return;
int i=0;
@ -209,7 +209,7 @@ void LargeArrayStats()
hsDlistNode * pNode = hsDlistNode::fpFirst;
char fnm[512];
sprintf(fnm,"Reports\\%s.txt","TArray");
snprintf(fnm,arrsize(fnm),"Reports\\%s.txt","TArray");
FILE * DumpLogFile = fopen( fnm, "w" );
if (!DumpLogFile) return;
int i=0;

20
Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp

@ -250,10 +250,7 @@ PF_CONSOLE_CMD( Avatar_Spawn, Respawn,"", "Moves the avatar back to the start po
PF_CONSOLE_CMD( Avatar_Spawn, SetSpawnOverride, "string spawnPointName", "Overrides the normal spawn point choice to be the object specified.")
{
plArmatureMod::SetSpawnPointOverride( (const char *)params[ 0 ] );
char str1[ 512 ];
sprintf( str1, "Spawn point override set to object %s", (const char *)params[ 0 ] );
PrintString( str1 );
PrintStringF(PrintString, "Spawn point override set to object %s", (const char *)params[ 0 ]);
}
PF_CONSOLE_CMD( Avatar_Spawn, DontPanic,"", "Toggles the Don't panic link flag.")
@ -263,9 +260,7 @@ PF_CONSOLE_CMD( Avatar_Spawn, DontPanic,"", "Toggles the Don't panic link flag."
if (avatar)
{
bool state = avatar->ToggleDontPanicLinkFlag();
char str1[256];
sprintf(str1, "DontPanic set to %s", state?"true":"false");
PrintString( str1 );
PrintStringF(PrintString, "DontPanic set to %s", state ? "true" : "false");
}
}
@ -484,10 +479,8 @@ PF_CONSOLE_CMD( Avatar,
{
plRelevanceMgr *mgr = plRelevanceMgr::Instance();
mgr->SetEnabled(!mgr->GetEnabled());
char buff[256];
sprintf(buff, "All relevance regions are now %s", (mgr->GetEnabled() ? "ENABLED" : "DISABLED"));
PrintString(buff);
PrintStringF(PrintString, "All relevance regions are now %s", (mgr->GetEnabled() ? "ENABLED" : "DISABLED"));
}
PF_CONSOLE_CMD( Avatar, SeekPoint, "string seekpoint", "Move to the given seekpoint.")
@ -756,10 +749,7 @@ PF_CONSOLE_CMD( Avatar_LOD, SetLODDistance, "float newDist", "Set Distance for s
PF_CONSOLE_CMD( Avatar_LOD, GetLODDistance, "", "Get Distance for switching Avatar LOD" )
{
char buffer[256];
sprintf(buffer, "Lod Distance = %f", plArmatureLODMod::fLODDistance);
PrintString(buffer);
PrintStringF(PrintString, "Lod Distance = %f", plArmatureLODMod::fLODDistance);
}
///////////////////////////////////////////////////////////////////////////////////////////////////

26
Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp

@ -287,34 +287,28 @@ bool pfConsole::MsgReceive( plMessage *msg )
{
// Change the following line once we have a better way of reporting
// errors in the parsing
static char str[ 256 ];
static char msg[ 1024 ];
sprintf( str, "Error parsing %s", cmd->GetString() );
sprintf( msg, "%s:\n\nCommand: '%s'\n%s", fEngine->GetErrorMsg(), fEngine->GetLastErrorLine(),
plString str = plString::Format("Error parsing %s", cmd->GetString());
plString msg = plString::Format("%s:\n\nCommand: '%s'\n%s", fEngine->GetErrorMsg(), fEngine->GetLastErrorLine(),
#ifdef HS_DEBUGGING
"" );
hsAssert( false, msg );
hsAssert( false, msg.c_str() );
#else
"\nPress OK to continue parsing files." );
hsMessageBox( msg, str, hsMessageBoxNormal );
hsMessageBox( msg.c_str(), str.c_str(), hsMessageBoxNormal );
#endif
}
}
else if( cmd->GetCmd() == plConsoleMsg::kAddLine )
IAddParagraph( (char *)cmd->GetString() );
IAddParagraph( cmd->GetString() );
else if( cmd->GetCmd() == plConsoleMsg::kExecuteLine )
{
if( !fEngine->RunCommand( (char *)cmd->GetString(), IAddLineCallback ) )
{
// Change the following line once we have a better way of reporting
// errors in the parsing
static char msg[ 1024 ];
sprintf( msg, "%s:\n\nCommand: '%s'\n", fEngine->GetErrorMsg(), fEngine->GetLastErrorLine() );
IAddLineCallback( msg );
AddLineF("%s:\n\nCommand: '%s'\n", fEngine->GetErrorMsg(), fEngine->GetLastErrorLine());
}
}
@ -755,9 +749,7 @@ void pfConsole::IHandleKey( plKeyEventMsg *msg )
// if there was a line then bump num lines
if ( fWorkingLine[0] != 0 )
{
char displine[300];
sprintf(displine,"... %s",fWorkingLine);
AddLine( displine );
AddLineF("... %s", fWorkingLine);
fPythonMultiLines++;
}
@ -795,9 +787,7 @@ void pfConsole::IHandleKey( plKeyEventMsg *msg )
// was there actually anything in the input buffer?
if ( fWorkingLine[0] != 0 )
{
char displine[300];
sprintf(displine,">>> %s",fWorkingLine);
AddLine( displine );
AddLineF(">>> %s", fWorkingLine);
// check to see if this is going to be a multi line mode ( a ':' at the end)
if ( fWorkingLine[eol-1] == ':' )
{

14
Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleEngine.cpp

@ -187,12 +187,11 @@ bool pfConsoleEngine::PrintCmdHelp( char *name, void (*PrintFn)( const char *
}
/// That's it!
sprintf( string, "\nHelp for the command %s:", cmd->GetName() );
PrintFn( string );
sprintf( string, "\\i%s", cmd->GetHelp() );
PrintFn( string );
sprintf( string, "\\iUsage: %s", cmd->GetSignature() );
PrintFn( string );
plStringStream ss;
ss << "\nHelp for the command " << cmd->GetName() << ":\n";
ss << "\\i" << cmd->GetHelp() << "\n";
ss << "\\iUsage: " << cmd->GetSignature();
PrintFn(ss.GetString().c_str());
return true;
}
@ -204,7 +203,6 @@ const char *pfConsoleEngine::GetCmdSignature( char *name )
pfConsoleCmd *cmd;
pfConsoleCmdGroup *group, *subGrp;
const char *ptr;
static char string[ 512 ];
/// Scan for subgroups. This can be an empty loop
@ -236,7 +234,7 @@ const char *pfConsoleEngine::GetCmdSignature( char *name )
}
/// That's it!
return (char *)cmd->GetSignature();
return cmd->GetSignature();
}
//// Dummy Local Function ////////////////////////////////////////////////////

11
Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp

@ -1267,9 +1267,8 @@ PyObject* cyAvatar::GetTintClothingItemL(const char* clothing_name, uint8_t laye
}
}
char errmsg[256];
sprintf(errmsg,"Cannot find clothing item %s to find out what tint it is",clothing_name);
PyErr_SetString(PyExc_KeyError, errmsg);
plString errmsg = plString::Format("Cannot find clothing item %s to find out what tint it is", clothing_name);
PyErr_SetString(PyExc_KeyError, errmsg.c_str());
// returning nil means an error occurred
return nil;
}
@ -1332,10 +1331,8 @@ PyObject* cyAvatar::GetTintSkin()
return pyColor::New(tint);
}
}
char errmsg[256];
sprintf(errmsg,"Cannot find the skin of the player. Whatever that means!");
PyErr_SetString(PyExc_KeyError, errmsg);
PyErr_SetString(PyExc_KeyError, "Cannot find the skin of the player. Whatever that means!");
// returning nil means an error occurred
return nil;
}

20
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -935,9 +935,8 @@ PyObject* cyMisc::GetDialogFromTagID(uint32_t tag)
return pyGUIDialog::New(pdialog->GetKey());
}
char errmsg[256];
sprintf(errmsg,"GUIDialog TagID %d not found",tag);
PyErr_SetString(PyExc_KeyError, errmsg);
plString errmsg = plString::Format("GUIDialog TagID %d not found", tag);
PyErr_SetString(PyExc_KeyError, errmsg.c_str());
return nil; // return nil, cause we threw an error
}
@ -952,9 +951,8 @@ PyObject* cyMisc::GetDialogFromString(const char* name)
return pyGUIDialog::New(pdialog->GetKey());
}
char errmsg[256];
sprintf(errmsg,"GUIDialog %s not found",name);
PyErr_SetString(PyExc_KeyError, errmsg);
plString errmsg = plString::Format("GUIDialog %s not found", name);
PyErr_SetString(PyExc_KeyError, errmsg.c_str());
return nil; // return nil, cause we threw an error
}
@ -989,9 +987,7 @@ PyObject* cyMisc::GetLocalAvatar()
if ( so )
return pySceneObject::New(so->GetKey());
char errmsg[256];
sprintf(errmsg,"Local avatar not found");
PyErr_SetString(PyExc_NameError, errmsg);
PyErr_SetString(PyExc_NameError, "Local avatar not found");
return nil; // returns nil, cause we threw an error
}
@ -1570,14 +1566,14 @@ void cyMisc::FogSetDefExp2(float end, float density)
void cyMisc::SetClearColor(float red, float green, float blue)
{
// do this command via the console to keep the maxplugins from barfing
char command[256];
sprintf(command,"Graphics.Renderer.SetClearColor %f %f %f",red,green,blue);
plString command = plString::Format("Graphics.Renderer.SetClearColor %f %f %f", red, green, blue);
// create message to send to the console
plControlEventMsg* pMsg = new plControlEventMsg;
pMsg->SetBCastFlag(plMessage::kBCastByType);
pMsg->SetControlCode(B_CONTROL_CONSOLE_COMMAND);
pMsg->SetControlActivated(true);
pMsg->SetCmdString(command);
pMsg->SetCmdString(command.c_str());
plgDispatch::MsgSend( pMsg ); // whoosh... off it goes
}

4
Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp

@ -2003,9 +2003,7 @@ PyObject* PythonInterface::CreateModule(const char* module)
if ((m = PyDict_GetItemString(modules, module)) != NULL && PyModule_Check(m))
{
// clear it
char message[256];
sprintf(message,"ERROR! Creating a python module of the same name - %s",module);
hsAssert(false,message);
hsAssert(false, plString::Format("ERROR! Creating a python module of the same name - %s", module).c_str());
_PyModule_Clear(m);
}

18
Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp

@ -554,9 +554,8 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough)
}
else
{
char str[ 256 ];
sprintf( str, " Keeping mode (%dx%d) on device %s", modes[j].GetWidth(), modes[j].GetHeight(), fRecords[ i ].GetDriverDesc() );
plDemoDebugFile::Write( str );
plString log = plString::Format(" Keeping mode (%dx%d) on device %s", modes[j].GetWidth(), modes[j].GetHeight(), fRecords[ i ].GetDriverDesc());
plDemoDebugFile::Write( log.c_str() );
}
}
@ -605,10 +604,9 @@ void hsG3DDeviceSelector::RemoveUnusableDevModes(bool bTough)
// Remove Direct3D devices with less than 11 megs of RAM
else if (bTough && ( totalMem = IAdjustDirectXMemory( fRecords[i].GetMemoryBytes() ) ) < 11*1024*1024 )
{
char str[ 256 ];
sprintf( str, " Removing Direct3D device with < 11MB RAM. Device RAM (in kB): %d (Description: %s)",
totalMem / 1024, fRecords[ i ].GetDriverDesc() );
plDemoDebugFile::Write( str );
plString log = plString::Format(" Removing Direct3D device with < 11MB RAM. Device RAM (in kB): %d (Description: %s)",
totalMem / 1024, fRecords[ i ].GetDriverDesc() );
plDemoDebugFile::Write( log.c_str() );
fRecords[i].SetDiscarded(true);
}
else
@ -1958,7 +1956,7 @@ void plDemoDebugFile::IDDFClose( void )
//// Write ////////////////////////////////////////////////////////////////////
// Writes a string to the DDF. If the DDF isn't open, opens it.
void plDemoDebugFile::Write( char *string )
void plDemoDebugFile::Write( const char *string )
{
#if M3DDEMOINFO // Demo Debug Build
if( !fIsOpen )
@ -1969,7 +1967,7 @@ void plDemoDebugFile::Write( char *string )
#endif
}
void plDemoDebugFile::Write( char *string1, char *string2 )
void plDemoDebugFile::Write( const char *string1, const char *string2 )
{
#if M3DDEMOINFO // Demo Debug Build
if( !fIsOpen )
@ -1980,7 +1978,7 @@ void plDemoDebugFile::Write( char *string1, char *string2 )
#endif
}
void plDemoDebugFile::Write( char *string1, int32_t value )
void plDemoDebugFile::Write( const char *string1, int32_t value )
{
#if M3DDEMOINFO // Demo Debug Build
if( !fIsOpen )

6
Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h

@ -456,13 +456,13 @@ class plDemoDebugFile
~plDemoDebugFile() { IDDFClose(); }
// Static function to write a string to the DDF
static void Write( char *string );
static void Write( const char *string );
// Static function to write two strings to the DDF
static void Write( char *string1, char *string2 );
static void Write( const char *string1, const char *string2 );
// Static function to write a string and a signed integer value to the DDF
static void Write( char *string1, int32_t value );
static void Write( const char *string1, int32_t value );
// Enables or disables the DDF class
static void Enable( bool yes ) { fEnabled = yes; }

18
Sources/Tools/MaxConvert/hsConverterUtils.cpp

@ -238,10 +238,9 @@ char *hsConverterUtils::MangleReference(char *mangName, const char *nodeName, co
// no room so make global
// Default is to make it global, but you can set another default (like same
// room as referencer) with defRoom.
char tempName[256];
sprintf(tempName, "%s..%s", defRoom, nodeName);
return hsStrcpy(mangName, tempName);
plString tempName = plString::Format("%s..%s", defRoom, nodeName);
return hsStrcpy(mangName, tempName.c_str());
}
return MangleReference(mangName, node);
@ -255,8 +254,7 @@ char *hsConverterUtils::MangleReference(char *mangName, INode *node, const char*
if (!node)
return nil;
char tempName[256];
plString tempName;
char *nodeName = node->GetName();
char *roomName = nil;
TSTR sdata;
@ -273,18 +271,18 @@ char *hsConverterUtils::MangleReference(char *mangName, INode *node, const char*
}
if (('.' == nodeName[0])&&('.' == nodeName[1]))
hsStrcpy(tempName, nodeName + 2);
tempName = (nodeName + 2);
else if (!*nodeName
|| strstr(nodeName, "..")
|| IsReservedKeyword(nodeName)
)
hsStrcpy(tempName, nodeName);
tempName = nodeName;
else if (roomName && *roomName)
sprintf(tempName, "%s..%s", roomName, nodeName);
tempName = plString::Format("%s..%s", roomName, nodeName);
else
sprintf(tempName, "%s..%s", defRoom, nodeName);
tempName = plString::Format("%s..%s", defRoom, nodeName);
return hsStrcpy(mangName, tempName);
return hsStrcpy(mangName, tempName.c_str());
hsGuardEnd;
}

2
Sources/Tools/MaxConvert/hsMaterialConverter.cpp

@ -305,7 +305,7 @@ void AttachLinkMtlAnims(plMaxNode *node, hsGMaterial *mat)
plLayerLinkAnimation* animLayer;
char suff[10];
sprintf(suff, "%d", k);
snprintf(suff, arrsize(suff), "%d", k);
opaCtl = new plLeafController;
opaCtl->QuickScalarController(numKeys, times, values, sizeof(float));

Loading…
Cancel
Save