Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/csh make history kind of work :-), turn libedit support on.



details:   https://anonhg.NetBSD.org/src/rev/551deeb7df94
branches:  trunk
changeset: 784265:551deeb7df94
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 23 16:39:03 2013 +0000

description:
make history kind of work :-), turn libedit support on.

diffstat:

 bin/csh/Makefile |   9 +++++----
 bin/csh/csh.c    |  10 +++++-----
 bin/csh/csh.h    |   3 ++-
 bin/csh/extern.h |   8 +++++++-
 bin/csh/hist.c   |  28 ++++++++++++++++++++++++++--
 bin/csh/lex.c    |  34 ++++++++++++++++++++++++++++++++--
 bin/csh/set.c    |  21 ++++++++++++++-------
 7 files changed, 91 insertions(+), 22 deletions(-)

diffs (275 lines):

diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/Makefile
--- a/bin/csh/Makefile  Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/Makefile  Wed Jan 23 16:39:03 2013 +0000
@@ -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
diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/csh.c
--- a/bin/csh/csh.c     Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/csh.c     Wed Jan 23 16:39:03 2013 +0000
@@ -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);
     }
diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/csh.h
--- a/bin/csh/csh.h     Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/csh.h     Wed Jan 23 16:39:03 2013 +0000
@@ -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;
 
diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/extern.h
--- a/bin/csh/extern.h  Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/extern.h  Wed Jan 23 16:39:03 2013 +0000
@@ -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);
diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/hist.c
--- a/bin/csh/hist.c    Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/hist.c    Wed Jan 23 16:39:03 2013 +0000
@@ -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) {
diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/lex.c
--- a/bin/csh/lex.c     Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/lex.c     Wed Jan 23 16:39:03 2013 +0000
@@ -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 */
 
@@ -188,6 +188,36 @@
     }
 }
 
+#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)
 {
diff -r f0a9a32112f0 -r 551deeb7df94 bin/csh/set.c
--- a/bin/csh/set.c     Wed Jan 23 15:29:15 2013 +0000
+++ b/bin/csh/set.c     Wed Jan 23 16:39:03 2013 +0000
@@ -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



Home | Main Index | Thread Index | Old Index