summaryrefslogtreecommitdiff
path: root/lib/libedit/TEST
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-14 02:27:13 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-14 02:27:13 +0000
commit0ef0269cecf991a765db2e04aa2d2938b7881554 (patch)
treed7b9f8be334099621c899f524054c2cc10256f51 /lib/libedit/TEST
parente8ba9fab8a4788af1a7a004979db6361b6d117ef (diff)
update from netbsd
Diffstat (limited to 'lib/libedit/TEST')
-rw-r--r--lib/libedit/TEST/test.c73
1 files changed, 52 insertions, 21 deletions
diff --git a/lib/libedit/TEST/test.c b/lib/libedit/TEST/test.c
index f456f51277c..f0ae4ebc97e 100644
--- a/lib/libedit/TEST/test.c
+++ b/lib/libedit/TEST/test.c
@@ -171,37 +171,68 @@ main(argc, argv)
#endif
if (!continuation && num == 1)
continue;
+
if (tok_line(tok, buf, &ac, &av) > 0) {
history(hist, continuation ? H_ADD : H_ENTER, buf);
continuation = 1;
continue;
}
+
history(hist, continuation ? H_ADD : H_ENTER, buf);
continuation = 0;
- if (el_parse(el, ac, av) != -1) {
- tok_reset(tok);
- continue;
- }
- switch (fork()) {
- case 0:
- execvp(av[0], av);
- perror(av[0]);
- _exit(1);
- /*NOTREACHED*/
- break;
-
- case -1:
- perror("fork");
- break;
-
- default:
- if (wait(&num) == -1)
- perror("wait");
- (void) fprintf(stderr, "Exit %x\n", num);
- break;
+ if (strcmp(av[0], "history") == 0) {
+ const struct HistEvent *he;
+
+ switch (ac) {
+ case 1:
+ for (he = history(hist, H_LAST); he;
+ he = history(hist, H_PREV))
+ (void) fprintf(stdout, "%4d %s", he->num, he->str);
+ break;
+
+ case 2:
+ if (strcmp(av[1], "clear") == 0)
+ history(hist, H_CLEAR);
+ else
+ goto badhist;
+ break;
+
+ case 3:
+ if (strcmp(av[1], "load") == 0)
+ history(hist, H_LOAD, av[2]);
+ else if (strcmp(av[1], "save") == 0)
+ history(hist, H_SAVE, av[2]);
+ break;
+
+ badhist:
+ default:
+ (void) fprintf(stderr, "Bad history arguments\n");
+ break;
+ }
+ }
+ else if (el_parse(el, ac, av) == -1) {
+ switch (fork()) {
+ case 0:
+ execvp(av[0], av);
+ perror(av[0]);
+ _exit(1);
+ /*NOTREACHED*/
+ break;
+
+ case -1:
+ perror("fork");
+ break;
+
+ default:
+ if (wait(&num) == -1)
+ perror("wait");
+ (void) fprintf(stderr, "Exit %x\n", num);
+ break;
+ }
}
+
tok_reset(tok);
}