Fix command line history in ash

Also did some cleanup in ash sources, to make minix modifications
more obvious, as well as some simplifications (by removing code which
is never compiled)

Removed EDITLINE support, use libedit, which does the termcap/terminfo
handling.

Change-Id: I19f7f425ed6a61298844631f9d7f3173cf7f30c0
This commit is contained in:
Lionel Sambuc 2013-01-30 15:36:51 +01:00
parent a8d553408d
commit 252a83f614
17 changed files with 43 additions and 117 deletions

View file

@ -8,8 +8,6 @@ MAN=
# Enable this line to disable command line editing # Enable this line to disable command line editing
#EDIT=-DNO_HISTORY #EDIT=-DNO_HISTORY
# Enable this line to use the editline library instead of libedit
EDIT=-DEDITLINE
# Enable this line if your system does not have a <paths.h> # Enable this line if your system does not have a <paths.h>
#NO_PATHS_H=-DNO_PATHS_H #NO_PATHS_H=-DNO_PATHS_H
@ -18,7 +16,7 @@ EDIT=-DEDITLINE
NO_JOBS=-DJOBS=0 NO_JOBS=-DJOBS=0
MKB_NO_JOBS=-j MKB_NO_JOBS=-j
SRCS= alias.c arith.y arith_lex.l cd.c eval.c exec.c expand.c \ SRCS= alias.c arith.y arith_lex.l cd.c complete.c eval.c exec.c expand.c \
histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \ histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
mystring.c options.c output.c parser.c redir.c show.c \ mystring.c options.c output.c parser.c redir.c show.c \
trap.c var.c setmode.c trap.c var.c setmode.c

View file

