-- Makefile.orig Sat Oct 2 18:48:00 1999 +++ Makefile Sat Oct 2 19:07:42 1999 @@ -4,6 +4,7 @@ SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c edit.c fio.c \ getname.c head.c v7.local.c lex.c list.c main.c names.c popen.c \ quit.c send.c strings.c temp.c tty.c vars.c +LDADD= -lreadline SFILES= mail.help mail.tildehelp EFILES= mail.rc LINKS= ${BINDIR}/mail ${BINDIR}/Mail --- def.h.orig Sat Jan 16 16:31:02 1999 +++ def.h Sat Oct 2 19:10:31 1999 @@ -53,6 +53,7 @@ #include "pathnames.h" #define MAILX 1 /* mailx mode */ /* 1994/08/31 (Wed) */ +#define USE_GNU_READLINE 1 #define APPEND /* New mail goes to end of mailbox */ --- extern.h.orig Sat Oct 2 18:44:36 1999 +++ extern.h Sat Oct 2 16:59:09 1999 @@ -215,7 +215,10 @@ void quit __P((void)); int quitcmd __P((void)); int raise __P((int)); +#ifdef USE_GNU_READLINE +#define readline mail_readline int readline __P((FILE *, char *, int)); +#endif void register_file __P((FILE *, int, int)); void regret __P((int)); void relsesigs __P((void)); --- lex.c.orig Sat Oct 2 18:44:29 1999 +++ lex.c Sat Oct 2 18:47:26 1999 @@ -38,6 +38,46 @@ #include "rcv.h" #include #include + +#ifdef USE_GNU_READLINE +#include +#include +static char * +gnu_readline(char *prompt) +{ + return readline(prompt); +} + +static int cmd_index, cmd_len; +extern struct cmd cmdtab[]; + +char * +cmd_completion(char *text, int state) +{ + char *name; + + if (!state) { + cmd_index = 0; + cmd_len = strlen(text); + } + while(name = cmdtab[cmd_index].c_name) { + cmd_index++; + if (strncmp(name, text, cmd_len) == 0) + return strdup(name); + } + return (char *)NULL; +} + +char ** +mail_completion(char *text, int start, int end) +{ + if (start == 0) + return completion_matches(text, cmd_completion); + else + return (char **)NULL; +} +#endif + #include "extern.h" /* @@ -169,6 +209,9 @@ register int n; char linebuf[LINESIZE]; void intr(), stop(), hangup(); +#ifdef USE_GNU_READLINE + int interactive = 0; +#endif if (!sourcing) { if (signal(SIGINT, SIG_IGN) != SIG_IGN) @@ -178,6 +221,10 @@ signal(SIGTSTP, stop); signal(SIGTTOU, stop); signal(SIGTTIN, stop); +#ifdef USE_GNU_READLINE + using_history(); + rl_attempted_completion_function = (CPPFunction *)mail_completion; +#endif } setexit(); for (;;) { @@ -187,7 +234,13 @@ */ if (!sourcing && value("interactive") != NOSTR) { reset_on_stop = 1; + if (value("prompt") != NOSTR) + prompt = value("prompt"); +#ifdef USE_GNU_READLINE + interactive = 1; +#else printf(prompt); +#endif } fflush(stdout); sreset(); @@ -197,6 +250,20 @@ */ n = 0; for (;;) { +#ifdef USE_GNU_READLINE + if (interactive) { + char *p; + p = gnu_readline((n == 0) ? prompt : "> "); + if (p == NULL) { + if (n == 0) + n = -1; + break; + } + if (strlen(p) >= LINESIZE - n) + p[LINESIZE - n - 1] = '\0'; + strcpy(&linebuf[n], p); + } else +#endif if (readline(input, &linebuf[n], LINESIZE - n) < 0) { if (n == 0) n = -1; @@ -209,6 +276,10 @@ break; linebuf[n++] = ' '; } +#ifdef USE_GNU_READLINE + if (interactive && n != -1 && linebuf[0] != '\0') + add_history(strdup(linebuf)); +#endif #if MAILX if (n != -1) { char *p;