X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fclip_printw.c;h=a1ee516bad2f28b1f2dca13881ad37be2d8765f7;hp=7af637cc9597a593d2fcf154580aff20ca1a2e78;hb=d66080c21038ad4feb2e41a0c4e517d5b4a03ab2;hpb=06ae48ca77d71610e4d86d138a8fd19db84634ce diff --git a/test/clip_printw.c b/test/clip_printw.c index 7af637cc..a1ee516b 100644 --- a/test/clip_printw.c +++ b/test/clip_printw.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2008 Free Software Foundation, Inc. * + * Copyright (c) 2008-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,12 +26,15 @@ * authorization. * ****************************************************************************/ /* - * $Id: clip_printw.c,v 1.1 2008/12/20 21:03:06 tom Exp $ + * $Id: clip_printw.c,v 1.15 2017/09/28 23:07:23 tom Exp $ * * demonstrate how to use printw without wrapping. */ #include +#include + +#ifdef HAVE_VW_PRINTW #define SHOW(n) ((n) == ERR ? "ERR" : "OK") #define COLOR_DEFAULT (-1) @@ -41,7 +44,7 @@ typedef struct { unsigned v; int status; int pair; - unsigned attr; + attr_t attr; int count; int ch; const char *c_msg; @@ -53,7 +56,7 @@ typedef struct { } STATUS; static int -clip_wprintw(WINDOW *win, const char *fmt,...) +clip_wprintw(WINDOW *win, NCURSES_CONST char *fmt,...) { int y0, x0, y1, x1, width; WINDOW *sub; @@ -109,7 +112,9 @@ color_params(unsigned state, int *pair) start_color(); for (n = 0; n < SIZEOF(table); ++n) { - init_pair(table[n].pair, table[n].fg, table[n].bg); + init_pair((short) table[n].pair, + (short) table[n].fg, + (short) table[n].bg); } } if (state < SIZEOF(table)) { @@ -121,18 +126,18 @@ color_params(unsigned state, int *pair) } static const char * -video_params(unsigned state, unsigned *attr) +video_params(unsigned state, attr_t *attr) { /* *INDENT-OFF* */ static struct { - unsigned attr; + attr_t attr; const char *msg; } table[] = { - { A_NORMAL, "normal" }, - { A_BOLD, "bold" }, - { A_REVERSE, "reverse" }, - { A_UNDERLINE, "underline" }, - { A_BLINK, "blink" }, + { WA_NORMAL, "normal" }, + { WA_BOLD, "bold" }, + { WA_REVERSE, "reverse" }, + { WA_UNDERLINE, "underline" }, + { WA_BLINK, "blink" }, }; /* *INDENT-ON* */ @@ -150,10 +155,17 @@ static void fill_window(WINDOW *win) { int y, x; + int y0 = -1, x0 = -1; getyx(win, y, x); wmove(win, 0, 0); while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) { + int y1, x1; + getyx(win, y1, x1); + if (y1 == y0 && x1 == x0) + break; + x0 = x1; + y0 = y1; } wmove(win, y, x); } @@ -196,6 +208,8 @@ do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *)) delwin(win1); touchwin(win); } else { + if (win1) + delwin(win1); beep(); } } @@ -218,7 +232,7 @@ init_status(WINDOW *win, STATUS * sp) static void show_help(WINDOW *win) { - static const char *table[] = + static const char *msgs[] = { "Basic commands:" ,"Use h/j/k/l or arrow keys to move the cursor." @@ -227,21 +241,13 @@ show_help(WINDOW *win) ,"Other commands:" ,"space toggles through the set of video attributes and colors." ,"t touches (forces repaint) of the current line." - ,". calls clip_wprintw at the current position with the given count." + ,". calls vw_printw at the current position with the given count." ,"= resets count to zero." ,"? shows this help-window" - ,"" + ,0 }; - int y_max, x_max; - int row; - - getmaxyx(win, y_max, x_max); - for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) { - mvwprintw(win, row, 0, "%.*s", x_max, table[row]); - } - while (wgetch(win) != 'q') - beep(); + popup_msg(win, msgs); } static void @@ -291,8 +297,8 @@ update_status(WINDOW *win, STATUS * sp) sp->count = 0; show_status(win, sp); break; - case '?': - do_subwindow(win, sp, show_help); + case HELP_KEY_1: + show_help(win); break; default: if (isdigit(sp->ch)) { @@ -318,20 +324,21 @@ test_clipping(WINDOW *win) do { switch (st.ch) { case '.': /* change from current position */ - wattrset(win, st.attr | COLOR_PAIR(st.pair)); + (void) wattrset(win, AttrArg(COLOR_PAIR(st.pair), st.attr)); if (st.count > 0) { - need = st.count + 1; - sprintf(fmt, "%%c%%%ds%%c", st.count); + need = (unsigned) st.count + 1; + _nc_SPRINTF(fmt, _nc_SLIMIT(sizeof(fmt)) "%%c%%%ds%%c", st.count); } else { - need = getmaxx(win) - 1; - strcpy(fmt, "%c%s%c"); + need = (unsigned) getmaxx(win) - 1; + _nc_STRCPY(fmt, "%c%s%c", sizeof(fmt)); } - if ((buffer = typeMalloc(char, need)) != 0) { + if ((buffer = typeMalloc(char, need + 1)) != 0) { for (j = 0; j < need; ++j) { - buffer[j] = 'A' + (j % 26); + buffer[j] = (char) ('A' + (j % 26)); } buffer[need - 1] = '\0'; st.status = clip_wprintw(win, fmt, '[', buffer, ']'); + free(buffer); } break; case 'w': @@ -358,3 +365,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) ExitProgram(EXIT_SUCCESS); } + +#else +int +main(void) +{ + printf("This program requires the curses vw_printw function\n"); + ExitProgram(EXIT_FAILURE); +} +#endif