-struct commands {
- NCURSES_CONST char *text;
- void (*function) (WINDOW *);
-};
-typedef struct commands COMMAND;
-
-const COMMAND command[] =
-{
- {"General Test", introTest},
- {"Pad Test", padTest},
-#if defined(PDCURSES) && !defined(XCURSES)
- {"Resize Test", resizeTest},
-#endif
- {"Scroll Test", scrollTest},
- {"Input Test", inputTest},
- {"Output Test", outputTest}
-};
-#define MAX_OPTIONS SIZEOF(command)
-
-#if !HAVE_STRDUP
-#define strdup my_strdup
-static char *
-strdup(char *s)
-{
- char *p = (char *) malloc(strlen(s) + 1);
- if (p)
- strcpy(p, s);
- return (p);
-}
-#endif /* not HAVE_STRDUP */
-
-int width, height;
-
-int
-main(
- int argc GCC_UNUSED,
- char *argv[]GCC_UNUSED)
-{
- WINDOW *win;
- int key;
- int old_option = (-1);
- int new_option = 0;
- bool quit = FALSE;
- unsigned n;
-
- setlocale(LC_ALL, "");
-
-#ifdef PDCDEBUG
- PDC_debug("testcurs started\n");
-#endif
- if (!initTest(&win))
- ExitProgram(EXIT_FAILURE);
-
- erase();
- display_menu(old_option, new_option);
- for (;;) {
-#ifdef A_COLOR
- if (has_colors()) {
- init_pair(1, COLOR_WHITE, COLOR_BLUE);
- wbkgd(win, COLOR_PAIR(1));
- } else
- wbkgd(win, A_REVERSE);
-#else
- wbkgd(win, A_REVERSE);
-#endif
- werase(win);
-
- noecho();
- keypad(stdscr, TRUE);
- raw();
- key = getch();
- if (key < KEY_MIN && key > 0 && isalpha(key)) {
- if (islower(key))
- key = toupper(key);
- for (n = 0; n < MAX_OPTIONS; ++n) {
- if (key == command[n].text[0]) {
- display_menu(old_option, new_option = n);
- key = ' ';
- break;
- }
- }
- }
- switch (key) {
- case 10:
- case 13:
- case KEY_ENTER:
- erase();
- refresh();
- (*command[new_option].function) (win);
- erase();
- display_menu(old_option, new_option);
- break;
- case KEY_UP:
- new_option = (new_option == 0) ? new_option : new_option - 1;
- display_menu(old_option, new_option);
- break;
- case KEY_DOWN:
- new_option = (new_option == MAX_OPTIONS - 1) ? new_option :
- new_option + 1;
- display_menu(old_option, new_option);
- break;
- case 'Q':
- case 'q':
- quit = TRUE;
- break;
- default:
- beep();
- break;
- case ' ':
- break;
- }
- if (quit == TRUE)
- break;
- }
-
- delwin(win);
-
- endwin();
-#ifdef XCURSES
- XCursesExit();
-#endif
- ExitProgram(EXIT_SUCCESS);
-}