Check for tcgetattr() to enable HAVE_TCGETATTR in sysunix.c this seems

to work better on embedded targets running off the initial console.

Also, first merge of patches from Debian.  This part holds all of the
sysunix.c changes and some 8-bit patches and SIGSTP patches in the
editline.c file.
This commit is contained in:
Joachim Nilsson 2008-06-09 21:37:01 +02:00
parent 9a94fc9d4d
commit f7b2ea938d
6 changed files with 85 additions and 16 deletions

View File

@ -64,6 +64,9 @@
/* Define to 1 if you have the <sys/types.h> header file. */ /* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H #undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the `tcgetattr' function. */
#undef HAVE_TCGETATTR
/* Define to 1 if you have the <termios.h> header file. */ /* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H #undef HAVE_TERMIOS_H

3
configure vendored
View File

@ -4875,7 +4875,8 @@ fi
for ac_func in strchr strdup strrchr
for ac_func in strchr strdup strrchr tcgetattr
do do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5 { echo "$as_me:$LINENO: checking for $ac_func" >&5

View File

@ -38,6 +38,6 @@ AC_PROG_GCC_TRADITIONAL
#AC_FUNC_MALLOC #AC_FUNC_MALLOC
#AC_FUNC_REALLOC #AC_FUNC_REALLOC
AC_FUNC_STAT AC_FUNC_STAT
AC_CHECK_FUNCS([strchr strdup strrchr]) AC_CHECK_FUNCS([strchr strdup strrchr tcgetattr])
AC_OUTPUT(Makefile src/Makefile include/Makefile man/Makefile examples/Makefile) AC_OUTPUT(Makefile src/Makefile include/Makefile man/Makefile examples/Makefile)

View File

@ -20,6 +20,8 @@
#define META(x) ((x) | 0x80) #define META(x) ((x) | 0x80)
#define ISMETA(x) ((x) & 0x80) #define ISMETA(x) ((x) & 0x80)
#define UNMETA(x) ((x) & 0x7F) #define UNMETA(x) ((x) & 0x7F)
#define MAPSIZE 33
#define METAMAPSIZE 17
#if !defined(HIST_SIZE) #if !defined(HIST_SIZE)
#define HIST_SIZE 20 #define HIST_SIZE 20
#endif /* !defined(HIST_SIZE) */ #endif /* !defined(HIST_SIZE) */
@ -63,6 +65,9 @@ int rl_erase;
int rl_intr; int rl_intr;
int rl_kill; int rl_kill;
int rl_quit; int rl_quit;
#if defined(DO_SIGTSTP)
int rl_susp;
#endif /* defined(DO_SIGTSTP) */
STATIC CHAR NIL[] = ""; STATIC CHAR NIL[] = "";
STATIC CONST CHAR *Input = NIL; STATIC CONST CHAR *Input = NIL;
@ -80,8 +85,8 @@ STATIC int Point;
STATIC int PushBack; STATIC int PushBack;
STATIC int Pushed; STATIC int Pushed;
STATIC int Signal; STATIC int Signal;
FORWARD KEYMAP Map[33]; FORWARD KEYMAP Map[MAPSIZE];
FORWARD KEYMAP MetaMap[17]; FORWARD KEYMAP MetaMap[METAMAPSIZE];
STATIC SIZE_T Length; STATIC SIZE_T Length;
STATIC SIZE_T ScreenCount; STATIC SIZE_T ScreenCount;
STATIC SIZE_T ScreenSize; STATIC SIZE_T ScreenSize;
@ -90,18 +95,17 @@ STATIC int TTYwidth;
STATIC int TTYrows; STATIC int TTYrows;
/* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */ /* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */
int rl_meta_chars = 0; int rl_meta_chars = 1;
/* /*
** Declarations. ** Declarations.
*/ */
STATIC CHAR *editinput(); STATIC CHAR *editinput();
extern int read();
extern int write();
#if defined(USE_TERMCAP) #if defined(USE_TERMCAP)
extern char *getenv(); extern char *getenv();
extern char *tgetstr(); extern char *tgetstr();
extern int tgetent(); extern int tgetent();
extern int tgetnum();
#endif /* defined(USE_TERMCAP) */ #endif /* defined(USE_TERMCAP) */
/* /*
@ -119,7 +123,7 @@ TTYflush()
STATIC void STATIC void
TTYput(c) TTYput(c)
CHAR c; CONST CHAR c;
{ {
Screen[ScreenCount] = c; Screen[ScreenCount] = c;
if (++ScreenCount >= ScreenSize - 1) { if (++ScreenCount >= ScreenSize - 1) {
@ -864,12 +868,16 @@ emacs(c)
STATUS s; STATUS s;
KEYMAP *kp; KEYMAP *kp;
#if 0 /* Debian patch removes this to be able to handle 8-bit input */
/* This test makes it impossible to enter eight-bit characters when
* meta-char mode is enabled. */
OldPoint = Point; OldPoint = Point;
if (rl_meta_chars && ISMETA(c)) { if (rl_meta_chars && ISMETA(c)) {
Pushed = 1; Pushed = 1;
PushBack = UNMETA(c); PushBack = UNMETA(c);
return meta(); return meta();
} }
#endif /* Debian patch removal. */
for (kp = Map; kp->Function; kp++) for (kp = Map; kp->Function; kp++)
if (kp->Key == c) if (kp->Key == c)
break; break;
@ -884,7 +892,7 @@ STATIC STATUS
TTYspecial(c) TTYspecial(c)
unsigned int c; unsigned int c;
{ {
if (ISMETA(c)) if (rl_meta_chars && ISMETA(c))
return CSdispatch; return CSdispatch;
if (c == rl_erase || c == DEL) if (c == rl_erase || c == DEL)
@ -907,6 +915,12 @@ TTYspecial(c)
Signal = SIGQUIT; Signal = SIGQUIT;
return CSeof; return CSeof;
} }
#if defined(DO_SIGTSTP)
if (c == rl_susp) {
Signal = SIGTSTP;
return CSsignal;
}
#endif /* defined(DO_SIGTSTP) */
return CSdispatch; return CSdispatch;
} }
@ -973,6 +987,32 @@ hist_add(p)
H.Pos = H.Size - 1; H.Pos = H.Size - 1;
} }
STATIC char *
read_redirected()
{
int size;
char *p;
char *line;
char *end;
for (size = MEM_INC, p = line = NEW(char, size), end = p + size; ; p++) {
if (p == end) {
size += MEM_INC;
p = line = realloc(line, size);
end = p + size;
}
if (read(0, p, 1) <= 0) {
/* Ignore "incomplete" lines at EOF, just like we do for a tty. */
free(line);
return NULL;
}
if (*p == '\n')
break;
}
*p = '\0';
return line;
}
/* /*
** For compatibility with FSF readline. ** For compatibility with FSF readline.
*/ */
@ -995,6 +1035,11 @@ readline(prompt)
CHAR *line; CHAR *line;
int s; int s;
if (!isatty(0)) {
TTYflush();
return read_redirected();
}
if (Line == NULL) { if (Line == NULL) {
Length = MEM_INC; Length = MEM_INC;
if ((Line = NEW(CHAR, Length)) == NULL) if ((Line = NEW(CHAR, Length)) == NULL)

View File

@ -67,6 +67,9 @@ extern int rl_erase;
extern int rl_intr; extern int rl_intr;
extern int rl_kill; extern int rl_kill;
extern int rl_quit; extern int rl_quit;
#if defined(DO_SIGTSTP)
extern int rl_susp;
#endif /* defined(DO_SIGTSTP) */
extern char *rl_complete(); extern char *rl_complete();
extern int rl_list_possib(char *pathname, char ***avp); extern int rl_list_possib(char *pathname, char ***avp);
extern void rl_ttyset(); extern void rl_ttyset();
@ -81,6 +84,7 @@ extern char *strcat();
extern char *strchr(); extern char *strchr();
extern char *strrchr(); extern char *strrchr();
extern char *strcpy(); extern char *strcpy();
extern char *strdup();
extern int strcmp(); extern int strcmp();
extern int strlen(); extern int strlen();
extern int strncmp(); extern int strncmp();

View File

@ -15,19 +15,22 @@ rl_ttyset(Reset)
struct termios new; struct termios new;
if (Reset == 0) { if (Reset == 0) {
(void)tcgetattr(0, &old); if (tcgetattr(0, &old) < 0) perror("tcgetattr");
rl_erase = old.c_cc[VERASE]; rl_erase = old.c_cc[VERASE];
rl_kill = old.c_cc[VKILL]; rl_kill = old.c_cc[VKILL];
rl_eof = old.c_cc[VEOF]; rl_eof = old.c_cc[VEOF];
rl_intr = old.c_cc[VINTR]; rl_intr = old.c_cc[VINTR];
rl_quit = old.c_cc[VQUIT]; rl_quit = old.c_cc[VQUIT];
#if defined(DO_SIGTSTP)
rl_susp = old.c_cc[VSUSP];
#endif /* defined(DO_SIGTSTP) */
new = old; new = old;
new.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN); new.c_lflag &= ~(ECHO | ICANON | ISIG);
new.c_iflag &= ~(ICRNL); new.c_iflag &= ~(ISTRIP | INPCK);
new.c_cc[VMIN] = 1; new.c_cc[VMIN] = 1;
new.c_cc[VTIME] = 0; new.c_cc[VTIME] = 0;
(void)tcsetattr(0, TCSADRAIN, &new); if (tcsetattr(0, TCSADRAIN, &new) < 0) perror("tcsetattr");
} }
else else
(void)tcsetattr(0, TCSADRAIN, &old); (void)tcsetattr(0, TCSADRAIN, &old);
@ -51,11 +54,13 @@ rl_ttyset(Reset)
rl_eof = old.c_cc[VEOF]; rl_eof = old.c_cc[VEOF];
rl_intr = old.c_cc[VINTR]; rl_intr = old.c_cc[VINTR];
rl_quit = old.c_cc[VQUIT]; rl_quit = old.c_cc[VQUIT];
#if defined(DO_SIGTSTP)
rl_susp = old.c_cc[VSUSP];
#endif /* defined(DO_SIGTSTP) */
new = old; new = old;
new.c_cc[VINTR] = -1; new.c_lflag &= ~(ECHO | ICANON | ISIG);
new.c_cc[VQUIT] = -1; new.c_iflag &= ~(ISTRIP | INPCK);
new.c_lflag &= ~(ECHO | ICANON);
new.c_cc[VMIN] = 1; new.c_cc[VMIN] = 1;
new.c_cc[VTIME] = 0; new.c_cc[VTIME] = 0;
(void)ioctl(0, TCSETAW, &new); (void)ioctl(0, TCSETAW, &new);
@ -75,6 +80,9 @@ rl_ttyset(Reset)
static struct tchars old_tchars; static struct tchars old_tchars;
struct sgttyb new_sgttyb; struct sgttyb new_sgttyb;
struct tchars new_tchars; struct tchars new_tchars;
#if defined(DO_SIGTSTP)
struct ltchars old_ltchars;
#endif /* defined(DO_SIGTSTP) */
if (Reset == 0) { if (Reset == 0) {
(void)ioctl(0, TIOCGETP, &old_sgttyb); (void)ioctl(0, TIOCGETP, &old_sgttyb);
@ -86,9 +94,17 @@ rl_ttyset(Reset)
rl_intr = old_tchars.t_intrc; rl_intr = old_tchars.t_intrc;
rl_quit = old_tchars.t_quitc; rl_quit = old_tchars.t_quitc;
#if defined(DO_SIGTSTP)
(void)ioctl(0, TIOCGLTC, &old_ltchars);
rl_susp = old_ltchars.t_suspc;
#endif /* defined(DO_SIGTSTP) */
new_sgttyb = old_sgttyb; new_sgttyb = old_sgttyb;
new_sgttyb.sg_flags &= ~ECHO; new_sgttyb.sg_flags &= ~ECHO;
new_sgttyb.sg_flags |= RAW; new_sgttyb.sg_flags |= RAW;
#if defined(PASS8)
new_sgttyb.sg_flags |= PASS8;
#endif /* defined(PASS8) */
(void)ioctl(0, TIOCSETP, &new_sgttyb); (void)ioctl(0, TIOCSETP, &new_sgttyb);
new_tchars = old_tchars; new_tchars = old_tchars;