Deleted Added
full compact
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
23 *
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

--- 9 unchanged lines hidden (view full) ---

38#ifndef lint
39__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
40 The Regents of the University of California. All rights reserved.\n");
41#endif /* not lint */
42
43#if !defined(lint) && !defined(SCCSID)
44static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
45#endif /* not lint && not SCCSID */
46__RCSID("$NetBSD: test.c,v 1.8 1999/09/21 00:07:03 lukem Exp $");
47__FBSDID("$FreeBSD: head/lib/libedit/TEST/test.c 84260 2001-10-01 08:41:27Z obrien $");
48
49/*
50 * test.c: A little test program
51 */
52#include "sys.h"
53#include <stdio.h>
54#include <string.h>
55#include <signal.h>
56#include <sys/wait.h>
57#include <ctype.h>
58#include <stdlib.h>
59#include <unistd.h>
60#include <dirent.h>
61
62#include "histedit.h"
63#include "tokenizer.h"
64
65static int continuation = 0;
66static EditLine *el = NULL;
67
68static u_char complete(EditLine *, int);
69 int main(int, char **);
70static char *prompt(EditLine *);
71static void sig(int);
72
73static char *
74prompt(EditLine *el)
75{
76 static char a[] = "Edit$";
77 static char b[] = "Edit>";
78
79 return (continuation ? b : a);
80}
81
82static void
83sig(int i)
84{
85
86 (void) fprintf(stderr, "Got signal %d.\n", i);
87 el_reset(el);
88}
89
90static unsigned char
91complete(EditLine *el, int ch)
92{
93 DIR *dd = opendir(".");
94 struct dirent *dp;
95 const char* ptr;
96 const LineInfo *lf = el_line(el);
97 int len;
98
99 /*
100 * Find the last word
101 */
102 for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
103 continue;
104 len = lf->cursor - ++ptr;
105
106 for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
107 if (len > strlen(dp->d_name))
108 continue;
109 if (strncmp(dp->d_name, ptr, len) == 0) {
110 closedir(dd);

--- 6 unchanged lines hidden (view full) ---

117
118 closedir(dd);
119 return (CC_ERROR);
120}
121
122int
123main(int argc, char *argv[])
124{
125 int num;
126 const char *buf;
127 Tokenizer *tok;
128 int lastevent = 0, ncontinuation;
129 History *hist;
130 HistEvent ev;
131
132 (void) signal(SIGINT, sig);
133 (void) signal(SIGQUIT, sig);
134 (void) signal(SIGHUP, sig);
135 (void) signal(SIGTERM, sig);
136

--- 27 unchanged lines hidden (view full) ---

164 el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
165
166 /*
167 * Source the user's defaults file.
168 */
169 el_source(el, NULL);
170
171 while ((buf = el_gets(el, &num)) != NULL && num != 0) {
172 int ac;
173 char **av;
174#ifdef DEBUG
175 (void) fprintf(stderr, "got %d %s", num, buf);
176#endif
177 if (!continuation && num == 1)
178 continue;
179
180 if (tok_line(tok, buf, &ac, &av) > 0)
181 ncontinuation = 1;
182
183#if 0
184 if (continuation) {
185 /*
186 * Append to the right event in case the user
187 * moved around in history.
188 */
189 if (history(hist, &ev, H_SET, lastevent) == -1)
190 err(1, "%d: %s\n", lastevent, ev.str);
191 history(hist, &ev, H_ADD , buf);
192 } else {
193 history(hist, &ev, H_ENTER, buf);
194 lastevent = ev.num;
195 }
196#else
197 /* Simpler */
198 history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
199#endif
200
201 continuation = ncontinuation;
202 ncontinuation = 0;
203
204 if (strcmp(av[0], "history") == 0) {
205 int rv;
206
207 switch (ac) {
208 case 1:
209 for (rv = history(hist, &ev, H_LAST); rv != -1;
210 rv = history(hist, &ev, H_PREV))

--- 19 unchanged lines hidden (view full) ---

230 default:
231 (void) fprintf(stderr,
232 "Bad history arguments\n");
233 break;
234 }
235 } else if (el_parse(el, ac, av) == -1) {
236 switch (fork()) {
237 case 0:
238 execvp(av[0], av);
239 perror(av[0]);
240 _exit(1);
241 /*NOTREACHED*/
242 break;
243
244 case -1:
245 perror("fork");
246 break;

--- 18 unchanged lines hidden ---