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. |
| 28 | Ctrl-E also works as End. The binary size increase is <3K. |
| 29 | |
| 30 | Editting will not display correctly for lines greater then the |
| 31 | terminal width. (more then one line.) However, history will. |
| 32 | */ |
| 33 | |
| 34 | #include "internal.h" |
| 35 | #ifdef BB_FEATURE_SH_COMMAND_EDITING |
| 36 | |
| 37 | #include <stdio.h> |
| 38 | #include <errno.h> |
| 39 | #include <unistd.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 42 | #include <sys/ioctl.h> |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 43 | #include <ctype.h> |
| 44 | #include <signal.h> |
| 45 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 46 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 47 | #define 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] | 48 | |
| 49 | #define ESC 27 |
| 50 | #define DEL 127 |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 51 | #define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0) |
| 52 | #define whitespace(c) (((c) == ' ') || ((c) == '\t')) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 53 | |
| 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 */ |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 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; |
Erik Andersen | 8ea7d8c | 2000-05-20 00:40:08 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | #ifndef _POSIX_VDISABLE |
| 76 | #define _POSIX_VDISABLE '\0' |
| 77 | #endif |
| 78 | |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
| 81 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 82 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 83 | static int cmdedit_termw = 80; /* actual terminal width */ |
| 84 | static int cmdedit_scroll = 27; /* width of EOL scrolling region */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 85 | static int history_counter = 0; /* Number of commands in history list */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 86 | static int reset_term = 0; /* Set to true if the terminal needs to be reset upon exit */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 87 | |
| 88 | struct history { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 89 | char *s; |
| 90 | struct history *p; |
| 91 | struct history *n; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 94 | #define xwrite write |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 95 | |
Mark Whitley | 5538070 | 2000-07-13 17:20:23 +0000 | [diff] [blame^] | 96 | /* |
| 97 | * TODO: Someday we want to implement 'horizontal scrolling' of the |
| 98 | * command-line when the user has typed more than the current width. This |
| 99 | * would allow the user to see a 'window' of what he has typed. |
| 100 | */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 101 | void |
| 102 | cmdedit_setwidth(int w) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 103 | { |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 104 | if (w > 20) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 105 | cmdedit_termw = w; |
| 106 | cmdedit_scroll = w / 3; |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 107 | } else { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 108 | errorMsg("\n*** Error: minimum screen width is 21\n"); |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 109 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 112 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 113 | void cmdedit_reset_term(void) |
| 114 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 115 | if (reset_term) |
Erik Andersen | a6c7522 | 2000-04-18 00:00:52 +0000 | [diff] [blame] | 116 | /* sparc and other have broken termios support: use old termio handling. */ |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 117 | setTermSettings(fileno(stdin), (void*) &initial_settings); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 120 | void clean_up_and_die(int sig) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 121 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 122 | cmdedit_reset_term(); |
| 123 | fprintf(stdout, "\n"); |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 124 | if (sig!=SIGINT) |
| 125 | exit(TRUE); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 128 | /* Go to HOME position */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 129 | void input_home(int outputFd, int *cursor) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 130 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 131 | while (*cursor > 0) { |
| 132 | xwrite(outputFd, "\b", 1); |
| 133 | --*cursor; |
| 134 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 137 | /* Go to END position */ |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 138 | void input_end(int outputFd, int *cursor, int len) |
| 139 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 140 | while (*cursor < len) { |
| 141 | xwrite(outputFd, "\033[C", 3); |
| 142 | ++*cursor; |
| 143 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 146 | /* Delete the char in back of the cursor */ |
| 147 | void input_backspace(char* command, int outputFd, int *cursor, int *len) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 148 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 149 | int j = 0; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 150 | |
Eric Andersen | 72965e3 | 2000-07-04 06:22:18 +0000 | [diff] [blame] | 151 | /* Debug crap */ |
| 152 | //fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command)); |
| 153 | //xwrite(outputFd, command, *len); |
| 154 | //*cursor = *len; |
| 155 | |
| 156 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 157 | if (*cursor > 0) { |
| 158 | xwrite(outputFd, "\b \b", 3); |
| 159 | --*cursor; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 160 | memmove(command + *cursor, command + *cursor + 1, |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 161 | BUFSIZ - *cursor + 1); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 162 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 163 | for (j = *cursor; j < (BUFSIZ - 1); j++) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 164 | if (!*(command + j)) |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 165 | break; |
| 166 | else |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 167 | xwrite(outputFd, (command + j), 1); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | xwrite(outputFd, " \b", 2); |
| 171 | |
| 172 | while (j-- > *cursor) |
| 173 | xwrite(outputFd, "\b", 1); |
| 174 | |
| 175 | --*len; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 176 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 179 | /* Delete the char in front of the cursor */ |
| 180 | void input_delete(char* command, int outputFd, int cursor, int *len) |
| 181 | { |
| 182 | int j = 0; |
Erik Andersen | a268573 | 2000-04-09 18:27:46 +0000 | [diff] [blame] | 183 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 184 | if (cursor == *len) |
| 185 | return; |
| 186 | |
| 187 | memmove(command + cursor, command + cursor + 1, |
| 188 | BUFSIZ - cursor - 1); |
| 189 | for (j = cursor; j < (BUFSIZ - 1); j++) { |
| 190 | if (!*(command + j)) |
| 191 | break; |
| 192 | else |
| 193 | xwrite(outputFd, (command + j), 1); |
| 194 | } |
| 195 | |
| 196 | xwrite(outputFd, " \b", 2); |
| 197 | |
| 198 | while (j-- > cursor) |
| 199 | xwrite(outputFd, "\b", 1); |
| 200 | --*len; |
| 201 | } |
| 202 | |
| 203 | /* Move forward one charactor */ |
| 204 | void input_forward(int outputFd, int *cursor, int len) |
| 205 | { |
| 206 | if (*cursor < len) { |
| 207 | xwrite(outputFd, "\033[C", 3); |
| 208 | ++*cursor; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* Move back one charactor */ |
| 213 | void input_backward(int outputFd, int *cursor) |
| 214 | { |
| 215 | if (*cursor > 0) { |
| 216 | xwrite(outputFd, "\033[D", 3); |
| 217 | --*cursor; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | |
| 222 | |
| 223 | #ifdef BB_FEATURE_SH_TAB_COMPLETION |
| 224 | char** username_tab_completion(char* command, int *num_matches) |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 225 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 226 | char **matches = (char **) NULL; |
| 227 | *num_matches=0; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 228 | fprintf(stderr, "\nin username_tab_completion\n"); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 229 | return (matches); |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 230 | } |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 231 | |
| 232 | #include <dirent.h> |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 233 | char** exe_n_cwd_tab_completion(char* command, int *num_matches) |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 234 | { |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 235 | char *dirName; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 236 | char **matches = (char **) NULL; |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 237 | DIR *dir; |
| 238 | struct dirent *next; |
| 239 | |
| 240 | matches = malloc( sizeof(char*)*50); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 241 | |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 242 | /* Stick a wildcard onto the command, for later use */ |
| 243 | strcat( command, "*"); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 244 | |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 245 | /* Now wall the current directory */ |
| 246 | dirName = get_current_dir_name(); |
| 247 | dir = opendir(dirName); |
| 248 | if (!dir) { |
| 249 | /* Don't print an error, just shut up and return */ |
| 250 | *num_matches=0; |
| 251 | return (matches); |
| 252 | } |
| 253 | while ((next = readdir(dir)) != NULL) { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 254 | |
Erik Andersen | 1dbe340 | 2000-03-19 10:46:06 +0000 | [diff] [blame] | 255 | /* Some quick sanity checks */ |
| 256 | if ((strcmp(next->d_name, "..") == 0) |
| 257 | || (strcmp(next->d_name, ".") == 0)) { |
| 258 | continue; |
| 259 | } |
| 260 | /* See if this matches */ |
| 261 | if (check_wildcard_match(next->d_name, command) == TRUE) { |
| 262 | /* Cool, found a match. Add it to the list */ |
| 263 | matches[*num_matches] = malloc(strlen(next->d_name)+1); |
| 264 | strcpy( matches[*num_matches], next->d_name); |
| 265 | ++*num_matches; |
| 266 | //matches = realloc( matches, sizeof(char*)*(*num_matches)); |
| 267 | } |
| 268 | } |
| 269 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 270 | return (matches); |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 271 | } |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 272 | |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 273 | void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 274 | { |
| 275 | /* Do TAB completion */ |
| 276 | static int num_matches=0; |
| 277 | static char **matches = (char **) NULL; |
| 278 | int pos = cursor; |
| 279 | |
| 280 | |
| 281 | if (lastWasTab == FALSE) { |
| 282 | char *tmp, *tmp1, *matchBuf; |
| 283 | |
| 284 | /* For now, we will not bother with trying to distinguish |
| 285 | * whether the cursor is in/at a command extression -- we |
Eric Andersen | 74c66ad | 2000-06-16 19:57:44 +0000 | [diff] [blame] | 286 | * will always try all possible matches. If you don't like |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 287 | * that then feel free to fix it. |
| 288 | */ |
| 289 | |
| 290 | /* Make a local copy of the string -- up |
| 291 | * to the position of the cursor */ |
| 292 | matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); |
| 293 | strncpy(matchBuf, command, cursor); |
| 294 | tmp=matchBuf; |
| 295 | |
| 296 | /* skip past any command seperator tokens */ |
| 297 | while (*tmp && (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) { |
| 298 | tmp=++tmp1; |
| 299 | /* skip any leading white space */ |
| 300 | while (*tmp && isspace(*tmp)) |
| 301 | ++tmp; |
| 302 | } |
| 303 | |
| 304 | /* skip any leading white space */ |
| 305 | while (*tmp && isspace(*tmp)) |
| 306 | ++tmp; |
| 307 | |
| 308 | /* Free up any memory already allocated */ |
| 309 | if (matches) { |
| 310 | free(matches); |
| 311 | matches = (char **) NULL; |
| 312 | } |
| 313 | |
| 314 | /* If the word starts with `~' and there is no slash in the word, |
| 315 | * then try completing this word as a username. */ |
| 316 | |
| 317 | /* FIXME -- this check is broken! */ |
| 318 | if (*tmp == '~' && !strchr(tmp, '/')) |
| 319 | matches = username_tab_completion(tmp, &num_matches); |
| 320 | |
| 321 | /* Try to match any executable in our path and everything |
| 322 | * in the current working directory that matches. */ |
| 323 | if (!matches) |
| 324 | matches = exe_n_cwd_tab_completion(tmp, &num_matches); |
| 325 | |
| 326 | /* Don't leak memory */ |
| 327 | free( matchBuf); |
| 328 | |
| 329 | /* Did we find exactly one match? */ |
| 330 | if (matches && num_matches==1) { |
| 331 | /* write out the matched command */ |
| 332 | strncpy(command+pos, matches[0]+pos, strlen(matches[0])-pos); |
| 333 | len=strlen(command); |
| 334 | cursor=len; |
| 335 | xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos); |
| 336 | break; |
| 337 | } |
| 338 | } else { |
| 339 | /* Ok -- the last char was a TAB. Since they |
| 340 | * just hit TAB again, print a list of all the |
| 341 | * available choices... */ |
| 342 | if ( matches && num_matches>0 ) { |
| 343 | int i, col; |
| 344 | |
| 345 | /* Go to the next line */ |
| 346 | xwrite(outputFd, "\n", 1); |
| 347 | /* Print the list of matches */ |
| 348 | for (i=0,col=0; i<num_matches; i++) { |
| 349 | char foo[17]; |
| 350 | sprintf(foo, "%-14s ", matches[i]); |
| 351 | col += xwrite(outputFd, foo, strlen(foo)); |
| 352 | if (col > 60 && matches[i+1] != NULL) { |
| 353 | xwrite(outputFd, "\n", 1); |
| 354 | col = 0; |
| 355 | } |
| 356 | } |
| 357 | /* Go to the next line */ |
| 358 | xwrite(outputFd, "\n", 1); |
| 359 | /* Rewrite the prompt */ |
| 360 | xwrite(outputFd, prompt, strlen(prompt)); |
| 361 | /* Rewrite the command */ |
| 362 | xwrite(outputFd, command, len); |
| 363 | /* Put the cursor back to where it used to be */ |
| 364 | for (cursor=len; cursor > pos; cursor--) |
| 365 | xwrite(outputFd, "\b", 1); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | #endif |
| 370 | |
| 371 | void get_previous_history(struct history **hp, char* command) |
| 372 | { |
| 373 | free((*hp)->s); |
| 374 | (*hp)->s = strdup(command); |
| 375 | *hp = (*hp)->p; |
| 376 | } |
| 377 | |
| 378 | void get_next_history(struct history **hp, char* command) |
| 379 | { |
| 380 | free((*hp)->s); |
| 381 | (*hp)->s = strdup(command); |
| 382 | *hp = (*hp)->n; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 385 | /* |
| 386 | * This function is used to grab a character buffer |
| 387 | * from the input file descriptor and allows you to |
| 388 | * a string with full command editing (sortof like |
| 389 | * a mini readline). |
| 390 | * |
| 391 | * The following standard commands are not implemented: |
| 392 | * ESC-b -- Move back one word |
| 393 | * ESC-f -- Move forward one word |
| 394 | * ESC-d -- Delete back one word |
| 395 | * ESC-h -- Delete forward one word |
| 396 | * CTL-t -- Transpose two characters |
| 397 | * |
| 398 | * Furthermore, the "vi" command editing keys are not implemented. |
| 399 | * |
| 400 | * TODO: implement TAB command completion. :) |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 401 | */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 402 | extern void cmdedit_read_input(char* prompt, char command[BUFSIZ]) |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 403 | { |
| 404 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 405 | int inputFd=fileno(stdin); |
| 406 | int outputFd=fileno(stdout); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 407 | int nr = 0; |
| 408 | int len = 0; |
| 409 | int j = 0; |
| 410 | int cursor = 0; |
| 411 | int break_out = 0; |
| 412 | int ret = 0; |
| 413 | int lastWasTab = FALSE; |
| 414 | char c = 0; |
| 415 | struct history *hp = his_end; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 416 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 417 | memset(command, 0, sizeof(command)); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 418 | if (!reset_term) { |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 419 | |
| 420 | getTermSettings(inputFd, (void*) &initial_settings); |
| 421 | memcpy(&new_settings, &initial_settings, sizeof(struct termios)); |
| 422 | new_settings.c_cc[VMIN] = 1; |
| 423 | new_settings.c_cc[VTIME] = 0; |
| 424 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; /* Turn off CTRL-C, so we can trap it */ |
| 425 | new_settings.c_lflag &= ~ICANON; /* unbuffered input */ |
| 426 | new_settings.c_lflag &= ~(ECHO|ECHOCTL|ECHONL); /* Turn off echoing */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 427 | reset_term = 1; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 428 | } |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 429 | setTermSettings(inputFd, (void*) &new_settings); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 430 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 431 | memset(command, 0, BUFSIZ); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 432 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 433 | while (1) { |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 434 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 435 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 436 | return; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 437 | //fprintf(stderr, "got a '%c' (%d)\n", c, c); |
Erik Andersen | f3b3d17 | 2000-04-09 18:24:05 +0000 | [diff] [blame] | 438 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 439 | switch (c) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 440 | case '\n': |
| 441 | case '\r': |
| 442 | /* Enter */ |
| 443 | *(command + len++ + 1) = c; |
| 444 | xwrite(outputFd, &c, 1); |
| 445 | break_out = 1; |
| 446 | break; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 447 | case 1: |
| 448 | /* Control-a -- Beginning of line */ |
| 449 | input_home(outputFd, &cursor); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 450 | case 2: |
| 451 | /* Control-b -- Move back one character */ |
| 452 | input_backward(outputFd, &cursor); |
| 453 | break; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 454 | case 3: |
| 455 | /* Control-c -- leave the current line, |
| 456 | * and start over on the next line */ |
| 457 | |
| 458 | /* Go to the next line */ |
| 459 | xwrite(outputFd, "\n", 1); |
| 460 | |
| 461 | /* Rewrite the prompt */ |
| 462 | xwrite(outputFd, prompt, strlen(prompt)); |
| 463 | |
| 464 | /* Reset the command string */ |
| 465 | memset(command, 0, sizeof(command)); |
| 466 | len = cursor = 0; |
| 467 | |
| 468 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 469 | case 4: |
| 470 | /* Control-d -- Delete one character, or exit |
| 471 | * if the len=0 and no chars to delete */ |
| 472 | if (len == 0) { |
| 473 | xwrite(outputFd, "exit", 4); |
| 474 | clean_up_and_die(0); |
| 475 | } else { |
| 476 | input_delete(command, outputFd, cursor, &len); |
| 477 | } |
| 478 | break; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 479 | case 5: |
| 480 | /* Control-e -- End of line */ |
| 481 | input_end(outputFd, &cursor, len); |
| 482 | break; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 483 | case 6: |
| 484 | /* Control-f -- Move forward one character */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 485 | input_forward(outputFd, &cursor, len); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 486 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 487 | case '\b': |
| 488 | case DEL: |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 489 | /* Control-h and DEL */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 490 | input_backspace(command, outputFd, &cursor, &len); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 491 | break; |
| 492 | case '\t': |
Erik Andersen | a268573 | 2000-04-09 18:27:46 +0000 | [diff] [blame] | 493 | #ifdef BB_FEATURE_SH_TAB_COMPLETION |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 494 | input_tab(command, prompt, outputFd, &cursor, &len); |
Erik Andersen | a268573 | 2000-04-09 18:27:46 +0000 | [diff] [blame] | 495 | #endif |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 496 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 497 | case 14: |
| 498 | /* Control-n -- Get next command in history */ |
| 499 | if (hp && hp->n && hp->n->s) { |
| 500 | get_next_history(&hp, command); |
| 501 | goto rewrite_line; |
| 502 | } else { |
| 503 | xwrite(outputFd, "\007", 1); |
| 504 | } |
| 505 | break; |
| 506 | case 16: |
| 507 | /* Control-p -- Get previous command from history */ |
| 508 | if (hp && hp->p) { |
| 509 | get_previous_history(&hp, command); |
| 510 | goto rewrite_line; |
| 511 | } else { |
| 512 | xwrite(outputFd, "\007", 1); |
| 513 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 514 | break; |
| 515 | case ESC:{ |
| 516 | /* escape sequence follows */ |
| 517 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 518 | return; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 519 | |
| 520 | if (c == '[') { /* 91 */ |
| 521 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 522 | return; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 523 | |
| 524 | switch (c) { |
| 525 | case 'A': |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 526 | /* Up Arrow -- Get previous command from history */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 527 | if (hp && hp->p) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 528 | get_previous_history(&hp, command); |
| 529 | goto rewrite_line; |
| 530 | } else { |
| 531 | xwrite(outputFd, "\007", 1); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 532 | } |
| 533 | break; |
| 534 | case 'B': |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 535 | /* Down Arrow -- Get next command in history */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 536 | if (hp && hp->n && hp->n->s) { |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 537 | get_next_history(&hp, command); |
| 538 | goto rewrite_line; |
| 539 | } else { |
| 540 | xwrite(outputFd, "\007", 1); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 541 | } |
| 542 | break; |
| 543 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 544 | /* Rewrite the line with the selected history item */ |
| 545 | rewrite_line: |
| 546 | /* erase old command from command line */ |
| 547 | len = strlen(command)-strlen(hp->s); |
Eric Andersen | 72965e3 | 2000-07-04 06:22:18 +0000 | [diff] [blame] | 548 | |
| 549 | while (len>cursor) |
| 550 | input_delete(command, outputFd, cursor, &len); |
| 551 | while (cursor>0) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 552 | input_backspace(command, outputFd, &cursor, &len); |
| 553 | input_home(outputFd, &cursor); |
| 554 | |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 555 | /* write new command */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 556 | strcpy(command, hp->s); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 557 | len = strlen(hp->s); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 558 | xwrite(outputFd, command, len); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 559 | cursor = len; |
| 560 | break; |
| 561 | case 'C': |
| 562 | /* Right Arrow -- Move forward one character */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 563 | input_forward(outputFd, &cursor, len); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 564 | break; |
| 565 | case 'D': |
| 566 | /* Left Arrow -- Move back one character */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 567 | input_backward(outputFd, &cursor); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 568 | break; |
| 569 | case '3': |
| 570 | /* Delete */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 571 | input_delete(command, outputFd, cursor, &len); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 572 | break; |
| 573 | case '1': |
| 574 | /* Home (Ctrl-A) */ |
| 575 | input_home(outputFd, &cursor); |
| 576 | break; |
| 577 | case '4': |
| 578 | /* End (Ctrl-E) */ |
| 579 | input_end(outputFd, &cursor, len); |
| 580 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 581 | default: |
| 582 | xwrite(outputFd, "\007", 1); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 583 | } |
| 584 | if (c == '1' || c == '3' || c == '4') |
| 585 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 586 | return; /* read 126 (~) */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 587 | } |
| 588 | if (c == 'O') { |
| 589 | /* 79 */ |
| 590 | if ((ret = read(inputFd, &c, 1)) < 1) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 591 | return; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 592 | switch (c) { |
| 593 | case 'H': |
| 594 | /* Home (xterm) */ |
| 595 | input_home(outputFd, &cursor); |
| 596 | break; |
| 597 | case 'F': |
| 598 | /* End (xterm) */ |
| 599 | input_end(outputFd, &cursor, len); |
| 600 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 601 | default: |
| 602 | xwrite(outputFd, "\007", 1); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | c = 0; |
| 606 | break; |
| 607 | } |
| 608 | |
| 609 | default: /* If it's regular input, do the normal thing */ |
| 610 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 611 | if (!isprint(c)) { /* Skip non-printable characters */ |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 612 | break; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 613 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 614 | |
| 615 | if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */ |
| 616 | break; |
| 617 | |
| 618 | len++; |
| 619 | |
| 620 | if (cursor == (len - 1)) { /* Append if at the end of the line */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 621 | *(command + cursor) = c; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 622 | } else { /* Insert otherwise */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 623 | memmove(command + cursor + 1, command + cursor, |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 624 | len - cursor - 1); |
| 625 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 626 | *(command + cursor) = c; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 627 | |
| 628 | for (j = cursor; j < len; j++) |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 629 | xwrite(outputFd, command + j, 1); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 630 | for (; j > cursor; j--) |
| 631 | xwrite(outputFd, "\033[D", 3); |
| 632 | } |
| 633 | |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 634 | cursor++; |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 635 | xwrite(outputFd, &c, 1); |
| 636 | break; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 637 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 638 | if (c == '\t') |
| 639 | lastWasTab = TRUE; |
| 640 | else |
| 641 | lastWasTab = FALSE; |
| 642 | |
| 643 | if (break_out) /* Enter is the command terminator, no more input. */ |
| 644 | break; |
| 645 | } |
| 646 | |
| 647 | nr = len + 1; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 648 | setTermSettings(inputFd, (void *) &initial_settings); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 649 | reset_term = 0; |
| 650 | |
| 651 | |
| 652 | /* Handle command history log */ |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 653 | if (*(command)) { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 654 | |
| 655 | struct history *h = his_end; |
| 656 | |
| 657 | if (!h) { |
| 658 | /* No previous history */ |
| 659 | h = his_front = malloc(sizeof(struct history)); |
| 660 | h->n = malloc(sizeof(struct history)); |
| 661 | |
| 662 | h->p = NULL; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 663 | h->s = strdup(command); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 664 | h->n->p = h; |
| 665 | h->n->n = NULL; |
| 666 | h->n->s = NULL; |
| 667 | his_end = h->n; |
| 668 | history_counter++; |
| 669 | } else { |
| 670 | /* Add a new history command */ |
| 671 | h->n = malloc(sizeof(struct history)); |
| 672 | |
| 673 | h->n->p = h; |
| 674 | h->n->n = NULL; |
| 675 | h->n->s = NULL; |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 676 | h->s = strdup(command); |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 677 | his_end = h->n; |
| 678 | |
| 679 | /* After max history, remove the oldest command */ |
| 680 | if (history_counter >= MAX_HISTORY) { |
| 681 | |
| 682 | struct history *p = his_front->n; |
| 683 | |
| 684 | p->p = NULL; |
| 685 | free(his_front->s); |
| 686 | free(his_front); |
| 687 | his_front = p; |
| 688 | } else { |
| 689 | history_counter++; |
| 690 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 691 | } |
Erik Andersen | 6273f65 | 2000-03-17 01:12:41 +0000 | [diff] [blame] | 692 | } |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 693 | |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 694 | return; |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | extern void cmdedit_init(void) |
| 698 | { |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 699 | atexit(cmdedit_reset_term); |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 700 | signal(SIGKILL, clean_up_and_die); |
Erik Andersen | f0657d3 | 2000-04-12 17:49:52 +0000 | [diff] [blame] | 701 | signal(SIGINT, clean_up_and_die); |
| 702 | signal(SIGQUIT, clean_up_and_die); |
| 703 | signal(SIGTERM, clean_up_and_die); |
Erik Andersen | 13456d1 | 2000-03-16 08:09:57 +0000 | [diff] [blame] | 704 | } |
Erik Andersen | c7c634b | 2000-03-19 05:28:55 +0000 | [diff] [blame] | 705 | #endif /* BB_FEATURE_SH_COMMAND_EDITING */ |