From 7467c8d3b6a50e2cbd8db750963d40b420ad38d1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 12 Jul 2001 20:26:32 +0000 Subject: Patch from vodz: Changed email address cmdedit API change optimizations for traceroute and md5sum added a new shared create_icmp_socket() function --- shell/cmdedit.c | 88 +++++++++++++++++---------------------------------------- 1 file changed, 26 insertions(+), 62 deletions(-) (limited to 'shell/cmdedit.c') diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 4f124d647..540eb7ea7 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c @@ -3,7 +3,7 @@ * Termios command line History and Editting. * * Copyright (c) 1986-2001 may safely be consumed by a BSD or GPL license. - * Written by: Vladimir Oleynik + * Written by: Vladimir Oleynik * * Used ideas: * Adam Rogoyski @@ -123,9 +123,8 @@ volatile int handlers_sets = 0; /* Set next bites: */ enum { SET_ATEXIT = 1, /* when atexit() has been called and get euid,uid,gid to fast compare */ - SET_TERM_HANDLERS = 2, /* set many terminates signal handlers */ - SET_WCHG_HANDLERS = 4, /* winchg signal handler */ - SET_RESET_TERM = 8, /* if the terminal needs to be reset upon exit */ + SET_WCHG_HANDLERS = 2, /* winchg signal handler */ + SET_RESET_TERM = 4, /* if the terminal needs to be reset upon exit */ }; @@ -142,10 +141,6 @@ static #endif char *cmdedit_prompt; /* --- "" - - "" - -"- --""-- --""--- */ -/* Link into lash to reset context to 0 on ^C and such */ -extern unsigned int shell_context; - - #ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR static char *user_buf = ""; static char *home_pwd_buf = ""; @@ -319,6 +314,7 @@ static void put_prompt(void) out1str(cmdedit_prompt); cmdedit_x = cmdedit_prmt_len; /* count real x terminal position */ cursor = 0; + cmdedit_y = 0; /* new quasireal y */ } #ifndef BB_FEATURE_SH_FANCY_PROMPT @@ -456,7 +452,6 @@ static void redraw(int y, int back_cursor) { if (y > 0) /* up to start y */ printf("\033[%dA", y); - cmdedit_y = 0; /* new quasireal y */ putchar('\r'); put_prompt(); input_end(); /* rewrite */ @@ -497,14 +492,6 @@ static void input_forward(void) } -static void clean_up_and_die(int sig) -{ - goto_new_line(); - if (sig != SIGINT) - exit(EXIT_SUCCESS); /* cmdedit_reset_term() called in atexit */ - cmdedit_reset_term(); -} - static void cmdedit_setwidth(int w, int redraw_flg) { cmdedit_termw = cmdedit_prmt_len + 2; @@ -525,7 +512,7 @@ static void cmdedit_setwidth(int w, int redraw_flg) } } -extern void cmdedit_init(void) +static void cmdedit_init(void) { cmdedit_prmt_len = 0; if ((handlers_sets & SET_WCHG_HANDLERS) == 0) { @@ -557,14 +544,6 @@ extern void cmdedit_init(void) handlers_sets |= SET_ATEXIT; atexit(cmdedit_reset_term); /* be sure to do this only once */ } - - if ((handlers_sets & SET_TERM_HANDLERS) == 0) { - signal(SIGKILL, clean_up_and_die); - signal(SIGINT, clean_up_and_die); - signal(SIGQUIT, clean_up_and_die); - signal(SIGTERM, clean_up_and_die); - handlers_sets |= SET_TERM_HANDLERS; - } } #ifdef BB_FEATURE_COMMAND_TAB_COMPLETION @@ -1220,7 +1199,7 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ]) fflush(stdout); /* buffered out to fast */ - if (read(0, &c, 1) < 1) + if (safe_read(0, &c, 1) < 1) /* if we can't read input then exit */ goto prepare_to_die; @@ -1241,22 +1220,21 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ]) break; case 3: /* Control-c -- stop gathering input */ - - /* Link into lash to reset context to 0 on ^C and such */ - shell_context = 0; - - /* Go to the next line */ goto_new_line(); command[0] = 0; - - return; + len = 0; + lastWasTab = FALSE; + put_prompt(); + break; case 4: /* Control-d -- Delete one character, or exit * if the len=0 and no chars to delete */ if (len == 0) { prepare_to_die: printf("exit"); - clean_up_and_die(0); + goto_new_line(); + /* cmdedit_reset_term() called in atexit */ + exit(EXIT_SUCCESS); } else { input_delete(); } @@ -1307,12 +1285,12 @@ prepare_to_die: case ESC:{ /* escape sequence follows */ - if (read(0, &c, 1) < 1) - return; + if (safe_read(0, &c, 1) < 1) + goto prepare_to_die; /* different vt100 emulations */ if (c == '[' || c == 'O') { - if (read(0, &c, 1) < 1) - return; + if (safe_read(0, &c, 1) < 1) + goto prepare_to_die; } switch (c) { #ifdef BB_FEATURE_COMMAND_TAB_COMPLETION @@ -1376,8 +1354,8 @@ prepare_to_die: } if (c >= '1' && c <= '9') do - if (read(0, &c, 1) < 1) - return; + if (safe_read(0, &c, 1) < 1) + goto prepare_to_die; while (c != '~'); break; } @@ -1386,8 +1364,8 @@ prepare_to_die: #ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT /* Control-V -- Add non-printable symbol */ if (c == 22) { - if (read(0, &c, 1) < 1) - return; + if (safe_read(0, &c, 1) < 1) + goto prepare_to_die; if (c == 0) { beep(); break; @@ -1485,23 +1463,10 @@ prepare_to_die: #if defined(BB_FEATURE_SH_FANCY_PROMPT) free(cmdedit_prompt); #endif - return; + cmdedit_reset_term(); } -/* Undo the effects of cmdedit_init(). */ -extern void cmdedit_terminate(void) -{ - cmdedit_reset_term(); - if ((handlers_sets & SET_TERM_HANDLERS) != 0) { - signal(SIGKILL, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGWINCH, SIG_DFL); - handlers_sets &= ~SET_TERM_HANDLERS; - } -} #endif /* BB_FEATURE_COMMAND_EDITING */ @@ -1515,8 +1480,6 @@ const char *memory_exhausted = "Memory exhausted"; #include #endif -unsigned int shell_context; - int main(int argc, char **argv) { char buff[BUFSIZ]; @@ -1532,15 +1495,16 @@ int main(int argc, char **argv) #ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT setlocale(LC_ALL, ""); #endif - shell_context = 1; - do { + while(1) { int l; cmdedit_read_input(prompt, buff); l = strlen(buff); + if(l==0) + break; if(l > 0 && buff[l-1] == '\n') buff[l-1] = 0; printf("*** cmdedit_read_input() returned line =%s=\n", buff); - } while (shell_context); + } printf("*** cmdedit_read_input() detect ^C\n"); return 0; } -- cgit v1.2.3