diff options
author | 1995-12-14 02:27:09 +0000 | |
---|---|---|
committer | 1995-12-14 02:27:09 +0000 | |
commit | 8bd3f282b2b7b75bc9632b09b816cfee760ceefe (patch) | |
tree | 8f7ff7785e568eec0a7bdb4ca91935dc1fb619c5 /lib/libedit/TEST | |
parent | from netbsd: (diff) | |
download | wireguard-openbsd-8bd3f282b2b7b75bc9632b09b816cfee760ceefe.tar.xz wireguard-openbsd-8bd3f282b2b7b75bc9632b09b816cfee760ceefe.zip |
update from netbsd
Diffstat (limited to 'lib/libedit/TEST')
-rw-r--r-- | lib/libedit/TEST/test.c | 73 |
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); } |