summaryrefslogtreecommitdiff
path: root/lib/libedit/TEST
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libedit/TEST')
-rw-r--r--lib/libedit/TEST/Makefile6
-rw-r--r--lib/libedit/TEST/tc1.c (renamed from lib/libedit/TEST/test.c)69
2 files changed, 54 insertions, 21 deletions
diff --git a/lib/libedit/TEST/Makefile b/lib/libedit/TEST/Makefile
index 2881d408dc4..7e6aca9a890 100644
--- a/lib/libedit/TEST/Makefile
+++ b/lib/libedit/TEST/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.1 2003/11/25 20:12:39 otto Exp $
-# $NetBSD: Makefile,v 1.1 2003/10/16 21:41:46 christos Exp $
+# $OpenBSD: Makefile,v 1.2 2010/06/30 00:05:35 nicm Exp $
+# $NetBSD: Makefile,v 1.5 2010/02/03 15:34:43 roy Exp $
NOMAN=1
-PROG=test
+PROG=tc1
CPPFLAGS=-I${.CURDIR}/..
LDADD+=-ledit -ltermcap
DPADD+=${LIBEDIT} ${LIBTERMCAP}
diff --git a/lib/libedit/TEST/test.c b/lib/libedit/TEST/tc1.c
index a4f61e331e0..0f0bc9a669b 100644
--- a/lib/libedit/TEST/test.c
+++ b/lib/libedit/TEST/tc1.c
@@ -1,5 +1,4 @@
-/* $OpenBSD: test.c,v 1.8 2009/10/27 23:59:28 deraadt Exp $ */
-/* $NetBSD: test.c,v 1.13 2003/08/07 16:44:35 agc Exp $ */
+/* $NetBSD: tc1.c,v 1.5 2010/04/18 21:17:47 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -46,16 +45,14 @@
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
+#include <locale.h>
#include "histedit.h"
-#include "tokenizer.h"
static int continuation = 0;
-static EditLine *el = NULL;
-
volatile sig_atomic_t gotsig = 0;
-static u_char complete(EditLine *, int);
+static unsigned char complete(EditLine *, int);
int main(int, char **);
static char *prompt(EditLine *);
static void sig(int);
@@ -63,8 +60,8 @@ static void sig(int);
static char *
prompt(EditLine *el)
{
- static char a[] = "Edit$";
- static char b[] = "Edit>";
+ static char a[] = "\1\033[7m\1Edit$\1\033[0m\1 ";
+ static char b[] = "Edit> ";
return (continuation ? b : a);
}
@@ -83,33 +80,36 @@ complete(EditLine *el, int ch)
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
+ int res = CC_ERROR;
/*
* Find the last word
*/
- for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
+ for (ptr = lf->cursor - 1;
+ !isspace((unsigned char)*ptr) && ptr > lf->buffer; ptr--)
continue;
- len = lf->cursor - ++ptr;
+ len = lf->cursor - ptr;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
- closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
- return (CC_ERROR);
+ res = CC_ERROR;
else
- return (CC_REFRESH);
+ res = CC_REFRESH;
+ break;
}
}
closedir(dd);
- return (CC_ERROR);
+ return res;
}
int
main(int argc, char *argv[])
{
+ EditLine *el = NULL;
int num;
const char *buf;
Tokenizer *tok;
@@ -120,6 +120,7 @@ main(int argc, char *argv[])
History *hist;
HistEvent ev;
+ (void) setlocale(LC_CTYPE, "");
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
@@ -136,7 +137,7 @@ main(int argc, char *argv[])
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
- el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
+ el_set(el, EL_PROMPT_ESC, prompt, '\1');/* Set the prompt function */
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
@@ -160,10 +161,20 @@ main(int argc, char *argv[])
el_source(el, NULL);
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
- int ac;
+ int ac, cc, co;
+#ifdef DEBUG
+ int i;
+#endif
const char **av;
+ const LineInfo *li;
+ li = el_line(el);
#ifdef DEBUG
- (void) fprintf(stderr, "got %d %s", num, buf);
+ (void) fprintf(stderr, "==> got %d %s", num, buf);
+ (void) fprintf(stderr, " > li `%.*s_%.*s'\n",
+ (li->cursor - li->buffer), li->buffer,
+ (li->lastchar - 1 - li->cursor),
+ (li->cursor >= li->lastchar) ? "" : li->cursor);
+
#endif
if (gotsig) {
(void) fprintf(stderr, "Got signal %d.\n", gotsig);
@@ -174,7 +185,17 @@ main(int argc, char *argv[])
if (!continuation && num == 1)
continue;
- ncontinuation = tok_line(tok, buf, &ac, &av) > 0;
+ ac = cc = co = 0;
+ ncontinuation = tok_line(tok, li, &ac, &av, &cc, &co);
+ if (ncontinuation < 0) {
+ (void) fprintf(stderr, "Internal error\n");
+ continuation = 0;
+ continue;
+ }
+#ifdef DEBUG
+ (void) fprintf(stderr, " > nc %d ac %d cc %d co %d\n",
+ ncontinuation, ac, cc, co);
+#endif
#if 0
if (continuation) {
/*
@@ -195,6 +216,18 @@ main(int argc, char *argv[])
continuation = ncontinuation;
ncontinuation = 0;
+ if (continuation)
+ continue;
+#ifdef DEBUG
+ for (i = 0; i < ac; i++) {
+ (void) fprintf(stderr, " > arg# %2d ", i);
+ if (i != cc)
+ (void) fprintf(stderr, "`%s'\n", av[i]);
+ else
+ (void) fprintf(stderr, "`%.*s_%s'\n",
+ co, av[i], av[i] + co);
+ }
+#endif
if (strcmp(av[0], "history") == 0) {
int rv;