some sprintf()s replaced with wxString::Printf
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Nov 1998 15:21:12 +0000 (15:21 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Nov 1998 15:21:12 +0000 (15:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1062 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/dbtable.cpp
src/common/docview.cpp
src/common/fileconf.cpp
src/common/filefn.cpp
src/common/http.cpp
src/common/postscrp.cpp
src/common/string.cpp
src/common/wxexpr.cpp

index 64d6bb674b92f59e1e24a612065b80d8ce307c56..aecb29b912791e9b15f7533112a89c2d02bdba9c 100644 (file)
@@ -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);
index a64026f17f9c2f7cd5b1b2ed9d9daeca1ab6ae4a..4f7427ebfec657c541cc160f48099bc22dcec95e 100644 (file)
@@ -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();
index f518ec1f589dbebb300f1a77402f9789c9b64281..79394e5f9b4e915bfd35aae7242b0ccbc64da589 100644 (file)
@@ -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 */)
index 2f882a54dd0c96dafb43ad473a7a52e0bce8f9fd..109eeabbd42a597fcbddf7d20cdcbff526b8b936 100644 (file)
 
 #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++
index 07ba17fa8b0e38918d9a7cc4ba308511f3fe473e..221dddb8761458a9f0736cc8b599884fda71abce 100644 (file)
@@ -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();
   }
index ed63d9456792f2d5a7020f424aad2763cdaff06f..22aa99fae9ffe676aee6fe96519e009e8149a09a 100644 (file)
@@ -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 ()
index 15976eb5e148c872ec53e27c52ee6158825f1518..8d3af4c8e6d5e5495e0b859e6178001fc4a6a63a 100644 (file)
@@ -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
 }
 
 // ----------------------------------------------------------------------------
index 3d4979ef4c92b331799343b0399da1bb7d888392..d709a7cb6d6ffc5b0adee94bccca6525ac49e784 100644 (file)
@@ -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;