X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Ftestcurs.c;h=255bb4cb228ccaf2f03a5420a81557a067b724b2;hp=e8aa918eacb9b57e026b697d16181369f4f4108e;hb=8fc9fa113b27e0749e0840fef04c9d4acad4aae7;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/test/testcurs.c b/test/testcurs.c index e8aa918e..255bb4cb 100644 --- a/test/testcurs.c +++ b/test/testcurs.c @@ -7,7 +7,7 @@ * wrs(5/28/93) -- modified to be consistent (perform identically) with either * PDCurses or under Unix System V, R4 * - * $Id: testcurs.c,v 1.32 2002/10/19 22:11:24 tom Exp $ + * $Id: testcurs.c,v 1.40 2009/08/29 18:47:26 tom Exp $ */ #include @@ -33,7 +33,7 @@ struct commands { }; typedef struct commands COMMAND; -const COMMAND command[] = +static const COMMAND command[] = { {"General Test", introTest}, {"Pad Test", padTest}, @@ -44,21 +44,21 @@ const COMMAND command[] = {"Input Test", inputTest}, {"Output Test", outputTest} }; -#define MAX_OPTIONS SIZEOF(command) +#define MAX_OPTIONS (int) SIZEOF(command) #if !HAVE_STRDUP #define strdup my_strdup static char * strdup(char *s) { - char *p = (char *) malloc(strlen(s) + 1); + char *p = typeMalloc(char, strlen(s) + 1); if (p) strcpy(p, s); return (p); } #endif /* not HAVE_STRDUP */ -int width, height; +static int width, height; int main( @@ -70,7 +70,7 @@ main( int old_option = (-1); int new_option = 0; bool quit = FALSE; - unsigned n; + int n; setlocale(LC_ALL, ""); @@ -120,12 +120,15 @@ main( display_menu(old_option, new_option); break; case KEY_UP: - new_option = (new_option == 0) ? new_option : new_option - 1; + 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; + new_option = ((new_option == (MAX_OPTIONS - 1)) + ? new_option + : new_option + 1); display_menu(old_option, new_option); break; case 'Q': @@ -158,7 +161,7 @@ Continue(WINDOW *win) int x1 = getmaxx(win); int y0 = y1 < 10 ? y1 : 10; int x0 = 1; - long save; + chtype save; save = mvwinch(win, y0, x1 - 1); @@ -342,13 +345,19 @@ inputTest(WINDOW *win) mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); + keypad(win, TRUE); raw(); noecho(); + +#if HAVE_TYPEAHEAD typeahead(-1); +#endif + #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif + for (;;) { wmove(win, 3, 5); c = wgetch(win); @@ -358,7 +367,7 @@ inputTest(WINDOW *win) else if (isprint(c)) wprintw(win, "Key Pressed: %c", c); else - wprintw(win, "Key Pressed: %s", unctrl(c)); + wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); #if defined(PDCURSES) if (c == KEY_MOUSE) { int button = 0; @@ -400,7 +409,8 @@ inputTest(WINDOW *win) repeat = 0; do { - static const char *fmt[] = { + static const char *fmt[] = + { "%d %10s", "%d %[a-zA-Z]s", "%d %[][a-zA-Z]s", @@ -439,6 +449,17 @@ outputTest(WINDOW *win) chtype ch; int by, bx; +#if !HAVE_TIGETSTR +#if HAVE_TGETENT + char tc_buffer[4096]; + char tc_parsed[4096]; + char *area_pointer = tc_parsed; + tgetent(tc_buffer, getenv("TERM")); +#else +#define tgetstr(a,b) 0 +#endif +#endif /* !HAVE_TIGETSTR */ + nl(); wclear(win); mvwaddstr(win, 1, 1, @@ -529,8 +550,10 @@ outputTest(WINDOW *win) winsch(win, ch); Continue(win); +#if HAVE_WINSSTR mvwinsstr(win, 6, 2, "A1B2C3D4E5"); Continue(win); +#endif wmove(win, 5, 1); winsertln(win); @@ -553,14 +576,14 @@ outputTest(WINDOW *win) *Buffer = 0; scanw("%s", Buffer); - if (tigetstr("cvvis") != 0) { + if (TIGETSTR("cvvis", "vs") != 0) { wclear(win); curs_set(2); mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)"); Continue(win); } - if (tigetstr("civis") != 0) { + if (TIGETSTR("civis", "vi") != 0) { wclear(win); curs_set(0); mvwaddstr(win, 1, 1, @@ -568,7 +591,7 @@ outputTest(WINDOW *win) Continue(win); } - if (tigetstr("cnorm") != 0) { + if (TIGETSTR("cnorm", "ve") != 0) { wclear(win); curs_set(1); mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)"); @@ -585,6 +608,8 @@ outputTest(WINDOW *win) #endif werase(win); + +#if HAVE_TERMNAME mvwaddstr(win, 1, 1, "Information About Your Terminal"); mvwaddstr(win, 3, 1, termname()); mvwaddstr(win, 4, 1, longname()); @@ -592,6 +617,7 @@ outputTest(WINDOW *win) mvwaddstr(win, 5, 1, "This terminal supports blinking."); else mvwaddstr(win, 5, 1, "This terminal does NOT support blinking."); +#endif mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); wrefresh(win); @@ -653,54 +679,59 @@ padTest(WINDOW *dummy GCC_UNUSED) { WINDOW *pad, *spad; - pad = newpad(50, 100); - wattron(pad, A_REVERSE); - mvwaddstr(pad, 5, 2, "This is a new pad"); - wattrset(pad, A_NORMAL); - mvwaddstr(pad, 8, 0, - "The end of this line should be truncated here:except now"); - mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); - wmove(pad, 10, 1); - wclrtoeol(pad); - mvwaddstr(pad, 10, 1, " Press any key to continue"); - prefresh(pad, 0, 0, 0, 0, 10, 45); - keypad(pad, TRUE); - raw(); - wgetch(pad); + if ((pad = newpad(50, 100)) != 0) { + wattron(pad, A_REVERSE); + mvwaddstr(pad, 5, 2, "This is a new pad"); + (void) wattrset(pad, A_NORMAL); + mvwaddstr(pad, 8, 0, + "The end of this line should be truncated here:except now"); + mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); + wmove(pad, 10, 1); + wclrtoeol(pad); + mvwaddstr(pad, 10, 1, " Press any key to continue"); + prefresh(pad, 0, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); - spad = subpad(pad, 12, 25, 6, 52); - mvwaddstr(spad, 2, 2, "This is a new subpad"); - box(spad, 0, 0); - prefresh(pad, 0, 0, 0, 0, 15, 75); - keypad(pad, TRUE); - raw(); - wgetch(pad); + spad = subpad(pad, 12, 25, 6, 52); + mvwaddstr(spad, 2, 2, "This is a new subpad"); + box(spad, 0, 0); + prefresh(pad, 0, 0, 0, 0, 15, 75); + keypad(pad, TRUE); + raw(); + wgetch(pad); - mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); - mvwaddstr(pad, 40, 1, " Press any key to continue"); - prefresh(pad, 30, 0, 0, 0, 10, 45); - keypad(pad, TRUE); - raw(); - wgetch(pad); + mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); + mvwaddstr(pad, 40, 1, " Press any key to continue"); + prefresh(pad, 30, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); - delwin(pad); + delwin(pad); + } } static void display_menu(int old_option, int new_option) { - register size_t i; + int i; + + assert((new_option >= 0) && (new_option < MAX_OPTIONS)); - attrset(A_NORMAL); + (void) attrset(A_NORMAL); mvaddstr(3, 20, "PDCurses Test Program"); - for (i = 0; i < MAX_OPTIONS; i++) + for (i = 0; i < (int) MAX_OPTIONS; i++) mvaddstr(5 + i, 25, command[i].text); - if (old_option != (-1)) + + if ((old_option >= 0) && (old_option < MAX_OPTIONS)) mvaddstr(5 + old_option, 25, command[old_option].text); - attrset(A_REVERSE); + + (void) attrset(A_REVERSE); mvaddstr(5 + new_option, 25, command[new_option].text); - attrset(A_NORMAL); + (void) attrset(A_NORMAL); mvaddstr(13, 3, "Use Up and Down Arrows to select - Enter to run - Q to quit"); refresh();