@ -41,18 +41,8 @@ __FBSDID("$FreeBSD: src/bin/sh/bltin/echo.c,v 1.14 2004/04/06 20:06:53 markm Exp
* Echo command. * Echo command.
*/ */
#ifdef __minix
#define MINIX
#endif
#include "bltin.h" #include "bltin.h"
#ifndef MINIX
/* #define eflag 1 */
#else
#undef eflag
#endif
int int
echocmd(argc, argv) echocmd(argc, argv)
int argc; int argc;
@ -63,7 +53,7 @@ echocmd(argc, argv)
char c; char c;
int count; int count;
int nflag = 0; int nflag = 0;
#ifndef eflag #ifdef __minix
int eflag = 0; int eflag = 0;
#endif #endif
@ -71,7 +61,7 @@ echocmd(argc, argv)
if (argc) if (argc)
ap++; ap++;
if ((p = *ap) != NULL) { if ((p = *ap) != NULL) {
#ifdef MINIX #ifdef __minix
if (equal(p, "--")) { if (equal(p, "--")) {
ap++; ap++;
} }
@ -80,7 +70,7 @@ echocmd(argc, argv)
nflag++; nflag++;
ap++; ap++;
} else if (equal(p, "-e")) { } else if (equal(p, "-e")) {
#ifndef eflag #ifdef __minix
eflag++; eflag++;
#endif #endif
ap++; ap++;

View file

@ -47,8 +47,9 @@
bltincmd builtin bltincmd builtin
commandcmd command commandcmd command
#alloccmd alloc #if JOBS
bgcmd -j bg bgcmd -j bg
#endif
breakcmd break continue breakcmd break continue
#catfcmd catf #catfcmd catf
cdcmd cd chdir cdcmd cd chdir
@ -62,15 +63,17 @@ exportcmd export readonly
exprcmd expr test [ exprcmd expr test [
falsecmd false falsecmd false
histcmd -h fc histcmd -h fc
#if JOBS
fgcmd -j fg fgcmd -j fg
#endif
getoptscmd getopts getoptscmd getopts
hashcmd hash hashcmd hash
jobidcmd jobid jobidcmd jobid
jobscmd jobs jobscmd jobs
#linecmd line
localcmd local localcmd local
#nlechocmd nlecho #ifndef SMALL
#printfcmd printf #printfcmd printf
#endif
pwdcmd pwd pwdcmd pwd
readcmd read readcmd read
returncmd return returncmd return
@ -84,11 +87,7 @@ umaskcmd umask
unaliascmd unalias unaliascmd unalias
unsetcmd unset unsetcmd unset
waitcmd wait waitcmd wait
#foocmd foo
aliascmd alias aliascmd alias
ulimitcmd ulimit ulimitcmd ulimit
bindcmd bind bindcmd bind
wordexpcmd wordexp wordexpcmd wordexp
#
# $PchId: builtins.def,v 1.5 2006/03/31 10:50:57 philip Exp $

View file

@ -72,7 +72,7 @@ __FBSDID("$FreeBSD: src/bin/sh/eval.c,v 1.42 2004/04/06 20:06:51 markm Exp $");
#include "error.h" #include "error.h"
#include "show.h" #include "show.h"
#include "mystring.h" #include "mystring.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
#include "myhistedit.h" #include "myhistedit.h"
#endif #endif
@ -194,7 +194,7 @@ evaltree(union node *n, int flags)
exitstatus = 0; exitstatus = 0;
goto out; goto out;
} }
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
displayhist = 1; /* show history substitutions done with fc */ displayhist = 1; /* show history substitutions done with fc */
#endif #endif
TRACE(("evaltree(0x%lx: %d) called\n", (long)n, n->type)); TRACE(("evaltree(0x%lx: %d) called\n", (long)n, n->type));

View file

@ -155,7 +155,7 @@ tryexec(char *cmd, char **argv, char **envp)
int e; int e;
execve(cmd, argv, envp); execve(cmd, argv, envp);
#if !__minix_vmd
e = errno; e = errno;
if (e == ENOEXEC) { if (e == ENOEXEC) {
initshellproc(); initshellproc();
@ -166,7 +166,6 @@ tryexec(char *cmd, char **argv, char **envp)
/*NOTREACHED*/ /*NOTREACHED*/
} }
errno = e; errno = e;
#endif
} }
/* /*

View file

@ -58,7 +58,7 @@ __FBSDID("$FreeBSD: src/bin/sh/histedit.c,v 1.26 2004/04/06 20:06:51 markm Exp $
#include "output.h" #include "output.h"
#include "mystring.h" #include "mystring.h"
#include "builtins.h" #include "builtins.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
#include "myhistedit.h" #include "myhistedit.h"
#include "complete.h" #include "complete.h"
#include "error.h" #include "error.h"
@ -179,7 +179,7 @@ sethistsize(hs)
if (hs == NULL || *hs == '\0' || if (hs == NULL || *hs == '\0' ||
(histsize = atoi(hs)) < 0) (histsize = atoi(hs)) < 0)
histsize = 100; histsize = 100;
history(hist, &he, H_EVENT, histsize); history(hist, &he, H_SETSIZE, histsize);
} }
} }
@ -526,7 +526,7 @@ bindcmd(int argc, char **argv)
error("not compiled with line editing support"); error("not compiled with line editing support");
return (0); return (0);
} }
#endif /* !NO_HISTORY && !EDITLINE */ #endif /* !NO_HISTORY */
/* /*
* $PchId: histedit.c,v 1.6 2006/04/10 14:52:58 philip Exp $ * $PchId: histedit.c,v 1.6 2006/04/10 14:52:58 philip Exp $

View file

@ -63,16 +63,7 @@ __FBSDID("$FreeBSD: src/bin/sh/input.c,v 1.22 2004/04/06 20:06:51 markm Exp $");
#include "error.h" #include "error.h"
#include "alias.h" #include "alias.h"
#include "parser.h" #include "parser.h"
#ifdef EDITLINE
#ifdef __minix_vmd
#include <readline/readline.h>
#else
/* What about other systems? */
char *readline(char *prompt);
#endif
#else
#include "myhistedit.h" #include "myhistedit.h"
#endif
#include "redir.h" #include "redir.h"
#include "trap.h" #include "trap.h"
@ -118,9 +109,7 @@ STATIC struct parsefile *parsefile = &basepf; /* current input file */
int init_editline = 0; /* editline library initialized? */ int init_editline = 0; /* editline library initialized? */
int whichprompt; /* -1 == PSE, 1 == PS1, 2 == PS2 */ int whichprompt; /* -1 == PSE, 1 == PS1, 2 == PS2 */
#ifndef EDITLINE
EditLine *el; /* cookie for editline package */ EditLine *el; /* cookie for editline package */
#endif
STATIC void pushfile(void); STATIC void pushfile(void);
static int preadfd(void); static int preadfd(void);
@ -193,7 +182,7 @@ preadfd(void)
int nr; int nr;
parsenextc = parsefile->buf; parsenextc = parsefile->buf;
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
if (el != NULL && gotwinch) { if (el != NULL && gotwinch) {
gotwinch = 0; gotwinch = 0;
el_resize(el); el_resize(el);
@ -201,37 +190,6 @@ preadfd(void)
#endif #endif
retry: retry:
#ifndef NO_HISTORY #ifndef NO_HISTORY
#ifdef EDITLINE
if (parsefile->fd == 0 && editable) {
static const char *rl_cp= NULL;
static size_t rl_off= 0;
if (!rl_cp)
{
rl_cp = readline(getprompt(NULL));
if (rl_cp == NULL)
nr = 0;
}
if (rl_cp)
{
nr= strlen(rl_cp+rl_off);
if (nr >= BUFSIZ-1)
{
nr= BUFSIZ-1;
(void) memcpy(parsenextc, rl_cp+rl_off, nr);
rl_off += nr;
}
else
{
(void) memcpy(parsenextc, rl_cp+rl_off, nr);
parsenextc[nr++]= '\n';
free((void *)rl_cp);
rl_cp= NULL;
rl_off= 0;
}
}
} else
#else /* !EDITLINE */
if (parsefile->fd == 0 && el) { if (parsefile->fd == 0 && el) {
const char *rl_cp; const char *rl_cp;
@ -243,7 +201,6 @@ retry:
(void) strcpy(parsenextc, rl_cp); (void) strcpy(parsenextc, rl_cp);
} }
} else } else
#endif /* !EDITLINE */
#endif #endif
nr = read(parsefile->fd, parsenextc, BUFSIZ - 1); nr = read(parsefile->fd, parsenextc, BUFSIZ - 1);
@ -343,7 +300,7 @@ check:
savec = *q; savec = *q;
*q = '\0'; *q = '\0';
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
if (parsefile->fd == 0 && hist && something) { if (parsefile->fd == 0 && hist && something) {
HistEvent he; HistEvent he;
INTOFF; INTOFF;

View file

@ -91,9 +91,7 @@ readcmd(int argc __unused, char **argv __unused)
struct timeval tv; struct timeval tv;
char *tvptr; char *tvptr;
#ifndef __minix #ifndef __minix
#ifndef __minix_vmd
fd_set ifds; fd_set ifds;
#endif
struct termios told, tnew; struct termios told, tnew;
int tsaved; int tsaved;
#endif #endif

View file

@ -59,7 +59,7 @@ __FBSDID("$FreeBSD: src/bin/sh/options.c,v 1.21 2004/04/06 20:06:51 markm Exp $"
#include "error.h" #include "error.h"
#include "mystring.h" #include "mystring.h"
#include "builtins.h" #include "builtins.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
#include "myhistedit.h" #include "myhistedit.h"
#endif #endif
@ -129,7 +129,7 @@ void
optschanged(void) optschanged(void)
{ {
setinteractive(iflag); setinteractive(iflag);
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
histedit(); histedit();
#endif #endif
setjobctl(mflag); setjobctl(mflag);

View file

@ -58,7 +58,7 @@ __FBSDID("$FreeBSD: src/bin/sh/parser.c,v 1.51.2.1 2005/03/03 03:43:20 obrien Ex
#include "alias.h" #include "alias.h"
#include "show.h" #include "show.h"
#include "eval.h" #include "eval.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
#include "myhistedit.h" #include "myhistedit.h"
#endif #endif
@ -1556,11 +1556,7 @@ setprompt(int which)
whichprompt = which; whichprompt = which;
#ifndef NO_HISTORY #ifndef NO_HISTORY
#ifdef EDITLINE
if (!editable)
#else
if (!el) if (!el)
#endif /* EDITLINE */
#endif /* !NO_HISTORY */ #endif /* !NO_HISTORY */
out2str(getprompt(NULL)); out2str(getprompt(NULL));
} }

View file

@ -81,11 +81,6 @@ extern char nullstr[1]; /* null string */
#define TRACE(param) #define TRACE(param)
#endif #endif
#if defined(__minix) && !defined(__NBSD_LIBC)
typedef long quad_t; /* XXX */
typedef unsigned long u_quad_t; /* XXX */
#endif
/* /*
* $PchId: shell.h,v 1.7 2006/05/22 12:47:00 philip Exp $ * $PchId: shell.h,v 1.7 2006/05/22 12:47:00 philip Exp $
*/ */

View file

@ -57,19 +57,11 @@ __FBSDID("$FreeBSD: src/bin/sh/trap.c,v 1.29 2004/04/06 20:06:51 markm Exp $");
#include "error.h" #include "error.h"
#include "trap.h" #include "trap.h"
#include "mystring.h" #include "mystring.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
#include "myhistedit.h" #include "myhistedit.h"
#endif #endif
#include "builtins.h" #include "builtins.h"
#if defined(__minix)
#if !defined(__NBSD_LIBC)
#define NO_SIGINTERRUPT
#endif
#define NO_SYS_SIGNAME
#define NO_SYS_SIGLIST
#endif
typedef void (*sig_T)(int); typedef void (*sig_T)(int);
/* /*
@ -511,7 +503,7 @@ int flag;
} }
#endif #endif
#ifdef NO_SYS_SIGNAME #ifdef __minix
static char *strsigname(sig) static char *strsigname(sig)
int sig; int sig;
{ {
@ -524,11 +516,7 @@ int sig;
case SIGILL: return "ill"; /* 4 */ case SIGILL: return "ill"; /* 4 */
case SIGTRAP: return "trap"; /* 5 */ case SIGTRAP: return "trap"; /* 5 */
case SIGABRT: return "abrt"; /* 6 */ case SIGABRT: return "abrt"; /* 6 */
#ifdef __minix_vmd
case SIGEMT: return "emt"; /* 7 */
#else
case SIGBUS: return "bus"; /* 7 */ case SIGBUS: return "bus"; /* 7 */
#endif
case SIGFPE: return "fpe"; /* 8 */ case SIGFPE: return "fpe"; /* 8 */
case SIGKILL: return "kill"; /* 9 */ case SIGKILL: return "kill"; /* 9 */
case SIGUSR1: return "usr1"; /* 10 */ case SIGUSR1: return "usr1"; /* 10 */
@ -537,11 +525,7 @@ int sig;
case SIGPIPE: return "pipe"; /* 13 */ case SIGPIPE: return "pipe"; /* 13 */
case SIGALRM: return "alrm"; /* 14 */ case SIGALRM: return "alrm"; /* 14 */
case SIGTERM: return "term"; /* 15 */ case SIGTERM: return "term"; /* 15 */
#ifdef __minix_vmd
case 16: return "Signal 16"; /* 16 */
#else
case SIGEMT: return "emt"; /* 16 */ case SIGEMT: return "emt"; /* 16 */
#endif
case SIGCHLD: return "chld"; /* 17 */ case SIGCHLD: return "chld"; /* 17 */
case SIGCONT: return "cont"; /* 18 */ case SIGCONT: return "cont"; /* 18 */
case SIGSTOP: return "stop"; /* 19 */ case SIGSTOP: return "stop"; /* 19 */
@ -551,9 +535,6 @@ int sig;
case SIGWINCH: return "winch"; /* 23 */ case SIGWINCH: return "winch"; /* 23 */
case SIGVTALRM: return "vtalrm"; /* 24 */ case SIGVTALRM: return "vtalrm"; /* 24 */
case SIGPROF: return "prof"; /* 25 */ case SIGPROF: return "prof"; /* 25 */
#ifdef __minix_vmd
case SIGFPEMU: return "fpemu"; /* 30 */
#endif
default: return "Signal n"; default: return "Signal n";
} }
} }
@ -565,7 +546,7 @@ int sig;
} }
#endif #endif
#ifdef NO_SYS_SIGLIST #ifdef __minix
#include "signames.h" #include "signames.h"
char *strsiglist(sig) char *strsiglist(sig)
int sig; int sig;

