diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-06-26 02:06:08 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-06-26 02:06:08 +0000 |
| commit | 78b0e379d7c2db84eec34ccd89cf9afb67b94901 (patch) | |
| tree | ae5bb34caa3b88968102e93193a01e4d90109b92 | |
| parent | addabd6f16aece578d94d810d3a9e9dc88f2cdb7 (diff) | |
| download | busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.tar.gz busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.tar.bz2 busybox-w32-78b0e379d7c2db84eec34ccd89cf9afb67b94901.zip | |
Vladimir's last_patch_15
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | cmdedit.c | 92 | ||||
| -rw-r--r-- | editors/vi.c | 4 | ||||
| -rw-r--r-- | hostname.c | 7 | ||||
| -rw-r--r-- | hush.c | 2 | ||||
| -rw-r--r-- | include/libbb.h | 6 | ||||
| -rw-r--r-- | libbb/libbb.h | 6 | ||||
| -rw-r--r-- | more.c | 100 | ||||
| -rw-r--r-- | networking/hostname.c | 7 | ||||
| -rw-r--r-- | networking/telnet.c | 46 | ||||
| -rw-r--r-- | shell/cmdedit.c | 92 | ||||
| -rw-r--r-- | shell/hush.c | 2 | ||||
| -rw-r--r-- | telnet.c | 46 | ||||
| -rw-r--r-- | util-linux/more.c | 100 | ||||
| -rw-r--r-- | vi.c | 4 |
15 files changed, 269 insertions, 247 deletions
| @@ -249,7 +249,7 @@ safe_read.c safe_strncpy.c syscalls.c syslog_msg_with_name.c time_string.c \ | |||
| 249 | trim.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \ | 249 | trim.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \ |
| 250 | xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \ | 250 | xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \ |
| 251 | copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \ | 251 | copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \ |
| 252 | dirname.c make_directory.c strdup_substr.c | 252 | dirname.c make_directory.c |
| 253 | LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC)) | 253 | LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC)) |
| 254 | LIBBB_CFLAGS = -I$(LIBBB) | 254 | LIBBB_CFLAGS = -I$(LIBBB) |
| 255 | ifneq ($(strip $(BB_SRC_DIR)),) | 255 | ifneq ($(strip $(BB_SRC_DIR)),) |
| @@ -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; | |||
| 106 | static struct history *his_end = NULL; | 106 | static 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 */ |
| 123 | static struct termios initial_settings, new_settings; | 114 | static struct termios initial_settings, new_settings; |
| 124 | 115 | ||
| 125 | 116 | ||
| 126 | #ifndef _POSIX_VDISABLE | ||
| 127 | #define _POSIX_VDISABLE '\0' | ||
| 128 | #endif | ||
| 129 | |||
| 130 | |||
| 131 | static | 117 | static |
| 132 | volatile int cmdedit_termw = 80; /* actual terminal width */ | 118 | volatile int cmdedit_termw = 80; /* actual terminal width */ |
| 133 | static int history_counter = 0; /* Number of commands in history list */ | 119 | static 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 { | |||
| 1169 | extern void cmdedit_read_input(char *prompt, char command[BUFSIZ]) | 1176 | extern 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/editors/vi.c b/editors/vi.c index bd183e8b0..e1ff9336f 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | char *vi_Version = | 21 | char *vi_Version = |
| 22 | "$Id: vi.c,v 1.9 2001/06/23 13:49:14 andersen Exp $"; | 22 | "$Id: vi.c,v 1.10 2001/06/26 02:06:08 bug1 Exp $"; |
| 23 | 23 | ||
| 24 | /* | 24 | /* |
| 25 | * To compile for standalone use: | 25 | * To compile for standalone use: |
| @@ -3152,8 +3152,10 @@ static void rawmode(void) | |||
| 3152 | term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's | 3152 | term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's |
| 3153 | term_vi.c_iflag &= (~IXON & ~ICRNL); | 3153 | term_vi.c_iflag &= (~IXON & ~ICRNL); |
| 3154 | term_vi.c_oflag &= (~ONLCR); | 3154 | term_vi.c_oflag &= (~ONLCR); |
| 3155 | #ifndef linux | ||
| 3155 | term_vi.c_cc[VMIN] = 1; | 3156 | term_vi.c_cc[VMIN] = 1; |
| 3156 | term_vi.c_cc[VTIME] = 0; | 3157 | term_vi.c_cc[VTIME] = 0; |
| 3158 | #endif | ||
| 3157 | erase_char = term_vi.c_cc[VERASE]; | 3159 | erase_char = term_vi.c_cc[VERASE]; |
| 3158 | tcsetattr(0, TCSANOW, &term_vi); | 3160 | tcsetattr(0, TCSANOW, &term_vi); |
| 3159 | } | 3161 | } |
diff --git a/hostname.c b/hostname.c index 573c8cece..d87851509 100644 --- a/hostname.c +++ b/hostname.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * $Id: hostname.c,v 1.29 2001/06/23 13:49:14 andersen Exp $ | 3 | * $Id: hostname.c,v 1.30 2001/06/26 02:06:08 bug1 Exp $ |
| 4 | * Mini hostname implementation for busybox | 4 | * Mini hostname implementation for busybox |
| 5 | * | 5 | * |
| 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
| @@ -49,10 +49,11 @@ static void do_sethostname(char *s, int isfile) | |||
| 49 | } else { | 49 | } else { |
| 50 | f = xfopen(s, "r"); | 50 | f = xfopen(s, "r"); |
| 51 | fgets(buf, 255, f); | 51 | fgets(buf, 255, f); |
| 52 | #ifdef BB_FEATURE_CLEAN_UP | ||
| 52 | fclose(f); | 53 | fclose(f); |
| 54 | #endif | ||
| 53 | chomp(buf); | 55 | chomp(buf); |
| 54 | if (sethostname(buf, strlen(buf)) < 0) | 56 | do_sethostname(buf, 0); |
| 55 | perror_msg_and_die("sethostname"); | ||
| 56 | } | 57 | } |
| 57 | } | 58 | } |
| 58 | 59 | ||
| @@ -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 | } |
diff --git a/include/libbb.h b/include/libbb.h index 102596c1f..3b0ced7d1 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -243,7 +243,11 @@ extern FILE *gz_open(FILE *compressed_file, int *pid); | |||
| 243 | extern struct hostent *xgethostbyname(const char *name); | 243 | extern struct hostent *xgethostbyname(const char *name); |
| 244 | 244 | ||
| 245 | char *dirname (const char *path); | 245 | char *dirname (const char *path); |
| 246 | char *strdup_substr (const char *s, int start, int end); | 246 | |
| 247 | static inline char *strdup_substr (const char *s, int start, int end) | ||
| 248 | { | ||
| 249 | return xstrndup (s+start, end-start); | ||
| 250 | } | ||
| 247 | int make_directory (char *path, mode_t mode, int flags); | 251 | int make_directory (char *path, mode_t mode, int flags); |
| 248 | 252 | ||
| 249 | #define CT_AUTO 0 | 253 | #define CT_AUTO 0 |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 102596c1f..3b0ced7d1 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
| @@ -243,7 +243,11 @@ extern FILE *gz_open(FILE *compressed_file, int *pid); | |||
| 243 | extern struct hostent *xgethostbyname(const char *name); | 243 | extern struct hostent *xgethostbyname(const char *name); |
| 244 | 244 | ||
| 245 | char *dirname (const char *path); | 245 | char *dirname (const char *path); |
| 246 | char *strdup_substr (const char *s, int start, int end); | 246 | |
| 247 | static inline char *strdup_substr (const char *s, int start, int end) | ||
| 248 | { | ||
| 249 | return xstrndup (s+start, end-start); | ||
| 250 | } | ||
| 247 | int make_directory (char *path, mode_t mode, int flags); | 251 | int make_directory (char *path, mode_t mode, int flags); |
| 248 | 252 | ||
| 249 | #define CT_AUTO 0 | 253 | #define CT_AUTO 0 |
| @@ -9,6 +9,8 @@ | |||
| 9 | * based on the original more implementation by Bruce, and code from the | 9 | * based on the original more implementation by Bruce, and code from the |
| 10 | * Debian boot-floppies team. | 10 | * Debian boot-floppies team. |
| 11 | * | 11 | * |
| 12 | * Termios corrects by Vladimir Oleynik <vodz@usa.net> | ||
| 13 | * | ||
| 12 | * This program is free software; you can redistribute it and/or modify | 14 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by | 15 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or | 16 | * the Free Software Foundation; either version 2 of the License, or |
| @@ -29,29 +31,26 @@ | |||
| 29 | #include <fcntl.h> | 31 | #include <fcntl.h> |
| 30 | #include <signal.h> | 32 | #include <signal.h> |
| 31 | #include <stdlib.h> | 33 | #include <stdlib.h> |
| 34 | #include <unistd.h> | ||
| 32 | #include <sys/ioctl.h> | 35 | #include <sys/ioctl.h> |
| 33 | #include "busybox.h" | 36 | #include "busybox.h" |
| 34 | 37 | ||
| 35 | /* ED: sparc termios is broken: revert back to old termio handling. */ | ||
| 36 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 37 | # if #cpu(sparc) | ||
| 38 | # include <termio.h> | ||
| 39 | # define termios termio | ||
| 40 | # define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp) | ||
| 41 | # define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp) | ||
| 42 | # else | ||
| 43 | # include <termios.h> | ||
| 44 | # define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
| 45 | # define getTermSettings(fd,argp) tcgetattr(fd, argp); | ||
| 46 | # endif | ||
| 47 | |||
| 48 | static FILE *cin; | 38 | static FILE *cin; |
| 49 | 39 | ||
| 40 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 41 | #include <termios.h> | ||
| 42 | #define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
| 43 | #define getTermSettings(fd,argp) tcgetattr(fd, argp); | ||
| 44 | |||
| 50 | static struct termios initial_settings, new_settings; | 45 | static struct termios initial_settings, new_settings; |
| 51 | 46 | ||
| 52 | static void gotsig(int sig) | 47 | static void set_tty_to_initial_mode(void) |
| 53 | { | 48 | { |
| 54 | setTermSettings(fileno(cin), &initial_settings); | 49 | setTermSettings(fileno(cin), &initial_settings); |
| 50 | } | ||
| 51 | |||
| 52 | static void gotsig(int sig) | ||
| 53 | { | ||
| 55 | putchar('\n'); | 54 | putchar('\n'); |
| 56 | exit(EXIT_FAILURE); | 55 | exit(EXIT_FAILURE); |
| 57 | } | 56 | } |
| @@ -65,7 +64,7 @@ static int terminal_height = 24; | |||
| 65 | extern int more_main(int argc, char **argv) | 64 | extern int more_main(int argc, char **argv) |
| 66 | { | 65 | { |
| 67 | int c, lines, input = 0; | 66 | int c, lines, input = 0; |
| 68 | int please_display_more_prompt; | 67 | int please_display_more_prompt = -1; |
| 69 | struct stat st; | 68 | struct stat st; |
| 70 | FILE *file; | 69 | FILE *file; |
| 71 | int len, page_height; | 70 | int len, page_height; |
| @@ -77,46 +76,57 @@ extern int more_main(int argc, char **argv) | |||
| 77 | argc--; | 76 | argc--; |
| 78 | argv++; | 77 | argv++; |
| 79 | 78 | ||
| 80 | do { | ||
| 81 | if (argc == 0) { | ||
| 82 | file = stdin; | ||
| 83 | } else | ||
| 84 | file = xfopen(*argv, "r"); | ||
| 85 | 79 | ||
| 86 | fstat(fileno(file), &st); | 80 | /* not use inputing from terminal if usage: more > outfile */ |
| 87 | 81 | if(isatty(fileno(stdout))) { | |
| 88 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 89 | cin = fopen("/dev/tty", "r"); | 82 | cin = fopen("/dev/tty", "r"); |
| 90 | if (!cin) | 83 | if (!cin) |
| 91 | cin = xfopen("/dev/console", "r"); | 84 | cin = xfopen("/dev/console", "r"); |
| 85 | please_display_more_prompt = 0; | ||
| 86 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 92 | getTermSettings(fileno(cin), &initial_settings); | 87 | getTermSettings(fileno(cin), &initial_settings); |
| 93 | new_settings = initial_settings; | 88 | new_settings = initial_settings; |
| 94 | new_settings.c_cc[VMIN] = 1; | ||
| 95 | new_settings.c_cc[VTIME] = 0; | ||
| 96 | new_settings.c_lflag &= ~ICANON; | 89 | new_settings.c_lflag &= ~ICANON; |
| 97 | new_settings.c_lflag &= ~ECHO; | 90 | new_settings.c_lflag &= ~ECHO; |
| 91 | #ifndef linux | ||
| 92 | /* Hmm, in linux c_cc[] not parsed if set ~ICANON */ | ||
| 93 | new_settings.c_cc[VMIN] = 1; | ||
| 94 | new_settings.c_cc[VTIME] = 0; | ||
| 95 | #endif | ||
| 98 | setTermSettings(fileno(cin), &new_settings); | 96 | setTermSettings(fileno(cin), &new_settings); |
| 97 | atexit(set_tty_to_initial_mode); | ||
| 98 | (void) signal(SIGINT, gotsig); | ||
| 99 | (void) signal(SIGQUIT, gotsig); | ||
| 100 | (void) signal(SIGTERM, gotsig); | ||
| 101 | #endif | ||
| 102 | } | ||
| 103 | |||
| 104 | do { | ||
| 105 | if (argc == 0) { | ||
| 106 | file = stdin; | ||
| 107 | } else | ||
| 108 | file = wfopen(*argv, "r"); | ||
| 109 | if(file==0) | ||
| 110 | goto loop; | ||
| 111 | |||
| 112 | fstat(fileno(file), &st); | ||
| 99 | 113 | ||
| 100 | # ifdef BB_FEATURE_AUTOWIDTH | 114 | if(please_display_more_prompt>0) |
| 115 | please_display_more_prompt = 0; | ||
| 116 | |||
| 117 | #if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS | ||
| 101 | ioctl(fileno(stdout), TIOCGWINSZ, &win); | 118 | ioctl(fileno(stdout), TIOCGWINSZ, &win); |
| 102 | if (win.ws_row > 4) | 119 | if (win.ws_row > 4) |
| 103 | terminal_height = win.ws_row - 2; | 120 | terminal_height = win.ws_row - 2; |
| 104 | if (win.ws_col > 0) | 121 | if (win.ws_col > 0) |
| 105 | terminal_width = win.ws_col - 1; | 122 | terminal_width = win.ws_col - 1; |
| 106 | # endif | ||
| 107 | |||
| 108 | (void) signal(SIGINT, gotsig); | ||
| 109 | (void) signal(SIGQUIT, gotsig); | ||
| 110 | (void) signal(SIGTERM, gotsig); | ||
| 111 | |||
| 112 | #endif | 123 | #endif |
| 113 | len=0; | 124 | len=0; |
| 114 | lines = 0; | 125 | lines = 0; |
| 115 | page_height = terminal_height; | 126 | page_height = terminal_height; |
| 116 | please_display_more_prompt = 0; | ||
| 117 | while ((c = getc(file)) != EOF) { | 127 | while ((c = getc(file)) != EOF) { |
| 118 | 128 | ||
| 119 | if (please_display_more_prompt) { | 129 | if (please_display_more_prompt>0) { |
| 120 | len = printf("--More-- "); | 130 | len = printf("--More-- "); |
| 121 | if (file != stdin) { | 131 | if (file != stdin) { |
| 122 | #if _FILE_OFFSET_BITS == 64 | 132 | #if _FILE_OFFSET_BITS == 64 |
| @@ -129,13 +139,6 @@ extern int more_main(int argc, char **argv) | |||
| 129 | (double) st.st_size)), (long)st.st_size); | 139 | (double) st.st_size)), (long)st.st_size); |
| 130 | #endif | 140 | #endif |
| 131 | } | 141 | } |
| 132 | len += printf("%s", | ||
| 133 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 134 | "" | ||
| 135 | #else | ||
| 136 | "\n" | ||
| 137 | #endif | ||
| 138 | ); | ||
| 139 | 142 | ||
| 140 | fflush(stdout); | 143 | fflush(stdout); |
| 141 | 144 | ||
| @@ -143,20 +146,16 @@ extern int more_main(int argc, char **argv) | |||
| 143 | * We've just displayed the "--More--" prompt, so now we need | 146 | * We've just displayed the "--More--" prompt, so now we need |
| 144 | * to get input from the user. | 147 | * to get input from the user. |
| 145 | */ | 148 | */ |
| 146 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 147 | input = getc(cin); | 149 | input = getc(cin); |
| 148 | #else | 150 | #ifndef BB_FEATURE_USE_TERMIOS |
| 149 | input = getc(stdin); | 151 | printf("\033[A"); /* up cursor */ |
| 150 | #endif | 152 | #endif |
| 151 | |||
| 152 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 153 | /* Erase the "More" message */ | 153 | /* Erase the "More" message */ |
| 154 | putc('\r', stdout); | 154 | putc('\r', stdout); |
| 155 | while (--len >= 0) | 155 | while (--len >= 0) |
| 156 | putc(' ', stdout); | 156 | putc(' ', stdout); |
| 157 | putc('\r', stdout); | 157 | putc('\r', stdout); |
| 158 | fflush(stdout); | 158 | fflush(stdout); |
| 159 | #endif | ||
| 160 | len=0; | 159 | len=0; |
| 161 | lines = 0; | 160 | lines = 0; |
| 162 | page_height = terminal_height; | 161 | page_height = terminal_height; |
| @@ -180,6 +179,7 @@ extern int more_main(int argc, char **argv) | |||
| 180 | /* increment by just one line if we are at | 179 | /* increment by just one line if we are at |
| 181 | * the end of this line */ | 180 | * the end of this line */ |
| 182 | if (input == '\n') | 181 | if (input == '\n') |
| 182 | if(please_display_more_prompt==0) | ||
| 183 | please_display_more_prompt = 1; | 183 | please_display_more_prompt = 1; |
| 184 | /* Adjust the terminal height for any overlap, so that | 184 | /* Adjust the terminal height for any overlap, so that |
| 185 | * no lines get lost off the top. */ | 185 | * no lines get lost off the top. */ |
| @@ -195,6 +195,7 @@ extern int more_main(int argc, char **argv) | |||
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | if (++lines >= page_height) { | 197 | if (++lines >= page_height) { |
| 198 | if(please_display_more_prompt==0) | ||
| 198 | please_display_more_prompt = 1; | 199 | please_display_more_prompt = 1; |
| 199 | } | 200 | } |
| 200 | len=0; | 201 | len=0; |
| @@ -208,12 +209,9 @@ extern int more_main(int argc, char **argv) | |||
| 208 | } | 209 | } |
| 209 | fclose(file); | 210 | fclose(file); |
| 210 | fflush(stdout); | 211 | fflush(stdout); |
| 211 | 212 | loop: | |
| 212 | argv++; | 213 | argv++; |
| 213 | } while (--argc > 0); | 214 | } while (--argc > 0); |
| 214 | end: | 215 | end: |
| 215 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 216 | setTermSettings(fileno(cin), &initial_settings); | ||
| 217 | #endif | ||
| 218 | return 0; | 216 | return 0; |
| 219 | } | 217 | } |
diff --git a/networking/hostname.c b/networking/hostname.c index 573c8cece..d87851509 100644 --- a/networking/hostname.c +++ b/networking/hostname.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * $Id: hostname.c,v 1.29 2001/06/23 13:49:14 andersen Exp $ | 3 | * $Id: hostname.c,v 1.30 2001/06/26 02:06:08 bug1 Exp $ |
| 4 | * Mini hostname implementation for busybox | 4 | * Mini hostname implementation for busybox |
| 5 | * | 5 | * |
| 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
| @@ -49,10 +49,11 @@ static void do_sethostname(char *s, int isfile) | |||
| 49 | } else { | 49 | } else { |
| 50 | f = xfopen(s, "r"); | 50 | f = xfopen(s, "r"); |
| 51 | fgets(buf, 255, f); | 51 | fgets(buf, 255, f); |
| 52 | #ifdef BB_FEATURE_CLEAN_UP | ||
| 52 | fclose(f); | 53 | fclose(f); |
| 54 | #endif | ||
| 53 | chomp(buf); | 55 | chomp(buf); |
| 54 | if (sethostname(buf, strlen(buf)) < 0) | 56 | do_sethostname(buf, 0); |
| 55 | perror_msg_and_die("sethostname"); | ||
| 56 | } | 57 | } |
| 57 | } | 58 | } |
| 58 | 59 | ||
diff --git a/networking/telnet.c b/networking/telnet.c index 2587193e2..ce82a0ee8 100644 --- a/networking/telnet.c +++ b/networking/telnet.c | |||
| @@ -64,8 +64,8 @@ static const int DOTRACE = 1; | |||
| 64 | #include <sys/time.h> | 64 | #include <sys/time.h> |
| 65 | #endif | 65 | #endif |
| 66 | 66 | ||
| 67 | static const int DATABUFSIZE = 128; | 67 | #define DATABUFSIZE 128 |
| 68 | static const int IACBUFSIZE = 128; | 68 | #define IACBUFSIZE 128 |
| 69 | 69 | ||
| 70 | static const int CHM_TRY = 0; | 70 | static const int CHM_TRY = 0; |
| 71 | static const int CHM_ON = 1; | 71 | static const int CHM_ON = 1; |
| @@ -90,15 +90,14 @@ typedef unsigned char byte; | |||
| 90 | static struct Globalvars { | 90 | static struct Globalvars { |
| 91 | int netfd; /* console fd:s are 0 and 1 (and 2) */ | 91 | int netfd; /* console fd:s are 0 and 1 (and 2) */ |
| 92 | /* same buffer used both for network and console read/write */ | 92 | /* same buffer used both for network and console read/write */ |
| 93 | char * buf; /* allocating so static size is smaller */ | 93 | char buf[DATABUFSIZE]; /* allocating so static size is smaller */ |
| 94 | short len; | ||
| 95 | byte telstate; /* telnet negotiation state from network input */ | 94 | byte telstate; /* telnet negotiation state from network input */ |
| 96 | byte telwish; /* DO, DONT, WILL, WONT */ | 95 | byte telwish; /* DO, DONT, WILL, WONT */ |
| 97 | byte charmode; | 96 | byte charmode; |
| 98 | byte telflags; | 97 | byte telflags; |
| 99 | byte gotsig; | 98 | byte gotsig; |
| 100 | /* buffer to handle telnet negotiations */ | 99 | /* buffer to handle telnet negotiations */ |
| 101 | char * iacbuf; | 100 | char iacbuf[IACBUFSIZE]; |
| 102 | short iaclen; /* could even use byte */ | 101 | short iaclen; /* could even use byte */ |
| 103 | struct termios termios_def; | 102 | struct termios termios_def; |
| 104 | struct termios termios_raw; | 103 | struct termios termios_raw; |
| @@ -198,7 +197,7 @@ static void conescape() | |||
| 198 | G.gotsig = 0; | 197 | G.gotsig = 0; |
| 199 | 198 | ||
| 200 | } | 199 | } |
| 201 | static void handlenetoutput() | 200 | static void handlenetoutput(int len) |
| 202 | { | 201 | { |
| 203 | /* here we could do smart tricks how to handle 0xFF:s in output | 202 | /* here we could do smart tricks how to handle 0xFF:s in output |
| 204 | * stream like writing twice every sequence of FF:s (thus doing | 203 | * stream like writing twice every sequence of FF:s (thus doing |
| @@ -209,7 +208,7 @@ static void handlenetoutput() | |||
| 209 | int i; | 208 | int i; |
| 210 | byte * p = G.buf; | 209 | byte * p = G.buf; |
| 211 | 210 | ||
| 212 | for (i = G.len; i > 0; i--, p++) | 211 | for (i = len; i > 0; i--, p++) |
| 213 | { | 212 | { |
| 214 | if (*p == 0x1d) | 213 | if (*p == 0x1d) |
| 215 | { | 214 | { |
| @@ -219,16 +218,16 @@ static void handlenetoutput() | |||
| 219 | if (*p == 0xff) | 218 | if (*p == 0xff) |
| 220 | *p = 0x7f; | 219 | *p = 0x7f; |
| 221 | } | 220 | } |
| 222 | write(G.netfd, G.buf, G.len); | 221 | write(G.netfd, G.buf, len); |
| 223 | } | 222 | } |
| 224 | 223 | ||
| 225 | 224 | ||
| 226 | static void handlenetinput() | 225 | static void handlenetinput(int len) |
| 227 | { | 226 | { |
| 228 | int i; | 227 | int i; |
| 229 | int cstart = 0; | 228 | int cstart = 0; |
| 230 | 229 | ||
| 231 | for (i = 0; i < G.len; i++) | 230 | for (i = 0; i < len; i++) |
| 232 | { | 231 | { |
| 233 | byte c = G.buf[i]; | 232 | byte c = G.buf[i]; |
| 234 | 233 | ||
| @@ -290,11 +289,11 @@ static void handlenetinput() | |||
| 290 | if (G.iaclen) iacflush(); | 289 | if (G.iaclen) iacflush(); |
| 291 | if (G.telstate == TS_0) G.telstate = 0; | 290 | if (G.telstate == TS_0) G.telstate = 0; |
| 292 | 291 | ||
| 293 | G.len = cstart; | 292 | len = cstart; |
| 294 | } | 293 | } |
| 295 | 294 | ||
| 296 | if (G.len) | 295 | if (len) |
| 297 | write(1, G.buf, G.len); | 296 | write(1, G.buf, len); |
| 298 | } | 297 | } |
| 299 | 298 | ||
| 300 | 299 | ||
| @@ -530,6 +529,7 @@ extern int telnet_main(int argc, char** argv) | |||
| 530 | { | 529 | { |
| 531 | struct in_addr host; | 530 | struct in_addr host; |
| 532 | int port; | 531 | int port; |
| 532 | int len; | ||
| 533 | #ifdef USE_POLL | 533 | #ifdef USE_POLL |
| 534 | struct pollfd ufds[2]; | 534 | struct pollfd ufds[2]; |
| 535 | #else | 535 | #else |
| @@ -547,15 +547,11 @@ extern int telnet_main(int argc, char** argv) | |||
| 547 | exit(1); | 547 | exit(1); |
| 548 | 548 | ||
| 549 | G.termios_raw = G.termios_def; | 549 | G.termios_raw = G.termios_def; |
| 550 | |||
| 551 | cfmakeraw(&G.termios_raw); | 550 | cfmakeraw(&G.termios_raw); |
| 552 | 551 | ||
| 553 | if (argc < 2) show_usage(); | 552 | if (argc < 2) show_usage(); |
| 554 | port = (argc > 2)? getport(argv[2]): 23; | 553 | port = (argc > 2)? getport(argv[2]): 23; |
| 555 | 554 | ||
| 556 | G.buf = xmalloc(DATABUFSIZE); | ||
| 557 | G.iacbuf = xmalloc(IACBUFSIZE); | ||
| 558 | |||
| 559 | host = getserver(argv[1]); | 555 | host = getserver(argv[1]); |
| 560 | 556 | ||
| 561 | G.netfd = remote_connect(host, port); | 557 | G.netfd = remote_connect(host, port); |
| @@ -599,14 +595,14 @@ extern int telnet_main(int argc, char** argv) | |||
| 599 | if (FD_ISSET(0, &rfds)) | 595 | if (FD_ISSET(0, &rfds)) |
| 600 | #endif | 596 | #endif |
| 601 | { | 597 | { |
| 602 | G.len = read(0, G.buf, DATABUFSIZE); | 598 | len = read(0, G.buf, DATABUFSIZE); |
| 603 | 599 | ||
| 604 | if (G.len <= 0) | 600 | if (len <= 0) |
| 605 | doexit(0); | 601 | doexit(0); |
| 606 | 602 | ||
| 607 | TRACE(0, ("Read con: %d\n", G.len)); | 603 | TRACE(0, ("Read con: %d\n", len)); |
| 608 | 604 | ||
| 609 | handlenetoutput(); | 605 | handlenetoutput(len); |
| 610 | } | 606 | } |
| 611 | 607 | ||
| 612 | #ifdef USE_POLL | 608 | #ifdef USE_POLL |
| @@ -615,16 +611,16 @@ extern int telnet_main(int argc, char** argv) | |||
| 615 | if (FD_ISSET(G.netfd, &rfds)) | 611 | if (FD_ISSET(G.netfd, &rfds)) |
| 616 | #endif | 612 | #endif |
| 617 | { | 613 | { |
| 618 | G.len = read(G.netfd, G.buf, DATABUFSIZE); | 614 | len = read(G.netfd, G.buf, DATABUFSIZE); |
| 619 | 615 | ||
| 620 | if (G.len <= 0) | 616 | if (len <= 0) |
| 621 | { | 617 | { |
| 622 | WriteCS(1, "Connection closed by foreign host.\r\n"); | 618 | WriteCS(1, "Connection closed by foreign host.\r\n"); |
| 623 | doexit(1); | 619 | doexit(1); |
| 624 | } | 620 | } |
| 625 | TRACE(0, ("Read netfd (%d): %d\n", G.netfd, G.len)); | 621 | TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len)); |
| 626 | 622 | ||
| 627 | handlenetinput(); | 623 | handlenetinput(len); |
| 628 | } | 624 | } |
| 629 | } | 625 | } |
| 630 | } | 626 | } |
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; | |||
| 106 | static struct history *his_end = NULL; | 106 | static 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 */ |
| 123 | static struct termios initial_settings, new_settings; | 114 | static struct termios initial_settings, new_settings; |
| 124 | 115 | ||
| 125 | 116 | ||
| 126 | #ifndef _POSIX_VDISABLE | ||
| 127 | #define _POSIX_VDISABLE '\0' | ||
| 128 | #endif | ||
| 129 | |||
| 130 | |||
| 131 | static | 117 | static |
| 132 | volatile int cmdedit_termw = 80; /* actual terminal width */ | 118 | volatile int cmdedit_termw = 80; /* actual terminal width */ |
| 133 | static int history_counter = 0; /* Number of commands in history list */ | 119 | static 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 { | |||
| 1169 | extern void cmdedit_read_input(char *prompt, char command[BUFSIZ]) | 1176 | extern 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 | } |
| @@ -64,8 +64,8 @@ static const int DOTRACE = 1; | |||
| 64 | #include <sys/time.h> | 64 | #include <sys/time.h> |
| 65 | #endif | 65 | #endif |
| 66 | 66 | ||
| 67 | static const int DATABUFSIZE = 128; | 67 | #define DATABUFSIZE 128 |
| 68 | static const int IACBUFSIZE = 128; | 68 | #define IACBUFSIZE 128 |
| 69 | 69 | ||
| 70 | static const int CHM_TRY = 0; | 70 | static const int CHM_TRY = 0; |
| 71 | static const int CHM_ON = 1; | 71 | static const int CHM_ON = 1; |
| @@ -90,15 +90,14 @@ typedef unsigned char byte; | |||
| 90 | static struct Globalvars { | 90 | static struct Globalvars { |
| 91 | int netfd; /* console fd:s are 0 and 1 (and 2) */ | 91 | int netfd; /* console fd:s are 0 and 1 (and 2) */ |
| 92 | /* same buffer used both for network and console read/write */ | 92 | /* same buffer used both for network and console read/write */ |
| 93 | char * buf; /* allocating so static size is smaller */ | 93 | char buf[DATABUFSIZE]; /* allocating so static size is smaller */ |
| 94 | short len; | ||
| 95 | byte telstate; /* telnet negotiation state from network input */ | 94 | byte telstate; /* telnet negotiation state from network input */ |
| 96 | byte telwish; /* DO, DONT, WILL, WONT */ | 95 | byte telwish; /* DO, DONT, WILL, WONT */ |
| 97 | byte charmode; | 96 | byte charmode; |
| 98 | byte telflags; | 97 | byte telflags; |
| 99 | byte gotsig; | 98 | byte gotsig; |
| 100 | /* buffer to handle telnet negotiations */ | 99 | /* buffer to handle telnet negotiations */ |
| 101 | char * iacbuf; | 100 | char iacbuf[IACBUFSIZE]; |
| 102 | short iaclen; /* could even use byte */ | 101 | short iaclen; /* could even use byte */ |
| 103 | struct termios termios_def; | 102 | struct termios termios_def; |
| 104 | struct termios termios_raw; | 103 | struct termios termios_raw; |
| @@ -198,7 +197,7 @@ static void conescape() | |||
| 198 | G.gotsig = 0; | 197 | G.gotsig = 0; |
| 199 | 198 | ||
| 200 | } | 199 | } |
| 201 | static void handlenetoutput() | 200 | static void handlenetoutput(int len) |
| 202 | { | 201 | { |
| 203 | /* here we could do smart tricks how to handle 0xFF:s in output | 202 | /* here we could do smart tricks how to handle 0xFF:s in output |
| 204 | * stream like writing twice every sequence of FF:s (thus doing | 203 | * stream like writing twice every sequence of FF:s (thus doing |
| @@ -209,7 +208,7 @@ static void handlenetoutput() | |||
| 209 | int i; | 208 | int i; |
| 210 | byte * p = G.buf; | 209 | byte * p = G.buf; |
| 211 | 210 | ||
| 212 | for (i = G.len; i > 0; i--, p++) | 211 | for (i = len; i > 0; i--, p++) |
| 213 | { | 212 | { |
| 214 | if (*p == 0x1d) | 213 | if (*p == 0x1d) |
| 215 | { | 214 | { |
| @@ -219,16 +218,16 @@ static void handlenetoutput() | |||
| 219 | if (*p == 0xff) | 218 | if (*p == 0xff) |
| 220 | *p = 0x7f; | 219 | *p = 0x7f; |
| 221 | } | 220 | } |
| 222 | write(G.netfd, G.buf, G.len); | 221 | write(G.netfd, G.buf, len); |
| 223 | } | 222 | } |
| 224 | 223 | ||
| 225 | 224 | ||
| 226 | static void handlenetinput() | 225 | static void handlenetinput(int len) |
| 227 | { | 226 | { |
| 228 | int i; | 227 | int i; |
| 229 | int cstart = 0; | 228 | int cstart = 0; |
| 230 | 229 | ||
| 231 | for (i = 0; i < G.len; i++) | 230 | for (i = 0; i < len; i++) |
| 232 | { | 231 | { |
| 233 | byte c = G.buf[i]; | 232 | byte c = G.buf[i]; |
| 234 | 233 | ||
| @@ -290,11 +289,11 @@ static void handlenetinput() | |||
| 290 | if (G.iaclen) iacflush(); | 289 | if (G.iaclen) iacflush(); |
| 291 | if (G.telstate == TS_0) G.telstate = 0; | 290 | if (G.telstate == TS_0) G.telstate = 0; |
| 292 | 291 | ||
| 293 | G.len = cstart; | 292 | len = cstart; |
| 294 | } | 293 | } |
| 295 | 294 | ||
| 296 | if (G.len) | 295 | if (len) |
| 297 | write(1, G.buf, G.len); | 296 | write(1, G.buf, len); |
| 298 | } | 297 | } |
| 299 | 298 | ||
| 300 | 299 | ||
| @@ -530,6 +529,7 @@ extern int telnet_main(int argc, char** argv) | |||
| 530 | { | 529 | { |
| 531 | struct in_addr host; | 530 | struct in_addr host; |
| 532 | int port; | 531 | int port; |
| 532 | int len; | ||
| 533 | #ifdef USE_POLL | 533 | #ifdef USE_POLL |
| 534 | struct pollfd ufds[2]; | 534 | struct pollfd ufds[2]; |
| 535 | #else | 535 | #else |
| @@ -547,15 +547,11 @@ extern int telnet_main(int argc, char** argv) | |||
| 547 | exit(1); | 547 | exit(1); |
| 548 | 548 | ||
| 549 | G.termios_raw = G.termios_def; | 549 | G.termios_raw = G.termios_def; |
| 550 | |||
| 551 | cfmakeraw(&G.termios_raw); | 550 | cfmakeraw(&G.termios_raw); |
| 552 | 551 | ||
| 553 | if (argc < 2) show_usage(); | 552 | if (argc < 2) show_usage(); |
| 554 | port = (argc > 2)? getport(argv[2]): 23; | 553 | port = (argc > 2)? getport(argv[2]): 23; |
| 555 | 554 | ||
| 556 | G.buf = xmalloc(DATABUFSIZE); | ||
| 557 | G.iacbuf = xmalloc(IACBUFSIZE); | ||
| 558 | |||
| 559 | host = getserver(argv[1]); | 555 | host = getserver(argv[1]); |
| 560 | 556 | ||
| 561 | G.netfd = remote_connect(host, port); | 557 | G.netfd = remote_connect(host, port); |
| @@ -599,14 +595,14 @@ extern int telnet_main(int argc, char** argv) | |||
| 599 | if (FD_ISSET(0, &rfds)) | 595 | if (FD_ISSET(0, &rfds)) |
| 600 | #endif | 596 | #endif |
| 601 | { | 597 | { |
| 602 | G.len = read(0, G.buf, DATABUFSIZE); | 598 | len = read(0, G.buf, DATABUFSIZE); |
| 603 | 599 | ||
| 604 | if (G.len <= 0) | 600 | if (len <= 0) |
| 605 | doexit(0); | 601 | doexit(0); |
| 606 | 602 | ||
| 607 | TRACE(0, ("Read con: %d\n", G.len)); | 603 | TRACE(0, ("Read con: %d\n", len)); |
| 608 | 604 | ||
| 609 | handlenetoutput(); | 605 | handlenetoutput(len); |
| 610 | } | 606 | } |
| 611 | 607 | ||
| 612 | #ifdef USE_POLL | 608 | #ifdef USE_POLL |
| @@ -615,16 +611,16 @@ extern int telnet_main(int argc, char** argv) | |||
| 615 | if (FD_ISSET(G.netfd, &rfds)) | 611 | if (FD_ISSET(G.netfd, &rfds)) |
| 616 | #endif | 612 | #endif |
| 617 | { | 613 | { |
| 618 | G.len = read(G.netfd, G.buf, DATABUFSIZE); | 614 | len = read(G.netfd, G.buf, DATABUFSIZE); |
| 619 | 615 | ||
| 620 | if (G.len <= 0) | 616 | if (len <= 0) |
| 621 | { | 617 | { |
| 622 | WriteCS(1, "Connection closed by foreign host.\r\n"); | 618 | WriteCS(1, "Connection closed by foreign host.\r\n"); |
| 623 | doexit(1); | 619 | doexit(1); |
| 624 | } | 620 | } |
| 625 | TRACE(0, ("Read netfd (%d): %d\n", G.netfd, G.len)); | 621 | TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len)); |
| 626 | 622 | ||
| 627 | handlenetinput(); | 623 | handlenetinput(len); |
| 628 | } | 624 | } |
| 629 | } | 625 | } |
| 630 | } | 626 | } |
diff --git a/util-linux/more.c b/util-linux/more.c index 9f07633c3..6cdec729b 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | * based on the original more implementation by Bruce, and code from the | 9 | * based on the original more implementation by Bruce, and code from the |
| 10 | * Debian boot-floppies team. | 10 | * Debian boot-floppies team. |
| 11 | * | 11 | * |
| 12 | * Termios corrects by Vladimir Oleynik <vodz@usa.net> | ||
| 13 | * | ||
| 12 | * This program is free software; you can redistribute it and/or modify | 14 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by | 15 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or | 16 | * the Free Software Foundation; either version 2 of the License, or |
| @@ -29,29 +31,26 @@ | |||
| 29 | #include <fcntl.h> | 31 | #include <fcntl.h> |
| 30 | #include <signal.h> | 32 | #include <signal.h> |
| 31 | #include <stdlib.h> | 33 | #include <stdlib.h> |
| 34 | #include <unistd.h> | ||
| 32 | #include <sys/ioctl.h> | 35 | #include <sys/ioctl.h> |
| 33 | #include "busybox.h" | 36 | #include "busybox.h" |
| 34 | 37 | ||
| 35 | /* ED: sparc termios is broken: revert back to old termio handling. */ | ||
| 36 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 37 | # if #cpu(sparc) | ||
| 38 | # include <termio.h> | ||
| 39 | # define termios termio | ||
| 40 | # define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp) | ||
| 41 | # define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp) | ||
| 42 | # else | ||
| 43 | # include <termios.h> | ||
| 44 | # define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
| 45 | # define getTermSettings(fd,argp) tcgetattr(fd, argp); | ||
| 46 | # endif | ||
| 47 | |||
| 48 | static FILE *cin; | 38 | static FILE *cin; |
| 49 | 39 | ||
| 40 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 41 | #include <termios.h> | ||
| 42 | #define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
| 43 | #define getTermSettings(fd,argp) tcgetattr(fd, argp); | ||
| 44 | |||
| 50 | static struct termios initial_settings, new_settings; | 45 | static struct termios initial_settings, new_settings; |
| 51 | 46 | ||
| 52 | static void gotsig(int sig) | 47 | static void set_tty_to_initial_mode(void) |
| 53 | { | 48 | { |
| 54 | setTermSettings(fileno(cin), &initial_settings); | 49 | setTermSettings(fileno(cin), &initial_settings); |
| 50 | } | ||
| 51 | |||
| 52 | static void gotsig(int sig) | ||
| 53 | { | ||
| 55 | putchar('\n'); | 54 | putchar('\n'); |
| 56 | exit(EXIT_FAILURE); | 55 | exit(EXIT_FAILURE); |
| 57 | } | 56 | } |
| @@ -65,7 +64,7 @@ static int terminal_height = 24; | |||
| 65 | extern int more_main(int argc, char **argv) | 64 | extern int more_main(int argc, char **argv) |
| 66 | { | 65 | { |
| 67 | int c, lines, input = 0; | 66 | int c, lines, input = 0; |
| 68 | int please_display_more_prompt; | 67 | int please_display_more_prompt = -1; |
| 69 | struct stat st; | 68 | struct stat st; |
| 70 | FILE *file; | 69 | FILE *file; |
| 71 | int len, page_height; | 70 | int len, page_height; |
| @@ -77,46 +76,57 @@ extern int more_main(int argc, char **argv) | |||
| 77 | argc--; | 76 | argc--; |
| 78 | argv++; | 77 | argv++; |
| 79 | 78 | ||
| 80 | do { | ||
| 81 | if (argc == 0) { | ||
| 82 | file = stdin; | ||
| 83 | } else | ||
| 84 | file = xfopen(*argv, "r"); | ||
| 85 | 79 | ||
| 86 | fstat(fileno(file), &st); | 80 | /* not use inputing from terminal if usage: more > outfile */ |
| 87 | 81 | if(isatty(fileno(stdout))) { | |
| 88 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 89 | cin = fopen("/dev/tty", "r"); | 82 | cin = fopen("/dev/tty", "r"); |
| 90 | if (!cin) | 83 | if (!cin) |
| 91 | cin = xfopen("/dev/console", "r"); | 84 | cin = xfopen("/dev/console", "r"); |
| 85 | please_display_more_prompt = 0; | ||
| 86 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 92 | getTermSettings(fileno(cin), &initial_settings); | 87 | getTermSettings(fileno(cin), &initial_settings); |
| 93 | new_settings = initial_settings; | 88 | new_settings = initial_settings; |
| 94 | new_settings.c_cc[VMIN] = 1; | ||
| 95 | new_settings.c_cc[VTIME] = 0; | ||
| 96 | new_settings.c_lflag &= ~ICANON; | 89 | new_settings.c_lflag &= ~ICANON; |
| 97 | new_settings.c_lflag &= ~ECHO; | 90 | new_settings.c_lflag &= ~ECHO; |
| 91 | #ifndef linux | ||
| 92 | /* Hmm, in linux c_cc[] not parsed if set ~ICANON */ | ||
| 93 | new_settings.c_cc[VMIN] = 1; | ||
| 94 | new_settings.c_cc[VTIME] = 0; | ||
| 95 | #endif | ||
| 98 | setTermSettings(fileno(cin), &new_settings); | 96 | setTermSettings(fileno(cin), &new_settings); |
| 97 | atexit(set_tty_to_initial_mode); | ||
| 98 | (void) signal(SIGINT, gotsig); | ||
| 99 | (void) signal(SIGQUIT, gotsig); | ||
| 100 | (void) signal(SIGTERM, gotsig); | ||
| 101 | #endif | ||
| 102 | } | ||
| 103 | |||
| 104 | do { | ||
| 105 | if (argc == 0) { | ||
| 106 | file = stdin; | ||
| 107 | } else | ||
| 108 | file = wfopen(*argv, "r"); | ||
| 109 | if(file==0) | ||
| 110 | goto loop; | ||
| 111 | |||
| 112 | fstat(fileno(file), &st); | ||
| 99 | 113 | ||
| 100 | # ifdef BB_FEATURE_AUTOWIDTH | 114 | if(please_display_more_prompt>0) |
| 115 | please_display_more_prompt = 0; | ||
| 116 | |||
| 117 | #if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS | ||
| 101 | ioctl(fileno(stdout), TIOCGWINSZ, &win); | 118 | ioctl(fileno(stdout), TIOCGWINSZ, &win); |
| 102 | if (win.ws_row > 4) | 119 | if (win.ws_row > 4) |
| 103 | terminal_height = win.ws_row - 2; | 120 | terminal_height = win.ws_row - 2; |
| 104 | if (win.ws_col > 0) | 121 | if (win.ws_col > 0) |
| 105 | terminal_width = win.ws_col - 1; | 122 | terminal_width = win.ws_col - 1; |
| 106 | # endif | ||
| 107 | |||
| 108 | (void) signal(SIGINT, gotsig); | ||
| 109 | (void) signal(SIGQUIT, gotsig); | ||
| 110 | (void) signal(SIGTERM, gotsig); | ||
| 111 | |||
| 112 | #endif | 123 | #endif |
| 113 | len=0; | 124 | len=0; |
| 114 | lines = 0; | 125 | lines = 0; |
| 115 | page_height = terminal_height; | 126 | page_height = terminal_height; |
| 116 | please_display_more_prompt = 0; | ||
| 117 | while ((c = getc(file)) != EOF) { | 127 | while ((c = getc(file)) != EOF) { |
| 118 | 128 | ||
| 119 | if (please_display_more_prompt) { | 129 | if (please_display_more_prompt>0) { |
| 120 | len = printf("--More-- "); | 130 | len = printf("--More-- "); |
| 121 | if (file != stdin) { | 131 | if (file != stdin) { |
| 122 | #if _FILE_OFFSET_BITS == 64 | 132 | #if _FILE_OFFSET_BITS == 64 |
| @@ -129,13 +139,6 @@ extern int more_main(int argc, char **argv) | |||
| 129 | (double) st.st_size)), (long)st.st_size); | 139 | (double) st.st_size)), (long)st.st_size); |
| 130 | #endif | 140 | #endif |
| 131 | } | 141 | } |
| 132 | len += printf("%s", | ||
| 133 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 134 | "" | ||
| 135 | #else | ||
| 136 | "\n" | ||
| 137 | #endif | ||
| 138 | ); | ||
| 139 | 142 | ||
| 140 | fflush(stdout); | 143 | fflush(stdout); |
| 141 | 144 | ||
| @@ -143,20 +146,16 @@ extern int more_main(int argc, char **argv) | |||
| 143 | * We've just displayed the "--More--" prompt, so now we need | 146 | * We've just displayed the "--More--" prompt, so now we need |
| 144 | * to get input from the user. | 147 | * to get input from the user. |
| 145 | */ | 148 | */ |
| 146 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 147 | input = getc(cin); | 149 | input = getc(cin); |
| 148 | #else | 150 | #ifndef BB_FEATURE_USE_TERMIOS |
| 149 | input = getc(stdin); | 151 | printf("\033[A"); /* up cursor */ |
| 150 | #endif | 152 | #endif |
| 151 | |||
| 152 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 153 | /* Erase the "More" message */ | 153 | /* Erase the "More" message */ |
| 154 | putc('\r', stdout); | 154 | putc('\r', stdout); |
| 155 | while (--len >= 0) | 155 | while (--len >= 0) |
| 156 | putc(' ', stdout); | 156 | putc(' ', stdout); |
| 157 | putc('\r', stdout); | 157 | putc('\r', stdout); |
| 158 | fflush(stdout); | 158 | fflush(stdout); |
| 159 | #endif | ||
| 160 | len=0; | 159 | len=0; |
| 161 | lines = 0; | 160 | lines = 0; |
| 162 | page_height = terminal_height; | 161 | page_height = terminal_height; |
| @@ -180,6 +179,7 @@ extern int more_main(int argc, char **argv) | |||
| 180 | /* increment by just one line if we are at | 179 | /* increment by just one line if we are at |
| 181 | * the end of this line */ | 180 | * the end of this line */ |
| 182 | if (input == '\n') | 181 | if (input == '\n') |
| 182 | if(please_display_more_prompt==0) | ||
| 183 | please_display_more_prompt = 1; | 183 | please_display_more_prompt = 1; |
| 184 | /* Adjust the terminal height for any overlap, so that | 184 | /* Adjust the terminal height for any overlap, so that |
| 185 | * no lines get lost off the top. */ | 185 | * no lines get lost off the top. */ |
| @@ -195,6 +195,7 @@ extern int more_main(int argc, char **argv) | |||
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | if (++lines >= page_height) { | 197 | if (++lines >= page_height) { |
| 198 | if(please_display_more_prompt==0) | ||
| 198 | please_display_more_prompt = 1; | 199 | please_display_more_prompt = 1; |
| 199 | } | 200 | } |
| 200 | len=0; | 201 | len=0; |
| @@ -208,12 +209,9 @@ extern int more_main(int argc, char **argv) | |||
| 208 | } | 209 | } |
| 209 | fclose(file); | 210 | fclose(file); |
| 210 | fflush(stdout); | 211 | fflush(stdout); |
| 211 | 212 | loop: | |
| 212 | argv++; | 213 | argv++; |
| 213 | } while (--argc > 0); | 214 | } while (--argc > 0); |
| 214 | end: | 215 | end: |
| 215 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 216 | setTermSettings(fileno(cin), &initial_settings); | ||
| 217 | #endif | ||
| 218 | return 0; | 216 | return 0; |
| 219 | } | 217 | } |
| @@ -19,7 +19,7 @@ | |||
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | char *vi_Version = | 21 | char *vi_Version = |
| 22 | "$Id: vi.c,v 1.9 2001/06/23 13:49:14 andersen Exp $"; | 22 | "$Id: vi.c,v 1.10 2001/06/26 02:06:08 bug1 Exp $"; |
| 23 | 23 | ||
| 24 | /* | 24 | /* |
| 25 | * To compile for standalone use: | 25 | * To compile for standalone use: |
| @@ -3152,8 +3152,10 @@ static void rawmode(void) | |||
| 3152 | term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's | 3152 | term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's |
| 3153 | term_vi.c_iflag &= (~IXON & ~ICRNL); | 3153 | term_vi.c_iflag &= (~IXON & ~ICRNL); |
| 3154 | term_vi.c_oflag &= (~ONLCR); | 3154 | term_vi.c_oflag &= (~ONLCR); |
| 3155 | #ifndef linux | ||
| 3155 | term_vi.c_cc[VMIN] = 1; | 3156 | term_vi.c_cc[VMIN] = 1; |
| 3156 | term_vi.c_cc[VTIME] = 0; | 3157 | term_vi.c_cc[VTIME] = 0; |
| 3158 | #endif | ||
| 3157 | erase_char = term_vi.c_cc[VERASE]; | 3159 | erase_char = term_vi.c_cc[VERASE]; |
| 3158 | tcsetattr(0, TCSANOW, &term_vi); | 3160 | tcsetattr(0, TCSANOW, &term_vi); |
| 3159 | } | 3161 | } |
