Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/csh Add a little libedit front end. Could be used as som...
details: https://anonhg.NetBSD.org/src/rev/26d6c21e3eb6
branches: trunk
changeset: 784232:26d6c21e3eb6
user: christos <christos%NetBSD.org@localhost>
date: Tue Jan 22 20:35:29 2013 +0000
description:
Add a little libedit front end. Could be used as someone's pet project to
learn how to program. It is not enabled in the Makefile, and it states why
there.
diffstat:
bin/csh/Makefile | 11 ++++++++++-
bin/csh/const.c | 5 +++--
bin/csh/csh.c | 39 +++++++++++++++++++++++++++++++++++----
bin/csh/csh.h | 8 +++++++-
bin/csh/extern.h | 5 ++++-
bin/csh/glob.c | 30 +++++++++++++++---------------
bin/csh/lex.c | 20 ++++++++++++++++----
bin/csh/set.c | 30 +++++++++++++++++++++++-------
8 files changed, 113 insertions(+), 35 deletions(-)
diffs (truncated from 369 to 300 lines):
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/Makefile
--- a/bin/csh/Makefile Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/Makefile Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.33 2011/08/28 07:49:16 christos Exp $
+# $NetBSD: Makefile,v 1.34 2013/01/22 20:35:29 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
#
# C Shell with process control; VM/UNIX VAX Makefile
@@ -10,6 +10,10 @@
PROG= csh
DFLAGS=-DBUILTIN -DFILEC -DNLS -DSHORT_STRINGS
+# - Not integrated with history
+# - Does not handle escaped prompts.
+# - Does not do completion
+# 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 \
@@ -56,8 +60,13 @@
COPTS.printf.c = -Wno-format-nonliteral
COPTS.proc.c = -Wno-format-nonliteral
+.if 0
LDADD+=-lutil
DPADD+=${LIBUTIL}
+.elese
+LDADD+=-ledit -lutil
+DPADD+=${LIBEDIT} ${LIBUTIL}
+.endif
.include <bsd.prog.mk>
.include <bsd.subdir.mk>
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/const.c
--- a/bin/csh/const.c Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/const.c Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: const.c,v 1.9 2003/08/07 09:05:03 agc Exp $ */
+/* $NetBSD: const.c,v 1.10 2013/01/22 20:35:29 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)const.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: const.c,v 1.9 2003/08/07 09:05:03 agc Exp $");
+__RCSID("$NetBSD: const.c,v 1.10 2013/01/22 20:35:29 christos Exp $");
#endif
#endif /* not lint */
@@ -83,6 +83,7 @@
Char STRdotdotsl[] = { '.', '.', '/', '\0' };
Char STRdotsl[] = { '.', '/', '\0' };
Char STRecho[] = { 'e', 'c', 'h', 'o', '\0' };
+Char STRedit[] = { 'e', 'd', 'i', 't', '\0' };
Char STRequal[] = { '=', '\0' };
Char STRfakecom[] = { '{', ' ', '.', '.', '.', ' ', '}', '\0' };
Char STRfakecom1[] = { '`', ' ', '.', '.', '.', ' ', '`', '\0' };
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/csh.c
--- a/bin/csh/csh.c Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/csh.c Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: csh.c,v 1.43 2012/01/22 18:36:14 christos Exp $ */
+/* $NetBSD: csh.c,v 1.44 2013/01/22 20:35:29 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.43 2012/01/22 18:36:14 christos Exp $");
+__RCSID("$NetBSD: csh.c,v 1.44 2013/01/22 20:35:29 christos Exp $");
#endif
#endif /* not lint */
@@ -105,8 +105,9 @@
#ifndef _PATH_DEFPATH
static Char **defaultpath(void);
#endif
-
-int main(int, char *[]);
+#ifdef EDITING
+int editing = 0;
+#endif
int
main(int argc, char *argv[])
@@ -1341,6 +1342,9 @@
{
Char *cp;
+ if (editing)
+ return;
+
if (!whyles) {
for (cp = value(STRprompt); *cp; cp++)
if (*cp == HIST)
@@ -1358,3 +1362,30 @@
(void)fprintf(cshout, "? ");
(void)fflush(cshout);
}
+
+#ifdef EDIT
+char *
+printpromptstr(EditLine *elx) {
+ static char pbuf[1024];
+ static char qspace[] = "? ";
+ Char *cp;
+ size_t i;
+
+ if (whyles)
+ return qspace;
+
+ i = 0;
+ for (cp = value(STRprompt); *cp; cp++) {
+ if (i >= sizeof(pbuf))
+ break;
+ if (*cp == HIST)
+ i += snprintf(pbuf + i, sizeof(pbuf) - i, "%d", eventno + 1);
+ else
+ pbuf[i++] = *cp;
+ }
+ if (i >= sizeof(pbuf))
+ i = sizeof(pbuf) - 1;
+ pbuf[i] = '\0';
+ return pbuf;
+}
+#endif
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/csh.h
--- a/bin/csh/csh.h Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/csh.h Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: csh.h,v 1.22 2011/11/09 19:16:00 christos Exp $ */
+/* $NetBSD: csh.h,v 1.23 2013/01/22 20:35:29 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -549,4 +549,10 @@
Char *STR_WORD_CHARS;
Char **STR_environ;
+#ifdef EDIT
+#include <histedit.h>
+EditLine *el;
+int editing;
+#endif
+
#endif /* !_CSH_H_ */
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/extern.h
--- a/bin/csh/extern.h Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/extern.h Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.26 2013/01/22 19:28:00 christos Exp $ */
+/* $NetBSD: extern.h,v 1.27 2013/01/22 20:35:29 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -48,6 +48,9 @@
__dead void pintr(int);
__dead void pintr1(int);
void printprompt(void);
+#ifdef EDIT
+char *printpromptstr(EditLine *);
+#endif
void process(int);
void rechist(void);
void untty(void);
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/glob.c
--- a/bin/csh/glob.c Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/glob.c Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: glob.c,v 1.25 2007/07/16 18:26:10 christos Exp $ */
+/* $NetBSD: glob.c,v 1.26 2013/01/22 20:35:29 christos Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)glob.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: glob.c,v 1.25 2007/07/16 18:26:10 christos Exp $");
+__RCSID("$NetBSD: glob.c,v 1.26 2013/01/22 20:35:29 christos Exp $");
#endif
#endif /* not lint */
@@ -213,13 +213,13 @@
static void
expbrace(Char ***nvp, Char ***elp, int size)
{
- Char **el, **nv, *s, **vl;
+ Char **ex, **nv, *s, **vl;
vl = nv = *nvp;
if (elp != NULL)
- el = *elp;
+ ex = *elp;
else
- for (el = vl; *el; el++)
+ for (ex = vl; *ex; ex++)
continue;
for (s = *vl; s; s = *++vl) {
@@ -243,24 +243,24 @@
continue;
}
len = blklen(bl);
- if (&el[len] >= &nv[size]) {
+ if (&ex[len] >= &nv[size]) {
int e, l;
- l = &el[len] - &nv[size];
+ l = &ex[len] - &nv[size];
size += GLOBSPACE > l ? GLOBSPACE : l;
l = vl - nv;
- e = el - nv;
+ e = ex - nv;
nv = (Char **)xrealloc((ptr_t)nv,
(size_t)size * sizeof(Char *));
vl = nv + l;
- el = nv + e;
+ ex = nv + e;
}
vp = vl--;
*vp = *bl;
len--;
- for (bp = el; bp != vp; bp--)
+ for (bp = ex; bp != vp; bp--)
bp[len] = *bp;
- el += len;
+ ex += len;
vp++;
for (bp = bl + 1; *bp; *vp++ = *bp++)
continue;
@@ -269,14 +269,14 @@
}
if (elp != NULL)
- *elp = el;
+ *elp = ex;
*nvp = nv;
}
static Char **
globexpand(Char **v)
{
- Char **el, **nv, *s, **vl;
+ Char **ex, **nv, *s, **vl;
int size;
size = GLOBSPACE;
@@ -321,8 +321,8 @@
/*
* Step 2: expand braces
*/
- el = vl;
- expbrace(&nv, &el, size);
+ ex = vl;
+ expbrace(&nv, &ex, size);
/*
* Step 3: expand ~
diff -r 25bee69c647e -r 26d6c21e3eb6 bin/csh/lex.c
--- a/bin/csh/lex.c Tue Jan 22 20:25:16 2013 +0000
+++ b/bin/csh/lex.c Tue Jan 22 20:35:29 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.27 2010/01/17 12:15:36 wiz Exp $ */
+/* $NetBSD: lex.c,v 1.28 2013/01/22 20:35:29 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.27 2010/01/17 12:15:36 wiz Exp $");
+__RCSID("$NetBSD: lex.c,v 1.28 2013/01/22 20:35:29 christos Exp $");
#endif
#endif /* not lint */
@@ -1440,9 +1440,21 @@
roomleft = BUFSIZE - off;
#ifdef FILEC
- roomleft = BUFSIZE - off;
for (;;) {
- if (filec && intty) {
+ if ((editing || filec) && intty) {
+#ifdef EDIT
+ if (editing) {
+ const char *p;
+ if ((p = el_gets(el, &c)) != NULL) {
+ size_t i;
+ /* XXX: Truncation */
+ numleft = c > BUFSIZE ? BUFSIZE : c;
+ for (i = 0; *p && i < BUFSIZE; i++, p++)
+ ttyline[i] = *p;
+ ttyline[i - (i == BUFSIZE)] = '\0';
Home |
Main Index |
Thread Index |
Old Index