diff options
| author | Eric Andersen <andersen@codepoet.org> | 2003-12-23 20:24:51 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2003-12-23 20:24:51 +0000 |
| commit | 27bb79080d675acb70ff6b0c20617c5558ebfaf0 (patch) | |
| tree | 8d329887239cee6a8752363b4680cb8c9fb16ffc /shell | |
| parent | a6beeb6a7e3eb984df76159d0e955e8cc291f2fc (diff) | |
| download | busybox-w32-27bb79080d675acb70ff6b0c20617c5558ebfaf0.tar.gz busybox-w32-27bb79080d675acb70ff6b0c20617c5558ebfaf0.tar.bz2 busybox-w32-27bb79080d675acb70ff6b0c20617c5558ebfaf0.zip | |
Cmdedit update from Vladimir N. Oleynik (vodz)
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/cmdedit.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 16825089d..a78642b9d 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
| @@ -55,6 +55,13 @@ | |||
| 55 | 55 | ||
| 56 | #else | 56 | #else |
| 57 | 57 | ||
| 58 | /* pretect redefined for test */ | ||
| 59 | #undef CONFIG_FEATURE_COMMAND_EDITING | ||
| 60 | #undef CONFIG_FEATURE_COMMAND_TAB_COMPLETION | ||
| 61 | #undef CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION | ||
| 62 | #undef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT | ||
| 63 | #undef CONFIG_FEATURE_CLEAN_UP | ||
| 64 | |||
| 58 | #define CONFIG_FEATURE_COMMAND_EDITING | 65 | #define CONFIG_FEATURE_COMMAND_EDITING |
| 59 | #define CONFIG_FEATURE_COMMAND_TAB_COMPLETION | 66 | #define CONFIG_FEATURE_COMMAND_TAB_COMPLETION |
| 60 | #define CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION | 67 | #define CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION |
| @@ -1187,8 +1194,7 @@ extern void save_history ( const char *tofile ) | |||
| 1187 | int i; | 1194 | int i; |
| 1188 | 1195 | ||
| 1189 | for ( i = 0; i < n_history; i++ ) { | 1196 | for ( i = 0; i < n_history; i++ ) { |
| 1190 | fputs ( history [i], fp ); | 1197 | fprintf(fp, "%s\n", history [i]); |
| 1191 | fputc ( '\n', fp ); | ||
| 1192 | } | 1198 | } |
| 1193 | fclose ( fp ); | 1199 | fclose ( fp ); |
| 1194 | } | 1200 | } |
| @@ -1238,7 +1244,6 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
| 1238 | new_settings.c_lflag &= ~ICANON; /* unbuffered input */ | 1244 | new_settings.c_lflag &= ~ICANON; /* unbuffered input */ |
| 1239 | /* Turn off echoing and CTRL-C, so we can trap it */ | 1245 | /* Turn off echoing and CTRL-C, so we can trap it */ |
| 1240 | new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG); | 1246 | new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG); |
| 1241 | #ifndef linux | ||
| 1242 | /* Hmm, in linux c_cc[] not parsed if set ~ICANON */ | 1247 | /* Hmm, in linux c_cc[] not parsed if set ~ICANON */ |
| 1243 | new_settings.c_cc[VMIN] = 1; | 1248 | new_settings.c_cc[VMIN] = 1; |
| 1244 | new_settings.c_cc[VTIME] = 0; | 1249 | new_settings.c_cc[VTIME] = 0; |
| @@ -1247,7 +1252,6 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
| 1247 | # define _POSIX_VDISABLE '\0' | 1252 | # define _POSIX_VDISABLE '\0' |
| 1248 | # endif | 1253 | # endif |
| 1249 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; | 1254 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; |
| 1250 | #endif | ||
| 1251 | command[0] = 0; | 1255 | command[0] = 0; |
| 1252 | 1256 | ||
| 1253 | setTermSettings(0, (void *) &new_settings); | 1257 | setTermSettings(0, (void *) &new_settings); |
| @@ -1286,12 +1290,8 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
| 1286 | goto_new_line(); | 1290 | goto_new_line(); |
| 1287 | command[0] = 0; | 1291 | command[0] = 0; |
| 1288 | len = 0; | 1292 | len = 0; |
| 1289 | #if !defined(CONFIG_ASH) | ||
| 1290 | lastWasTab = FALSE; | 1293 | lastWasTab = FALSE; |
| 1291 | put_prompt(); | 1294 | put_prompt(); |
| 1292 | #else | ||
| 1293 | break_out = 2; | ||
| 1294 | #endif | ||
| 1295 | break; | 1295 | break; |
| 1296 | case 4: | 1296 | case 4: |
| 1297 | /* Control-d -- Delete one character, or exit | 1297 | /* Control-d -- Delete one character, or exit |
| @@ -1336,7 +1336,7 @@ prepare_to_die: | |||
| 1336 | printf("\033[J"); | 1336 | printf("\033[J"); |
| 1337 | break; | 1337 | break; |
| 1338 | case 12: | 1338 | case 12: |
| 1339 | /* Control-l -- clear screen */ | 1339 | /* Control-l -- clear screen */ |
| 1340 | printf("\033[H"); | 1340 | printf("\033[H"); |
| 1341 | redraw(0, len-cursor); | 1341 | redraw(0, len-cursor); |
| 1342 | break; | 1342 | break; |
| @@ -1363,6 +1363,13 @@ prepare_to_die: | |||
| 1363 | redraw(cmdedit_y, len -= cursor); | 1363 | redraw(cmdedit_y, len -= cursor); |
| 1364 | } | 1364 | } |
| 1365 | break; | 1365 | break; |
| 1366 | case 23: | ||
| 1367 | /* Control-W -- Remove the last word */ | ||
| 1368 | while (cursor > 0 && isspace(command[cursor-1])) | ||
| 1369 | input_backspace(); | ||
| 1370 | while (cursor > 0 &&!isspace(command[cursor-1])) | ||
| 1371 | input_backspace(); | ||
| 1372 | break; | ||
| 1366 | case ESC:{ | 1373 | case ESC:{ |
| 1367 | /* escape sequence follows */ | 1374 | /* escape sequence follows */ |
| 1368 | if (safe_read(0, &c, 1) < 1) | 1375 | if (safe_read(0, &c, 1) < 1) |
| @@ -1511,7 +1518,7 @@ rewrite_line: | |||
| 1511 | } | 1518 | } |
| 1512 | #endif | 1519 | #endif |
| 1513 | #endif /* MAX_HISTORY >= 1 */ | 1520 | #endif /* MAX_HISTORY >= 1 */ |
| 1514 | if(break_out == 1) { | 1521 | if (break_out > 0) { |
| 1515 | command[len++] = '\n'; /* set '\n' */ | 1522 | command[len++] = '\n'; /* set '\n' */ |
| 1516 | command[len] = 0; | 1523 | command[len] = 0; |
| 1517 | } | 1524 | } |
| @@ -1522,11 +1529,7 @@ rewrite_line: | |||
| 1522 | free(cmdedit_prompt); | 1529 | free(cmdedit_prompt); |
| 1523 | #endif | 1530 | #endif |
| 1524 | cmdedit_reset_term(); | 1531 | cmdedit_reset_term(); |
| 1525 | #if !defined(CONFIG_ASH) | ||
| 1526 | return len; | 1532 | return len; |
| 1527 | #else | ||
| 1528 | return break_out < 0 ? break_out : len; | ||
| 1529 | #endif | ||
| 1530 | } | 1533 | } |
| 1531 | 1534 | ||
| 1532 | 1535 | ||
| @@ -1537,7 +1540,6 @@ rewrite_line: | |||
| 1537 | #ifdef TEST | 1540 | #ifdef TEST |
| 1538 | 1541 | ||
| 1539 | const char *bb_applet_name = "debug stuff usage"; | 1542 | const char *bb_applet_name = "debug stuff usage"; |
| 1540 | const char *memory_exhausted = "Memory exhausted"; | ||
| 1541 | 1543 | ||
| 1542 | #ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT | 1544 | #ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT |
| 1543 | #include <locale.h> | 1545 | #include <locale.h> |
| @@ -1560,15 +1562,15 @@ int main(int argc, char **argv) | |||
| 1560 | #endif | 1562 | #endif |
| 1561 | while(1) { | 1563 | while(1) { |
| 1562 | int l; | 1564 | int l; |
| 1563 | cmdedit_read_input(prompt, buff); | 1565 | l = cmdedit_read_input(prompt, buff); |
| 1564 | l = strlen(buff); | 1566 | if(l > 0 && buff[l-1] == '\n') { |
| 1565 | if(l==0) | ||
| 1566 | break; | ||
| 1567 | if(l > 0 && buff[l-1] == '\n') | ||
| 1568 | buff[l-1] = 0; | 1567 | buff[l-1] = 0; |
| 1569 | printf("*** cmdedit_read_input() returned line =%s=\n", buff); | 1568 | printf("*** cmdedit_read_input() returned line =%s=\n", buff); |
| 1569 | } else { | ||
| 1570 | break; | ||
| 1571 | } | ||
| 1570 | } | 1572 | } |
| 1571 | printf("*** cmdedit_read_input() detect ^C\n"); | 1573 | printf("*** cmdedit_read_input() detect ^D\n"); |
| 1572 | return 0; | 1574 | return 0; |
| 1573 | } | 1575 | } |
| 1574 | 1576 | ||
