diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-04-21 01:26:49 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-04-21 01:26:49 +0000 |
| commit | 1d1d95051a288b6bf64498aac9fb20047f384b7d (patch) | |
| tree | 2c99ce8ba7d4d592806fbf81899e663bc884676b /shell | |
| parent | cf8d38a3eb46f4f9c4e674d43cff486cd79c9c0f (diff) | |
| download | busybox-w32-1d1d95051a288b6bf64498aac9fb20047f384b7d.tar.gz busybox-w32-1d1d95051a288b6bf64498aac9fb20047f384b7d.tar.bz2 busybox-w32-1d1d95051a288b6bf64498aac9fb20047f384b7d.zip | |
More Doc updates. cmdedit and more termio fixes.
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/cmdedit.c | 74 | ||||
| -rw-r--r-- | shell/cmdedit.h | 2 | ||||
| -rw-r--r-- | shell/lash.c | 1 |
3 files changed, 57 insertions, 20 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index ebc6b9696..e4c88c265 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
| @@ -39,7 +39,7 @@ | |||
| 39 | #include <unistd.h> | 39 | #include <unistd.h> |
| 40 | #include <stdlib.h> | 40 | #include <stdlib.h> |
| 41 | #include <string.h> | 41 | #include <string.h> |
| 42 | #include <termio.h> | 42 | #include <sys/ioctl.h> |
| 43 | #include <ctype.h> | 43 | #include <ctype.h> |
| 44 | #include <signal.h> | 44 | #include <signal.h> |
| 45 | 45 | ||
| @@ -53,7 +53,26 @@ | |||
| 53 | 53 | ||
| 54 | static struct history *his_front = NULL; /* First element in command line list */ | 54 | static struct history *his_front = NULL; /* First element in command line list */ |
| 55 | static struct history *his_end = NULL; /* Last element in command line list */ | 55 | static struct history *his_end = NULL; /* Last element in command line list */ |
| 56 | static struct termio old_term, new_term; /* Current termio and the previous termio before starting ash */ | 56 | |
| 57 | /* ED: sparc termios is broken: revert back to old termio handling. */ | ||
| 58 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 59 | |||
| 60 | #if #cpu(sparc) | ||
| 61 | # include <termio.h> | ||
| 62 | # define termios termio | ||
| 63 | # define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp) | ||
| 64 | # define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp) | ||
| 65 | #else | ||
| 66 | # include <termios.h> | ||
| 67 | # define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
| 68 | # define getTermSettings(fd,argp) tcgetattr(fd, argp); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | /* Current termio and the previous termio before starting sh */ | ||
| 72 | struct termios initial_settings, new_settings; | ||
| 73 | #endif | ||
| 74 | |||
| 75 | |||
| 57 | 76 | ||
| 58 | static int cmdedit_termw = 80; /* actual terminal width */ | 77 | static int cmdedit_termw = 80; /* actual terminal width */ |
| 59 | static int cmdedit_scroll = 27; /* width of EOL scrolling region */ | 78 | static int cmdedit_scroll = 27; /* width of EOL scrolling region */ |
| @@ -84,14 +103,15 @@ void cmdedit_reset_term(void) | |||
| 84 | { | 103 | { |
| 85 | if (reset_term) | 104 | if (reset_term) |
| 86 | /* sparc and other have broken termios support: use old termio handling. */ | 105 | /* sparc and other have broken termios support: use old termio handling. */ |
| 87 | ioctl(fileno(stdin), TCSETA, (void *) &old_term); | 106 | setTermSettings(fileno(stdin), (void*) &initial_settings); |
| 88 | } | 107 | } |
| 89 | 108 | ||
| 90 | void clean_up_and_die(int sig) | 109 | void clean_up_and_die(int sig) |
| 91 | { | 110 | { |
| 92 | cmdedit_reset_term(); | 111 | cmdedit_reset_term(); |
| 93 | fprintf(stdout, "\n"); | 112 | fprintf(stdout, "\n"); |
| 94 | exit(TRUE); | 113 | if (sig!=SIGINT) |
| 114 | exit(TRUE); | ||
| 95 | } | 115 | } |
| 96 | 116 | ||
| 97 | /* Go to HOME position */ | 117 | /* Go to HOME position */ |
| @@ -233,7 +253,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches) | |||
| 233 | return (matches); | 253 | return (matches); |
| 234 | } | 254 | } |
| 235 | 255 | ||
| 236 | void input_tab(char* command, int outputFd, int *cursor, int *len) | 256 | void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len) |
| 237 | { | 257 | { |
| 238 | /* Do TAB completion */ | 258 | /* Do TAB completion */ |
| 239 | static int num_matches=0; | 259 | static int num_matches=0; |
| @@ -379,19 +399,17 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
| 379 | 399 | ||
| 380 | memset(command, 0, sizeof(command)); | 400 | memset(command, 0, sizeof(command)); |
| 381 | if (!reset_term) { | 401 | if (!reset_term) { |
| 382 | /* sparc and other have broken termios support: use old termio handling. */ | 402 | |
| 383 | ioctl(inputFd, TCGETA, (void *) &old_term); | 403 | getTermSettings(inputFd, (void*) &initial_settings); |
| 384 | memcpy(&new_term, &old_term, sizeof(struct termio)); | 404 | memcpy(&new_settings, &initial_settings, sizeof(struct termios)); |
| 385 | 405 | new_settings.c_cc[VMIN] = 1; | |
| 386 | new_term.c_cc[VMIN] = 1; | 406 | new_settings.c_cc[VTIME] = 0; |
| 387 | new_term.c_cc[VTIME] = 0; | 407 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; /* Turn off CTRL-C, so we can trap it */ |
| 388 | new_term.c_lflag &= ~ICANON; /* unbuffered input */ | 408 | new_settings.c_lflag &= ~ICANON; /* unbuffered input */ |
| 389 | new_term.c_lflag &= ~ECHO; | 409 | new_settings.c_lflag &= ~(ECHO|ECHOCTL|ECHONL); /* Turn off echoing */ |
| 390 | reset_term = 1; | 410 | reset_term = 1; |
| 391 | ioctl(inputFd, TCSETA, (void *) &new_term); | ||
| 392 | } else { | ||
| 393 | ioctl(inputFd, TCSETA, (void *) &new_term); | ||
| 394 | } | 411 | } |
| 412 | setTermSettings(inputFd, (void*) &new_settings); | ||
| 395 | 413 | ||
| 396 | memset(command, 0, BUFSIZ); | 414 | memset(command, 0, BUFSIZ); |
| 397 | 415 | ||
| @@ -399,6 +417,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
| 399 | 417 | ||
| 400 | if ((ret = read(inputFd, &c, 1)) < 1) | 418 | if ((ret = read(inputFd, &c, 1)) < 1) |
| 401 | return; | 419 | return; |
| 420 | //fprintf(stderr, "got a '%c' (%d)\n", c, c); | ||
| 402 | 421 | ||
| 403 | switch (c) { | 422 | switch (c) { |
| 404 | case '\n': | 423 | case '\n': |
| @@ -415,6 +434,21 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
| 415 | /* Control-b -- Move back one character */ | 434 | /* Control-b -- Move back one character */ |
| 416 | input_backward(outputFd, &cursor); | 435 | input_backward(outputFd, &cursor); |
| 417 | break; | 436 | break; |
| 437 | case 3: | ||
| 438 | /* Control-c -- leave the current line, | ||
| 439 | * and start over on the next line */ | ||
| 440 | |||
| 441 | /* Go to the next line */ | ||
| 442 | xwrite(outputFd, "\n", 1); | ||
| 443 | |||
| 444 | /* Rewrite the prompt */ | ||
| 445 | xwrite(outputFd, prompt, strlen(prompt)); | ||
| 446 | |||
| 447 | /* Reset the command string */ | ||
| 448 | memset(command, 0, sizeof(command)); | ||
| 449 | len = cursor = 0; | ||
| 450 | |||
| 451 | break; | ||
| 418 | case 4: | 452 | case 4: |
| 419 | /* Control-d -- Delete one character, or exit | 453 | /* Control-d -- Delete one character, or exit |
| 420 | * if the len=0 and no chars to delete */ | 454 | * if the len=0 and no chars to delete */ |
| @@ -435,12 +469,12 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
| 435 | break; | 469 | break; |
| 436 | case '\b': | 470 | case '\b': |
| 437 | case DEL: | 471 | case DEL: |
| 438 | /* control-h and DEL */ | 472 | /* Control-h and DEL */ |
| 439 | input_backspace(command, outputFd, &cursor, &len); | 473 | input_backspace(command, outputFd, &cursor, &len); |
| 440 | break; | 474 | break; |
| 441 | case '\t': | 475 | case '\t': |
| 442 | #ifdef BB_FEATURE_SH_TAB_COMPLETION | 476 | #ifdef BB_FEATURE_SH_TAB_COMPLETION |
| 443 | input_tab(command, outputFd, &cursor, &len); | 477 | input_tab(command, prompt, outputFd, &cursor, &len); |
| 444 | #endif | 478 | #endif |
| 445 | break; | 479 | break; |
| 446 | case 14: | 480 | case 14: |
| @@ -591,8 +625,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
| 591 | } | 625 | } |
| 592 | 626 | ||
| 593 | nr = len + 1; | 627 | nr = len + 1; |
| 594 | /* sparc and other have broken termios support: use old termio handling. */ | 628 | setTermSettings(inputFd, (void *) &initial_settings); |
| 595 | ioctl(inputFd, TCSETA, (void *) &old_term); | ||
| 596 | reset_term = 0; | 629 | reset_term = 0; |
| 597 | 630 | ||
| 598 | 631 | ||
| @@ -644,6 +677,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) | |||
| 644 | extern void cmdedit_init(void) | 677 | extern void cmdedit_init(void) |
| 645 | { | 678 | { |
| 646 | atexit(cmdedit_reset_term); | 679 | atexit(cmdedit_reset_term); |
| 680 | signal(SIGKILL, clean_up_and_die); | ||
| 647 | signal(SIGINT, clean_up_and_die); | 681 | signal(SIGINT, clean_up_and_die); |
| 648 | signal(SIGQUIT, clean_up_and_die); | 682 | signal(SIGQUIT, clean_up_and_die); |
| 649 | signal(SIGTERM, clean_up_and_die); | 683 | signal(SIGTERM, clean_up_and_die); |
diff --git a/shell/cmdedit.h b/shell/cmdedit.h index 0e465e50e..9ac7daca3 100644 --- a/shell/cmdedit.h +++ b/shell/cmdedit.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | typedef size_t (*cmdedit_strwidth_proc)(char *); | 11 | typedef size_t (*cmdedit_strwidth_proc)(char *); |
| 12 | 12 | ||
| 13 | void cmdedit_init(void); | ||
| 13 | void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */ | 14 | void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */ |
| 14 | void cmdedit_setwidth(int); /* specify width of screen */ | 15 | void cmdedit_setwidth(int); /* specify width of screen */ |
| 15 | void cmdedit_histadd(char *); /* adds entries to hist */ | 16 | void cmdedit_histadd(char *); /* adds entries to hist */ |
| @@ -21,6 +22,7 @@ extern int (*cmdedit_tab_hook)(char *, int, int *); | |||
| 21 | 22 | ||
| 22 | #else /* not __STDC__ */ | 23 | #else /* not __STDC__ */ |
| 23 | 24 | ||
| 25 | void cmdedit_init(void); | ||
| 24 | void cmdedit_read_input(char* promptStr, char* command); | 26 | void cmdedit_read_input(char* promptStr, char* command); |
| 25 | void cmdedit_setwidth(); | 27 | void cmdedit_setwidth(); |
| 26 | void cmdedit_histadd(); | 28 | void cmdedit_histadd(); |
diff --git a/shell/lash.c b/shell/lash.c index 97db8afaf..b96b46456 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
| @@ -947,6 +947,7 @@ int shell_main(int argc, char **argv) | |||
| 947 | getcwd(cwd, sizeof(cwd)); | 947 | getcwd(cwd, sizeof(cwd)); |
| 948 | 948 | ||
| 949 | #ifdef BB_FEATURE_SH_COMMAND_EDITING | 949 | #ifdef BB_FEATURE_SH_COMMAND_EDITING |
| 950 | cmdedit_init(); | ||
| 950 | signal(SIGWINCH, win_changed); | 951 | signal(SIGWINCH, win_changed); |
| 951 | win_changed(0); | 952 | win_changed(0); |
| 952 | #endif | 953 | #endif |
