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
#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>
#NO_PATHS_H=-DNO_PATHS_H
@ -18,7 +16,7 @@ EDIT=-DEDITLINE
NO_JOBS=-DJOBS=0
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 \
mystring.c options.c output.c parser.c redir.c show.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.
*/
#ifdef __minix
#define MINIX
#endif
#include "bltin.h"
#ifndef MINIX
/* #define eflag 1 */
#else
#undef eflag
#endif
int
echocmd(argc, argv)
int argc;
@ -63,7 +53,7 @@ echocmd(argc, argv)
char c;
int count;
int nflag = 0;
#ifndef eflag
#ifdef __minix
int eflag = 0;
#endif
@ -71,7 +61,7 @@ echocmd(argc, argv)
if (argc)
ap++;
if ((p = *ap) != NULL) {
#ifdef MINIX
#ifdef __minix
if (equal(p, "--")) {
ap++;
}
@ -80,7 +70,7 @@ echocmd(argc, argv)
nflag++;
ap++;
} else if (equal(p, "-e")) {
#ifndef eflag
#ifdef __minix
eflag++;
#endif
ap++;

View file

@ -47,8 +47,9 @@
bltincmd builtin
commandcmd command
#alloccmd alloc
#if JOBS
bgcmd -j bg
#endif
breakcmd break continue
#catfcmd catf
cdcmd cd chdir
@ -62,15 +63,17 @@ exportcmd export readonly
exprcmd expr test [
falsecmd false
histcmd -h fc
#if JOBS
fgcmd -j fg
#endif
getoptscmd getopts
hashcmd hash
jobidcmd jobid
jobscmd jobs
#linecmd line
localcmd local
#nlechocmd nlecho
#ifndef SMALL
#printfcmd printf
#endif
pwdcmd pwd
readcmd read
returncmd return
@ -84,11 +87,7 @@ umaskcmd umask
unaliascmd unalias
unsetcmd unset
waitcmd wait
#foocmd foo
aliascmd alias
ulimitcmd ulimit
bindcmd bind
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 "show.h"
#include "mystring.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
#include "myhistedit.h"
#endif
@ -194,7 +194,7 @@ evaltree(union node *n, int flags)
exitstatus = 0;
goto out;
}
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
displayhist = 1; /* show history substitutions done with fc */
#endif
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;
execve(cmd, argv, envp);
#if !__minix_vmd
e = errno;
if (e == ENOEXEC) {
initshellproc();
@ -166,7 +166,6 @@ tryexec(char *cmd, char **argv, char **envp)
/*NOTREACHED*/
}
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 "mystring.h"
#include "builtins.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
#include "myhistedit.h"
#include "complete.h"
#include "error.h"
@ -179,7 +179,7 @@ sethistsize(hs)
if (hs == NULL || *hs == '\0' ||
(histsize = atoi(hs)) < 0)
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");
return (0);
}
#endif /* !NO_HISTORY && !EDITLINE */
#endif /* !NO_HISTORY */
/*
* $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 "alias.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"
#endif
#include "redir.h"
#include "trap.h"
@ -118,9 +109,7 @@ STATIC struct parsefile *parsefile = &basepf; /* current input file */
int init_editline = 0; /* editline library initialized? */
int whichprompt; /* -1 == PSE, 1 == PS1, 2 == PS2 */
#ifndef EDITLINE
EditLine *el; /* cookie for editline package */
#endif
STATIC void pushfile(void);
static int preadfd(void);
@ -193,7 +182,7 @@ preadfd(void)
int nr;
parsenextc = parsefile->buf;
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
if (el != NULL && gotwinch) {
gotwinch = 0;
el_resize(el);
@ -201,37 +190,6 @@ preadfd(void)
#endif
retry:
#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) {
const char *rl_cp;
@ -243,7 +201,6 @@ retry:
(void) strcpy(parsenextc, rl_cp);
}
} else
#endif /* !EDITLINE */
#endif
nr = read(parsefile->fd, parsenextc, BUFSIZ - 1);
@ -343,7 +300,7 @@ check:
savec = *q;
*q = '\0';
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
if (parsefile->fd == 0 && hist && something) {
HistEvent he;
INTOFF;

View file

@ -91,9 +91,7 @@ readcmd(int argc __unused, char **argv __unused)
struct timeval tv;
char *tvptr;
#ifndef __minix
#ifndef __minix_vmd
fd_set ifds;
#endif
struct termios told, tnew;
int tsaved;
#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 "mystring.h"
#include "builtins.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
#include "myhistedit.h"
#endif
@ -129,7 +129,7 @@ void
optschanged(void)
{
setinteractive(iflag);
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
histedit();
#endif
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 "show.h"
#include "eval.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
#include "myhistedit.h"
#endif
@ -1556,11 +1556,7 @@ setprompt(int which)
whichprompt = which;
#ifndef NO_HISTORY
#ifdef EDITLINE
if (!editable)
#else
if (!el)
#endif /* EDITLINE */
#endif /* !NO_HISTORY */
out2str(getprompt(NULL));
}

View file

@ -81,11 +81,6 @@ extern char nullstr[1]; /* null string */
#define TRACE(param)
#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 $
*/

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 "trap.h"
#include "mystring.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
#include "myhistedit.h"
#endif
#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);
/*
@ -511,7 +503,7 @@ int flag;
}
#endif
#ifdef NO_SYS_SIGNAME
#ifdef __minix
static char *strsigname(sig)
int sig;
{
@ -524,11 +516,7 @@ int sig;
case SIGILL: return "ill"; /* 4 */
case SIGTRAP: return "trap"; /* 5 */
case SIGABRT: return "abrt"; /* 6 */
#ifdef __minix_vmd
case SIGEMT: return "emt"; /* 7 */
#else
case SIGBUS: return "bus"; /* 7 */
#endif
case SIGFPE: return "fpe"; /* 8 */
case SIGKILL: return "kill"; /* 9 */
case SIGUSR1: return "usr1"; /* 10 */
@ -537,11 +525,7 @@ int sig;
case SIGPIPE: return "pipe"; /* 13 */
case SIGALRM: return "alrm"; /* 14 */
case SIGTERM: return "term"; /* 15 */
#ifdef __minix_vmd
case 16: return "Signal 16"; /* 16 */
#else
case SIGEMT: return "emt"; /* 16 */
#endif
case SIGCHLD: return "chld"; /* 17 */
case SIGCONT: return "cont"; /* 18 */
case SIGSTOP: return "stop"; /* 19 */
@ -551,9 +535,6 @@ int sig;
case SIGWINCH: return "winch"; /* 23 */
case SIGVTALRM: return "vtalrm"; /* 24 */
case SIGPROF: return "prof"; /* 25 */
#ifdef __minix_vmd
case SIGFPEMU: return "fpemu"; /* 30 */
#endif
default: return "Signal n";
}
}
@ -565,7 +546,7 @@ int sig;
}
#endif
#ifdef NO_SYS_SIGLIST
#ifdef __minix
#include "signames.h"
char *strsiglist(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 "mystring.h"
#include "parser.h"
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
#include "myhistedit.h"
#endif
@ -102,7 +102,7 @@ struct var vvers;
STATIC struct var voptind;
STATIC const struct varinit varinit[] = {
#if !defined(NO_HISTORY) && !defined(EDITLINE)
#if !defined(NO_HISTORY)
{ &vhistsize, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE=",
sethistsize },
#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:
The terminfo update is also linked to the databases functions,
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.
# 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
case $- in *i*)
hostname=$(expr $(uname -n) : '\([^.]*\)')
eval "cd()
{
@ -24,4 +25,6 @@ then
}"
unset hostname
cd .
;;
esac
fi

View file

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

View file

@ -201,11 +201,12 @@ _EOF
# generate editline.c from various .c files
#
# LSC: Needed by MINIX's ASH, so do not hide those
-e)
echo "$FILES" | tr ' ' '\012' | $AWK '
BEGIN {
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");
}
{