1 | #include "owl.h" |
---|
2 | #include <unistd.h> |
---|
3 | #include <stdlib.h> |
---|
4 | |
---|
5 | static const char fileIdent[] = "$Id$"; |
---|
6 | |
---|
7 | owl_global g; |
---|
8 | |
---|
9 | void screeninit() { |
---|
10 | char buff[1024]; |
---|
11 | |
---|
12 | sprintf(buff, "TERMINFO=%s", TERMINFO); |
---|
13 | putenv(buff); |
---|
14 | |
---|
15 | initscr(); |
---|
16 | start_color(); |
---|
17 | /* cbreak(); */ |
---|
18 | raw(); |
---|
19 | noecho(); |
---|
20 | intrflush(stdscr,FALSE); |
---|
21 | keypad(stdscr,TRUE); |
---|
22 | nodelay(stdscr,1); |
---|
23 | clear(); |
---|
24 | refresh(); |
---|
25 | meta(stdscr, TRUE); |
---|
26 | } |
---|
27 | |
---|
28 | void test1() { |
---|
29 | int j; |
---|
30 | owl_editwin e; |
---|
31 | |
---|
32 | screeninit(); |
---|
33 | |
---|
34 | owl_editwin_init(&e, stdscr, LINES, COLS, OWL_EDITWIN_STYLE_MULTILINE, NULL); |
---|
35 | /* owl_editwin_set_locktext(&e, "Here is some locktext:\n");*/ |
---|
36 | doupdate(); |
---|
37 | while (1) { |
---|
38 | usleep(50); |
---|
39 | |
---|
40 | j=getch(); |
---|
41 | |
---|
42 | if (j==ERR) continue; |
---|
43 | |
---|
44 | if (j==3) break; |
---|
45 | |
---|
46 | if (j==27) { |
---|
47 | j=getch(); |
---|
48 | if (j==ERR) continue; |
---|
49 | owl_editwin_process_char(&e, j); |
---|
50 | doupdate(); |
---|
51 | } else { |
---|
52 | owl_editwin_process_char(&e, j); |
---|
53 | doupdate(); |
---|
54 | } |
---|
55 | } |
---|
56 | endwin(); |
---|
57 | printf("Had:\n%s", owl_editwin_get_text(&e)); |
---|
58 | } |
---|
59 | |
---|
60 | void test2(char *in) { |
---|
61 | owl_fmtext t; |
---|
62 | |
---|
63 | screeninit(); |
---|
64 | |
---|
65 | owl_fmtext_init_null(&t); |
---|
66 | owl_fmtext_append_ztext(&t, in); |
---|
67 | owl_fmtext_curs_waddstr(&t, stdscr); |
---|
68 | wrefresh(stdscr); |
---|
69 | sleep(5000); |
---|
70 | endwin(); |
---|
71 | } |
---|
72 | |
---|
73 | void test3() { |
---|
74 | ZNotice_t *n; |
---|
75 | |
---|
76 | printf("%i\n", sizeof(n->z_uid.zuid_addr)); |
---|
77 | /* gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); */ |
---|
78 | } |
---|
79 | |
---|
80 | void colorinfo() { |
---|
81 | char buff[1024]; |
---|
82 | |
---|
83 | screeninit(); |
---|
84 | sprintf(buff, "Have %i COLOR_PAIRS\n", COLOR_PAIRS); |
---|
85 | addstr(buff); |
---|
86 | refresh(); |
---|
87 | sleep(10); |
---|
88 | endwin(); |
---|
89 | } |
---|
90 | |
---|
91 | void test4() { |
---|
92 | int j; |
---|
93 | char buff[1024]; |
---|
94 | |
---|
95 | screeninit(); |
---|
96 | |
---|
97 | while (1) { |
---|
98 | usleep(100); |
---|
99 | |
---|
100 | j=getch(); |
---|
101 | |
---|
102 | if (j==ERR) continue; |
---|
103 | |
---|
104 | if (j==3) break; |
---|
105 | sprintf(buff, "%o\n", j); |
---|
106 | addstr(buff); |
---|
107 | } |
---|
108 | endwin(); |
---|
109 | } |
---|
110 | |
---|
111 | void test_keypress() { |
---|
112 | int j, rev; |
---|
113 | char buff[1024], buff2[64]; |
---|
114 | |
---|
115 | screeninit(); |
---|
116 | |
---|
117 | while (1) { |
---|
118 | usleep(100); |
---|
119 | |
---|
120 | j=wgetch(stdscr); |
---|
121 | |
---|
122 | if (j==ERR) continue; |
---|
123 | |
---|
124 | if (j==3) break; |
---|
125 | if (0 == owl_keypress_tostring(j, 0, buff2, 1000)) { |
---|
126 | rev = owl_keypress_fromstring(buff2); |
---|
127 | sprintf(buff, "%s : 0x%x 0%o %d %d %s\n", buff2, j, j, j, rev, |
---|
128 | (j==rev?"matches":"*** WARNING: Does Not Reverse")); |
---|
129 | } else { |
---|
130 | sprintf(buff, "UNKNOWN : 0x%x 0%o %d\n", j, j, j); |
---|
131 | } |
---|
132 | addstr(buff); |
---|
133 | } |
---|
134 | endwin(); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | int main(int argc, char **argv, char **env) { |
---|
139 | int numfailures=0; |
---|
140 | if (argc==2 && 0==strcmp(argv[1],"reg")) { |
---|
141 | numfailures += owl_util_regtest(); |
---|
142 | numfailures += owl_dict_regtest(); |
---|
143 | numfailures += owl_variable_regtest(); |
---|
144 | if (numfailures) { |
---|
145 | fprintf(stderr, "*** WARNING: %d failures total\n", numfailures); |
---|
146 | } |
---|
147 | return(numfailures); |
---|
148 | } else if (argc==2 && 0==strcmp(argv[1],"test1")) { |
---|
149 | test1(); |
---|
150 | } else if (argc==2 && 0==strcmp(argv[1],"colorinfo")) { |
---|
151 | colorinfo(); |
---|
152 | } else if (argc==2 && 0==strcmp(argv[1],"test4")) { |
---|
153 | test4(); |
---|
154 | } else if (argc==2 && 0==strcmp(argv[1],"keypress")) { |
---|
155 | test_keypress(); |
---|
156 | } else { |
---|
157 | fprintf(stderr, "No test specified. Current options are: reg test1\n"); |
---|
158 | } |
---|
159 | return(0); |
---|
160 | } |
---|
161 | |
---|