2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char copyright[] =
39 "@(#) Copyright (c) 1992, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
43 #if !defined(lint) && !defined(SCCSID)
44 static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
45 #endif /* not lint && not SCCSID */
48 * test.c: A little test program
61 #include "tokenizer.h"
63 static int continuation = 0;
64 static EditLine *el = NULL;
71 static char a[] = "Edit$";
72 static char b[] = "Edit>";
73 return continuation ? b : a;
80 (void) fprintf(stderr, "Got signal %d.\n", i);
90 DIR *dd = opendir(".");
93 const LineInfo *lf = el_line(el);
99 for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
101 len = lf->cursor - ++ptr;
103 for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
104 if (len > strlen(dp->d_name))
106 if (strncmp(dp->d_name, ptr, len) == 0) {
108 if (el_insertstr(el, &dp->d_name[len]) == -1)
130 (void) signal(SIGINT, sig);
131 (void) signal(SIGQUIT, sig);
132 (void) signal(SIGHUP, sig);
133 (void) signal(SIGTERM, sig);
135 hist = history_init(); /* Init the builtin history */
136 history(hist, H_EVENT, 100); /* Remember 100 events */
138 tok = tok_init(NULL); /* Initialize the tokenizer */
140 el = el_init(*argv, stdin, stdout); /* Initialize editline */
142 el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
143 el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
144 el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
146 /* Tell editline to use this history interface */
147 el_set(el, EL_HIST, history, hist);
149 /* Add a user-defined function */
150 el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
152 el_set(el, EL_BIND, "^I", "ed-complete", NULL);/* Bind tab to it */
155 * Bind j, k in vi command mode to previous and next line, instead
156 * of previous and next history.
158 el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
159 el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
162 * Source the user's defaults file.
166 while ((buf = el_gets(el, &num)) != NULL && num != 0) {
170 (void) fprintf(stderr, "got %d %s", num, buf);
172 if (!continuation && num == 1)
174 if (tok_line(tok, buf, &ac, &av) > 0) {
175 history(hist, continuation ? H_ADD : H_ENTER, buf);
179 history(hist, continuation ? H_ADD : H_ENTER, buf);
183 if (strcmp(av[0], "history") == 0) {
184 const struct HistEvent *he;
188 for (he = history(hist, H_LAST); he;
189 he = history(hist, H_PREV))
190 (void) fprintf(stdout, "%4d %s", he->num, he->str);
194 if (strcmp(av[1], "clear") == 0)
195 history(hist, H_CLEAR);
201 if (strcmp(av[1], "load") == 0)
202 history(hist, H_LOAD, av[2]);
203 else if (strcmp(av[1], "save") == 0)
204 history(hist, H_SAVE, av[2]);
209 (void) fprintf(stderr, "Bad history arguments\n");
213 else if (el_parse(el, ac, av) == -1) {
227 if (wait(&num) == -1)
229 (void) fprintf(stderr, "Exit %x\n", num);