aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-06-26 02:06:08 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-06-26 02:06:08 +0000
commit78b0e379d7c2db84eec34ccd89cf9afb67b94901 (patch)
treeae5bb34caa3b88968102e93193a01e4d90109b92 /shell
parentaddabd6f16aece578d94d810d3a9e9dc88f2cdb7 (diff)
downloadbusybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.tar.gz
busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.tar.bz2
busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.zip
Vladimir's last_patch_15
Diffstat (limited to 'shell')
-rw-r--r--shell/cmdedit.c92
-rw-r--r--shell/hush.c2
2 files changed, 52 insertions, 42 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index a2b238603..981253db1 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -81,11 +81,11 @@
81#endif 81#endif
82 82
83#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR 83#ifdef BB_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
87#include <pwd.h> 87# include <pwd.h>
88#endif /* TEST */ 88# endif /* TEST */
89#endif /* advanced FEATURES */ 89#endif /* advanced FEATURES */
90 90
91 91
@@ -106,28 +106,14 @@ static struct history *his_front = NULL;
106static struct history *his_end = NULL; 106static struct history *his_end = NULL;
107 107
108 108
109/* ED: sparc termios is broken: revert back to old termio handling. */ 109#include <termios.h>
110 110#define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
111#if #cpu(sparc) 111#define getTermSettings(fd,argp) tcgetattr(fd, argp);
112# include <termio.h>
113# define termios termio
114# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
115# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
116#else
117# include <termios.h>
118# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
119# define getTermSettings(fd,argp) tcgetattr(fd, argp);
120#endif
121 112
122/* Current termio and the previous termio before starting sh */ 113/* Current termio and the previous termio before starting sh */
123static struct termios initial_settings, new_settings; 114static struct termios initial_settings, new_settings;
124 115
125 116
126#ifndef _POSIX_VDISABLE
127#define _POSIX_VDISABLE '\0'
128#endif
129
130
131static 117static
132volatile int cmdedit_termw = 80; /* actual terminal width */ 118volatile int cmdedit_termw = 80; /* actual terminal width */
133static int history_counter = 0; /* Number of commands in history list */ 119static int history_counter = 0; /* Number of commands in history list */
@@ -356,7 +342,7 @@ static void parse_prompt(const char *prmt_ptr)
356 char *pbuf; 342 char *pbuf;
357 343
358 if (!pwd_buf) { 344 if (!pwd_buf) {
359 pwd_buf=unknown; 345 pwd_buf=(char *)unknown;
360 } 346 }
361 347
362 while (*prmt_ptr) { 348 while (*prmt_ptr) {
@@ -1041,9 +1027,30 @@ static void input_tab(int *lastWasTab)
1041 * in the current working directory that matches. */ 1027 * in the current working directory that matches. */
1042 if (!matches) 1028 if (!matches)
1043 matches = 1029 matches =
1044 exe_n_cwd_tab_completion(matchBuf, &num_matches, 1030 exe_n_cwd_tab_completion(matchBuf,
1045 find_type); 1031 &num_matches, find_type);
1046 1032 /* Remove duplicate found */
1033 if(matches) {
1034 int i, j;
1035 /* bubble */
1036 for(i=0; i<(num_matches-1); i++)
1037 for(j=i+1; j<num_matches; j++)
1038 if(matches[i]!=0 && matches[j]!=0 &&
1039 strcmp(matches[i], matches[j])==0) {
1040 free(matches[j]);
1041 matches[j]=0;
1042 }
1043 j=num_matches;
1044 num_matches = 0;
1045 for(i=0; i<j; i++)
1046 if(matches[i]) {
1047 if(!strcmp(matches[i], "./"))
1048 matches[i][1]=0;
1049 else if(!strcmp(matches[i], "../"))
1050 matches[i][2]=0;
1051 matches[num_matches++]=matches[i];
1052 }
1053 }
1047 /* Did we find exactly one match? */ 1054 /* Did we find exactly one match? */
1048 if (!matches || num_matches > 1) { 1055 if (!matches || num_matches > 1) {
1049 char *tmp1; 1056 char *tmp1;
@@ -1169,8 +1176,6 @@ enum {
1169extern void cmdedit_read_input(char *prompt, char command[BUFSIZ]) 1176extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
1170{ 1177{
1171 1178
1172 int inputFd = fileno(stdin);
1173
1174 int break_out = 0; 1179 int break_out = 0;
1175 int lastWasTab = FALSE; 1180 int lastWasTab = FALSE;
1176 unsigned char c = 0; 1181 unsigned char c = 0;
@@ -1181,23 +1186,28 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
1181 len = 0; 1186 len = 0;
1182 command_ps = command; 1187 command_ps = command;
1183 1188
1184 if (new_settings.c_cc[VMIN] == 0) { /* first call */ 1189 if (new_settings.c_cc[VERASE] == 0) { /* first call */
1185 1190
1186 getTermSettings(inputFd, (void *) &initial_settings); 1191 getTermSettings(0, (void *) &initial_settings);
1187 memcpy(&new_settings, &initial_settings, sizeof(struct termios)); 1192 memcpy(&new_settings, &initial_settings, sizeof(struct termios));
1188 1193 new_settings.c_lflag &= ~ICANON; /* unbuffered input */
1194 /* Turn off echoing and CTRL-C, so we can trap it */
1195 new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
1196#ifndef linux
1197 /* Hmm, in linux c_cc[] not parsed if set ~ICANON */
1189 new_settings.c_cc[VMIN] = 1; 1198 new_settings.c_cc[VMIN] = 1;
1190 new_settings.c_cc[VTIME] = 0; 1199 new_settings.c_cc[VTIME] = 0;
1191 /* Turn off CTRL-C, so we can trap it */ 1200 /* Turn off CTRL-C, so we can trap it */
1201# ifndef _POSIX_VDISABLE
1202# define _POSIX_VDISABLE '\0'
1203# endif
1192 new_settings.c_cc[VINTR] = _POSIX_VDISABLE; 1204 new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
1193 new_settings.c_lflag &= ~ICANON; /* unbuffered input */ 1205#endif
1194 /* Turn off echoing */
1195 new_settings.c_lflag &= ~(ECHO | ECHOCTL | ECHONL);
1196 } 1206 }
1197 1207
1198 command[0] = 0; 1208 command[0] = 0;
1199 1209
1200 setTermSettings(inputFd, (void *) &new_settings); 1210 setTermSettings(0, (void *) &new_settings);
1201 handlers_sets |= SET_RESET_TERM; 1211 handlers_sets |= SET_RESET_TERM;
1202 1212
1203 /* Now initialize things */ 1213 /* Now initialize things */
@@ -1209,7 +1219,7 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
1209 1219
1210 fflush(stdout); /* buffered out to fast */ 1220 fflush(stdout); /* buffered out to fast */
1211 1221
1212 if (read(inputFd, &c, 1) < 1) 1222 if (read(0, &c, 1) < 1)
1213 /* if we can't read input then exit */ 1223 /* if we can't read input then exit */
1214 goto prepare_to_die; 1224 goto prepare_to_die;
1215 1225
@@ -1296,11 +1306,11 @@ prepare_to_die:
1296 1306
1297 case ESC:{ 1307 case ESC:{
1298 /* escape sequence follows */ 1308 /* escape sequence follows */
1299 if (read(inputFd, &c, 1) < 1) 1309 if (read(0, &c, 1) < 1)
1300 return; 1310 return;
1301 /* different vt100 emulations */ 1311 /* different vt100 emulations */
1302 if (c == '[' || c == 'O') { 1312 if (c == '[' || c == 'O') {
1303 if (read(inputFd, &c, 1) < 1) 1313 if (read(0, &c, 1) < 1)
1304 return; 1314 return;
1305 } 1315 }
1306 switch (c) { 1316 switch (c) {
@@ -1365,7 +1375,7 @@ prepare_to_die:
1365 } 1375 }
1366 if (c >= '1' && c <= '9') 1376 if (c >= '1' && c <= '9')
1367 do 1377 do
1368 if (read(inputFd, &c, 1) < 1) 1378 if (read(0, &c, 1) < 1)
1369 return; 1379 return;
1370 while (c != '~'); 1380 while (c != '~');
1371 break; 1381 break;
@@ -1375,7 +1385,7 @@ prepare_to_die:
1375#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT 1385#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT
1376 /* Control-V -- Add non-printable symbol */ 1386 /* Control-V -- Add non-printable symbol */
1377 if (c == 22) { 1387 if (c == 22) {
1378 if (read(inputFd, &c, 1) < 1) 1388 if (read(0, &c, 1) < 1)
1379 return; 1389 return;
1380 if (c == 0) { 1390 if (c == 0) {
1381 beep(); 1391 beep();
@@ -1416,7 +1426,7 @@ prepare_to_die:
1416 lastWasTab = FALSE; 1426 lastWasTab = FALSE;
1417 } 1427 }
1418 1428
1419 setTermSettings(inputFd, (void *) &initial_settings); 1429 setTermSettings(0, (void *) &initial_settings);
1420 handlers_sets &= ~SET_RESET_TERM; 1430 handlers_sets &= ~SET_RESET_TERM;
1421 1431
1422 /* Handle command history log */ 1432 /* Handle command history log */
diff --git a/shell/hush.c b/shell/hush.c
index b0637f806..859353dcf 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -861,7 +861,7 @@ static inline void setup_prompt_string(int promptmode, char **prompt_str)
861 *prompt_str = PS2; 861 *prompt_str = PS2;
862 } 862 }
863#else 863#else
864 *prompt_str = (promptmode==0)? PS1 : PS2; 864 *prompt_str = (promptmode==1)? PS1 : PS2;
865#endif 865#endif
866 debug_printf("result %s\n",*prompt_str); 866 debug_printf("result %s\n",*prompt_str);
867} 867}