View file

@ -66,7 +66,7 @@ __FBSDID("$FreeBSD: src/bin/sh/var.c,v 1.26.2.1 2004/09/30 04:41:55 des Exp $");
#include "error.h" #include "error.h"
#include "mystring.h" #include "mystring.h"
#include "parser.h" #include "parser.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
#include "myhistedit.h" #include "myhistedit.h"
#endif #endif
@ -102,7 +102,7 @@ struct var vvers;
STATIC struct var voptind; STATIC struct var voptind;
STATIC const struct varinit varinit[] = { STATIC const struct varinit varinit[] = {
#if !defined(NO_HISTORY) && !defined(EDITLINE) #if !defined(NO_HISTORY)
{ &vhistsize, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE=", { &vhistsize, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE=",
sethistsize }, sethistsize },
#endif #endif

View file

@ -1,3 +1,12 @@
20130130:
With the shell update, and following update of 'test', some
modifications are needed in .profile and .ashrc.
If you use the defaults, simply execute the following for all
of your users:
# cp etc/ast/.ashrc ~/
# cp etc/ast/.profile ~/
20130114: 20130114:
The terminfo update is also linked to the databases functions, The terminfo update is also linked to the databases functions,
which means the tool used to generate the termcap entries has to which means the tool used to generate the termcap entries has to

View file

@ -12,8 +12,9 @@ export PATH=$HOME/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:
} # End of no-repeat. } # End of no-repeat.
# Let cd display the current directory on the status line. # Let cd display the current directory on the status line.
if [ "$-" : '.*i.*' -a -t 0 -a -f /usr/bin/tget ] && tget -flag hs if [ -t 0 -a -f /usr/bin/tget ] && tget -flag hs
then then
case $- in *i*)
hostname=$(expr $(uname -n) : '\([^.]*\)') hostname=$(expr $(uname -n) : '\([^.]*\)')
eval "cd() eval "cd()
{ {
@ -24,4 +25,6 @@ then
}" }"
unset hostname unset hostname
cd . cd .
;;
esac
fi fi

View file

@ -1,7 +1,7 @@
# Login shell profile. # Login shell profile.
# Erase character and erase line interrupt keys # Activate emacs keybindings and command line history support
stty sane erase '^H' kill '^U' set -o emacs
# Check terminal type. # Check terminal type.
case $TERM in case $TERM in

View file

@ -201,11 +201,12 @@ _EOF
# generate editline.c from various .c files # generate editline.c from various .c files
# #
# LSC: Needed by MINIX's ASH, so do not hide those
-e) -e)
echo "$FILES" | tr ' ' '\012' | $AWK ' echo "$FILES" | tr ' ' '\012' | $AWK '
BEGIN { BEGIN {
printf("/* Automatically generated file, do not edit */\n"); printf("/* Automatically generated file, do not edit */\n");
printf("#define protected static\n"); printf("#define protected /* LSC: see makelist static*/\n");
printf("#define SCCSID\n"); printf("#define SCCSID\n");
} }
{ {