Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 2 | /* |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 3 | * Termios command line History and Editting, originally |
| 4 | * intended for NetBSD sh (ash) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 5 | * Copyright (c) 1999 |
| 6 | * Main code: Adam Rogoyski <rogoyski@cs.utexas.edu> |
| 7 | * Etc: Dave Cinege <dcinege@psychosis.com> |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 8 | * Majorly adjusted/re-written for busybox: |
| 9 | * Erik Andersen <andersee@debian.org> |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 10 | * |
| 11 | * You may use this code as you wish, so long as the original author(s) |
| 12 | * are attributed in any redistributions of the source code. |
| 13 | * This code is 'as is' with no warranty. |
| 14 | * This code may safely be consumed by a BSD or GPL license. |
| 15 | * |
| 16 | * v 0.5 19990328 Initial release |
| 17 | * |
| 18 | * Future plans: Simple file and path name completion. (like BASH) |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | Usage and Known bugs: |
| 24 | Terminal key codes are not extensive, and more will probably |
| 25 | need to be added. This version was created on Debian GNU/Linux 2.x. |
| 26 | Delete, Backspace, Home, End, and the arrow keys were tested |
| 27 | to work in an Xterm and console. Ctrl-A also works as Home. |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 28 | Ctrl-E also works as End. |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 29 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 30 | |
| 31 | Editor with vertical scrolling and completion by |
| 32 | Vladimir Oleynik. vodz@usa.net (c) 2001 |
| 33 | |
| 34 | Small bug: not true work if terminal size (x*y symbols) less |
| 35 | size (prompt + editor`s line + 2 symbols) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 38 | |
| 39 | |
Eric Andersen | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 40 | #include "busybox.h" |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 41 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 42 | #ifdef BB_FEATURE_SH_COMMAND_EDITING |
| 43 | |
| 44 | #include <stdio.h> |
| 45 | #include <errno.h> |
| 46 | #include <unistd.h> |
| 47 | #include <stdlib.h> |
| 48 | #include <string.h> |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 49 | #include <sys/ioctl.h> |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 50 | #include <ctype.h> |
| 51 | #include <signal.h> |
| 52 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 53 | #ifdef BB_FEATURE_SH_TAB_COMPLETION |
| 54 | #include <sys/stat.h> |
| 55 | #endif |
| 56 | |
| 57 | #ifdef BB_FEATURE_USERNAME_COMPLETION |
| 58 | #include <pwd.h> |
| 59 | #endif |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 60 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 61 | static const int MAX_HISTORY = 15; /* Maximum length of the linked list for the command line history */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 62 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 63 | enum { |
| 64 | ESC = 27, |
| 65 | DEL = 127, |
| 66 | }; |
| 67 | |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 68 | #define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0) |
| 69 | #define whitespace(c) (((c) == ' ') || ((c) == '\t')) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 70 | |
| 71 | static struct history *his_front = NULL; /* First element in command line list */ |
| 72 | static struct history *his_end = NULL; /* Last element in command line list */ |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 73 | |
| 74 | /* ED: sparc termios is broken: revert back to old termio handling. */ |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 75 | |
| 76 | #if #cpu(sparc) |
| 77 | # include <termio.h> |
| 78 | # define termios termio |
| 79 | # define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp) |
| 80 | # define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp) |
| 81 | #else |
| 82 | # include <termios.h> |
| 83 | # define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) |
| 84 | # define getTermSettings(fd,argp) tcgetattr(fd, argp); |
| 85 | #endif |
| 86 | |
| 87 | /* Current termio and the previous termio before starting sh */ |
Eric Andersen | 63a8622 | 2000-11-07 06:52:13 +0000 | [diff] [blame] | 88 | static struct termios initial_settings, new_settings; |
Erik Andersen | 8ea7d8c | 2000-05-20 00:40:08 +0000 | [diff] [blame] | 89 | |
| 90 | |
| 91 | #ifndef _POSIX_VDISABLE |
| 92 | #define _POSIX_VDISABLE '\0' |
| 93 | #endif |
| 94 | |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 95 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 96 | static |
| 97 | volatile int cmdedit_termw; /* actual terminal width */ |
| 98 | static int history_counter = 0; /* Number of commands in history list */ |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 99 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 100 | static |
| 101 | volatile int handlers_sets = 0; /* Set next bites |
| 102 | when atexit() has been called |
| 103 | and set many "terminates" signal handlers |
| 104 | and winchg signal handler |
| 105 | and if the terminal needs to be reset upon exit |
| 106 | */ |
| 107 | enum { |
| 108 | SET_ATEXIT = 1, |
| 109 | SET_TERM_HANDLERS = 2, |
| 110 | SET_WCHG_HANDLERS = 4, |
| 111 | SET_RESET_TERM = 8, |
| 112 | }; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 113 | |
Eric Andersen | 8634977 | 2000-12-18 20:25:50 +0000 | [diff] [blame] | 114 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 115 | static int cmdedit_x; /* real x terminal position, |
| 116 | require put prompt in start x position */ |
| 117 | static int cmdedit_y; /* pseudoreal y terminal position */ |
| 118 | static int cmdedit_prmt_len; /* for fast running, without duplicate calculate */ |
| 119 | |
| 120 | static int cursor; /* required global for signal handler */ |
| 121 | static int len; /* --- "" - - "" - -"- --""-- --""--- */ |
| 122 | static char *command_ps; /* --- "" - - "" - -"- --""-- --""--- */ |
| 123 | static const char *cmdedit_prompt;/* --- "" - - "" - -"- --""-- --""--- */ |
Eric Andersen | 8634977 | 2000-12-18 20:25:50 +0000 | [diff] [blame] | 124 | |
| 125 | /* Link into lash to reset context to 0 |
| 126 | * on ^C and such */ |
| 127 | extern unsigned int shell_context; |
| 128 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 129 | |
| 130 | struct history { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 131 | char *s; |
| 132 | struct history *p; |
| 133 | struct history *n; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 136 | static void cmdedit_setwidth(int w, int redraw_flg); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 137 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 138 | static void win_changed(int nsig) |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 139 | { |
| 140 | struct winsize win = { 0, 0, 0, 0 }; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 141 | static __sighandler_t previous_SIGWINCH_handler; /* for reset */ |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 142 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 143 | /* emulate || signal call */ |
| 144 | if(nsig == -SIGWINCH || nsig == SIGWINCH) { |
| 145 | ioctl(0, TIOCGWINSZ, &win); |
| 146 | if (win.ws_col > 0) { |
| 147 | cmdedit_setwidth( win.ws_col, nsig == SIGWINCH ); |
| 148 | } |
| 149 | } |
| 150 | /* Unix not all standart in recall signal */ |
| 151 | |
| 152 | if(nsig == -SIGWINCH) /* save previous handler */ |
| 153 | previous_SIGWINCH_handler = signal(SIGWINCH, win_changed); |
| 154 | else if(nsig == SIGWINCH) /* signaled called handler */ |
| 155 | signal(SIGWINCH, win_changed); /* set for next call */ |
| 156 | else /* set previous handler */ |
| 157 | signal(SIGWINCH, previous_SIGWINCH_handler); /* reset */ |
| 158 | } |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 159 | |
| 160 | static void cmdedit_reset_term(void) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 161 | { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 162 | if((handlers_sets & SET_RESET_TERM)!=0) { |
Erik Andersen | a6c7522 | 2000-04-18 00:00:52 +0000 | [diff] [blame] | 163 | /* sparc and other have broken termios support: use old termio handling. */ |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 164 | setTermSettings(fileno(stdin), (void*) &initial_settings); |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 165 | handlers_sets &= ~SET_RESET_TERM; |
| 166 | } |
| 167 | if((handlers_sets & SET_WCHG_HANDLERS)!=0) { |
| 168 | /* reset SIGWINCH handler to previous (default) */ |
| 169 | win_changed(0); |
| 170 | handlers_sets &= ~SET_WCHG_HANDLERS; |
| 171 | } |
| 172 | fflush(stdout); |
Eric Andersen | b040d4f | 2000-07-25 18:01:20 +0000 | [diff] [blame] | 173 | #ifdef BB_FEATURE_CLEAN_UP |
| 174 | if (his_front) { |
| 175 | struct history *n; |
| 176 | //while(his_front!=his_end) { |
| 177 | while(his_front!=his_end) { |
| 178 | n = his_front->n; |
| 179 | free(his_front->s); |
| 180 | free(his_front); |
| 181 | his_front=n; |
| 182 | } |
| 183 | } |
| 184 | #endif |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 187 | |
| 188 | |
| 189 | /* special for recount position for scroll and remove terminal margin effect */ |
| 190 | static void cmdedit_set_out_char(int c, int next_char) { |
| 191 | putchar(c); |
| 192 | if(++cmdedit_x>=cmdedit_termw) { |
| 193 | /* terminal is scrolled down */ |
| 194 | cmdedit_y++; |
| 195 | cmdedit_x=0; |
| 196 | |
| 197 | if(!next_char) |
| 198 | next_char = ' '; |
| 199 | /* destroy "(auto)margin" */ |
| 200 | putchar(next_char); |
| 201 | putchar('\b'); |
| 202 | } |
| 203 | cursor++; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 206 | /* Move to end line. Bonus: rewrite line from cursor without use |
| 207 | special control terminal strings, also saved size and speed! */ |
| 208 | static void input_end (void) { |
| 209 | while(cursor < len) |
| 210 | cmdedit_set_out_char(command_ps[cursor], 0); |
| 211 | } |
| 212 | |
| 213 | /* Go to the next line */ |
| 214 | static void goto_new_line(void) { |
| 215 | input_end(); |
| 216 | cmdedit_set_out_char('\n', 0); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | static inline void out1str(const char *s) { fputs (s, stdout); } |
| 221 | static inline void beep (void) { putchar('\007'); } |
| 222 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 223 | /* Go to HOME position */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 224 | static void input_home(void) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 225 | { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 226 | while(cmdedit_y>0) { /* up to start y */ |
| 227 | out1str("\033[A"); |
| 228 | cmdedit_y--; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 229 | } |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 230 | putchar('\r'); |
| 231 | cursor = 0; |
| 232 | out1str(cmdedit_prompt); |
| 233 | cmdedit_x = cmdedit_prmt_len; |
| 234 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 237 | /* Move back one charactor */ |
| 238 | static void input_backward(void) { |
| 239 | if (cursor > 0) { |
| 240 | cursor--; |
| 241 | if(cmdedit_x!=0) { /* no first position in terminal line */ |
| 242 | putchar('\b'); |
| 243 | cmdedit_x--; |
| 244 | } |
| 245 | else { |
| 246 | out1str("\033[A"); /* up */ |
| 247 | cmdedit_y--; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 248 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 249 | /* to end in current terminal line */ |
| 250 | while(cmdedit_x<(cmdedit_termw-1)) { |
| 251 | out1str("\033[C"); |
| 252 | cmdedit_x++; |
| 253 | } |
| 254 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 255 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 258 | /* Delete the char in front of the cursor */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 259 | static void input_delete(void) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 260 | { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 261 | int j = cursor; |
Erik Andersen | a268573 | 2000-04-09 18:27:46 +0000 | [diff] [blame] | 262 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 263 | if (j == len) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 264 | return; |
| 265 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 266 | memmove (command_ps + j, command_ps + j + 1, BUFSIZ - j - 1); |
| 267 | len--; |
| 268 | input_end(); /* rewtite new line */ |
| 269 | cmdedit_set_out_char(' ', 0); /* destroy end char */ |
| 270 | while (j < cursor) |
| 271 | input_backward(); /* back to old pos cursor */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 274 | /* Delete the char in back of the cursor */ |
| 275 | static void input_backspace(void) |
| 276 | { |
| 277 | if (cursor > 0) { |
| 278 | input_backward(); |
| 279 | input_delete (); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 284 | /* Move forward one charactor */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 285 | static void input_forward(void) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 286 | { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 287 | if (cursor < len) |
| 288 | cmdedit_set_out_char(command_ps[cursor], command_ps[cursor + 1]); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 292 | static void clean_up_and_die(int sig) |
| 293 | { |
| 294 | goto_new_line(); |
| 295 | if (sig!=SIGINT) |
| 296 | exit(EXIT_SUCCESS); /* cmdedit_reset_term() called in atexit */ |
| 297 | cmdedit_reset_term(); |
| 298 | } |
| 299 | |
| 300 | static void cmdedit_setwidth(int w, int redraw_flg) |
| 301 | { |
| 302 | cmdedit_termw = cmdedit_prmt_len+2; |
| 303 | if (w > cmdedit_termw) { |
| 304 | |
| 305 | cmdedit_termw = w; |
| 306 | |
| 307 | if(redraw_flg) { |
| 308 | int sav_cursor = cursor; |
| 309 | |
| 310 | /* set variables for new terminal size */ |
| 311 | cmdedit_y = sav_cursor/w; |
| 312 | cmdedit_x = sav_cursor-cmdedit_y*w; |
| 313 | |
| 314 | /* redraw */ |
| 315 | input_home(); |
| 316 | input_end(); |
| 317 | while(sav_cursor<cursor) |
| 318 | input_backward(); |
| 319 | } |
| 320 | } else { |
| 321 | error_msg("\n*** Error: minimum screen width is %d\n", cmdedit_termw); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | extern void cmdedit_init(void) |
| 326 | { |
| 327 | if((handlers_sets & SET_WCHG_HANDLERS)==0) { |
| 328 | /* emulate usage handler to set handler and call yours work */ |
| 329 | win_changed(-SIGWINCH); |
| 330 | handlers_sets |= SET_WCHG_HANDLERS; |
| 331 | } |
| 332 | |
| 333 | if((handlers_sets & SET_ATEXIT)==0) { |
| 334 | atexit(cmdedit_reset_term); /* be sure to do this only once */ |
| 335 | handlers_sets |= SET_ATEXIT; |
| 336 | } |
| 337 | if((handlers_sets & SET_TERM_HANDLERS)==0) { |
| 338 | signal(SIGKILL, clean_up_and_die); |
| 339 | signal(SIGINT, clean_up_and_die); |
| 340 | signal(SIGQUIT, clean_up_and_die); |
| 341 | signal(SIGTERM, clean_up_and_die); |
| 342 | handlers_sets |= SET_TERM_HANDLERS; |
| 343 | } |
| 344 | } |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 345 | |
| 346 | #ifdef BB_FEATURE_SH_TAB_COMPLETION |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 347 | |
| 348 | #ifdef BB_FEATURE_USERNAME_COMPLETION |
| 349 | static char** username_tab_completion(char *ud, int *num_matches) |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 350 | { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 351 | static struct passwd *entry; |
| 352 | int userlen; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 353 | char **matches = (char **) NULL; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 354 | char *temp; |
| 355 | int nm = 0; |
| 356 | |
| 357 | setpwent (); |
| 358 | userlen = strlen (ud + 1); |
| 359 | |
| 360 | while ((entry = getpwent ()) != NULL) { |
| 361 | /* Null usernames should result in all users as possible completions. */ |
| 362 | if (!userlen || !strncmp (ud + 1, entry->pw_name, userlen)) { |
| 363 | |
| 364 | temp = xmalloc (3 + strlen (entry->pw_name)); |
| 365 | sprintf(temp, "~%s/", entry->pw_name); |
| 366 | |
| 367 | matches = xrealloc(matches, (nm+1)*sizeof(char *)); |
| 368 | matches[nm++] = temp; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | endpwent (); |
| 373 | (*num_matches) = nm; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 374 | return (matches); |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 375 | } |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 376 | #endif |
| 377 | |
| 378 | enum { |
| 379 | FIND_EXE_ONLY = 0, |
| 380 | FIND_DIR_ONLY = 1, |
| 381 | FIND_FILE_ONLY = 2, |
| 382 | }; |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 383 | |
| 384 | #include <dirent.h> |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 385 | |
| 386 | static int path_parse(char ***p, int flags) |
| 387 | { |
| 388 | int npth; |
| 389 | char *tmp; |
| 390 | char *pth; |
| 391 | |
| 392 | if(flags!=FIND_EXE_ONLY || (pth=getenv("PATH"))==0) { |
| 393 | /* if not setenv PATH variable, to search cur dir "." */ |
| 394 | (*p) = xmalloc(sizeof(char *)); |
| 395 | (*p)[0] = xstrdup("."); |
| 396 | return 1; |
| 397 | } |
| 398 | |
| 399 | tmp = pth; |
| 400 | npth=0; |
| 401 | |
| 402 | for(;;) { |
| 403 | npth++; /* count words is + 1 count ':' */ |
| 404 | tmp = strchr(tmp, ':'); |
| 405 | if(tmp) |
| 406 | tmp++; |
| 407 | else |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | *p = xmalloc(npth*sizeof(char *)); |
| 412 | |
| 413 | tmp = pth; |
| 414 | (*p)[0] = xstrdup(tmp); |
| 415 | npth=1; /* count words is + 1 count ':' */ |
| 416 | |
| 417 | for(;;) { |
| 418 | tmp = strchr(tmp, ':'); |
| 419 | if(tmp) { |
| 420 | (*p)[0][(tmp-pth)]=0; /* ':' -> '\0'*/ |
| 421 | tmp++; |
| 422 | } else |
| 423 | break; |
| 424 | (*p)[npth++] = &(*p)[0][(tmp-pth)]; /* p[next]=p[0][&'\0'+1] */ |
| 425 | } |
| 426 | |
| 427 | return npth; |
| 428 | } |
| 429 | |
| 430 | static char** exe_n_cwd_tab_completion(char* command, int *num_matches, int type) |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 431 | { |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 432 | char *dirName; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 433 | char **matches = 0; |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 434 | DIR *dir; |
| 435 | struct dirent *next; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 436 | char cmd [BUFSIZ+4]; |
| 437 | char *dirbuf; |
| 438 | char found [BUFSIZ+4]; |
| 439 | int nm = *num_matches; |
| 440 | struct stat st; |
| 441 | char **paths; |
| 442 | int npaths; |
| 443 | int i; |
| 444 | char full_pth[BUFSIZ+4+PATH_MAX]; |
| 445 | |
| 446 | |
| 447 | strcpy(cmd, command); /* save for change (last '/' to '\0') */ |
| 448 | |
| 449 | dirName = strrchr(cmd, '/'); |
| 450 | if(dirName==NULL) { |
| 451 | /* no dir, if flags==EXE_ONLY - get paths, else "." */ |
| 452 | npaths = path_parse(&paths, type); |
| 453 | if(npaths==0) |
| 454 | return 0; |
| 455 | } else { |
| 456 | /* with dir */ |
| 457 | |
| 458 | /* save dir */ |
| 459 | dirbuf = xstrdup(cmd); |
| 460 | /* set only dirname */ |
| 461 | dirbuf[(dirName-cmd)+1]=0; |
| 462 | |
| 463 | /* strip dirname in cmd */ |
| 464 | strcpy(cmd, dirName+1); |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 465 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 466 | paths = xmalloc(sizeof(char*)); |
| 467 | paths[0] = dirbuf; |
| 468 | npaths = 1; /* only 1 dir */ |
| 469 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 470 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 471 | for(i=0; i < npaths; i++) { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 472 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 473 | dir = opendir(paths[i]); |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 474 | if (!dir) { |
| 475 | /* Don't print an error, just shut up and return */ |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 476 | return (matches); |
| 477 | } |
| 478 | while ((next = readdir(dir)) != NULL) { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 479 | /* matched ? */ |
| 480 | if(strncmp(next->d_name, cmd, strlen(cmd))) |
| 481 | continue; |
| 482 | /* not see .name without .match */ |
| 483 | if(*next->d_name == '.' && *cmd != '.') |
| 484 | continue; |
| 485 | sprintf(full_pth, "%s/%s", paths[i], next->d_name); |
| 486 | /* hmm, remover in progress? */ |
| 487 | if(stat(full_pth, &st)<0) |
| 488 | continue; |
| 489 | /* Cool, found a match. */ |
| 490 | if (S_ISDIR(st.st_mode)) { |
| 491 | /* name is directory */ |
| 492 | strcpy(found, next->d_name); |
| 493 | strcat(found, "/"); |
| 494 | if(type==FIND_DIR_ONLY) |
| 495 | strcat(found, " "); |
| 496 | } else { |
| 497 | /* not put found file if search only dirs for cd */ |
| 498 | if(type==FIND_DIR_ONLY) |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 499 | continue; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 500 | strcpy(found, next->d_name); |
| 501 | strcat(found, " "); |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 502 | } |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 503 | /* Add it to the list */ |
| 504 | matches = xrealloc(matches, (nm+1)*sizeof(char *)); |
| 505 | matches[nm++] = xstrdup(found); |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 508 | free(paths[0]); /* allocate memory only in first member */ |
| 509 | free(paths); |
| 510 | *num_matches = nm; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 511 | return (matches); |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 512 | } |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 513 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 514 | static void input_tab(int lastWasTab) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 515 | { |
| 516 | /* Do TAB completion */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 517 | static int num_matches; |
| 518 | static char **matches; |
| 519 | |
| 520 | char matchBuf[BUFSIZ]; |
| 521 | |
| 522 | int pos = cursor; |
| 523 | int find_type=FIND_FILE_ONLY; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 524 | |
| 525 | |
| 526 | if (lastWasTab == FALSE) { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 527 | char *tmp, *tmp1; |
| 528 | int len_found; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 529 | |
| 530 | /* For now, we will not bother with trying to distinguish |
| 531 | * whether the cursor is in/at a command extression -- we |
Eric Andersen | 74c66ad | 2000-06-16 19:57:44 +0000 | [diff] [blame] | 532 | * will always try all possible matches. If you don't like |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 533 | * that then feel free to fix it. |
| 534 | */ |
| 535 | |
| 536 | /* Make a local copy of the string -- up |
| 537 | * to the position of the cursor */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 538 | memset(matchBuf, 0, BUFSIZ); |
| 539 | tmp = strncpy(matchBuf, command_ps, cursor); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 540 | |
| 541 | /* skip past any command seperator tokens */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 542 | while ( (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) { |
| 543 | tmp = ++tmp1; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* skip any leading white space */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 547 | while (*tmp == ' ') |
| 548 | tmp++; |
| 549 | |
| 550 | if(strncmp(tmp, "cd ", 3)==0) |
| 551 | find_type = FIND_DIR_ONLY; |
| 552 | else if(strchr(tmp, ' ')==NULL) |
| 553 | find_type = FIND_EXE_ONLY; |
| 554 | |
| 555 | /* find begin curent word */ |
| 556 | if( (tmp1=strrchr(tmp, ' ')) != NULL) { |
| 557 | tmp = ++tmp1; |
| 558 | } |
| 559 | strcpy(matchBuf, tmp); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 560 | |
| 561 | /* Free up any memory already allocated */ |
| 562 | if (matches) { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 563 | while(num_matches>0) |
| 564 | free(matches[--num_matches]); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 565 | free(matches); |
| 566 | matches = (char **) NULL; |
| 567 | } |
| 568 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 569 | #ifdef BB_FEATURE_USERNAME_COMPLETION |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 570 | /* If the word starts with `~' and there is no slash in the word, |
| 571 | * then try completing this word as a username. */ |
| 572 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 573 | if (matchBuf[0]=='~' && strchr(matchBuf, '/')==0) { |
| 574 | matches = username_tab_completion(matchBuf, &num_matches); |
| 575 | } |
| 576 | #endif |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 577 | /* Try to match any executable in our path and everything |
| 578 | * in the current working directory that matches. */ |
| 579 | if (!matches) |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 580 | matches = exe_n_cwd_tab_completion(matchBuf, &num_matches, find_type); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 581 | |
| 582 | /* Did we find exactly one match? */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 583 | if(!matches || num_matches>1) { |
| 584 | beep(); |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | len_found = strlen(matches[0]); |
| 589 | |
| 590 | /* have space to placed match? */ |
| 591 | if ( (len_found-strlen(matchBuf)+len) < BUFSIZ ) { |
| 592 | |
| 593 | int recalc_pos = len; |
| 594 | |
| 595 | /* before word for match */ |
| 596 | command_ps[pos-strlen(matchBuf)]=0; |
| 597 | |
| 598 | /* tail line */ |
| 599 | strcpy(matchBuf, command_ps+pos); |
| 600 | |
| 601 | /* add match */ |
| 602 | strcat(command_ps, matches[0]); |
| 603 | /* add tail */ |
| 604 | strcat(command_ps, matchBuf); |
| 605 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 606 | /* write out the matched command */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 607 | len=strlen(command_ps); |
| 608 | recalc_pos = len-recalc_pos+pos; |
| 609 | input_end(); /* write */ |
| 610 | while(recalc_pos<cursor) |
| 611 | input_backward(); |
Eric Andersen | a75466e | 2000-11-02 17:02:26 +0000 | [diff] [blame] | 612 | return; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 613 | } |
| 614 | } else { |
| 615 | /* Ok -- the last char was a TAB. Since they |
| 616 | * just hit TAB again, print a list of all the |
| 617 | * available choices... */ |
| 618 | if ( matches && num_matches>0 ) { |
| 619 | int i, col; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 620 | int sav_cursor = cursor; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 621 | |
| 622 | /* Go to the next line */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 623 | goto_new_line(); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 624 | for (i=0,col=0; i<num_matches; i++) { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 625 | printf("%s ", matches[i]); |
| 626 | col += strlen(matches[i])+2; |
| 627 | col -= (col/cmdedit_termw)*cmdedit_termw; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 628 | if (col > 60 && matches[i+1] != NULL) { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 629 | putchar('\n'); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 630 | col = 0; |
| 631 | } |
| 632 | } |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 633 | /* Go to the next line and rewrite the prompt */ |
| 634 | printf("\n%s", cmdedit_prompt); |
| 635 | cmdedit_x = cmdedit_prmt_len; |
| 636 | cmdedit_y = 0; |
| 637 | cursor = 0; |
| 638 | input_end(); /* Rewrite the command */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 639 | /* Put the cursor back to where it used to be */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 640 | while (sav_cursor < cursor) |
| 641 | input_backward(); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | } |
| 645 | #endif |
| 646 | |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 647 | static void get_previous_history(struct history **hp, char* command) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 648 | { |
Eric Andersen | 91a4400 | 2000-07-19 17:37:57 +0000 | [diff] [blame] | 649 | if ((*hp)->s) |
| 650 | free((*hp)->s); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 651 | (*hp)->s = strdup(command); |
| 652 | *hp = (*hp)->p; |
| 653 | } |
| 654 | |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 655 | static void get_next_history(struct history **hp, char* command) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 656 | { |
Eric Andersen | 91a4400 | 2000-07-19 17:37:57 +0000 | [diff] [blame] | 657 | if ((*hp)->s) |
| 658 | free((*hp)->s); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 659 | (*hp)->s = strdup(command); |
| 660 | *hp = (*hp)->n; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 663 | /* |
| 664 | * This function is used to grab a character buffer |
| 665 | * from the input file descriptor and allows you to |
| 666 | * a string with full command editing (sortof like |
| 667 | * a mini readline). |
| 668 | * |
| 669 | * The following standard commands are not implemented: |
| 670 | * ESC-b -- Move back one word |
| 671 | * ESC-f -- Move forward one word |
| 672 | * ESC-d -- Delete back one word |
| 673 | * ESC-h -- Delete forward one word |
| 674 | * CTL-t -- Transpose two characters |
| 675 | * |
| 676 | * Furthermore, the "vi" command editing keys are not implemented. |
| 677 | * |
| 678 | * TODO: implement TAB command completion. :) |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 679 | */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 680 | extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 681 | { |
| 682 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 683 | int inputFd=fileno(stdin); |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 684 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 685 | int j = 0; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 686 | int break_out = 0; |
| 687 | int ret = 0; |
| 688 | int lastWasTab = FALSE; |
| 689 | char c = 0; |
| 690 | struct history *hp = his_end; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 691 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 692 | len = 0; |
| 693 | cursor = 0; |
| 694 | command_ps = command; |
| 695 | |
| 696 | if (new_settings.c_cc[VMIN]==0) { |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 697 | |
| 698 | getTermSettings(inputFd, (void*) &initial_settings); |
| 699 | memcpy(&new_settings, &initial_settings, sizeof(struct termios)); |
| 700 | new_settings.c_cc[VMIN] = 1; |
| 701 | new_settings.c_cc[VTIME] = 0; |
| 702 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; /* Turn off CTRL-C, so we can trap it */ |
| 703 | new_settings.c_lflag &= ~ICANON; /* unbuffered input */ |
| 704 | new_settings.c_lflag &= ~(ECHO|ECHOCTL|ECHONL); /* Turn off echoing */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 705 | } |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 706 | setTermSettings(inputFd, (void*) &new_settings); |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 707 | handlers_sets |= SET_RESET_TERM; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 708 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 709 | memset(command, 0, BUFSIZ); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 710 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 711 | cmdedit_init(); |
| 712 | |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 713 | /* Print out the command prompt */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 714 | cmdedit_prompt = prompt; |
| 715 | cmdedit_prmt_len = strlen(prompt); |
| 716 | printf("%s", prompt); |
| 717 | cmdedit_x = cmdedit_prmt_len; /* count real x terminal position */ |
| 718 | cmdedit_y = 0; /* quasireal y, not true work if line > xt*yt */ |
| 719 | |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 720 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 721 | while (1) { |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 722 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 723 | fflush(stdout); /* buffered out to fast */ |
| 724 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 725 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 726 | return; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 727 | //fprintf(stderr, "got a '%c' (%d)\n", c, c); |
Erik Andersen | f3b3d17 | 2000-04-09 18:24:05 +0000 | [diff] [blame] | 728 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 729 | switch (c) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 730 | case '\n': |
| 731 | case '\r': |
| 732 | /* Enter */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 733 | *(command + len) = c; |
| 734 | len++; |
| 735 | input_end (); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 736 | break_out = 1; |
| 737 | break; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 738 | case 1: |
| 739 | /* Control-a -- Beginning of line */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 740 | input_home(); |
| 741 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 742 | case 2: |
| 743 | /* Control-b -- Move back one character */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 744 | input_backward(); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 745 | break; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 746 | case 3: |
Eric Andersen | 8634977 | 2000-12-18 20:25:50 +0000 | [diff] [blame] | 747 | /* Control-c -- stop gathering input */ |
| 748 | |
| 749 | /* Link into lash to reset context to 0 on ^C and such */ |
| 750 | shell_context = 0; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 751 | |
| 752 | /* Go to the next line */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 753 | goto_new_line(); |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 754 | |
Eric Andersen | 8634977 | 2000-12-18 20:25:50 +0000 | [diff] [blame] | 755 | #if 0 |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 756 | /* Rewrite the prompt */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 757 | printf("%s", prompt); |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 758 | |
| 759 | /* Reset the command string */ |
Eric Andersen | 4ac6cb5 | 2000-07-14 01:13:37 +0000 | [diff] [blame] | 760 | memset(command, 0, BUFSIZ); |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 761 | len = cursor = 0; |
Eric Andersen | 8634977 | 2000-12-18 20:25:50 +0000 | [diff] [blame] | 762 | #endif |
| 763 | return; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 764 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 765 | case 4: |
| 766 | /* Control-d -- Delete one character, or exit |
| 767 | * if the len=0 and no chars to delete */ |
| 768 | if (len == 0) { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 769 | printf("exit"); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 770 | clean_up_and_die(0); |
| 771 | } else { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 772 | input_delete(); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 773 | } |
| 774 | break; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 775 | case 5: |
| 776 | /* Control-e -- End of line */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 777 | input_end(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 778 | break; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 779 | case 6: |
| 780 | /* Control-f -- Move forward one character */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 781 | input_forward(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 782 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 783 | case '\b': |
| 784 | case DEL: |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 785 | /* Control-h and DEL */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 786 | input_backspace(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 787 | break; |
| 788 | case '\t': |
Erik Andersen | a268573 | 2000-04-09 18:27:46 +0000 | [diff] [blame] | 789 | #ifdef BB_FEATURE_SH_TAB_COMPLETION |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 790 | input_tab(lastWasTab); |
Erik Andersen | a268573 | 2000-04-09 18:27:46 +0000 | [diff] [blame] | 791 | #endif |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 792 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 793 | case 14: |
| 794 | /* Control-n -- Get next command in history */ |
| 795 | if (hp && hp->n && hp->n->s) { |
| 796 | get_next_history(&hp, command); |
| 797 | goto rewrite_line; |
| 798 | } else { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 799 | beep(); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 800 | } |
| 801 | break; |
| 802 | case 16: |
| 803 | /* Control-p -- Get previous command from history */ |
| 804 | if (hp && hp->p) { |
| 805 | get_previous_history(&hp, command); |
| 806 | goto rewrite_line; |
| 807 | } else { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 808 | beep(); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 809 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 810 | break; |
| 811 | case ESC:{ |
| 812 | /* escape sequence follows */ |
| 813 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 814 | return; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 815 | |
| 816 | if (c == '[') { /* 91 */ |
| 817 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 818 | return; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 819 | |
| 820 | switch (c) { |
| 821 | case 'A': |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 822 | /* Up Arrow -- Get previous command from history */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 823 | if (hp && hp->p) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 824 | get_previous_history(&hp, command); |
| 825 | goto rewrite_line; |
| 826 | } else { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 827 | beep(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 828 | } |
| 829 | break; |
| 830 | case 'B': |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 831 | /* Down Arrow -- Get next command in history */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 832 | if (hp && hp->n && hp->n->s) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 833 | get_next_history(&hp, command); |
| 834 | goto rewrite_line; |
| 835 | } else { |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 836 | beep(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 837 | } |
| 838 | break; |
| 839 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 840 | /* Rewrite the line with the selected history item */ |
| 841 | rewrite_line: |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 842 | /* return to begin of line */ |
| 843 | input_home (); |
| 844 | /* for next memmoves without set '\0' */ |
| 845 | memset (command, 0, BUFSIZ); |
| 846 | /* change command */ |
| 847 | strcpy (command, hp->s); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 848 | /* write new command */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 849 | for (j=0; command[j]; j++) |
| 850 | cmdedit_set_out_char(command[j], 0); |
| 851 | ret = cursor; |
| 852 | /* erase tail if required */ |
| 853 | for (j = ret; j < len; j++) |
| 854 | cmdedit_set_out_char(' ', 0); |
| 855 | /* and backward cursor */ |
| 856 | for (j = ret; j < len; j++) |
| 857 | input_backward(); |
| 858 | len = cursor; /* set new len */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 859 | break; |
| 860 | case 'C': |
| 861 | /* Right Arrow -- Move forward one character */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 862 | input_forward(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 863 | break; |
| 864 | case 'D': |
| 865 | /* Left Arrow -- Move back one character */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 866 | input_backward(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 867 | break; |
| 868 | case '3': |
| 869 | /* Delete */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 870 | input_delete(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 871 | break; |
| 872 | case '1': |
| 873 | /* Home (Ctrl-A) */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 874 | input_home(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 875 | break; |
| 876 | case '4': |
| 877 | /* End (Ctrl-E) */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 878 | input_end(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 879 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 880 | default: |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 881 | beep(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 882 | } |
| 883 | if (c == '1' || c == '3' || c == '4') |
| 884 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 885 | return; /* read 126 (~) */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 886 | } |
| 887 | if (c == 'O') { |
| 888 | /* 79 */ |
| 889 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 890 | return; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 891 | switch (c) { |
| 892 | case 'H': |
| 893 | /* Home (xterm) */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 894 | input_home(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 895 | break; |
| 896 | case 'F': |
| 897 | /* End (xterm) */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 898 | input_end(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 899 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 900 | default: |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 901 | beep(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | c = 0; |
| 905 | break; |
| 906 | } |
| 907 | |
| 908 | default: /* If it's regular input, do the normal thing */ |
| 909 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 910 | if (!isprint(c)) { /* Skip non-printable characters */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 911 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 912 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 913 | |
| 914 | if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */ |
| 915 | break; |
| 916 | |
| 917 | len++; |
| 918 | |
| 919 | if (cursor == (len - 1)) { /* Append if at the end of the line */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 920 | *(command + cursor) = c; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 921 | cmdedit_set_out_char(c, command[cursor+1]); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 922 | } else { /* Insert otherwise */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 923 | memmove(command + cursor + 1, command + cursor, |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 924 | len - cursor - 1); |
| 925 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 926 | *(command + cursor) = c; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 927 | j = cursor+1; |
| 928 | /* rewrite from cursor */ |
| 929 | input_end (); |
| 930 | /* to prev x pos + 1 */ |
| 931 | while(cursor > j) |
| 932 | input_backward(); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 935 | break; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 936 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 937 | if (c == '\t') |
| 938 | lastWasTab = TRUE; |
| 939 | else |
| 940 | lastWasTab = FALSE; |
| 941 | |
| 942 | if (break_out) /* Enter is the command terminator, no more input. */ |
| 943 | break; |
| 944 | } |
| 945 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 946 | setTermSettings (inputFd, (void *) &initial_settings); |
| 947 | handlers_sets &= ~SET_RESET_TERM; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 948 | |
| 949 | /* Handle command history log */ |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 950 | if (len>1) { /* no put empty line (only '\n') */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 951 | |
| 952 | struct history *h = his_end; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 953 | char *ss; |
| 954 | |
| 955 | command[len-1] = 0; /* destroy end '\n' */ |
| 956 | ss = strdup(command); /* duplicate without '\n' */ |
| 957 | command[len-1] = '\n'; /* restore '\n' */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 958 | |
| 959 | if (!h) { |
Eric Andersen | 91a4400 | 2000-07-19 17:37:57 +0000 | [diff] [blame] | 960 | /* No previous history -- this memory is never freed */ |
Matt Kraai | 322ae93 | 2000-09-13 02:46:14 +0000 | [diff] [blame] | 961 | h = his_front = xmalloc(sizeof(struct history)); |
| 962 | h->n = xmalloc(sizeof(struct history)); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 963 | |
| 964 | h->p = NULL; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 965 | h->s = ss; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 966 | h->n->p = h; |
| 967 | h->n->n = NULL; |
| 968 | h->n->s = NULL; |
| 969 | his_end = h->n; |
| 970 | history_counter++; |
| 971 | } else { |
Eric Andersen | 91a4400 | 2000-07-19 17:37:57 +0000 | [diff] [blame] | 972 | /* Add a new history command -- this memory is never freed */ |
Matt Kraai | 322ae93 | 2000-09-13 02:46:14 +0000 | [diff] [blame] | 973 | h->n = xmalloc(sizeof(struct history)); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 974 | |
| 975 | h->n->p = h; |
| 976 | h->n->n = NULL; |
| 977 | h->n->s = NULL; |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 978 | h->s = ss; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 979 | his_end = h->n; |
| 980 | |
| 981 | /* After max history, remove the oldest command */ |
| 982 | if (history_counter >= MAX_HISTORY) { |
| 983 | |
| 984 | struct history *p = his_front->n; |
| 985 | |
| 986 | p->p = NULL; |
| 987 | free(his_front->s); |
| 988 | free(his_front); |
| 989 | his_front = p; |
| 990 | } else { |
| 991 | history_counter++; |
| 992 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 993 | } |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 994 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 995 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 996 | return; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Eric Andersen | b3dc3b8 | 2001-01-04 11:08:45 +0000 | [diff] [blame] | 999 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 1000 | /* Undo the effects of cmdedit_init(). */ |
Eric Andersen | 501c88b | 2000-07-28 15:14:45 +0000 | [diff] [blame] | 1001 | extern void cmdedit_terminate(void) |
| 1002 | { |
| 1003 | cmdedit_reset_term(); |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 1004 | if((handlers_sets & SET_TERM_HANDLERS)!=0) { |
| 1005 | signal(SIGKILL, SIG_DFL); |
| 1006 | signal(SIGINT, SIG_DFL); |
| 1007 | signal(SIGQUIT, SIG_DFL); |
| 1008 | signal(SIGTERM, SIG_DFL); |
| 1009 | signal(SIGWINCH, SIG_DFL); |
| 1010 | handlers_sets &= ~SET_TERM_HANDLERS; |
| 1011 | } |
Eric Andersen | 501c88b | 2000-07-28 15:14:45 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | |
Mark Whitley | 4e33875 | 2001-01-26 20:42:23 +0000 | [diff] [blame^] | 1016 | #endif /* BB_FEATURE_SH_COMMAND_EDITING */ |