Wed Jan 23 16:39:04 2013 UTC ()
make history kind of work :-), turn libedit support on.
(christos)
diff -r1.35 -r1.36 src/bin/csh/Makefile
diff -r1.44 -r1.45 src/bin/csh/csh.c
diff -r1.24 -r1.25 src/bin/csh/csh.h
diff -r1.27 -r1.28 src/bin/csh/extern.h
diff -r1.18 -r1.19 src/bin/csh/hist.c
diff -r1.28 -r1.29 src/bin/csh/lex.c
diff -r1.30 -r1.31 src/bin/csh/set.c
--- src/bin/csh/Makefile 2013/01/22 22:40:31 1.35
+++ src/bin/csh/Makefile 2013/01/23 16:39:03 1.36
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.35 2013/01/22 22:40:31 christos Exp $
+# $NetBSD: Makefile,v 1.36 2013/01/23 16:39:03 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
#
# C Shell with process control; VM/UNIX VAX Makefile
@@ -10,10 +10,11 @@
PROG= csh
DFLAGS=-DBUILTIN -DFILEC -DNLS -DSHORT_STRINGS
-# - Not integrated with history
+# - Editor history not always aligned with shell history,
+# should implement internally
# - Does not handle escaped prompts.
# - Does not do completion
-# DFLAGS+=-DEDIT
+DFLAGS+=-DEDIT
CPPFLAGS+=-I${.CURDIR} -I. ${DFLAGS}
SRCS= alloc.c char.c const.c csh.c dir.c dol.c err.c exec.c exp.c file.c \
func.c glob.c hist.c init.c lex.c misc.c parse.c printf.c proc.c \
@@ -60,7 +61,7 @@
COPTS.printf.c = -Wno-format-nonliteral
COPTS.proc.c = -Wno-format-nonliteral
-.if 0
+.if !empty(DFLAGS:M*EDIT)
LDADD+=-ledit -lutil
DPADD+=${LIBEDIT} ${LIBUTIL}
.else
--- src/bin/csh/csh.c 2013/01/22 20:35:29 1.44
+++ src/bin/csh/csh.c 2013/01/23 16:39:03 1.45
@@ -1,4 +1,4 @@
-/* $NetBSD: csh.c,v 1.44 2013/01/22 20:35:29 christos Exp $ */
+/* $NetBSD: csh.c,v 1.45 2013/01/23 16:39:03 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)csh.c 8.2 (Berkeley) 10/12/93";
#else
-__RCSID("$NetBSD: csh.c,v 1.44 2013/01/22 20:35:29 christos Exp $");
+__RCSID("$NetBSD: csh.c,v 1.45 2013/01/23 16:39:03 christos Exp $");
#endif
#endif /* not lint */
@@ -78,7 +78,7 @@
*/
Char *dumphist[] = {STRhistory, STRmh, 0, 0};
-Char *loadhist[] = {STRsource, STRmh, STRtildothist, 0};
+Char *tildehist[] = {STRsource, STRmh, STRtildothist, 0};
int nofile = 0;
int batch = 0;
@@ -542,8 +542,8 @@
* Source history before .login so that it is available in .login
*/
if ((cp = value(STRhistfile)) != STRNULL)
- loadhist[2] = cp;
- dosource(loadhist, NULL);
+ tildehist[2] = cp;
+ dosource(tildehist, NULL);
if (loginsh)
(void)srccat(value(STRhome), STRsldotlogin);
}
--- src/bin/csh/csh.h 2013/01/22 22:40:31 1.24
+++ src/bin/csh/csh.h 2013/01/23 16:39:03 1.25
@@ -1,4 +1,4 @@
-/* $NetBSD: csh.h,v 1.24 2013/01/22 22:40:31 christos Exp $ */
+/* $NetBSD: csh.h,v 1.25 2013/01/23 16:39:03 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -552,6 +552,7 @@
#ifdef EDIT
#include <histedit.h>
EditLine *el;
+History *hi;
#endif
int editing;
--- src/bin/csh/extern.h 2013/01/22 20:35:29 1.27
+++ src/bin/csh/extern.h 2013/01/23 16:39:03 1.28
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.27 2013/01/22 20:35:29 christos Exp $ */
+/* $NetBSD: extern.h,v 1.28 2013/01/23 16:39:03 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -175,6 +175,9 @@
*/
void dohist(Char **, struct command *);
struct Hist *enthist(int, struct wordent *, int);
+#ifdef EDIT
+void loadhist(struct Hist *);
+#endif
void savehist(struct wordent *);
/*
@@ -189,6 +192,9 @@
void freelex(struct wordent *);
int lex(struct wordent *);
void prlex(FILE *, struct wordent *);
+#ifdef EDIT
+int sprlex(char **, struct wordent *);
+#endif
int readc(int);
void settell(void);
void unreadc(int);
--- src/bin/csh/hist.c 2007/07/16 18:26:10 1.18
+++ src/bin/csh/hist.c 2013/01/23 16:39:03 1.19
@@ -1,4 +1,4 @@
-/* $NetBSD: hist.c,v 1.18 2007/07/16 18:26:10 christos Exp $ */
+/* $NetBSD: hist.c,v 1.19 2013/01/23 16:39:03 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: hist.c,v 1.18 2007/07/16 18:26:10 christos Exp $");
+__RCSID("$NetBSD: hist.c,v 1.19 2013/01/23 16:39:03 christos Exp $");
#endif
#endif /* not lint */
@@ -82,11 +82,35 @@
(void) enthist(++eventno, sp, 1);
}
+#ifdef EDIT
+void
+loadhist(struct Hist *hp) {
+ char *h = NULL;
+
+ if (hi == NULL || hp == NULL)
+ return;
+ loadhist(hp->Hnext);
+ if (sprlex(&h, &hp->Hlex) != -1) {
+ HistEvent ev;
+ history(hi, &ev, H_ENTER, h);
+ }
+}
+#endif
+
struct Hist *
enthist(int event, struct wordent *lp, int docopy)
{
struct Hist *np;
+#ifdef EDIT
+ if (hi) {
+ char *h = NULL;
+ if (sprlex(&h, lp) != -1) {
+ HistEvent ev;
+ history(hi, &ev, H_ENTER, h);
+ }
+ }
+#endif
np = (struct Hist *)xmalloc((size_t)sizeof(*np));
np->Hnum = np->Href = event;
if (docopy) {
--- src/bin/csh/lex.c 2013/01/22 20:35:29 1.28
+++ src/bin/csh/lex.c 2013/01/23 16:39:03 1.29
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.28 2013/01/22 20:35:29 christos Exp $ */
+/* $NetBSD: lex.c,v 1.29 2013/01/23 16:39:03 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: lex.c,v 1.28 2013/01/22 20:35:29 christos Exp $");
+__RCSID("$NetBSD: lex.c,v 1.29 2013/01/23 16:39:03 christos Exp $");
#endif
#endif /* not lint */
@@ -187,6 +187,36 @@
(void) fputc(' ', fp);
}
}
+
+#ifdef EDIT
+int
+sprlex(char **s, struct wordent *sp0)
+{
+ struct wordent *sp;
+
+ sp = sp0->next;
+ char *os = *s;
+ for (;;) {
+ char *w = vis_str(sp->word);
+ if (os == NULL) {
+ if (asprintf(s, "%s", w) < 0)
+ return -1;
+ os = *s;
+ } else if (*os != '\n') {
+ if (asprintf(s, "%s %s", os, w) < 0) {
+ free(os);
+ return 1;
+ }
+ free(os);
+ os = *s;
+ }
+ sp = sp->next;
+ if (sp == sp0)
+ break;
+ }
+ return 0;
+}
+#endif
void
copylex(struct wordent *hp, struct wordent *fp)
--- src/bin/csh/set.c 2013/01/22 20:35:29 1.30
+++ src/bin/csh/set.c 2013/01/23 16:39:03 1.31
@@ -1,4 +1,4 @@
-/* $NetBSD: set.c,v 1.30 2013/01/22 20:35:29 christos Exp $ */
+/* $NetBSD: set.c,v 1.31 2013/01/23 16:39:03 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)set.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: set.c,v 1.30 2013/01/22 20:35:29 christos Exp $");
+__RCSID("$NetBSD: set.c,v 1.31 2013/01/23 16:39:03 christos Exp $");
#endif
#endif /* not lint */
@@ -176,11 +176,16 @@
#endif
#ifdef EDIT
else if (eq(vp, STRedit)) {
- editing = 1;
- el = el_init_fd(getprogname(), cshin, cshout, csherr,
- SHIN, SHOUT, SHERR);
- el_set(el, EL_EDITOR, "emacs");
- el_set(el, EL_PROMPT, printpromptstr);
+ HistEvent ev;
+ editing = 1;
+ el = el_init_fd(getprogname(), cshin, cshout, csherr,
+ SHIN, SHOUT, SHERR);
+ el_set(el, EL_EDITOR, "emacs");
+ el_set(el, EL_PROMPT, printpromptstr);
+ hi = history_init();
+ history(hi, &ev, H_SETSIZE, getn(value(STRhistory)));
+ loadhist(Histlist.Hnext);
+ el_set(el, EL_HIST, history, hi);
}
#endif
} while ((p = *v++) != NULL);
@@ -516,7 +521,9 @@
#ifdef EDIT
else if (adrof(STRedit) == 0) {
el_end(el);
+ history_end(hi);
el = NULL;
+ hi = NULL;
editing = 0;
}
#endif