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