aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-29 10:39:06 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-29 10:39:06 +0200
commit4b7db4f2ca232c630e334fa56b1eb89848d5fcc5 (patch)
tree55608587f33fc1d6f6a8e40dfdf7fea66c750d7a
parent171932d7ca62dbb0e0b84a0919e1f3a8a68f03f2 (diff)
downloadbusybox-w32-4b7db4f2ca232c630e334fa56b1eb89848d5fcc5.tar.gz
busybox-w32-4b7db4f2ca232c630e334fa56b1eb89848d5fcc5.tar.bz2
busybox-w32-4b7db4f2ca232c630e334fa56b1eb89848d5fcc5.zip
read_key: drop optimization where we read 3 bytes at once
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h96
-rw-r--r--libbb/lineedit.c11
-rw-r--r--libbb/read_key.c13
-rw-r--r--shell/hush.c4
4 files changed, 65 insertions, 59 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 788140d14..963e2af28 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -933,54 +933,6 @@ void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC;
933#endif 933#endif
934 934
935 935
936/* "Keycodes" that report an escape sequence.
937 * We use something which fits into signed char,
938 * yet doesn't represent any valid Unicode characher.
939 * Also, -1 is reserved for error indication and we don't use it. */
940enum {
941 KEYCODE_UP = -2,
942 KEYCODE_DOWN = -3,
943 KEYCODE_RIGHT = -4,
944 KEYCODE_LEFT = -5,
945 KEYCODE_HOME = -6,
946 KEYCODE_END = -7,
947 KEYCODE_INSERT = -8,
948 KEYCODE_DELETE = -9,
949 KEYCODE_PAGEUP = -10,
950 KEYCODE_PAGEDOWN = -11,
951#if 0
952 KEYCODE_FUN1 = -12,
953 KEYCODE_FUN2 = -13,
954 KEYCODE_FUN3 = -14,
955 KEYCODE_FUN4 = -15,
956 KEYCODE_FUN5 = -16,
957 KEYCODE_FUN6 = -17,
958 KEYCODE_FUN7 = -18,
959 KEYCODE_FUN8 = -19,
960 KEYCODE_FUN9 = -20,
961 KEYCODE_FUN10 = -21,
962 KEYCODE_FUN11 = -22,
963 KEYCODE_FUN12 = -23,
964#endif
965 KEYCODE_CURSOR_POS = -0x100,
966 /* How long is the longest ESC sequence we know?
967 * We want it big enough to be able to contain
968 * cursor position sequence "ESC [ 9999 ; 9999 R"
969 */
970 KEYCODE_BUFFER_SIZE = 16
971};
972/* Note: fd may be in blocking or non-blocking mode, both make sense.
973 * For one, less uses non-blocking mode.
974 * Only the first read syscall inside read_key may block indefinitely
975 * (unless fd is in non-blocking mode),
976 * subsequent reads will time out after a few milliseconds.
977 * Return of -1 means EOF or error (errno == 0 on EOF).
978 * buffer[0] is used as a counter of buffered chars and must be 0
979 * on first call.
980 */
981int64_t read_key(int fd, char *buffer) FAST_FUNC;
982
983
984/* Networking */ 936/* Networking */
985int create_icmp_socket(void) FAST_FUNC; 937int create_icmp_socket(void) FAST_FUNC;
986int create_icmp6_socket(void) FAST_FUNC; 938int create_icmp6_socket(void) FAST_FUNC;
@@ -1209,6 +1161,54 @@ unsigned long long bb_makedev(unsigned int major, unsigned int minor) FAST_FUNC;
1209#endif 1161#endif
1210 1162
1211 1163
1164/* "Keycodes" that report an escape sequence.
1165 * We use something which fits into signed char,
1166 * yet doesn't represent any valid Unicode characher.
1167 * Also, -1 is reserved for error indication and we don't use it. */
1168enum {
1169 KEYCODE_UP = -2,
1170 KEYCODE_DOWN = -3,
1171 KEYCODE_RIGHT = -4,
1172 KEYCODE_LEFT = -5,
1173 KEYCODE_HOME = -6,
1174 KEYCODE_END = -7,
1175 KEYCODE_INSERT = -8,
1176 KEYCODE_DELETE = -9,
1177 KEYCODE_PAGEUP = -10,
1178 KEYCODE_PAGEDOWN = -11,
1179#if 0
1180 KEYCODE_FUN1 = -12,
1181 KEYCODE_FUN2 = -13,
1182 KEYCODE_FUN3 = -14,
1183 KEYCODE_FUN4 = -15,
1184 KEYCODE_FUN5 = -16,
1185 KEYCODE_FUN6 = -17,
1186 KEYCODE_FUN7 = -18,
1187 KEYCODE_FUN8 = -19,
1188 KEYCODE_FUN9 = -20,
1189 KEYCODE_FUN10 = -21,
1190 KEYCODE_FUN11 = -22,
1191 KEYCODE_FUN12 = -23,
1192#endif
1193 KEYCODE_CURSOR_POS = -0x100,
1194 /* How long is the longest ESC sequence we know?
1195 * We want it big enough to be able to contain
1196 * cursor position sequence "ESC [ 9999 ; 9999 R"
1197 */
1198 KEYCODE_BUFFER_SIZE = 16
1199};
1200/* Note: fd may be in blocking or non-blocking mode, both make sense.
1201 * For one, less uses non-blocking mode.
1202 * Only the first read syscall inside read_key may block indefinitely
1203 * (unless fd is in non-blocking mode),
1204 * subsequent reads will time out after a few milliseconds.
1205 * Return of -1 means EOF or error (errno == 0 on EOF).
1206 * buffer[0] is used as a counter of buffered chars and must be 0
1207 * on first call.
1208 */
1209int64_t read_key(int fd, char *buffer) FAST_FUNC;
1210
1211
1212#if ENABLE_FEATURE_EDITING 1212#if ENABLE_FEATURE_EDITING
1213/* It's NOT just ENABLEd or disabled. It's a number: */ 1213/* It's NOT just ENABLEd or disabled. It's a number: */
1214# ifdef CONFIG_FEATURE_EDITING_HISTORY 1214# ifdef CONFIG_FEATURE_EDITING_HISTORY
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index a0b1bcf8e..81f6fdeff 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1451,10 +1451,13 @@ static int lineedit_read_key(char *read_key_buffer)
1451 pfd.events = POLLIN; 1451 pfd.events = POLLIN;
1452 do { 1452 do {
1453 poll_again: 1453 poll_again:
1454 /* Wait for input. Can't just call read_key, it will return 1454 if (read_key_buffer[0] == 0) {
1455 * at once if stdin is in non-blocking mode. */ 1455 /* Wait for input. Can't just call read_key,
1456 safe_poll(&pfd, 1, -1); 1456 * it returns at once if stdin
1457 /* note: read_key sets errno to 0 on success: */ 1457 * is in non-blocking mode. */
1458 safe_poll(&pfd, 1, -1);
1459 }
1460 /* Note: read_key sets errno to 0 on success: */
1458 ic = read_key(STDIN_FILENO, read_key_buffer); 1461 ic = read_key(STDIN_FILENO, read_key_buffer);
1459 if (ENABLE_FEATURE_EDITING_ASK_TERMINAL 1462 if (ENABLE_FEATURE_EDITING_ASK_TERMINAL
1460 && (int32_t)ic == KEYCODE_CURSOR_POS 1463 && (int32_t)ic == KEYCODE_CURSOR_POS
diff --git a/libbb/read_key.c b/libbb/read_key.c
index 3771045d2..6f6c39e45 100644
--- a/libbb/read_key.c
+++ b/libbb/read_key.c
@@ -69,11 +69,14 @@ int64_t FAST_FUNC read_key(int fd, char *buffer)
69 errno = 0; 69 errno = 0;
70 n = (unsigned char) *buffer++; 70 n = (unsigned char) *buffer++;
71 if (n == 0) { 71 if (n == 0) {
72 /* If no data, block waiting for input. If we read more 72 /* If no data, block waiting for input.
73 * than the minimal ESC sequence size, the "n=0" below 73 * It is tempting to read more than one byte here,
74 * would instead have to figure out how much to keep, 74 * but it breaks pasting. Example: at shell prompt,
75 * resulting in larger code. */ 75 * user presses "c","a","t" and then pastes "\nline\n".
76 n = safe_read(fd, buffer, 3); 76 * When we were reading 3 bytes here, we were eating
77 * "li" too, and cat was getting wrong input.
78 */
79 n = safe_read(fd, buffer, 1);
77 if (n <= 0) 80 if (n <= 0)
78 return -1; 81 return -1;
79 } 82 }
diff --git a/shell/hush.c b/shell/hush.c
index add40eb5f..5fa693b0a 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1006,7 +1006,7 @@ static void restore_G_args(save_arg_t *sv, char **argv)
1006 * Commands run in command substitution ("`cmd`") 1006 * Commands run in command substitution ("`cmd`")
1007 * have SIGTTIN, SIGTTOU, SIGTSTP set to SIG_IGN. 1007 * have SIGTTIN, SIGTTOU, SIGTSTP set to SIG_IGN.
1008 * 1008 *
1009 * Ordinary commands have signals set to SIG_IGN/DFL set as inherited 1009 * Ordinary commands have signals set to SIG_IGN/DFL as inherited
1010 * by the shell from its parent. 1010 * by the shell from its parent.
1011 * 1011 *
1012 * Siganls which differ from SIG_DFL action 1012 * Siganls which differ from SIG_DFL action
@@ -1285,7 +1285,7 @@ static int set_local_var(char *str, int flg_export, int flg_read_only)
1285 if (strncmp(cur->varstr, str, name_len) != 0) { 1285 if (strncmp(cur->varstr, str, name_len) != 0) {
1286 if (!cur->next) { 1286 if (!cur->next) {
1287 /* Bail out. Note that now cur points 1287 /* Bail out. Note that now cur points
1288 * to last var in linked list */ 1288 * to the last var in the linked list */
1289 break; 1289 break;
1290 } 1290 }
1291 cur = cur->next; 1291 cur = cur->next;