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