aboutsummaryrefslogtreecommitdiff
path: root/shell/cmdedit.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-10-24 05:00:29 +0000
committerEric Andersen <andersen@codepoet.org>2001-10-24 05:00:29 +0000
commitbdfd0d78bc44e73d693510e70087857785b3b521 (patch)
tree153a573095afac8d8d0ea857759ecabd77fb28b7 /shell/cmdedit.c
parent9260fc5552a3ee52eb95823aa6689d52a1ffd33c (diff)
downloadbusybox-w32-bdfd0d78bc44e73d693510e70087857785b3b521.tar.gz
busybox-w32-bdfd0d78bc44e73d693510e70087857785b3b521.tar.bz2
busybox-w32-bdfd0d78bc44e73d693510e70087857785b3b521.zip
Major rework of the directory structure and the entire build system.
-Erik
Diffstat (limited to 'shell/cmdedit.c')
-rw-r--r--shell/cmdedit.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 16ec2f823..d1b9111ea 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -43,7 +43,7 @@
43 43
44#include "busybox.h" 44#include "busybox.h"
45 45
46#ifdef BB_LOCALE_SUPPORT 46#ifdef CONFIG_LOCALE_SUPPORT
47#define Isprint(c) isprint((c)) 47#define Isprint(c) isprint((c))
48#else 48#else
49#define Isprint(c) ( (c) >= ' ' && (c) != ((unsigned char)'\233') ) 49#define Isprint(c) ( (c) >= ' ' && (c) != ((unsigned char)'\233') )
@@ -55,32 +55,32 @@
55 55
56#else 56#else
57 57
58#define BB_FEATURE_COMMAND_EDITING 58#define CONFIG_FEATURE_COMMAND_EDITING
59#define BB_FEATURE_COMMAND_TAB_COMPLETION 59#define CONFIG_FEATURE_COMMAND_TAB_COMPLETION
60#define BB_FEATURE_COMMAND_USERNAME_COMPLETION 60#define CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION
61#define BB_FEATURE_NONPRINTABLE_INVERSE_PUT 61#define CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
62#define BB_FEATURE_CLEAN_UP 62#define CONFIG_FEATURE_CLEAN_UP
63 63
64#define D(x) x 64#define D(x) x
65 65
66#endif /* TEST */ 66#endif /* TEST */
67 67
68#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION 68#ifdef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
69#include <dirent.h> 69#include <dirent.h>
70#include <sys/stat.h> 70#include <sys/stat.h>
71#endif 71#endif
72 72
73#ifdef BB_FEATURE_COMMAND_EDITING 73#ifdef CONFIG_FEATURE_COMMAND_EDITING
74 74
75#ifndef BB_FEATURE_COMMAND_TAB_COMPLETION 75#ifndef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
76#undef BB_FEATURE_COMMAND_USERNAME_COMPLETION 76#undef CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION
77#endif 77#endif
78 78
79#if defined(BB_FEATURE_COMMAND_USERNAME_COMPLETION) || defined(BB_FEATURE_SH_FANCY_PROMPT) 79#if defined(CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION) || defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
80#define BB_FEATURE_GETUSERNAME_AND_HOMEDIR 80#define CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
81#endif 81#endif
82 82
83#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 83#ifdef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
84# ifndef TEST 84# ifndef TEST
85# include "pwd_grp/pwd.h" 85# include "pwd_grp/pwd.h"
86# else 86# else
@@ -136,33 +136,33 @@ static int cursor; /* required global for signal handler */
136static int len; /* --- "" - - "" - -"- --""-- --""--- */ 136static int len; /* --- "" - - "" - -"- --""-- --""--- */
137static char *command_ps; /* --- "" - - "" - -"- --""-- --""--- */ 137static char *command_ps; /* --- "" - - "" - -"- --""-- --""--- */
138static 138static
139#ifndef BB_FEATURE_SH_FANCY_PROMPT 139#ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
140 const 140 const
141#endif 141#endif
142char *cmdedit_prompt; /* --- "" - - "" - -"- --""-- --""--- */ 142char *cmdedit_prompt; /* --- "" - - "" - -"- --""-- --""--- */
143 143
144#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 144#ifdef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
145static char *user_buf = ""; 145static char *user_buf = "";
146static char *home_pwd_buf = ""; 146static char *home_pwd_buf = "";
147static int my_euid; 147static int my_euid;
148#endif 148#endif
149 149
150#ifdef BB_FEATURE_SH_FANCY_PROMPT 150#ifdef CONFIG_FEATURE_SH_FANCY_PROMPT
151static char *hostname_buf = ""; 151static char *hostname_buf = "";
152static int num_ok_lines = 1; 152static int num_ok_lines = 1;
153#endif 153#endif
154 154
155 155
156#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION 156#ifdef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
157 157
158#ifndef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 158#ifndef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
159static int my_euid; 159static int my_euid;
160#endif 160#endif
161 161
162static int my_uid; 162static int my_uid;
163static int my_gid; 163static int my_gid;
164 164
165#endif /* BB_FEATURE_COMMAND_TAB_COMPLETION */ 165#endif /* CONFIG_FEATURE_COMMAND_TAB_COMPLETION */
166 166
167/* It seems that libc5 doesn't know what a sighandler_t is... */ 167/* It seems that libc5 doesn't know what a sighandler_t is... */
168#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1) 168#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
@@ -207,7 +207,7 @@ static void cmdedit_reset_term(void)
207 handlers_sets &= ~SET_WCHG_HANDLERS; 207 handlers_sets &= ~SET_WCHG_HANDLERS;
208 } 208 }
209 fflush(stdout); 209 fflush(stdout);
210#ifdef BB_FEATURE_CLEAN_UP 210#ifdef CONFIG_FEATURE_CLEAN_UP
211 if (his_front) { 211 if (his_front) {
212 struct history *n; 212 struct history *n;
213 213
@@ -230,7 +230,7 @@ static void cmdedit_set_out_char(int next_char)
230 230
231 if (c == 0) 231 if (c == 0)
232 c = ' '; /* destroy end char? */ 232 c = ' '; /* destroy end char? */
233#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 233#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
234 if (!Isprint(c)) { /* Inverse put non-printable characters */ 234 if (!Isprint(c)) { /* Inverse put non-printable characters */
235 if (c >= 128) 235 if (c >= 128)
236 c -= 128; 236 c -= 128;
@@ -321,7 +321,7 @@ static void put_prompt(void)
321 cmdedit_y = 0; /* new quasireal y */ 321 cmdedit_y = 0; /* new quasireal y */
322} 322}
323 323
324#ifndef BB_FEATURE_SH_FANCY_PROMPT 324#ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
325static void parse_prompt(const char *prmt_ptr) 325static void parse_prompt(const char *prmt_ptr)
326{ 326{
327 cmdedit_prompt = prmt_ptr; 327 cmdedit_prompt = prmt_ptr;
@@ -359,7 +359,7 @@ static void parse_prompt(const char *prmt_ptr)
359 break; 359 break;
360 c = *prmt_ptr++; 360 c = *prmt_ptr++;
361 switch (c) { 361 switch (c) {
362#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 362#ifdef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
363 case 'u': 363 case 'u':
364 pbuf = user_buf; 364 pbuf = user_buf;
365 break; 365 break;
@@ -382,7 +382,7 @@ static void parse_prompt(const char *prmt_ptr)
382 case '$': 382 case '$':
383 c = my_euid == 0 ? '#' : '$'; 383 c = my_euid == 0 ? '#' : '$';
384 break; 384 break;
385#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 385#ifdef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
386 case 'w': 386 case 'w':
387 pbuf = pwd_buf; 387 pbuf = pwd_buf;
388 l = strlen(home_pwd_buf); 388 l = strlen(home_pwd_buf);
@@ -526,7 +526,7 @@ static void cmdedit_init(void)
526 } 526 }
527 527
528 if ((handlers_sets & SET_ATEXIT) == 0) { 528 if ((handlers_sets & SET_ATEXIT) == 0) {
529#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 529#ifdef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
530 struct passwd *entry; 530 struct passwd *entry;
531 531
532 my_euid = geteuid(); 532 my_euid = geteuid();
@@ -537,20 +537,20 @@ static void cmdedit_init(void)
537 } 537 }
538#endif 538#endif
539 539
540#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION 540#ifdef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
541 541
542#ifndef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 542#ifndef CONFIG_FEATURE_GETUSERNAME_AND_HOMEDIR
543 my_euid = geteuid(); 543 my_euid = geteuid();
544#endif 544#endif
545 my_uid = getuid(); 545 my_uid = getuid();
546 my_gid = getgid(); 546 my_gid = getgid();
547#endif /* BB_FEATURE_COMMAND_TAB_COMPLETION */ 547#endif /* CONFIG_FEATURE_COMMAND_TAB_COMPLETION */
548 handlers_sets |= SET_ATEXIT; 548 handlers_sets |= SET_ATEXIT;
549 atexit(cmdedit_reset_term); /* be sure to do this only once */ 549 atexit(cmdedit_reset_term); /* be sure to do this only once */
550 } 550 }
551} 551}
552 552
553#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION 553#ifdef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
554 554
555static int is_execute(const struct stat *st) 555static int is_execute(const struct stat *st)
556{ 556{
@@ -561,7 +561,7 @@ static int is_execute(const struct stat *st)
561 return FALSE; 561 return FALSE;
562} 562}
563 563
564#ifdef BB_FEATURE_COMMAND_USERNAME_COMPLETION 564#ifdef CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION
565 565
566static char **username_tab_completion(char *ud, int *num_matches) 566static char **username_tab_completion(char *ud, int *num_matches)
567{ 567{
@@ -623,7 +623,7 @@ static char **username_tab_completion(char *ud, int *num_matches)
623 return (matches); 623 return (matches);
624 } 624 }
625} 625}
626#endif /* BB_FEATURE_COMMAND_USERNAME_COMPLETION */ 626#endif /* CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION */
627 627
628enum { 628enum {
629 FIND_EXE_ONLY = 0, 629 FIND_EXE_ONLY = 0,
@@ -720,7 +720,7 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches,
720 strcpy(dirbuf, command); 720 strcpy(dirbuf, command);
721 /* set dir only */ 721 /* set dir only */
722 dirbuf[(pfind - command) + 1] = 0; 722 dirbuf[(pfind - command) + 1] = 0;
723#ifdef BB_FEATURE_COMMAND_USERNAME_COMPLETION 723#ifdef CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION
724 if (dirbuf[0] == '~') /* ~/... or ~user/... */ 724 if (dirbuf[0] == '~') /* ~/... or ~user/... */
725 username_tab_completion(dirbuf, 0); 725 username_tab_completion(dirbuf, 0);
726#endif 726#endif
@@ -826,12 +826,12 @@ static int find_match(char *matchBuf, int *len_with_quotes)
826 collapse_pos(j, j + 1); 826 collapse_pos(j, j + 1);
827 int_buf[j] |= QUOT; 827 int_buf[j] |= QUOT;
828 i++; 828 i++;
829#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 829#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
830 if (matchBuf[i] == '\t') /* algorithm equivalent */ 830 if (matchBuf[i] == '\t') /* algorithm equivalent */
831 int_buf[j] = ' ' | QUOT; 831 int_buf[j] = ' ' | QUOT;
832#endif 832#endif
833 } 833 }
834#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 834#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
835 else if (matchBuf[i] == '\t') 835 else if (matchBuf[i] == '\t')
836 int_buf[j] = ' '; 836 int_buf[j] = ' ';
837#endif 837#endif
@@ -1000,7 +1000,7 @@ static void input_tab(int *lastWasTab)
1000 /* Free up any memory already allocated */ 1000 /* Free up any memory already allocated */
1001 input_tab(0); 1001 input_tab(0);
1002 1002
1003#ifdef BB_FEATURE_COMMAND_USERNAME_COMPLETION 1003#ifdef CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION
1004 /* If the word starts with `~' and there is no slash in the word, 1004 /* If the word starts with `~' and there is no slash in the word,
1005 * then try completing this word as a username. */ 1005 * then try completing this word as a username. */
1006 1006
@@ -1119,7 +1119,7 @@ static void input_tab(int *lastWasTab)
1119 } 1119 }
1120 } 1120 }
1121} 1121}
1122#endif /* BB_FEATURE_COMMAND_TAB_COMPLETION */ 1122#endif /* CONFIG_FEATURE_COMMAND_TAB_COMPLETION */
1123 1123
1124static void get_previous_history(struct history **hp, struct history *p) 1124static void get_previous_history(struct history **hp, struct history *p)
1125{ 1125{
@@ -1232,7 +1232,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
1232 * if the len=0 and no chars to delete */ 1232 * if the len=0 and no chars to delete */
1233 if (len == 0) { 1233 if (len == 0) {
1234prepare_to_die: 1234prepare_to_die:
1235#if !defined(BB_ASH) 1235#if !defined(CONFIG_ASH)
1236 printf("exit"); 1236 printf("exit");
1237 goto_new_line(); 1237 goto_new_line();
1238 /* cmdedit_reset_term() called in atexit */ 1238 /* cmdedit_reset_term() called in atexit */
@@ -1259,7 +1259,7 @@ prepare_to_die:
1259 input_backspace(); 1259 input_backspace();
1260 break; 1260 break;
1261 case '\t': 1261 case '\t':
1262#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION 1262#ifdef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
1263 input_tab(&lastWasTab); 1263 input_tab(&lastWasTab);
1264#endif 1264#endif
1265 break; 1265 break;
@@ -1299,7 +1299,7 @@ prepare_to_die:
1299 goto prepare_to_die; 1299 goto prepare_to_die;
1300 } 1300 }
1301 switch (c) { 1301 switch (c) {
1302#ifdef BB_FEATURE_COMMAND_TAB_COMPLETION 1302#ifdef CONFIG_FEATURE_COMMAND_TAB_COMPLETION
1303 case '\t': /* Alt-Tab */ 1303 case '\t': /* Alt-Tab */
1304 1304
1305 input_tab(&lastWasTab); 1305 input_tab(&lastWasTab);
@@ -1367,7 +1367,7 @@ prepare_to_die:
1367 } 1367 }
1368 1368
1369 default: /* If it's regular input, do the normal thing */ 1369 default: /* If it's regular input, do the normal thing */
1370#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 1370#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
1371 /* Control-V -- Add non-printable symbol */ 1371 /* Control-V -- Add non-printable symbol */
1372 if (c == 22) { 1372 if (c == 22) {
1373 if (safe_read(0, &c, 1) < 1) 1373 if (safe_read(0, &c, 1) < 1)
@@ -1457,7 +1457,7 @@ prepare_to_die:
1457 history_counter++; 1457 history_counter++;
1458 } 1458 }
1459 } 1459 }
1460#if defined(BB_FEATURE_SH_FANCY_PROMPT) 1460#if defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
1461 num_ok_lines++; 1461 num_ok_lines++;
1462#endif 1462#endif
1463 } 1463 }
@@ -1465,10 +1465,10 @@ prepare_to_die:
1465 command[len++] = '\n'; /* set '\n' */ 1465 command[len++] = '\n'; /* set '\n' */
1466 command[len] = 0; 1466 command[len] = 0;
1467 } 1467 }
1468#if defined(BB_FEATURE_CLEAN_UP) && defined(BB_FEATURE_COMMAND_TAB_COMPLETION) 1468#if defined(CONFIG_FEATURE_CLEAN_UP) && defined(CONFIG_FEATURE_COMMAND_TAB_COMPLETION)
1469 input_tab(0); /* strong free */ 1469 input_tab(0); /* strong free */
1470#endif 1470#endif
1471#if defined(BB_FEATURE_SH_FANCY_PROMPT) 1471#if defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
1472 free(cmdedit_prompt); 1472 free(cmdedit_prompt);
1473#endif 1473#endif
1474 cmdedit_reset_term(); 1474 cmdedit_reset_term();
@@ -1477,7 +1477,7 @@ prepare_to_die:
1477 1477
1478 1478
1479 1479
1480#endif /* BB_FEATURE_COMMAND_EDITING */ 1480#endif /* CONFIG_FEATURE_COMMAND_EDITING */
1481 1481
1482 1482
1483#ifdef TEST 1483#ifdef TEST
@@ -1485,7 +1485,7 @@ prepare_to_die:
1485const char *applet_name = "debug stuff usage"; 1485const char *applet_name = "debug stuff usage";
1486const char *memory_exhausted = "Memory exhausted"; 1486const char *memory_exhausted = "Memory exhausted";
1487 1487
1488#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 1488#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
1489#include <locale.h> 1489#include <locale.h>
1490#endif 1490#endif
1491 1491
@@ -1493,7 +1493,7 @@ int main(int argc, char **argv)
1493{ 1493{
1494 char buff[BUFSIZ]; 1494 char buff[BUFSIZ];
1495 char *prompt = 1495 char *prompt =
1496#if defined(BB_FEATURE_SH_FANCY_PROMPT) 1496#if defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
1497 "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:\ 1497 "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:\
1498\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] \ 1498\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] \
1499\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]"; 1499\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]";
@@ -1501,7 +1501,7 @@ int main(int argc, char **argv)
1501 "% "; 1501 "% ";
1502#endif 1502#endif
1503 1503
1504#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 1504#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
1505 setlocale(LC_ALL, ""); 1505 setlocale(LC_ALL, "");
1506#endif 1506#endif
1507 while(1) { 1507 while(1) {