From 025e36ee418371e344ae0c9967b0f9cf2e571dc2 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 8 Feb 2009 03:32:27 +0000 Subject: [PATCH] - Changed I_GetFromClipboard() to return an FString. SVN r1414 (trunk) --- docs/rh-log.txt | 1 + src/c_console.cpp | 12 ++++++------ src/ct_chat.cpp | 13 ++++++++----- src/m_misc.cpp | 2 +- src/sdl/i_input.h | 2 +- src/sdl/i_system.cpp | 6 +++--- src/win32/i_input.cpp | 21 +++++++++++---------- src/win32/i_input.h | 2 +- 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 4bc567f1a..25043a4f5 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,5 @@ February 7, 2009 +- Changed I_GetFromClipboard() to return an FString. - Added GTK+-based clipboard support for Linux. - Fixed: Most Linux filesystems do not fill in d_type for scandir(), so we cannot rely on it to detect directories. diff --git a/src/c_console.cpp b/src/c_console.cpp index d6ec09c0b..0b9307ffc 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -1739,13 +1739,14 @@ static bool C_HandleKey (event_t *ev, BYTE *buffer, int len) } else { // paste from clipboard - char *clip = I_GetFromClipboard (); - if (clip != NULL) + FString clip = I_GetFromClipboard (); + if (clip.IsNotEmpty()) { - strtok (clip, "\r\n\b"); - int cliplen = (int)strlen (clip); + // Only paste the first line. + long brk = clip.IndexOfAny("\r\n\b"); + int cliplen = brk >= 0 ? brk : clip.Len(); - cliplen = MIN(len, cliplen); + // Make sure there's room for the whole thing. if (buffer[0] + cliplen > len) { cliplen = len - buffer[0]; @@ -1764,7 +1765,6 @@ static bool C_HandleKey (event_t *ev, BYTE *buffer, int len) makestartposgood (); HistPos = NULL; } - delete[] clip; } break; } diff --git a/src/ct_chat.cpp b/src/ct_chat.cpp index f2cb1706d..40a7e8757 100644 --- a/src/ct_chat.cpp +++ b/src/ct_chat.cpp @@ -150,16 +150,19 @@ bool CT_Responder (event_t *ev) } else if (ev->data1 == 'V' && (ev->data3 & GKM_CTRL)) { - char *clip = I_GetFromClipboard (); - if (clip != NULL) + FString clip = I_GetFromClipboard (); + if (clip.IsNotEmpty()) { - char *clip_p = clip; - strtok (clip, "\n\r\b"); + // Only paste the first line. + const char *clip_p = clip; while (*clip_p) { + if (*clip_p == '\n' || *clip_p == '\r' || *clip_p == '\b') + { + break; + } CT_AddChar (*clip_p++); } - delete[] clip; } } } diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 2011c7d70..0ce267d1c 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -646,7 +646,7 @@ void M_ScreenShot (const char *filename) else #endif { - int dirlen; + size_t dirlen; autoname = Args->CheckValue("-shotdir"); if (autoname == NULL) { diff --git a/src/sdl/i_input.h b/src/sdl/i_input.h index feb75343c..14b5b4624 100644 --- a/src/sdl/i_input.h +++ b/src/sdl/i_input.h @@ -2,7 +2,7 @@ #define __I_INPUT_H__ void I_PutInClipboard (const char *str); -char *I_GetFromClipboard (); +FString I_GetFromClipboard (); struct GUIDName { diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index cf2c2d403..3898edcf6 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -596,7 +596,7 @@ void I_PutInClipboard (const char *str) #endif } -char *I_GetFromClipboard () +FString I_GetFromClipboard () { #ifndef NO_GTK if (GtkAvailable) @@ -607,12 +607,12 @@ char *I_GetFromClipboard () gchar *text = gtk_clipboard_wait_for_text(clipboard); if (text != NULL) { - char *copy = copystring(text); + FString copy(text); g_free(text); return copy; } } } #endif - return NULL; + return ""; } diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index cfc668b28..294e76bd4 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -2024,15 +2024,15 @@ void I_PutInClipboard (const char *str) CloseClipboard (); } -char *I_GetFromClipboard () +FString I_GetFromClipboard () { - char *retstr = NULL; + FString retstr; HGLOBAL cliphandle; char *clipstr; char *nlstr; if (!IsClipboardFormatAvailable (CF_TEXT) || !OpenClipboard (Window)) - return NULL; + return retstr; cliphandle = GetClipboardData (CF_TEXT); if (cliphandle != NULL) @@ -2040,15 +2040,16 @@ char *I_GetFromClipboard () clipstr = (char *)GlobalLock (cliphandle); if (clipstr != NULL) { - retstr = copystring (clipstr); - GlobalUnlock (clipstr); - nlstr = retstr; - - // Convert CR-LF pairs to just LF - while ( (nlstr = strstr (retstr, "\r\n")) ) + // Convert CR-LF pairs to just LF while copying to the FString + for (nlstr = clipstr; *nlstr != '\0'; ++nlstr) { - memmove (nlstr, nlstr + 1, strlen (nlstr) - 1); + if (nlstr[0] == '\r' && nlstr[1] == '\n') + { + nlstr++; + } + retstr += *nlstr; } + GlobalUnlock (clipstr); } } diff --git a/src/win32/i_input.h b/src/win32/i_input.h index b75caa153..04ff3f7bb 100644 --- a/src/win32/i_input.h +++ b/src/win32/i_input.h @@ -39,7 +39,7 @@ bool I_InitInput (void *hwnd); void I_ShutdownInput (); void I_PutInClipboard (const char *str); -char *I_GetFromClipboard (); +FString I_GetFromClipboard (); void I_GetEvent ();