From: Alan Cox Date: Sat, 6 Oct 2018 00:01:37 +0000 (+0100) Subject: sh: initial readline tiny changes X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6d1963e871b3271b6acb5808526d4773a1eb5c67;p=FUZIX.git sh: initial readline tiny changes This is still a work in progress to get us a /bin/sh with nice modern editing behaviour --- diff --git a/Applications/V7/cmd/sh/Makefile.z80 b/Applications/V7/cmd/sh/Makefile.z80 index 8825fdab..c661a795 100644 --- a/Applications/V7/cmd/sh/Makefile.z80 +++ b/Applications/V7/cmd/sh/Makefile.z80 @@ -9,19 +9,25 @@ SRCS = args.c blok.c builtin.c cmd.c ctype.c error.c expand.c fault.c io.c \ INCS = brkincr.h ctype.h defs.h mac.h mode.h name.h stak.h sym.h timeout.h OBJS = $(SRCS:.c=.rel) +FOBJS = $(patsubst %.c,fshbuild/%.rel, $(SRCS)) -all: sh +all: fsh sh sh: $(OBJS) $(FCC) $(Z80_PLATFORM) $(OBJS) -o $@ +fsh: $(FOBJS) + $(FCC) $(Z80_PLATFORM) $(FOBJS) -o $@ -lreadline + $(OBJS): $(INCS) -.c.rel: +$(FOBJS): $(INCS) + +$(OBJS): %.rel: %.c $(FCC) $(Z80_PLATFORM) -c $< -%: %.rel - $(FCC) $(Z80_PLATFORM) $< -o $@ +$(FOBJS): fshbuild/%.rel: %.c + $(FCC) $(Z80_PLATFORM) -c -DBUILD_FSH $< -o $@ clean: rm -f $(OBJS) sh $(SRCS:.c=) core *~ *.asm *.lst *.sym *.map *.noi *.lk *.ihx *.tmp *.bin diff --git a/Applications/V7/cmd/sh/main.c b/Applications/V7/cmd/sh/main.c index 2c0b136a..d69de093 100644 --- a/Applications/V7/cmd/sh/main.c +++ b/Applications/V7/cmd/sh/main.c @@ -18,7 +18,8 @@ #include "timeout.h" #include #include -#include +#include +#include UFD output = 2; static BOOL beenhere = FALSE; @@ -29,6 +30,33 @@ char* tempfile; static void exfile(BOOL); +#ifdef BUILD_FSH +static char history[1024]; + +static int line_input(char *prmpt) +{ + int l; + if (!isatty(standin->fdes)) + return -1; /* Not a tty */ + do { + l = rl_edit(standin->fdes, output, + prmpt, + standin->fbuf, standin->fsiz); + if (l >= 0) { + standin->fbuf[l] = '\n'; + standin->fnxt = standin->fbuf; + standin->fend = standin->fbuf + l; + } + } while(l == -2); + /* 0 - EOF, 1+ buffer including \n */ + return l + 1; +} + +#else +#define rl_hinit(x,y) +#define line_input(x) (-1) +#endif + int main(int c, const char *v[]) { register int rflag = ttyflg; @@ -41,6 +69,8 @@ int main(int c, const char *v[]) setbrk(BRKINCR); addblok((POS) 0); + rl_hinit(history, sizeof(history)); + /* set names from userenv */ sh_getenv(); @@ -158,8 +188,11 @@ static void exfile(BOOL prof) prs(mailmsg); } mailtime = statb.st_mtime; - prs(ps1nod.namval); - alarm(TIMEOUT); + if (line_input(ps1nod.namval) < 0) + { + prs(ps1nod.namval); + alarm(TIMEOUT); + } flags |= waiting; } @@ -176,8 +209,10 @@ static void exfile(BOOL prof) void chkpr(char eor) { - if ((flags & prompt) && standin->fstak == 0 && eor == NL) - prs(ps2nod.namval); + if ((flags & prompt) && standin->fstak == 0 && eor == NL) { + if (line_input(ps2nod.namval) < 0) + prs(ps2nod.namval); + } } void settmp(void) diff --git a/Applications/V7/cmd/sh/mode.h b/Applications/V7/cmd/sh/mode.h index 9a975cf0..efe1ad0c 100644 --- a/Applications/V7/cmd/sh/mode.h +++ b/Applications/V7/cmd/sh/mode.h @@ -71,7 +71,14 @@ struct blk { BLKPTR word; }; +/* We need a real line worth of buffering for fsh to work nicely and as it's + a bigger target we can afford it */ +#ifdef BUILD_FSH +#define BUFSIZ 256 +#else #define BUFSIZ 64 +#endif + struct fileblk { UFD fdes; POS flin;