tc1.c (269016) | tc1.c (276881) |
---|---|
1/* $NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $ */ 2 |
|
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 --- 16 unchanged lines hidden (view full) --- 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 | 3/*- 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Christos Zoulas of Cornell University. 9 * 10 * Redistribution and use in source and binary forms, with or without --- 16 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 |
33#include <sys/cdefs.h> | 35#include "config.h" |
34#ifndef lint 35__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ 36 The Regents of the University of California. All rights reserved.\n"); 37#endif /* not lint */ 38 39#if !defined(lint) && !defined(SCCSID) | 36#ifndef lint 37__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ 38 The Regents of the University of California. All rights reserved.\n"); 39#endif /* not lint */ 40 41#if !defined(lint) && !defined(SCCSID) |
42#if 0 |
|
40static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; | 43static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; |
44#else 45__RCSID("$NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $"); 46#endif |
|
41#endif /* not lint && not SCCSID */ | 47#endif /* not lint && not SCCSID */ |
42__RCSID("$NetBSD: test.c,v 1.3 2009/07/17 12:25:52 christos Exp $"); 43__FBSDID("$FreeBSD: head/lib/libedit/TEST/tc1.c 269016 2014-07-23 15:12:17Z pfg $"); | 48__FBSDID("$FreeBSD: head/lib/libedit/TEST/tc1.c 276881 2015-01-09 07:40:56Z bapt $"); |
44 45/* 46 * test.c: A little test program 47 */ | 49 50/* 51 * test.c: A little test program 52 */ |
48#include "sys.h" | |
49#include <stdio.h> 50#include <string.h> 51#include <signal.h> 52#include <sys/wait.h> 53#include <ctype.h> 54#include <stdlib.h> 55#include <unistd.h> 56#include <dirent.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#include <locale.h> |
|
57 58#include "histedit.h" 59 60static int continuation = 0; 61volatile sig_atomic_t gotsig = 0; 62 63static unsigned char complete(EditLine *, int); 64 int main(int, char **); 65static char *prompt(EditLine *); 66static void sig(int); 67 68static char * 69prompt(EditLine *el) 70{ | 62 63#include "histedit.h" 64 65static int continuation = 0; 66volatile sig_atomic_t gotsig = 0; 67 68static unsigned char complete(EditLine *, int); 69 int main(int, char **); 70static char *prompt(EditLine *); 71static void sig(int); 72 73static char * 74prompt(EditLine *el) 75{ |
71 static char a[] = "\1\e[7m\1Edit$\1\e[0m\1 "; | 76 static char a[] = "\1\033[7m\1Edit$\1\033[0m\1 "; |
72 static char b[] = "Edit> "; 73 74 return (continuation ? b : a); 75} 76 77static void 78sig(int i) 79{ 80 gotsig = i; 81} 82 83static unsigned char 84complete(EditLine *el, int ch) 85{ 86 DIR *dd = opendir("."); 87 struct dirent *dp; 88 const char* ptr; 89 const LineInfo *lf = el_line(el); 90 int len; | 77 static char b[] = "Edit> "; 78 79 return (continuation ? b : a); 80} 81 82static void 83sig(int i) 84{ 85 gotsig = i; 86} 87 88static unsigned char 89complete(EditLine *el, int ch) 90{ 91 DIR *dd = opendir("."); 92 struct dirent *dp; 93 const char* ptr; 94 const LineInfo *lf = el_line(el); 95 int len; |
96 int res = CC_ERROR; |
|
91 92 /* 93 * Find the last word 94 */ 95 for (ptr = lf->cursor - 1; 96 !isspace((unsigned char)*ptr) && ptr > lf->buffer; ptr--) 97 continue; 98 len = lf->cursor - ++ptr; 99 100 for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) { 101 if (len > strlen(dp->d_name)) 102 continue; 103 if (strncmp(dp->d_name, ptr, len) == 0) { | 97 98 /* 99 * Find the last word 100 */ 101 for (ptr = lf->cursor - 1; 102 !isspace((unsigned char)*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) { |
104 closedir(dd); | |
105 if (el_insertstr(el, &dp->d_name[len]) == -1) | 110 if (el_insertstr(el, &dp->d_name[len]) == -1) |
106 return (CC_ERROR); | 111 res = CC_ERROR; |
107 else | 112 else |
108 return (CC_REFRESH); | 113 res = CC_REFRESH; 114 break; |
109 } 110 } 111 112 closedir(dd); | 115 } 116 } 117 118 closedir(dd); |
113 return (CC_ERROR); | 119 return res; |
114} 115 116int 117main(int argc, char *argv[]) 118{ 119 EditLine *el = NULL; 120 int num; 121 const char *buf; 122 Tokenizer *tok; 123#if 0 124 int lastevent = 0; 125#endif 126 int ncontinuation; 127 History *hist; 128 HistEvent ev; 129 | 120} 121 122int 123main(int argc, char *argv[]) 124{ 125 EditLine *el = NULL; 126 int num; 127 const char *buf; 128 Tokenizer *tok; 129#if 0 130 int lastevent = 0; 131#endif 132 int ncontinuation; 133 History *hist; 134 HistEvent ev; 135 |
136 (void) setlocale(LC_CTYPE, ""); |
|
130 (void) signal(SIGINT, sig); 131 (void) signal(SIGQUIT, sig); 132 (void) signal(SIGHUP, sig); 133 (void) signal(SIGTERM, sig); 134 135 hist = history_init(); /* Init the builtin history */ 136 /* Remember 100 events */ 137 history(hist, &ev, H_SETSIZE, 100); --- 161 unchanged lines hidden --- | 137 (void) signal(SIGINT, sig); 138 (void) signal(SIGQUIT, sig); 139 (void) signal(SIGHUP, sig); 140 (void) signal(SIGTERM, sig); 141 142 hist = history_init(); /* Init the builtin history */ 143 /* Remember 100 events */ 144 history(hist, &ev, H_SETSIZE, 100); --- 161 unchanged lines hidden --- |