diff options
author | Erik Andersen | 2000-04-21 01:26:49 +0000 |
---|---|---|
committer | Erik Andersen | 2000-04-21 01:26:49 +0000 |
commit | 1d1d95051a288b6bf64498aac9fb20047f384b7d (patch) | |
tree | 2c99ce8ba7d4d592806fbf81899e663bc884676b /shell | |
parent | cf8d38a3eb46f4f9c4e674d43cff486cd79c9c0f (diff) | |
download | busybox-1d1d95051a288b6bf64498aac9fb20047f384b7d.zip busybox-1d1d95051a288b6bf64498aac9fb20047f384b7d.tar.gz |
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 ebc6b96..e4c88c2 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c @@ -39,7 +39,7 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> -#include <termio.h> +#include <sys/ioctl.h> #include <ctype.h> #include <signal.h> @@ -53,7 +53,26 @@ static struct history *his_front = NULL; /* First element in command line list */ static struct history *his_end = NULL; /* Last element in command line list */ -static struct termio old_term, new_term; /* Current termio and the previous termio before starting ash */ + +/* ED: sparc termios is broken: revert back to old termio handling. */ +#ifdef BB_FEATURE_USE_TERMIOS + +#if #cpu(sparc) +# include <termio.h> +# define termios termio +# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp) +# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp) +#else +# include <termios.h> +# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) +# define getTermSettings(fd,argp) tcgetattr(fd, argp); +#endif + +/* Current termio and the previous termio before starting sh */ +struct termios initial_settings, new_settings; +#endif + + static int cmdedit_termw = 80; /* actual terminal width */ static int cmdedit_scroll = 27; /* width of EOL scrolling region */ @@ -84,14 +103,15 @@ void cmdedit_reset_term(void) { if (reset_term) /* sparc and other have broken termios support: use old termio handling. */ - ioctl(fileno(stdin), TCSETA, (void *) &old_term); + setTermSettings(fileno(stdin), (void*) &initial_settings); } void clean_up_and_die(int sig) { cmdedit_reset_term(); fprintf(stdout, "\n"); - exit(TRUE); + if (sig!=SIGINT) + exit(TRUE); } /* Go to HOME position */ @@ -233,7 +253,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches) return (matches); } -void input_tab(char* command, int outputFd, int *cursor, int *len) +void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len) { /* Do TAB completion */ static int num_matches=0; @@ -379,19 +399,17 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) memset(command, 0, sizeof(command)); if (!reset_term) { - /* sparc and other have broken termios support: use old termio handling. */ - ioctl(inputFd, TCGETA, (void *) &old_term); - memcpy(&new_term, &old_term, sizeof(struct termio)); - - new_term.c_cc[VMIN] = 1; - new_term.c_cc[VTIME] = 0; - new_term.c_lflag &= ~ICANON; /* unbuffered input */ - new_term.c_lflag &= ~ECHO; + + getTermSettings(inputFd, (void*) &initial_settings); + memcpy(&new_settings, &initial_settings, sizeof(struct termios)); + new_settings.c_cc[VMIN] = 1; + new_settings.c_cc[VTIME] = 0; + new_settings.c_cc[VINTR] = _POSIX_VDISABLE; /* Turn off CTRL-C, so we can trap it */ + new_settings.c_lflag &= ~ICANON; /* unbuffered input */ + new_settings.c_lflag &= ~(ECHO|ECHOCTL|ECHONL); /* Turn off echoing */ reset_term = 1; - ioctl(inputFd, TCSETA, (void *) &new_term); - } else { - ioctl(inputFd, TCSETA, (void *) &new_term); } + setTermSettings(inputFd, (void*) &new_settings); memset(command, 0, BUFSIZ); @@ -399,6 +417,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) if ((ret = read(inputFd, &c, 1)) < 1) return; + //fprintf(stderr, "got a '%c' (%d)\n", c, c); switch (c) { case '\n': @@ -415,6 +434,21 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) /* Control-b -- Move back one character */ input_backward(outputFd, &cursor); break; + case 3: + /* Control-c -- leave the current line, + * and start over on the next line */ + + /* Go to the next line */ + xwrite(outputFd, "\n", 1); + + /* Rewrite the prompt */ + xwrite(outputFd, prompt, strlen(prompt)); + + /* Reset the command string */ + memset(command, 0, sizeof(command)); + len = cursor = 0; + + break; case 4: /* Control-d -- Delete one character, or exit * if the len=0 and no chars to delete */ @@ -435,12 +469,12 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) break; case '\b': case DEL: - /* control-h and DEL */ + /* Control-h and DEL */ input_backspace(command, outputFd, &cursor, &len); break; case '\t': #ifdef BB_FEATURE_SH_TAB_COMPLETION - input_tab(command, outputFd, &cursor, &len); + input_tab(command, prompt, outputFd, &cursor, &len); #endif break; case 14: @@ -591,8 +625,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) } nr = len + 1; - /* sparc and other have broken termios support: use old termio handling. */ - ioctl(inputFd, TCSETA, (void *) &old_term); + setTermSettings(inputFd, (void *) &initial_settings); reset_term = 0; @@ -644,6 +677,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) extern void cmdedit_init(void) { atexit(cmdedit_reset_term); + signal(SIGKILL, clean_up_and_die); signal(SIGINT, clean_up_and_die); signal(SIGQUIT, clean_up_and_die); signal(SIGTERM, clean_up_and_die); diff --git a/shell/cmdedit.h b/shell/cmdedit.h index 0e465e5..9ac7dac 100644 --- a/shell/cmdedit.h +++ b/shell/cmdedit.h @@ -10,6 +10,7 @@ typedef size_t (*cmdedit_strwidth_proc)(char *); +void cmdedit_init(void); void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */ void cmdedit_setwidth(int); /* specify width of screen */ void cmdedit_histadd(char *); /* adds entries to hist */ @@ -21,6 +22,7 @@ extern int (*cmdedit_tab_hook)(char *, int, int *); #else /* not __STDC__ */ +void cmdedit_init(void); void cmdedit_read_input(char* promptStr, char* command); void cmdedit_setwidth(); void cmdedit_histadd(); diff --git a/shell/lash.c b/shell/lash.c index 97db8af..b96b464 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -947,6 +947,7 @@ int shell_main(int argc, char **argv) getcwd(cwd, sizeof(cwd)); #ifdef BB_FEATURE_SH_COMMAND_EDITING + cmdedit_init(); signal(SIGWINCH, win_changed); win_changed(0); #endif |