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