X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3bce6687f47dfa5fb8d4bab92702a5b5b1eb3485..9cb98d899582a69072a51a4c06199cebf625c039:/src/common/utilscmn.cpp?ds=sidebyside diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index d88d0e5206..2d9e558416 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -98,134 +98,10 @@ const wxChar *wxFatalErrorStr = wxT("wxWindows Fatal Error"); #endif // WXWIN_COMPATIBILITY_2_2 -// ---------------------------------------------------------------------------- -// function protoypes -// ---------------------------------------------------------------------------- - // ============================================================================ // implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// string functions -// ---------------------------------------------------------------------------- - -#if defined(__WXMAC__) && !defined(__DARWIN__) -int strcasecmp(const char *str_1, const char *str_2) -{ - register char c1, c2; - do { - c1 = tolower(*str_1++); - c2 = tolower(*str_2++); - } while ( c1 && (c1 == c2) ); - - return c1 - c2; -} - -int strncasecmp(const char *str_1, const char *str_2, size_t maxchar) -{ - - register char c1, c2; - while( maxchar--) - { - c1 = tolower(*str_1++); - c2 = tolower(*str_2++); - - if ( !c1 || c1!=c2 ) - return c1 - c2; - - } ; - - return 0 ; - -} -#endif // __WXMAC__ && !__DARWIN__ - -#if defined( __VMS__ ) && ( __VMS_VER < 70000000 ) -// we have no strI functions under VMS, therefore I have implemented -// an inefficient but portable version: convert copies of strings to lowercase -// and then use the normal comparison -static void myLowerString(char *s) -{ - while(*s){ - if(isalpha(*s)) *s = (char)tolower(*s); - s++; - } -} - -int strcasecmp(const char *str_1, const char *str_2) -{ - char *temp1 = new char[strlen(str_1)+1]; - char *temp2 = new char[strlen(str_2)+1]; - strcpy(temp1,str_1); - strcpy(temp2,str_2); - myLowerString(temp1); - myLowerString(temp2); - - int result = wxStrcmp(temp1,temp2); - delete[] temp1; - delete[] temp2; - - return(result); -} - -int strncasecmp(const char *str_1, const char *str_2, size_t maxchar) -{ - char *temp1 = new char[strlen(str_1)+1]; - char *temp2 = new char[strlen(str_2)+1]; - strcpy(temp1,str_1); - strcpy(temp2,str_2); - myLowerString(temp1); - myLowerString(temp2); - - int result = strncmp(temp1,temp2,maxchar); - delete[] temp1; - delete[] temp2; - - return(result); -} -#endif // __VMS__ - -#if defined(__WINDOWS__) && !defined(__WXMICROWIN__) && !defined(__WXWINE__) - -#ifndef __GNUWIN32__ -#ifndef __MWERKS__ -#define strcasecmp stricmp -#define strncasecmp strnicmp -#else -#define strcasecmp _stricmp -#define strncasecmp _strnicmp -#endif -#endif - -#else - -#ifdef __EMX__ -#define strcasecmp stricmp -#define strncasecmp strnicmp -#endif - -// This declaration is missing in SunOS! -// (Yes, I know it is NOT ANSI-C but its in BSD libc) -#if defined(__xlC) || defined(__AIX__) || defined(__GNUG__) -extern "C" -{ - int strcasecmp (const char *, const char *); - int strncasecmp (const char *, const char *, size_t); -} -#endif -#endif /* __WXMSW__ */ - -#ifdef __WXPM__ -#define strcasecmp stricmp -#define strncasecmp strnicmp -#endif - -#ifdef __WATCOMC__ -#define strcasecmp stricmp -#define strncasecmp strnicmp -#endif - wxChar * copystring (const wxChar *s) { @@ -360,9 +236,9 @@ wxString wxDecToHex(int dec) return wxString(buf); } -// Match a string INDEPENDENT OF CASE +#if WXWIN_COMPATIBILITY_2 bool -StringMatch (const char *str1, const char *str2, bool subString, bool exact) +StringMatch (const wxChar *str1, const wxChar *str2, bool subString, bool exact) { if (str1 == NULL || str2 == NULL) return FALSE; @@ -371,43 +247,44 @@ StringMatch (const char *str1, const char *str2, bool subString, bool exact) if (subString) { - int len1 = strlen (str1); - int len2 = strlen (str2); + int len1 = wxStrlen (str1); + int len2 = wxStrlen (str2); int i; // Search for str1 in str2 // Slow .... but acceptable for short strings for (i = 0; i <= len2 - len1; i++) { - if (strncasecmp (str1, str2 + i, len1) == 0) + if (wxStrnicmp (str1, str2 + i, len1) == 0) return TRUE; } } else if (exact) { - if (strcasecmp (str1, str2) == 0) + if (wxStricmp (str1, str2) == 0) return TRUE; } else { - int len1 = strlen (str1); - int len2 = strlen (str2); + int len1 = wxStrlen (str1); + int len2 = wxStrlen (str2); - if (strncasecmp (str1, str2, wxMin (len1, len2)) == 0) + if (wxStrnicmp (str1, str2, wxMin (len1, len2)) == 0) return TRUE; } return FALSE; } +#endif // Return the current date/time // [volatile] wxString wxNow() { - time_t now = time((time_t *) NULL); - char *date = ctime(&now); - date[24] = '\0'; - return wxString(date); + time_t now = time((time_t *) NULL); + char *date = ctime(&now); + date[24] = '\0'; + return wxString::FromAscii(date); } #if wxUSE_GUI @@ -554,10 +431,10 @@ wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt) if (frame->GetToolBar()) extraChildren.Append(frame->GetToolBar()); - wxNode* node = extraChildren.First(); + wxNode* node = extraChildren.GetFirst(); while (node) { - wxWindow* child = (wxWindow*) node->Data(); + wxWindow* child = (wxWindow*) node->GetData(); wxWindow* foundWin = wxFindWindowAtPoint(child, pt); if (foundWin) return foundWin; @@ -566,14 +443,14 @@ wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt) } */ - wxNode* node = win->GetChildren().Last(); + wxWindowList::Node *node = win->GetChildren().GetLast(); while (node) { - wxWindow* child = (wxWindow*) node->Data(); + wxWindow* child = node->GetData(); wxWindow* foundWin = wxFindWindowAtPoint(child, pt); if (foundWin) return foundWin; - node = node->Previous(); + node = node->GetPrevious(); } wxPoint pos = win->GetPosition(); @@ -595,14 +472,14 @@ wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt) // Go backwards through the list since windows // on top are likely to have been appended most // recently. - wxNode* node = wxTopLevelWindows.Last(); + wxWindowList::Node *node = wxTopLevelWindows.GetLast(); while (node) { - wxWindow* win = (wxWindow*) node->Data(); + wxWindow* win = node->GetData(); wxWindow* found = wxFindWindowAtPoint(win, pt); if (found) return found; - node = node->Previous(); + node = node->GetPrevious(); } return NULL; } @@ -995,11 +872,15 @@ wxWindowDisabler::~wxWindowDisabler() // Yield to other apps/messages and disable user input to all windows except // the given one -bool wxSafeYield(wxWindow *win) +bool wxSafeYield(wxWindow *win, bool onlyIfNeeded) { wxWindowDisabler wd(win); - bool rc = wxYield(); + bool rc; + if (onlyIfNeeded) + rc = wxYieldIfNeeded(); + else + rc = wxYield(); return rc; } @@ -1023,13 +904,13 @@ bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) ) const wxChar *wxGetInstallPrefix() { wxString prefix; - + if ( wxGetEnv(wxT("WXPREFIX"), &prefix) ) return prefix.c_str(); - + #ifdef wxINSTALL_PREFIX return wxT(wxINSTALL_PREFIX); -#else +#else return wxT(""); #endif } @@ -1185,6 +1066,40 @@ wxString wxGetCurrentDir() // wxExecute // ---------------------------------------------------------------------------- +// wxDoExecuteWithCapture() helper: reads an entire stream into one array +// +// returns TRUE if ok, FALSE if error +#if wxUSE_STREAMS +static bool ReadAll(wxInputStream *is, wxArrayString& output) +{ + wxCHECK_MSG( is, FALSE, _T("NULL stream in wxExecute()?") ); + + // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state + is->Reset(); + + wxTextInputStream tis(*is); + + bool cont = TRUE; + while ( cont ) + { + wxString line = tis.ReadLine(); + if ( is->Eof() ) + break; + + if ( !*is ) + { + cont = FALSE; + } + else + { + output.Add(line); + } + } + + return cont; +} +#endif // wxUSE_STREAMS + // this is a private function because it hasn't a clean interface: the first // array is passed by reference, the second by pointer - instead we have 2 // public versions of wxExecute() below @@ -1206,51 +1121,15 @@ static long wxDoExecuteWithCapture(const wxString& command, #if wxUSE_STREAMS if ( rc != -1 ) { - wxInputStream* is = process->GetInputStream(); - wxCHECK_MSG( is, -1, _T("if wxExecute() succeded, stream can't be NULL") ); - wxTextInputStream tis(*is); + if ( !ReadAll(process->GetInputStream(), output) ) + rc = -1; - wxTextInputStream *tes = NULL; - wxInputStream *es = NULL; if ( error ) { - es = process->GetErrorStream(); - - wxCHECK_MSG( es, -1, _T("stderr can't be NULL") ); - - tes = new wxTextInputStream(*es); - } - - bool cont; - do - { - cont = FALSE; - - if ( !is->Eof() && is->IsOk() ) - { - wxString line = tis.ReadLine(); - if ( is->LastError() ) - break; - - cont = TRUE; - - output.Add(line); - } - - if ( error && !es->Eof() && es->IsOk() ) - { - wxString line = tes->ReadLine(); - if ( es->LastError() ) - break; - - cont = TRUE; - - error->Add(line); - } + if ( !ReadAll(process->GetErrorStream(), *error) ) + rc = -1; } - while ( cont ); - delete tes; } #endif // wxUSE_STREAMS