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
36 * @(#) Copyright (c) 1992, 1993 The Regents of the University of California. All rights reserved.
37 * @(#)test.c 8.1 (Berkeley) 6/4/93
41 * test.c: A little test program
54 #include "tokenizer.h"
56 static int continuation = 0;
57 static EditLine *el = NULL;
64 static char a[] = "Edit$";
65 static char b[] = "Edit>";
66 return continuation ? b : a;
73 (void) fprintf(stderr, "Got signal %d.\n", i);
83 DIR *dd = opendir(".");
86 const LineInfo *lf = el_line(el);
92 for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
94 len = lf->cursor - ++ptr;
96 for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
97 if (len > strlen(dp->d_name))
99 if (strncmp(dp->d_name, ptr, len) == 0) {
101 if (el_insertstr(el, &dp->d_name[len]) == -1)
123 (void) signal(SIGINT, sig);
124 (void) signal(SIGQUIT, sig);
125 (void) signal(SIGHUP, sig);
126 (void) signal(SIGTERM, sig);
128 hist = history_init(); /* Init the builtin history */
129 history(hist, H_EVENT, 100); /* Remember 100 events */
131 tok = tok_init(NULL); /* Initialize the tokenizer */
133 el = el_init(*argv, stdin, stdout); /* Initialize editline */
135 el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
136 el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
137 el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
139 /* Tell editline to use this history interface */
140 el_set(el, EL_HIST, history, hist);
142 /* Add a user-defined function */
143 el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
145 el_set(el, EL_BIND, "^I", "ed-complete", NULL);/* Bind tab to it */
148 * Bind j, k in vi command mode to previous and next line, instead
149 * of previous and next history.
151 el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
152 el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
155 * Source the user's defaults file.
159 while ((buf = el_gets(el, &num)) != NULL && num != 0) {
163 (void) fprintf(stderr, "got %d %s", num, buf);
165 if (!continuation && num == 1)
167 if (tok_line(tok, buf, &ac, &av) > 0) {
168 history(hist, continuation ? H_ADD : H_ENTER, buf);
172 history(hist, continuation ? H_ADD : H_ENTER, buf);
176 if (strcmp(av[0], "history") == 0) {
177 const struct HistEvent *he;
181 for (he = history(hist, H_LAST); he;
182 he = history(hist, H_PREV))
183 (void) fprintf(stdout, "%4d %s", he->num, he->str);
187 if (strcmp(av[1], "clear") == 0)
188 history(hist, H_CLEAR);
194 if (strcmp(av[1], "load") == 0)
195 history(hist, H_LOAD, av[2]);
196 else if (strcmp(av[1], "save") == 0)
197 history(hist, H_SAVE, av[2]);
202 (void) fprintf(stderr, "Bad history arguments\n");
206 else if (el_parse(el, ac, av) == -1) {
220 if (wait(&num) == -1)
222 (void) fprintf(stderr, "Exit %x\n", num);