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
#include "timeout.h"
#include <sys/types.h>
#include <sys/stat.h>
-#include <setjmp.h>
+#include <setjmp.h>
+#include <readline/readline.h>
UFD output = 2;
static BOOL beenhere = FALSE;
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;
setbrk(BRKINCR);
addblok((POS) 0);
+ rl_hinit(history, sizeof(history));
+
/* set names from userenv */
sh_getenv();
prs(mailmsg);
}
mailtime = statb.st_mtime;
- prs(ps1nod.namval);
- alarm(TIMEOUT);
+ if (line_input(ps1nod.namval) < 0)
+ {
+ prs(ps1nod.namval);
+ alarm(TIMEOUT);
+ }
flags |= waiting;
}
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)