trim.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \
xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \
copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \
-dirname.c make_directory.c strdup_substr.c
+dirname.c make_directory.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
LIBBB_CFLAGS = -I$(LIBBB)
ifneq ($(strip $(BB_SRC_DIR)),)
#endif
#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR
-#ifndef TEST
-#include "pwd_grp/pwd.h"
-#else
-#include <pwd.h>
-#endif /* TEST */
+# ifndef TEST
+# include "pwd_grp/pwd.h"
+# else
+# include <pwd.h>
+# endif /* TEST */
#endif /* advanced FEATURES */
static struct history *his_end = NULL;
-/* ED: sparc termios is broken: revert back to old termio handling. */
-
-#if #cpu(sparc)
-# include <termio.h>
-# define termios termio
-# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
-# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
-#else
-# include <termios.h>
-# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
-# define getTermSettings(fd,argp) tcgetattr(fd, argp);
-#endif
+#include <termios.h>
+#define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
+#define getTermSettings(fd,argp) tcgetattr(fd, argp);
/* Current termio and the previous termio before starting sh */
static struct termios initial_settings, new_settings;
-#ifndef _POSIX_VDISABLE
-#define _POSIX_VDISABLE '\0'
-#endif
-
-
static
volatile int cmdedit_termw = 80; /* actual terminal width */
static int history_counter = 0; /* Number of commands in history list */
char *pbuf;
if (!pwd_buf) {
- pwd_buf=unknown;
+ pwd_buf=(char *)unknown;
}
while (*prmt_ptr) {
* in the current working directory that matches. */
if (!matches)
matches =
- exe_n_cwd_tab_completion(matchBuf, &num_matches,
- find_type);
-
+ exe_n_cwd_tab_completion(matchBuf,
+ &num_matches, find_type);
+ /* Remove duplicate found */
+ if(matches) {
+ int i, j;
+ /* bubble */
+ for(i=0; i<(num_matches-1); i++)
+ for(j=i+1; j<num_matches; j++)
+ if(matches[i]!=0 && matches[j]!=0 &&
+ strcmp(matches[i], matches[j])==0) {
+ free(matches[j]);
+ matches[j]=0;
+ }
+ j=num_matches;
+ num_matches = 0;
+ for(i=0; i<j; i++)
+ if(matches[i]) {
+ if(!strcmp(matches[i], "./"))
+ matches[i][1]=0;
+ else if(!strcmp(matches[i], "../"))
+ matches[i][2]=0;
+ matches[num_matches++]=matches[i];
+ }
+ }
/* Did we find exactly one match? */
if (!matches || num_matches > 1) {
char *tmp1;
extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
{
- int inputFd = fileno(stdin);
-
int break_out = 0;
int lastWasTab = FALSE;
unsigned char c = 0;
len = 0;
command_ps = command;
- if (new_settings.c_cc[VMIN] == 0) { /* first call */
+ if (new_settings.c_cc[VERASE] == 0) { /* first call */
- getTermSettings(inputFd, (void *) &initial_settings);
+ getTermSettings(0, (void *) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
-
+ new_settings.c_lflag &= ~ICANON; /* unbuffered input */
+ /* Turn off echoing and CTRL-C, so we can trap it */
+ new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
+#ifndef linux
+ /* Hmm, in linux c_cc[] not parsed if set ~ICANON */
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
/* Turn off CTRL-C, so we can trap it */
+# ifndef _POSIX_VDISABLE
+# define _POSIX_VDISABLE '\0'
+# endif
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
- new_settings.c_lflag &= ~ICANON; /* unbuffered input */
- /* Turn off echoing */
- new_settings.c_lflag &= ~(ECHO | ECHOCTL | ECHONL);
+#endif
}
command[0] = 0;
- setTermSettings(inputFd, (void *) &new_settings);
+ setTermSettings(0, (void *) &new_settings);
handlers_sets |= SET_RESET_TERM;
/* Now initialize things */
fflush(stdout); /* buffered out to fast */
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
/* if we can't read input then exit */
goto prepare_to_die;
case ESC:{
/* escape sequence follows */
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
/* different vt100 emulations */
if (c == '[' || c == 'O') {
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
}
switch (c) {
}
if (c >= '1' && c <= '9')
do
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
while (c != '~');
break;
#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT
/* Control-V -- Add non-printable symbol */
if (c == 22) {
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
if (c == 0) {
beep();
lastWasTab = FALSE;
}
- setTermSettings(inputFd, (void *) &initial_settings);
+ setTermSettings(0, (void *) &initial_settings);
handlers_sets &= ~SET_RESET_TERM;
/* Handle command history log */
*/
char *vi_Version =
- "$Id: vi.c,v 1.9 2001/06/23 13:49:14 andersen Exp $";
+ "$Id: vi.c,v 1.10 2001/06/26 02:06:08 bug1 Exp $";
/*
* To compile for standalone use:
term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's
term_vi.c_iflag &= (~IXON & ~ICRNL);
term_vi.c_oflag &= (~ONLCR);
+#ifndef linux
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
+#endif
erase_char = term_vi.c_cc[VERASE];
tcsetattr(0, TCSANOW, &term_vi);
}
/* vi: set sw=4 ts=4: */
/*
- * $Id: hostname.c,v 1.29 2001/06/23 13:49:14 andersen Exp $
+ * $Id: hostname.c,v 1.30 2001/06/26 02:06:08 bug1 Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
} else {
f = xfopen(s, "r");
fgets(buf, 255, f);
+#ifdef BB_FEATURE_CLEAN_UP
fclose(f);
+#endif
chomp(buf);
- if (sethostname(buf, strlen(buf)) < 0)
- perror_msg_and_die("sethostname");
+ do_sethostname(buf, 0);
}
}
*prompt_str = PS2;
}
#else
- *prompt_str = (promptmode==0)? PS1 : PS2;
+ *prompt_str = (promptmode==1)? PS1 : PS2;
#endif
debug_printf("result %s\n",*prompt_str);
}
extern struct hostent *xgethostbyname(const char *name);
char *dirname (const char *path);
-char *strdup_substr (const char *s, int start, int end);
+
+static inline char *strdup_substr (const char *s, int start, int end)
+{
+ return xstrndup (s+start, end-start);
+}
int make_directory (char *path, mode_t mode, int flags);
#define CT_AUTO 0
extern struct hostent *xgethostbyname(const char *name);
char *dirname (const char *path);
-char *strdup_substr (const char *s, int start, int end);
+
+static inline char *strdup_substr (const char *s, int start, int end)
+{
+ return xstrndup (s+start, end-start);
+}
int make_directory (char *path, mode_t mode, int flags);
#define CT_AUTO 0
* based on the original more implementation by Bruce, and code from the
* Debian boot-floppies team.
*
+ * Termios corrects by Vladimir Oleynik <vodz@usa.net>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
+#include <unistd.h>
#include <sys/ioctl.h>
#include "busybox.h"
-/* ED: sparc termios is broken: revert back to old termio handling. */
-#ifdef BB_FEATURE_USE_TERMIOS
-# if #cpu(sparc)
-# include <termio.h>
-# define termios termio
-# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
-# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
-# else
-# include <termios.h>
-# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
-# define getTermSettings(fd,argp) tcgetattr(fd, argp);
-# endif
-
static FILE *cin;
+#ifdef BB_FEATURE_USE_TERMIOS
+#include <termios.h>
+#define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
+#define getTermSettings(fd,argp) tcgetattr(fd, argp);
+
static struct termios initial_settings, new_settings;
-static void gotsig(int sig)
+static void set_tty_to_initial_mode(void)
{
setTermSettings(fileno(cin), &initial_settings);
+}
+
+static void gotsig(int sig)
+{
putchar('\n');
exit(EXIT_FAILURE);
}
extern int more_main(int argc, char **argv)
{
int c, lines, input = 0;
- int please_display_more_prompt;
+ int please_display_more_prompt = -1;
struct stat st;
FILE *file;
int len, page_height;
argc--;
argv++;
- do {
- if (argc == 0) {
- file = stdin;
- } else
- file = xfopen(*argv, "r");
- fstat(fileno(file), &st);
-
-#ifdef BB_FEATURE_USE_TERMIOS
+ /* not use inputing from terminal if usage: more > outfile */
+ if(isatty(fileno(stdout))) {
cin = fopen("/dev/tty", "r");
if (!cin)
cin = xfopen("/dev/console", "r");
+ please_display_more_prompt = 0;
+#ifdef BB_FEATURE_USE_TERMIOS
getTermSettings(fileno(cin), &initial_settings);
new_settings = initial_settings;
- new_settings.c_cc[VMIN] = 1;
- new_settings.c_cc[VTIME] = 0;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
+#ifndef linux
+ /* Hmm, in linux c_cc[] not parsed if set ~ICANON */
+ new_settings.c_cc[VMIN] = 1;
+ new_settings.c_cc[VTIME] = 0;
+#endif
setTermSettings(fileno(cin), &new_settings);
+ atexit(set_tty_to_initial_mode);
+ (void) signal(SIGINT, gotsig);
+ (void) signal(SIGQUIT, gotsig);
+ (void) signal(SIGTERM, gotsig);
+#endif
+ }
+
+ do {
+ if (argc == 0) {
+ file = stdin;
+ } else
+ file = wfopen(*argv, "r");
+ if(file==0)
+ goto loop;
+
+ fstat(fileno(file), &st);
-# ifdef BB_FEATURE_AUTOWIDTH
+ if(please_display_more_prompt>0)
+ please_display_more_prompt = 0;
+
+#if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_row > 4)
terminal_height = win.ws_row - 2;
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
-# endif
-
- (void) signal(SIGINT, gotsig);
- (void) signal(SIGQUIT, gotsig);
- (void) signal(SIGTERM, gotsig);
-
#endif
len=0;
lines = 0;
page_height = terminal_height;
- please_display_more_prompt = 0;
while ((c = getc(file)) != EOF) {
- if (please_display_more_prompt) {
+ if (please_display_more_prompt>0) {
len = printf("--More-- ");
if (file != stdin) {
#if _FILE_OFFSET_BITS == 64
(double) st.st_size)), (long)st.st_size);
#endif
}
- len += printf("%s",
-#ifdef BB_FEATURE_USE_TERMIOS
- ""
-#else
- "\n"
-#endif
- );
fflush(stdout);
* We've just displayed the "--More--" prompt, so now we need
* to get input from the user.
*/
-#ifdef BB_FEATURE_USE_TERMIOS
input = getc(cin);
-#else
- input = getc(stdin);
+#ifndef BB_FEATURE_USE_TERMIOS
+ printf("\033[A"); /* up cursor */
#endif
-
-#ifdef BB_FEATURE_USE_TERMIOS
/* Erase the "More" message */
putc('\r', stdout);
while (--len >= 0)
putc(' ', stdout);
putc('\r', stdout);
fflush(stdout);
-#endif
len=0;
lines = 0;
page_height = terminal_height;
/* increment by just one line if we are at
* the end of this line */
if (input == '\n')
+ if(please_display_more_prompt==0)
please_display_more_prompt = 1;
/* Adjust the terminal height for any overlap, so that
* no lines get lost off the top. */
}
}
if (++lines >= page_height) {
+ if(please_display_more_prompt==0)
please_display_more_prompt = 1;
}
len=0;
}
fclose(file);
fflush(stdout);
-
+loop:
argv++;
} while (--argc > 0);
end:
-#ifdef BB_FEATURE_USE_TERMIOS
- setTermSettings(fileno(cin), &initial_settings);
-#endif
return 0;
}
/* vi: set sw=4 ts=4: */
/*
- * $Id: hostname.c,v 1.29 2001/06/23 13:49:14 andersen Exp $
+ * $Id: hostname.c,v 1.30 2001/06/26 02:06:08 bug1 Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
} else {
f = xfopen(s, "r");
fgets(buf, 255, f);
+#ifdef BB_FEATURE_CLEAN_UP
fclose(f);
+#endif
chomp(buf);
- if (sethostname(buf, strlen(buf)) < 0)
- perror_msg_and_die("sethostname");
+ do_sethostname(buf, 0);
}
}
#include <sys/time.h>
#endif
-static const int DATABUFSIZE = 128;
-static const int IACBUFSIZE = 128;
+#define DATABUFSIZE 128
+#define IACBUFSIZE 128
static const int CHM_TRY = 0;
static const int CHM_ON = 1;
static struct Globalvars {
int netfd; /* console fd:s are 0 and 1 (and 2) */
/* same buffer used both for network and console read/write */
- char * buf; /* allocating so static size is smaller */
- short len;
+ char buf[DATABUFSIZE]; /* allocating so static size is smaller */
byte telstate; /* telnet negotiation state from network input */
byte telwish; /* DO, DONT, WILL, WONT */
byte charmode;
byte telflags;
byte gotsig;
/* buffer to handle telnet negotiations */
- char * iacbuf;
+ char iacbuf[IACBUFSIZE];
short iaclen; /* could even use byte */
struct termios termios_def;
struct termios termios_raw;
G.gotsig = 0;
}
-static void handlenetoutput()
+static void handlenetoutput(int len)
{
/* here we could do smart tricks how to handle 0xFF:s in output
* stream like writing twice every sequence of FF:s (thus doing
int i;
byte * p = G.buf;
- for (i = G.len; i > 0; i--, p++)
+ for (i = len; i > 0; i--, p++)
{
if (*p == 0x1d)
{
if (*p == 0xff)
*p = 0x7f;
}
- write(G.netfd, G.buf, G.len);
+ write(G.netfd, G.buf, len);
}
-static void handlenetinput()
+static void handlenetinput(int len)
{
int i;
int cstart = 0;
- for (i = 0; i < G.len; i++)
+ for (i = 0; i < len; i++)
{
byte c = G.buf[i];
if (G.iaclen) iacflush();
if (G.telstate == TS_0) G.telstate = 0;
- G.len = cstart;
+ len = cstart;
}
- if (G.len)
- write(1, G.buf, G.len);
+ if (len)
+ write(1, G.buf, len);
}
{
struct in_addr host;
int port;
+ int len;
#ifdef USE_POLL
struct pollfd ufds[2];
#else
exit(1);
G.termios_raw = G.termios_def;
-
cfmakeraw(&G.termios_raw);
if (argc < 2) show_usage();
port = (argc > 2)? getport(argv[2]): 23;
- G.buf = xmalloc(DATABUFSIZE);
- G.iacbuf = xmalloc(IACBUFSIZE);
-
host = getserver(argv[1]);
G.netfd = remote_connect(host, port);
if (FD_ISSET(0, &rfds))
#endif
{
- G.len = read(0, G.buf, DATABUFSIZE);
+ len = read(0, G.buf, DATABUFSIZE);
- if (G.len <= 0)
+ if (len <= 0)
doexit(0);
- TRACE(0, ("Read con: %d\n", G.len));
+ TRACE(0, ("Read con: %d\n", len));
- handlenetoutput();
+ handlenetoutput(len);
}
#ifdef USE_POLL
if (FD_ISSET(G.netfd, &rfds))
#endif
{
- G.len = read(G.netfd, G.buf, DATABUFSIZE);
+ len = read(G.netfd, G.buf, DATABUFSIZE);
- if (G.len <= 0)
+ if (len <= 0)
{
WriteCS(1, "Connection closed by foreign host.\r\n");
doexit(1);
}
- TRACE(0, ("Read netfd (%d): %d\n", G.netfd, G.len));
+ TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len));
- handlenetinput();
+ handlenetinput(len);
}
}
}
#endif
#ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR
-#ifndef TEST
-#include "pwd_grp/pwd.h"
-#else
-#include <pwd.h>
-#endif /* TEST */
+# ifndef TEST
+# include "pwd_grp/pwd.h"
+# else
+# include <pwd.h>
+# endif /* TEST */
#endif /* advanced FEATURES */
static struct history *his_end = NULL;
-/* ED: sparc termios is broken: revert back to old termio handling. */
-
-#if #cpu(sparc)
-# include <termio.h>
-# define termios termio
-# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
-# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
-#else
-# include <termios.h>
-# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
-# define getTermSettings(fd,argp) tcgetattr(fd, argp);
-#endif
+#include <termios.h>
+#define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
+#define getTermSettings(fd,argp) tcgetattr(fd, argp);
/* Current termio and the previous termio before starting sh */
static struct termios initial_settings, new_settings;
-#ifndef _POSIX_VDISABLE
-#define _POSIX_VDISABLE '\0'
-#endif
-
-
static
volatile int cmdedit_termw = 80; /* actual terminal width */
static int history_counter = 0; /* Number of commands in history list */
char *pbuf;
if (!pwd_buf) {
- pwd_buf=unknown;
+ pwd_buf=(char *)unknown;
}
while (*prmt_ptr) {
* in the current working directory that matches. */
if (!matches)
matches =
- exe_n_cwd_tab_completion(matchBuf, &num_matches,
- find_type);
-
+ exe_n_cwd_tab_completion(matchBuf,
+ &num_matches, find_type);
+ /* Remove duplicate found */
+ if(matches) {
+ int i, j;
+ /* bubble */
+ for(i=0; i<(num_matches-1); i++)
+ for(j=i+1; j<num_matches; j++)
+ if(matches[i]!=0 && matches[j]!=0 &&
+ strcmp(matches[i], matches[j])==0) {
+ free(matches[j]);
+ matches[j]=0;
+ }
+ j=num_matches;
+ num_matches = 0;
+ for(i=0; i<j; i++)
+ if(matches[i]) {
+ if(!strcmp(matches[i], "./"))
+ matches[i][1]=0;
+ else if(!strcmp(matches[i], "../"))
+ matches[i][2]=0;
+ matches[num_matches++]=matches[i];
+ }
+ }
/* Did we find exactly one match? */
if (!matches || num_matches > 1) {
char *tmp1;
extern void cmdedit_read_input(char *prompt, char command[BUFSIZ])
{
- int inputFd = fileno(stdin);
-
int break_out = 0;
int lastWasTab = FALSE;
unsigned char c = 0;
len = 0;
command_ps = command;
- if (new_settings.c_cc[VMIN] == 0) { /* first call */
+ if (new_settings.c_cc[VERASE] == 0) { /* first call */
- getTermSettings(inputFd, (void *) &initial_settings);
+ getTermSettings(0, (void *) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
-
+ new_settings.c_lflag &= ~ICANON; /* unbuffered input */
+ /* Turn off echoing and CTRL-C, so we can trap it */
+ new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
+#ifndef linux
+ /* Hmm, in linux c_cc[] not parsed if set ~ICANON */
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
/* Turn off CTRL-C, so we can trap it */
+# ifndef _POSIX_VDISABLE
+# define _POSIX_VDISABLE '\0'
+# endif
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
- new_settings.c_lflag &= ~ICANON; /* unbuffered input */
- /* Turn off echoing */
- new_settings.c_lflag &= ~(ECHO | ECHOCTL | ECHONL);
+#endif
}
command[0] = 0;
- setTermSettings(inputFd, (void *) &new_settings);
+ setTermSettings(0, (void *) &new_settings);
handlers_sets |= SET_RESET_TERM;
/* Now initialize things */
fflush(stdout); /* buffered out to fast */
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
/* if we can't read input then exit */
goto prepare_to_die;
case ESC:{
/* escape sequence follows */
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
/* different vt100 emulations */
if (c == '[' || c == 'O') {
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
}
switch (c) {
}
if (c >= '1' && c <= '9')
do
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
while (c != '~');
break;
#ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT
/* Control-V -- Add non-printable symbol */
if (c == 22) {
- if (read(inputFd, &c, 1) < 1)
+ if (read(0, &c, 1) < 1)
return;
if (c == 0) {
beep();
lastWasTab = FALSE;
}
- setTermSettings(inputFd, (void *) &initial_settings);
+ setTermSettings(0, (void *) &initial_settings);
handlers_sets &= ~SET_RESET_TERM;
/* Handle command history log */
*prompt_str = PS2;
}
#else
- *prompt_str = (promptmode==0)? PS1 : PS2;
+ *prompt_str = (promptmode==1)? PS1 : PS2;
#endif
debug_printf("result %s\n",*prompt_str);
}
#include <sys/time.h>
#endif
-static const int DATABUFSIZE = 128;
-static const int IACBUFSIZE = 128;
+#define DATABUFSIZE 128
+#define IACBUFSIZE 128
static const int CHM_TRY = 0;
static const int CHM_ON = 1;
static struct Globalvars {
int netfd; /* console fd:s are 0 and 1 (and 2) */
/* same buffer used both for network and console read/write */
- char * buf; /* allocating so static size is smaller */
- short len;
+ char buf[DATABUFSIZE]; /* allocating so static size is smaller */
byte telstate; /* telnet negotiation state from network input */
byte telwish; /* DO, DONT, WILL, WONT */
byte charmode;
byte telflags;
byte gotsig;
/* buffer to handle telnet negotiations */
- char * iacbuf;
+ char iacbuf[IACBUFSIZE];
short iaclen; /* could even use byte */
struct termios termios_def;
struct termios termios_raw;
G.gotsig = 0;
}
-static void handlenetoutput()
+static void handlenetoutput(int len)
{
/* here we could do smart tricks how to handle 0xFF:s in output
* stream like writing twice every sequence of FF:s (thus doing
int i;
byte * p = G.buf;
- for (i = G.len; i > 0; i--, p++)
+ for (i = len; i > 0; i--, p++)
{
if (*p == 0x1d)
{
if (*p == 0xff)
*p = 0x7f;
}
- write(G.netfd, G.buf, G.len);
+ write(G.netfd, G.buf, len);
}
-static void handlenetinput()
+static void handlenetinput(int len)
{
int i;
int cstart = 0;
- for (i = 0; i < G.len; i++)
+ for (i = 0; i < len; i++)
{
byte c = G.buf[i];
if (G.iaclen) iacflush();
if (G.telstate == TS_0) G.telstate = 0;
- G.len = cstart;
+ len = cstart;
}
- if (G.len)
- write(1, G.buf, G.len);
+ if (len)
+ write(1, G.buf, len);
}
{
struct in_addr host;
int port;
+ int len;
#ifdef USE_POLL
struct pollfd ufds[2];
#else
exit(1);
G.termios_raw = G.termios_def;
-
cfmakeraw(&G.termios_raw);
if (argc < 2) show_usage();
port = (argc > 2)? getport(argv[2]): 23;
- G.buf = xmalloc(DATABUFSIZE);
- G.iacbuf = xmalloc(IACBUFSIZE);
-
host = getserver(argv[1]);
G.netfd = remote_connect(host, port);
if (FD_ISSET(0, &rfds))
#endif
{
- G.len = read(0, G.buf, DATABUFSIZE);
+ len = read(0, G.buf, DATABUFSIZE);
- if (G.len <= 0)
+ if (len <= 0)
doexit(0);
- TRACE(0, ("Read con: %d\n", G.len));
+ TRACE(0, ("Read con: %d\n", len));
- handlenetoutput();
+ handlenetoutput(len);
}
#ifdef USE_POLL
if (FD_ISSET(G.netfd, &rfds))
#endif
{
- G.len = read(G.netfd, G.buf, DATABUFSIZE);
+ len = read(G.netfd, G.buf, DATABUFSIZE);
- if (G.len <= 0)
+ if (len <= 0)
{
WriteCS(1, "Connection closed by foreign host.\r\n");
doexit(1);
}
- TRACE(0, ("Read netfd (%d): %d\n", G.netfd, G.len));
+ TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len));
- handlenetinput();
+ handlenetinput(len);
}
}
}
* based on the original more implementation by Bruce, and code from the
* Debian boot-floppies team.
*
+ * Termios corrects by Vladimir Oleynik <vodz@usa.net>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
+#include <unistd.h>
#include <sys/ioctl.h>
#include "busybox.h"
-/* ED: sparc termios is broken: revert back to old termio handling. */
-#ifdef BB_FEATURE_USE_TERMIOS
-# if #cpu(sparc)
-# include <termio.h>
-# define termios termio
-# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
-# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
-# else
-# include <termios.h>
-# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
-# define getTermSettings(fd,argp) tcgetattr(fd, argp);
-# endif
-
static FILE *cin;
+#ifdef BB_FEATURE_USE_TERMIOS
+#include <termios.h>
+#define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
+#define getTermSettings(fd,argp) tcgetattr(fd, argp);
+
static struct termios initial_settings, new_settings;
-static void gotsig(int sig)
+static void set_tty_to_initial_mode(void)
{
setTermSettings(fileno(cin), &initial_settings);
+}
+
+static void gotsig(int sig)
+{
putchar('\n');
exit(EXIT_FAILURE);
}
extern int more_main(int argc, char **argv)
{
int c, lines, input = 0;
- int please_display_more_prompt;
+ int please_display_more_prompt = -1;
struct stat st;
FILE *file;
int len, page_height;
argc--;
argv++;
- do {
- if (argc == 0) {
- file = stdin;
- } else
- file = xfopen(*argv, "r");
- fstat(fileno(file), &st);
-
-#ifdef BB_FEATURE_USE_TERMIOS
+ /* not use inputing from terminal if usage: more > outfile */
+ if(isatty(fileno(stdout))) {
cin = fopen("/dev/tty", "r");
if (!cin)
cin = xfopen("/dev/console", "r");
+ please_display_more_prompt = 0;
+#ifdef BB_FEATURE_USE_TERMIOS
getTermSettings(fileno(cin), &initial_settings);
new_settings = initial_settings;
- new_settings.c_cc[VMIN] = 1;
- new_settings.c_cc[VTIME] = 0;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
+#ifndef linux
+ /* Hmm, in linux c_cc[] not parsed if set ~ICANON */
+ new_settings.c_cc[VMIN] = 1;
+ new_settings.c_cc[VTIME] = 0;
+#endif
setTermSettings(fileno(cin), &new_settings);
+ atexit(set_tty_to_initial_mode);
+ (void) signal(SIGINT, gotsig);
+ (void) signal(SIGQUIT, gotsig);
+ (void) signal(SIGTERM, gotsig);
+#endif
+ }
+
+ do {
+ if (argc == 0) {
+ file = stdin;
+ } else
+ file = wfopen(*argv, "r");
+ if(file==0)
+ goto loop;
+
+ fstat(fileno(file), &st);
-# ifdef BB_FEATURE_AUTOWIDTH
+ if(please_display_more_prompt>0)
+ please_display_more_prompt = 0;
+
+#if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_row > 4)
terminal_height = win.ws_row - 2;
if (win.ws_col > 0)
terminal_width = win.ws_col - 1;
-# endif
-
- (void) signal(SIGINT, gotsig);
- (void) signal(SIGQUIT, gotsig);
- (void) signal(SIGTERM, gotsig);
-
#endif
len=0;
lines = 0;
page_height = terminal_height;
- please_display_more_prompt = 0;
while ((c = getc(file)) != EOF) {
- if (please_display_more_prompt) {
+ if (please_display_more_prompt>0) {
len = printf("--More-- ");
if (file != stdin) {
#if _FILE_OFFSET_BITS == 64
(double) st.st_size)), (long)st.st_size);
#endif
}
- len += printf("%s",
-#ifdef BB_FEATURE_USE_TERMIOS
- ""
-#else
- "\n"
-#endif
- );
fflush(stdout);
* We've just displayed the "--More--" prompt, so now we need
* to get input from the user.
*/
-#ifdef BB_FEATURE_USE_TERMIOS
input = getc(cin);
-#else
- input = getc(stdin);
+#ifndef BB_FEATURE_USE_TERMIOS
+ printf("\033[A"); /* up cursor */
#endif
-
-#ifdef BB_FEATURE_USE_TERMIOS
/* Erase the "More" message */
putc('\r', stdout);
while (--len >= 0)
putc(' ', stdout);
putc('\r', stdout);
fflush(stdout);
-#endif
len=0;
lines = 0;
page_height = terminal_height;
/* increment by just one line if we are at
* the end of this line */
if (input == '\n')
+ if(please_display_more_prompt==0)
please_display_more_prompt = 1;
/* Adjust the terminal height for any overlap, so that
* no lines get lost off the top. */
}
}
if (++lines >= page_height) {
+ if(please_display_more_prompt==0)
please_display_more_prompt = 1;
}
len=0;
}
fclose(file);
fflush(stdout);
-
+loop:
argv++;
} while (--argc > 0);
end:
-#ifdef BB_FEATURE_USE_TERMIOS
- setTermSettings(fileno(cin), &initial_settings);
-#endif
return 0;
}
*/
char *vi_Version =
- "$Id: vi.c,v 1.9 2001/06/23 13:49:14 andersen Exp $";
+ "$Id: vi.c,v 1.10 2001/06/26 02:06:08 bug1 Exp $";
/*
* To compile for standalone use:
term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's
term_vi.c_iflag &= (~IXON & ~ICRNL);
term_vi.c_oflag &= (~ONLCR);
+#ifndef linux
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
+#endif
erase_char = term_vi.c_cc[VERASE];
tcsetattr(0, TCSANOW, &term_vi);
}