From a2faa975cb67c6110ec7ef4a281271758ae09588 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Fri, 20 Dec 2019 16:39:19 -0600 Subject: [PATCH 1/6] Allow Clipboard actions. --- src/m_menu.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index e367041e0..eb9bbaffe 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10436,6 +10436,28 @@ static void M_HandleConnectIP(INT32 choice) if (l >= 28-1) break; + const char *paste = I_ClipboardPaste(); // Paste clipboard into char + + if ( ctrldown ) { + switch (choice) { + case 118: // ctrl+v, pasting + if (paste != NULL) + strcat(setupm_ip, paste); // Concat the ip field with clipboard + setupm_ip[127] = 0; // Truncate to maximum length + break; + case 99: // ctrl+c, copying + I_ClipboardCopy(setupm_ip, l); + break; + case 120: // ctrl+x, cutting + I_ClipboardCopy(setupm_ip, l); + setupm_ip[0] = 0; + break; + default: // otherwise do nothing + break; + } + break; // break + } + // Rudimentary number and period enforcing - also allows letters so hostnames can be used instead if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z')) { From ed847e831b562ee86f4d1eba49013ba844d76d2b Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Fri, 20 Dec 2019 20:28:30 -0600 Subject: [PATCH 2/6] Fix pasting going out of bounds and dash the possibility of memory leaks while pasting. --- src/m_menu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index eb9bbaffe..ad0f70eb2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10436,14 +10436,16 @@ static void M_HandleConnectIP(INT32 choice) if (l >= 28-1) break; - const char *paste = I_ClipboardPaste(); // Paste clipboard into char + char *paste = (char *)I_ClipboardPaste(); // Paste clipboard into char if ( ctrldown ) { switch (choice) { case 118: // ctrl+v, pasting - if (paste != NULL) + if (paste != NULL) { + if (strlen(paste) + strlen(setupm_ip) >= 28-1) + paste[28-1 - strlen(setupm_ip)] = 0; strcat(setupm_ip, paste); // Concat the ip field with clipboard - setupm_ip[127] = 0; // Truncate to maximum length + } break; case 99: // ctrl+c, copying I_ClipboardCopy(setupm_ip, l); From 1f93ab0e0ffe5c19dee2fa1c47f1dbe0c161d207 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Mon, 23 Dec 2019 18:53:41 -0600 Subject: [PATCH 3/6] Optimise further, play beep on cut/copy, play beep when paste is successful. --- src/m_menu.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index ad0f70eb2..fed0d65b1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10433,33 +10433,42 @@ static void M_HandleConnectIP(INT32 choice) default: l = strlen(setupm_ip); - if (l >= 28-1) - break; - - char *paste = (char *)I_ClipboardPaste(); // Paste clipboard into char if ( ctrldown ) { switch (choice) { case 118: // ctrl+v, pasting + ; + char *paste = (char *)I_ClipboardPaste(); // Paste clipboard into char + if (paste != NULL) { - if (strlen(paste) + strlen(setupm_ip) >= 28-1) - paste[28-1 - strlen(setupm_ip)] = 0; + if (strlen(paste) + l >= 28-1) + paste[28-1 - l] = 0; strcat(setupm_ip, paste); // Concat the ip field with clipboard + if (strlen(paste) != 0) // Don't play sound if nothing was pasted + S_StartSound(NULL,sfx_menu1); // Tails } break; + case 99: // ctrl+c, copying I_ClipboardCopy(setupm_ip, l); + S_StartSound(NULL,sfx_menu1); // Tails break; + case 120: // ctrl+x, cutting I_ClipboardCopy(setupm_ip, l); + S_StartSound(NULL,sfx_menu1); // Tails setupm_ip[0] = 0; break; + default: // otherwise do nothing break; } - break; // break + break; // don't check for typed keys } + if (l >= 28-1) + break; + // Rudimentary number and period enforcing - also allows letters so hostnames can be used instead if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z')) { From ae9adce873cbb4938a34657d783286fa14469c8a Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 29 Dec 2019 18:26:56 -0600 Subject: [PATCH 4/6] Replace magic numbers with less magic and more readable chars. --- src/m_menu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index fed0d65b1..e1e28b671 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10436,7 +10436,8 @@ static void M_HandleConnectIP(INT32 choice) if ( ctrldown ) { switch (choice) { - case 118: // ctrl+v, pasting + case 'v': + case 'V': // ctrl+v, pasting ; char *paste = (char *)I_ClipboardPaste(); // Paste clipboard into char @@ -10448,13 +10449,15 @@ static void M_HandleConnectIP(INT32 choice) S_StartSound(NULL,sfx_menu1); // Tails } break; - - case 99: // ctrl+c, copying + + case 'c': + case 'C': // ctrl+c, copying I_ClipboardCopy(setupm_ip, l); S_StartSound(NULL,sfx_menu1); // Tails break; - case 120: // ctrl+x, cutting + case 'x': + case 'X': // ctrl+x, cutting I_ClipboardCopy(setupm_ip, l); S_StartSound(NULL,sfx_menu1); // Tails setupm_ip[0] = 0; From 9d701d722ebd08d4939ea43e195a5f0325338e0a Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 29 Dec 2019 20:15:18 -0600 Subject: [PATCH 5/6] Reverted to better, less complex system, and added support for Shift+Insert and Shift+Delete. Major thanks to James for helping me. Turns out that strncpy thwarts the memory leaks for me. Silly, me! --- src/m_menu.c | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index e1e28b671..ef9335907 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10424,13 +10424,15 @@ static void M_HandleConnectIP(INT32 choice) break; case KEY_DEL: - if (setupm_ip[0]) + if (setupm_ip[0] && !shiftdown) // Shift+Delete is used for something else. { S_StartSound(NULL,sfx_menu1); // Tails setupm_ip[0] = 0; } - break; - + if (!shiftdown) // Shift+Delete is used for something else. + break; + + /* FALLTHRU */ default: l = strlen(setupm_ip); @@ -10438,18 +10440,17 @@ static void M_HandleConnectIP(INT32 choice) switch (choice) { case 'v': case 'V': // ctrl+v, pasting - ; - char *paste = (char *)I_ClipboardPaste(); // Paste clipboard into char - + { + const char *paste = I_ClipboardPaste(); + if (paste != NULL) { - if (strlen(paste) + l >= 28-1) - paste[28-1 - l] = 0; - strcat(setupm_ip, paste); // Concat the ip field with clipboard + strncat(setupm_ip, paste, 28-1 - l); // Concat the ip field with clipboard if (strlen(paste) != 0) // Don't play sound if nothing was pasted S_StartSound(NULL,sfx_menu1); // Tails } + break; - + } case 'c': case 'C': // ctrl+c, copying I_ClipboardCopy(setupm_ip, l); @@ -10469,6 +10470,31 @@ static void M_HandleConnectIP(INT32 choice) break; // don't check for typed keys } + if ( shiftdown ) { + switch (choice) { + case KEY_INS: + { + const char *paste = I_ClipboardPaste(); + + if (paste != NULL) { + strncat(setupm_ip, paste, 28-1 - l); // Concat the ip field with clipboard + if (strlen(paste) != 0) // Don't play sound if nothing was pasted + S_StartSound(NULL,sfx_menu1); // Tails + } + + break; + } + case KEY_DEL: // shift+delete, cutting + I_ClipboardCopy(setupm_ip, l); + S_StartSound(NULL,sfx_menu1); // Tails + setupm_ip[0] = 0; + break; + default: // otherwise do nothing. + break; + } + break; // don't check for typed keys + } + if (l >= 28-1) break; From bc88def2254afd6d24f6503fddf49f008b811bc9 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 29 Dec 2019 20:22:58 -0600 Subject: [PATCH 6/6] Slap in some Ctrl+Insert (copy) support too while I'm at it. Also added a comment but you didn't see that. --- src/m_menu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index ef9335907..e9cbe9980 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10431,7 +10431,7 @@ static void M_HandleConnectIP(INT32 choice) } if (!shiftdown) // Shift+Delete is used for something else. break; - + /* FALLTHRU */ default: l = strlen(setupm_ip); @@ -10451,8 +10451,9 @@ static void M_HandleConnectIP(INT32 choice) break; } + case KEY_INS: case 'c': - case 'C': // ctrl+c, copying + case 'C': // ctrl+c, ctrl+insert, copying I_ClipboardCopy(setupm_ip, l); S_StartSound(NULL,sfx_menu1); // Tails break; @@ -10472,7 +10473,7 @@ static void M_HandleConnectIP(INT32 choice) if ( shiftdown ) { switch (choice) { - case KEY_INS: + case KEY_INS: // shift+insert, pasting { const char *paste = I_ClipboardPaste();