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