From 53c6e7ccd2c012afe1819485260e9d34eba09538 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 26 Nov 1998 15:21:12 +0000 Subject: [PATCH] some sprintf()s replaced with wxString::Printf git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1062 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/dbtable.cpp | 24 ++++++++++++------------ src/common/docview.cpp | 31 ++++++++++++++++--------------- src/common/fileconf.cpp | 6 +++--- src/common/filefn.cpp | 10 +++------- src/common/http.cpp | 10 ++++++---- src/common/postscrp.cpp | 1 - src/common/string.cpp | 11 ----------- src/common/wxexpr.cpp | 2 -- 8 files changed, 40 insertions(+), 55 deletions(-) diff --git a/src/common/dbtable.cpp b/src/common/dbtable.cpp index 64d6bb674b..aecb29b912 100644 --- a/src/common/dbtable.cpp +++ b/src/common/dbtable.cpp @@ -220,8 +220,8 @@ bool wxTable::Open(void) // Verify that the table exists in the database if (!pDb->TableExists(tableName)) { - char s[128]; - sprintf(s, "Error opening '%s', table/view does not exist in the database.", tableName); + wxString s; + s.Printf("Error opening '%s', table/view does not exist in the database.", tableName); pDb->LogError(s); return(FALSE); } @@ -694,11 +694,11 @@ bool wxTable::CreateTable(void) // For varchars, append the size of the string if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR) { - char s[10]; // strcat(sqlStmt, "("); // strcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10)); // strcat(sqlStmt, ")"); - sprintf(s, "(%d)", colDefs[i].SzDataObj); + wxString s; + s.Printf("(%d)", colDefs[i].SzDataObj); strcat(sqlStmt, s); } needComma = TRUE; @@ -1064,7 +1064,7 @@ void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause) void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere) { bool moreThanOneColumn = FALSE; - char colValue[255]; + wxString colValue; // Loop through the columns building a where clause as you go for (int i = 0; i < noCols; i++) @@ -1087,25 +1087,25 @@ void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere) switch(colDefs[i].SqlCtype) { case SQL_C_CHAR: - sprintf(colValue, "'%s'", (UCHAR FAR *) colDefs[i].PtrDataObj); + colValue.Printf("'%s'", (UCHAR FAR *) colDefs[i].PtrDataObj); break; case SQL_C_SSHORT: - sprintf(colValue, "%hi", *((SWORD *) colDefs[i].PtrDataObj)); + colValue.Printf("%hi", *((SWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_USHORT: - sprintf(colValue, "%hu", *((UWORD *) colDefs[i].PtrDataObj)); + colValue.Printf("%hu", *((UWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_SLONG: - sprintf(colValue, "%li", *((SDWORD *) colDefs[i].PtrDataObj)); + colValue.Printf("%li", *((SDWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_ULONG: - sprintf(colValue, "%lu", *((UDWORD *) colDefs[i].PtrDataObj)); + colValue.Printf("%lu", *((UDWORD *) colDefs[i].PtrDataObj)); break; case SQL_C_FLOAT: - sprintf(colValue, "%.6f", *((SFLOAT *) colDefs[i].PtrDataObj)); + colValue.Printf("%.6f", *((SFLOAT *) colDefs[i].PtrDataObj)); break; case SQL_C_DOUBLE: - sprintf(colValue, "%.6f", *((SDOUBLE *) colDefs[i].PtrDataObj)); + colValue.Printf("%.6f", *((SDOUBLE *) colDefs[i].PtrDataObj)); break; } strcat(pWhereClause, colValue); diff --git a/src/common/docview.cpp b/src/common/docview.cpp index a64026f17f..4f7427ebfe 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -358,7 +358,6 @@ bool wxDocument::OnSaveModified(void) { if (IsModified()) { - char buf[400]; wxString title; GetPrintableName(title); @@ -368,9 +367,12 @@ bool wxDocument::OnSaveModified(void) else msgTitle = wxString(_("Warning")); - sprintf(buf, _("Do you want to save changes to document %s?"), (const char *)title); - int res = wxMessageBox(buf, msgTitle, wxYES_NO|wxCANCEL|wxICON_QUESTION, - GetDocumentWindow()); + wxString prompt; + prompt.Printf(_("Do you want to save changes to document %s?"), + (const char *)title); + int res = wxMessageBox(prompt, msgTitle, + wxYES_NO|wxCANCEL|wxICON_QUESTION, + GetDocumentWindow()); if (res == wxNO) { Modify(FALSE); @@ -1003,10 +1005,9 @@ wxDocument *wxDocManager::GetCurrentDocument(void) const // Make a default document name bool wxDocManager::MakeDefaultName(wxString& name) { - char buf[256]; - sprintf(buf, _("unnamed%d"), m_defaultDocumentNameCounter); - m_defaultDocumentNameCounter ++; - name = buf; + name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter); + m_defaultDocumentNameCounter++; + return TRUE; } @@ -1141,7 +1142,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templat { // We can only have multiple filters in Windows #ifdef __WXMSW__ - char *descrBuf = new char[1000]; + char *descrBuf = new char[1000]; // FIXME static buffer descrBuf[0] = 0; int i; for (i = 0; i < noTemplates; i++) @@ -1788,8 +1789,8 @@ void wxFileHistory::AddFileToHistory(const wxString& file) for (i = 0; i < m_fileHistoryN; i++) if (m_fileHistory[i]) { - char buf[400]; - sprintf(buf, "&%d %s", i+1, m_fileHistory[i]); + wxString buf; + buf.Printf("&%d %s", i+1, m_fileHistory[i]); wxNode* node = m_fileMenus.First(); while (node) { @@ -1822,14 +1823,14 @@ void wxFileHistory::RemoveMenu(wxMenu *menu) void wxFileHistory::Load(wxConfigBase& config) { m_fileHistoryN = 0; - char buf[400]; - sprintf(buf, "file%d", m_fileHistoryN+1); - wxString historyFile(""); + wxString buf; + buf.Printf("file%d", m_fileHistoryN+1); + wxString historyFile; while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != "")) { m_fileHistory[m_fileHistoryN] = copystring((const char*) historyFile); m_fileHistoryN ++; - sprintf(buf, "file%d", m_fileHistoryN+1); + buf.Printf("file%d", m_fileHistoryN+1); historyFile = ""; } AddFilesToMenu(); diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index f518ec1f58..79394e5f9b 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -626,9 +626,9 @@ bool wxFileConfig::Write(const wxString& key, const wxString& szValue) bool wxFileConfig::Write(const wxString& key, long lValue) { // ltoa() is not ANSI :-( - char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits) - sprintf(szBuf, "%ld", lValue); - return Write(key, szBuf); + wxString buf; + buf.Printf("%ld", lValue); + return Write(key, buf); } bool wxFileConfig::Flush(bool /* bCurrentOnly */) diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 2f882a54dd..109eeabbd4 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -80,10 +80,6 @@ #define _MAXPATHLEN 500 -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) -#endif - extern char *wxBuffer; void wxPathList::Add (const wxString& path) @@ -955,7 +951,7 @@ char *wxGetTempFileName(const wxString& prefix, char *buf) #else static short last_temp = 0; // cache last to speed things a bit // At most 1000 temp files to a process! We use a ring count. - char tmp[100]; + char tmp[100]; // FIXME static buffer for (short suffix = last_temp + 1; suffix != last_temp; ++suffix %= 1000) { @@ -1029,7 +1025,7 @@ char *wxFindFirstFile(const char *spec, int flags) char *wxFindNextFile(void) { #ifndef __VMS__ - static char buf[400]; + static char buf[400]; // FIXME static buffer /* MATTHEW: [2] Don't crash if we read too many times */ if (!wxDirStream) @@ -1555,4 +1551,4 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) #ifdef _MSC_VER #pragma warning(default:4706) // assignment within conditional expression -#endif // VC++ \ No newline at end of file +#endif // VC++ diff --git a/src/common/http.cpp b/src/common/http.cpp index 07ba17fa8b..221dddb876 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -97,12 +97,14 @@ void wxHTTP::SendHeaders() { wxNode *head = m_headers.First(); - while (head) { + while (head) + { wxString *str = (wxString *)head->Data(); - char buf[100]; - sprintf(buf, "%s: %s\n\r", head->GetKeyString(), str->GetData()); - Write(buf, strlen(buf)); + wxString buf; + buf.Printf("%s: %s\n\r", head->GetKeyString(), str->GetData()); + + Write(buf, buf.Len()); head = head->Next(); } diff --git a/src/common/postscrp.cpp b/src/common/postscrp.cpp index ed63d94567..22aa99fae9 100644 --- a/src/common/postscrp.cpp +++ b/src/common/postscrp.cpp @@ -169,7 +169,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxPostScriptModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC) IMPLEMENT_DYNAMIC_CLASS(wxPrintSetupData, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperType, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxPrintPaperDatabase, wxList) #endif wxPostScriptDC::wxPostScriptDC () diff --git a/src/common/string.cpp b/src/common/string.cpp index 15976eb5e1..8d3af4c8e6 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -941,16 +941,6 @@ int wxString::Printf(const char *pszFormat, ...) int wxString::PrintfV(const char* pszFormat, va_list argptr) { -#if defined(__BORLANDC__) || defined(__GNUWIN32__) - static char s_szScratch[1024]; - - int iLen = vsprintf(s_szScratch, pszFormat, argptr); - AllocBeforeWrite(iLen); - strcpy(m_pchData, s_szScratch); - - return iLen; -#else - // static buffer to avoid dynamic memory allocation each time static char s_szScratch[1024]; @@ -986,7 +976,6 @@ int wxString::PrintfV(const char* pszFormat, va_list argptr) free(buffer); return iLen; -#endif } // ---------------------------------------------------------------------------- diff --git a/src/common/wxexpr.cpp b/src/common/wxexpr.cpp index 3d4979ef4c..d709a7cb6d 100644 --- a/src/common/wxexpr.cpp +++ b/src/common/wxexpr.cpp @@ -45,8 +45,6 @@ extern "C" void LexFromString(char *buf); wxExprDatabase *thewxExprDatabase = NULL; wxExprErrorHandler currentwxExprErrorHandler; -IMPLEMENT_DYNAMIC_CLASS(wxExprDatabase, wxList) - wxExpr::wxExpr(const wxString& functor) { type = wxExprList; -- 2.45.2