From 1051e5f924808ea27fcf8f5b624e63d07788b86e Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 13 May 2007 00:52:59 +0000 Subject: [PATCH 1/1] ncurses 5.6 - patch 20070512 + add 'O' (wide-character panel test) in ncurses.c to demonstrate a problem reported by Sadrul H Chowdhury with repainting parts of a fullwidth cell. + modify slk_init() so that if there are preceding calls to ripoffline(), those affect the available lines for soft-keys (adapted from patch by Clive Nicolson). + document some portability issues in man/curs_getyx.3x --- NEWS | 11 +- dist.mk | 4 +- man/curs_getyx.3x | 22 +- man/curs_opaque.3x | 3 +- man/panel.3x | 37 ++-- ncurses/base/lib_set_term.c | 72 +++---- ncurses/base/lib_slkinit.c | 15 +- ncurses/curses.priv.h | 9 +- ncurses/tinfo/lib_data.c | 4 +- ncurses/tinfo/setbuf.c | 6 +- ncurses/tinfo/write_entry.c | 11 +- ncurses/tty/lib_twait.c | 6 +- ncurses/widechar/lib_cchar.c | 9 +- ncurses/widechar/lib_get_wch.c | 6 +- test/ncurses.c | 359 +++++++++++++++++---------------- 15 files changed, 309 insertions(+), 265 deletions(-) diff --git a/NEWS b/NEWS index a2c32ca6..91ba1efb 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.1124 2007/05/05 21:31:43 tom Exp $ +-- $Id: NEWS,v 1.1127 2007/05/12 22:31:49 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,15 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20070512 + + add 'O' (wide-character panel test) in ncurses.c to demonstrate a + problem reported by Sadrul H Chowdhury with repainting parts of + a fullwidth cell. + + modify slk_init() so that if there are preceding calls to + ripoffline(), those affect the available lines for soft-keys (adapted + from patch by Clive Nicolson). + + document some portability issues in man/curs_getyx.3x + 20070505 + fix a bug in Ada95/samples/ncurses which caused a variable to become uninitialized in the "b" test. diff --git a/dist.mk b/dist.mk index 3c7eb78b..c141803e 100644 --- a/dist.mk +++ b/dist.mk @@ -25,7 +25,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.592 2007/05/05 15:43:26 tom Exp $ +# $Id: dist.mk,v 1.593 2007/05/12 15:09:42 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -37,7 +37,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 5 NCURSES_MINOR = 6 -NCURSES_PATCH = 20070505 +NCURSES_PATCH = 20070512 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/man/curs_getyx.3x b/man/curs_getyx.3x index 701b15d4..2581253d 100644 --- a/man/curs_getyx.3x +++ b/man/curs_getyx.3x @@ -26,7 +26,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $Id: curs_getyx.3x,v 1.15 2007/04/07 23:21:34 tom Exp $ +.\" $Id: curs_getyx.3x,v 1.16 2007/05/12 16:34:49 tom Exp $ .TH curs_getyx 3X "" .SH NAME \fBgetyx\fR, @@ -69,7 +69,7 @@ The \fBgetmaxyx\fR macros are described in the XSI Curses standard, Issue 4. .PP -This implementation also provides +This implementation also provides functions \fBgetbegx\fR, \fBgetbegy\fR, \fBgetcurx\fR, @@ -79,9 +79,25 @@ This implementation also provides \fBgetparx\fR and \fBgetpary\fR for compatibility with older versions of curses. +.PP +Although X/Open Curses does not address this, +many implementations provide members of the WINDOW structure +containing values corresponding to these macros. +For best portability, do not rely on using the data in WINDOW, +since some implementations make WINDOW opaque (do not allow +direct use of its members). +.PP +Besides the problem of opaque structures, +the data stored in like-named members may not have like-values in +different implementations. +For example, the WINDOW._maxx and WINDOW._maxy values in ncurses +have (at least since release 1.8.1) differed by one from some +other implementations. +The difference is hidden by means of the macro \fBgetmaxyx\fP. .SH SEE ALSO \fBcurses\fR(3X), -\fBcurs_legacy\fR(3X) +\fBcurs_legacy\fR(3X), +\fBcurs_opaque\fR(3X) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/man/curs_opaque.3x b/man/curs_opaque.3x index ac538123..15e5c61a 100644 --- a/man/curs_opaque.3x +++ b/man/curs_opaque.3x @@ -26,7 +26,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $Id: curs_opaque.3x,v 1.2 2007/04/14 20:19:39 tom Exp $ +.\" $Id: curs_opaque.3x,v 1.3 2007/05/12 17:04:47 tom Exp $ .TH curs_opaque 3X "" .na .hy 0 @@ -100,7 +100,6 @@ returns the value set in \fBscrollok\fR .TP 5 \fBis_syncok\fR returns the value set in \fBsyncok\fR -.RE .SH RETURN VALUE These functions all return TRUE or FALSE. .SH NOTES diff --git a/man/panel.3x b/man/panel.3x index 2896f01a..719a9e63 100644 --- a/man/panel.3x +++ b/man/panel.3x @@ -1,5 +1,5 @@ .\"*************************************************************************** -.\" Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 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,7 +26,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $Id: panel.3x,v 1.12 2006/05/13 15:35:45 tom Exp $ +.\" $Id: panel.3x,v 1.14 2007/05/12 20:45:20 tom Exp $ .TH panel 3X "" .ds n 5 .ds d @TERMINFO@ @@ -84,13 +84,13 @@ Panel routines are a functional layer added to \fBcurses\fR(3X), make only high-level curses calls, and work anywhere terminfo curses does. .SH FUNCTIONS .TP -\fBnew_panel(win)\fR +.B new_panel(win) allocates a \fBPANEL\fR structure, associates it with \fBwin\fR, places the panel on the top of the stack (causes it to be displayed above any other panel) and returns a pointer to the new panel. .TP -\fBvoid update_panels()\fR +.B update_panels() refreshes the virtual screen to reflect the relations between the panels in the stack, but does not call doupdate() to refresh the physical screen. Use this function and not wrefresh or wnoutrefresh. @@ -98,52 +98,57 @@ update_panels() may be called more than once before a call to doupdate(), but doupdate() is the function responsible for updating the physical screen. .TP -\fBdel_panel(pan)\fR +.B del_panel(pan) removes the given panel from the stack and deallocates the \fBPANEL\fR structure (but not its associated window). .TP -\fBhide_panel(pan)\fR +.B hide_panel(pan) removes the given panel from the panel stack and thus hides it from view. The \fBPANEL\fR structure is not lost, merely removed from the stack. .TP -\fBshow_panel(pan)\fR +.B panel_hidden(pan) +returns TRUE if the panel is in the panel stack, +FALSE if it is not. +If the panel is a null pointer, return ERR. +.TP +.B show_panel(pan) makes a hidden panel visible by placing it on top of the panels in the panel stack. See COMPATIBILITY below. .TP -\fBtop_panel(pan)\fR +.B top_panel(pan) puts the given visible panel on top of all panels in the stack. See COMPATIBILITY below. .TP -\fBbottom_panel(pan)\fR +.B bottom_panel(pan) puts panel at the bottom of all panels. .TP -\fBmove_panel(pan,starty,startx)\fR +.B move_panel(pan,starty,startx) moves the given panel window so that its upper-left corner is at \fBstarty\fR, \fBstartx\fR. It does not change the position of the panel in the stack. Be sure to use this function, not \fBmvwin()\fR, to move a panel window. .TP -\fBreplace_panel(pan,window)\fR +.B replace_panel(pan,window) replaces the current window of panel with \fBwindow\fR (useful, for example if you want to resize a panel; if you're using \fBncurses\fR, you can call \fBreplace_panel\fR on the output of \fBwresize\fR(3X)). It does not change the position of the panel in the stack. .TP -\fBpanel_above(pan)\fR +.B panel_above(pan) returns a pointer to the panel above pan. If the panel argument is \fB(PANEL *)0\fR, it returns a pointer to the bottom panel in the stack. .TP -\fBpanel_below(pan)\fR +.B panel_below(pan) returns a pointer to the panel just below pan. If the panel argument is \fB(PANEL *)0\fR, it returns a pointer to the top panel in the stack. .TP -\fBset_panel_userptr(pan,ptr)\fR +.B set_panel_userptr(pan,ptr) sets the panel's user pointer. .TP -\fBpanel_userptr(pan)\fR +.B panel_userptr(pan) returns the user pointer for a given panel. .TP -\fBpanel_window(pan)\fR +.B panel_window(pan) returns a pointer to the window of the given panel. .SH DIAGNOSTICS Each routine that returns a pointer returns \fBNULL\fR if an error diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c index 14a821e7..e13bd81c 100644 --- a/ncurses/base/lib_set_term.c +++ b/ncurses/base/lib_set_term.c @@ -44,7 +44,7 @@ #include /* cur_term */ #include -MODULE_ID("$Id: lib_set_term.c,v 1.97 2007/04/26 19:39:48 tom Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.98 2007/05/12 19:37:04 tom Exp $") NCURSES_EXPORT(SCREEN *) set_term(SCREEN *screenp) @@ -166,8 +166,6 @@ delscreen(SCREEN *sp) returnVoid; } -#define N_RIPS SIZEOF(SP->_rippedoff) - static bool no_mouse_event(SCREEN *sp GCC_UNUSED) { @@ -228,8 +226,8 @@ _nc_setupscreen(int slines GCC_UNUSED, int slk_format) { int bottom_stolen = 0; - int i; bool support_cookies = USE_XMC_SUPPORT; + ripoff_t *rop; T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"), slines, scolumns, output, filtered, slk_format)); @@ -271,18 +269,6 @@ _nc_setupscreen(int slines GCC_UNUSED, cursor_home = carriage_return; T(("filter screensize %dx%d", LINES, COLS)); } - - /* If we must simulate soft labels, grab off the line to be used. - We assume that we must simulate, if it is none of the standard - formats (4-4 or 3-2-3) for which there may be some hardware - support. */ - if (num_labels <= 0 || !SLK_STDFMT(slk_format)) { - if (slk_format) { - if (ERR == _nc_ripoffline(-SLK_LINES(slk_format), - _nc_slk_initialize)) - returnCode(ERR); - } - } #ifdef __DJGPP__ T(("setting output mode to binary")); fflush(output); @@ -549,38 +535,43 @@ _nc_setupscreen(int slines GCC_UNUSED, def_shell_mode(); def_prog_mode(); - for (i = 0, ripoff_sp = ripoff_stack; - ripoff_sp->line && (i < (int) N_RIPS); - ripoff_sp++, i++) { - - T(("ripping off line %d at %s", i, - ((ripoff_sp->line < 0) - ? "bottom" - : "top"))); - - SP->_rippedoff[i] = ripoff_stack[i]; - if (ripoff_sp->hook) { - int count = (ripoff_sp->line < 0) ? -ripoff_sp->line : ripoff_sp->line; - - SP->_rippedoff[i].w = newwin(count, - scolumns, - ((ripoff_sp->line < 0) - ? SP->_lines_avail - count - : 0), - 0); - if (SP->_rippedoff[i].w != 0) - SP->_rippedoff[i].hook(SP->_rippedoff[i].w, scolumns); + for (rop = ripoff_stack; + rop != ripoff_sp && (rop - ripoff_stack) < N_RIPS; + rop++) { + + /* If we must simulate soft labels, grab off the line to be used. + We assume that we must simulate, if it is none of the standard + formats (4-4 or 3-2-3) for which there may be some hardware + support. */ + if (rop->hook == _nc_slk_initialize) + if (!(num_labels <= 0 || !SLK_STDFMT(slk_format))) + continue; + if (rop->hook) { + int count; + WINDOW *w; + + count = (rop->line < 0) ? -rop->line : rop->line; + T(("ripping off %i lines at %s", count, + ((rop->line < 0) + ? "bottom" + : "top"))); + + w = newwin(count, scolumns, + ((rop->line < 0) + ? SP->_lines_avail - count + : 0), + 0); + if (w) + rop->hook(w, scolumns); else returnCode(ERR); - if (ripoff_sp->line < 0) + if (rop->line < 0) bottom_stolen += count; else SP->_topstolen += count; SP->_lines_avail -= count; } - ripoff_sp->line = 0; } - SP->_rip_count = i; /* reset the stack */ ripoff_sp = ripoff_stack; @@ -615,7 +606,6 @@ _nc_ripoffline(int line, int (*init) (WINDOW *, int)) ripoff_sp->line = line; ripoff_sp->hook = init; - ripoff_sp->w = 0; ripoff_sp++; } diff --git a/ncurses/base/lib_slkinit.c b/ncurses/base/lib_slkinit.c index f003b5f0..20c0baa5 100644 --- a/ncurses/base/lib_slkinit.c +++ b/ncurses/base/lib_slkinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2007 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 * @@ -38,14 +38,17 @@ */ #include -MODULE_ID("$Id: lib_slkinit.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkinit.c,v 1.6 2007/05/12 18:14:21 tom Exp $") NCURSES_EXPORT(int) slk_init(int format) { + int code = ERR; + T((T_CALLED("slk_init(%d)"), format)); - if (format < 0 || format > 3) - returnCode(ERR); - _nc_slk_format = 1 + format; - returnCode(OK); + if (format >= 0 && format <= 3 && !_nc_slk_format) { + _nc_slk_format = 1 + format; + code = _nc_ripoffline(-SLK_LINES(_nc_slk_format), _nc_slk_initialize); + } + returnCode(code); } diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index 80dbdb2b..44e4528d 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -34,7 +34,7 @@ /* - * $Id: curses.priv.h,v 1.330 2007/04/21 23:52:28 tom Exp $ + * $Id: curses.priv.h,v 1.331 2007/05/12 18:10:46 tom Exp $ * * curses.priv.h * @@ -380,7 +380,6 @@ typedef struct _SLK { typedef struct { int line; /* lines to take, < 0 => from bottom*/ int (*hook)(WINDOW *, int); /* callback for user */ - WINDOW *w; /* maybe we need this for cleanup */ } ripoff_t; #if USE_GPM_SUPPORT @@ -539,6 +538,8 @@ typedef struct { extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals; +#define N_RIPS 5 + /* * Global data which is swept up into a SCREEN when one is created. * It may be modified before the next SCREEN is created. @@ -547,7 +548,7 @@ typedef struct { bool use_env; bool filter_mode; attr_t previous_attr; - ripoff_t rippedoff[5]; + ripoff_t rippedoff[N_RIPS]; ripoff_t *rsp; TPARM_STATE tparm_state; #if BROKEN_LINKER || USE_REENTRANT @@ -575,8 +576,6 @@ struct screen { NCURSES_SIZE_T _lines_avail; /* lines available for stdscr */ NCURSES_SIZE_T _topstolen; /* lines stolen from top */ - ripoff_t _rippedoff[5]; /* list of lines stolen */ - int _rip_count; /* ...and total lines stolen */ WINDOW *_curscr; /* current screen */ WINDOW *_newscr; /* virtual screen to be updated to */ diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c index f7e6ef4d..aee05075 100644 --- a/ncurses/tinfo/lib_data.c +++ b/ncurses/tinfo/lib_data.c @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_data.c,v 1.24 2007/04/21 23:55:13 tom Exp $") +MODULE_ID("$Id: lib_data.c,v 1.25 2007/05/12 18:12:12 tom Exp $") /* * OS/2's native linker complains if we don't initialize public data when @@ -182,7 +182,7 @@ NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { #define STACK_FRAME_0s { STACK_FRAME_0 } #define NUM_VARS_0s { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } -#define RIPOFF_0 { 0,0,0 } +#define RIPOFF_0 { 0,0 } #define RIPOFF_0s { RIPOFF_0 } NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = { diff --git a/ncurses/tinfo/setbuf.c b/ncurses/tinfo/setbuf.c index 94bb6d34..ba910e89 100644 --- a/ncurses/tinfo/setbuf.c +++ b/ncurses/tinfo/setbuf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2007 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 * @@ -40,7 +40,7 @@ #include -MODULE_ID("$Id: setbuf.c,v 1.12 2003/11/15 23:55:34 tom Exp $") +MODULE_ID("$Id: setbuf.c,v 1.13 2007/05/12 19:04:02 tom Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -102,7 +102,7 @@ _nc_set_buffer(FILE *ofp, bool buffered) { /* optional optimization hack -- do before any output to ofp */ #if HAVE_SETVBUF || HAVE_SETBUFFER - if (SP->_buffered != (int)buffered) { + if (SP->_buffered != buffered) { unsigned buf_len; char *buf_ptr; diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index 5426f1fc..dfd3723b 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 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 * @@ -54,7 +54,7 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.68 2006/10/14 20:45:16 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.69 2007/05/12 19:04:13 tom Exp $") static int total_written; @@ -502,7 +502,8 @@ compute_offsets(char **Strings, unsigned strmax, short *offsets) } else { offsets[i] = nextfree; nextfree += strlen(Strings[i]) + 1; - TRACE_OUT(("put Strings[%d]=%s(%d)", i, _nc_visbuf(Strings[i]), nextfree)); + TRACE_OUT(("put Strings[%d]=%s(%d)", (int) i, + _nc_visbuf(Strings[i]), nextfree)); } } return nextfree; @@ -740,7 +741,7 @@ write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) */ for (i = 0; i < tp->ext_Strings; i++) { if (VALID_STRING(tp->Strings[i + STRCOUNT])) { - TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, + TRACE_OUT(("WRITE ext_Strings[%d]=%s", (int) i, _nc_visbuf(tp->Strings[i + STRCOUNT]))); if (!WRITE_STRING(tp->Strings[i + STRCOUNT])) return (ERR); @@ -751,7 +752,7 @@ write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) * Write the extended names */ for (i = 0; i < extcnt; i++) { - TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i])); + TRACE_OUT(("WRITE ext_Names[%d]=%s", (int) i, tp->ext_Names[i])); if (!WRITE_STRING(tp->ext_Names[i])) return (ERR); } diff --git a/ncurses/tty/lib_twait.c b/ncurses/tty/lib_twait.c index e18756c2..440e4101 100644 --- a/ncurses/tty/lib_twait.c +++ b/ncurses/tty/lib_twait.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 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 * @@ -62,7 +62,7 @@ # endif #endif -MODULE_ID("$Id: lib_twait.c,v 1.52 2006/12/30 16:56:28 tom Exp $") +MODULE_ID("$Id: lib_twait.c,v 1.53 2007/05/12 19:02:31 tom Exp $") #if HAVE_GETTIMEOFDAY # define PRECISE_GETTIME 1 @@ -186,7 +186,7 @@ _nc_timed_wait(int mode, } #endif -#if PRECISE_GETTIME +#if PRECISE_GETTIME && HAVE_NANOSLEEP retry: #endif starttime = _nc_gettime(&t0, TRUE); diff --git a/ncurses/widechar/lib_cchar.c b/ncurses/widechar/lib_cchar.c index b6458ee4..b4a0c37a 100644 --- a/ncurses/widechar/lib_cchar.c +++ b/ncurses/widechar/lib_cchar.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001-2004,2005 Free Software Foundation, Inc. * + * Copyright (c) 2001-2005,2007 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 * @@ -35,7 +35,7 @@ #include -MODULE_ID("$Id: lib_cchar.c,v 1.11 2005/01/29 21:29:16 tom Exp $") +MODULE_ID("$Id: lib_cchar.c,v 1.12 2007/05/12 19:03:06 tom Exp $") /* * The SuSv2 description leaves some room for interpretation. We'll assume wch @@ -54,8 +54,9 @@ setcchar(cchar_t *wcval, int len; int code = OK; - TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%ld,%d,%p)"), - wcval, _nc_viswbuf(wch), attrs, color_pair, opts)); + TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"), + wcval, _nc_viswbuf(wch), + (unsigned long) attrs, color_pair, opts)); len = wcslen(wch); if (opts != NULL diff --git a/ncurses/widechar/lib_get_wch.c b/ncurses/widechar/lib_get_wch.c index c73c363b..7985df25 100644 --- a/ncurses/widechar/lib_get_wch.c +++ b/ncurses/widechar/lib_get_wch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2002-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 2002-2006,2007 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 * @@ -40,7 +40,7 @@ #include #include -MODULE_ID("$Id: lib_get_wch.c,v 1.13 2006/06/03 17:27:57 tom Exp $") +MODULE_ID("$Id: lib_get_wch.c,v 1.14 2007/05/12 19:03:16 tom Exp $") #if HAVE_MBTOWC && HAVE_MBLEN #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0) @@ -77,7 +77,7 @@ wget_wch(WINDOW *win, wint_t *result) * _nc_wgetch(), while we want to return a wide character or KEY_xxx code. */ for (;;) { - T(("reading %d of %d", count + 1, sizeof(buffer))); + T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer))); code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist *) 0)); if (code == ERR) { break; diff --git a/test/ncurses.c b/test/ncurses.c index 7f45f9a3..863d5660 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.283 2007/03/10 19:11:50 tom Exp $ +$Id: ncurses.c,v 1.288 2007/05/12 23:04:11 tom Exp $ ***************************************************************************/ @@ -955,11 +955,11 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ; if ((temp = wcstos(wchar_buf)) != 0) { wprintw(win, "I saw %d characters:\n\t`%s'.", - wcslen(wchar_buf), temp); + (int) wcslen(wchar_buf), temp); free(temp); } else { wprintw(win, "I saw %d characters (cannot convert).", - wcslen(wchar_buf)); + (int) wcslen(wchar_buf)); } } wclrtoeol(win); @@ -3947,7 +3947,11 @@ saywhat(NCURSES_CONST char *text) { wmove(stdscr, LINES - 1, 0); wclrtoeol(stdscr); - waddstr(stdscr, text); + if (text != 0 && *text != '\0') { + waddstr(stdscr, text); + waddstr(stdscr, "; "); + } + waddstr(stdscr, "press any key to continue"); } /* end of saywhat */ /*+------------------------------------------------------------------------- @@ -3999,6 +4003,17 @@ pflush(void) /*+------------------------------------------------------------------------- fill_panel(win) --------------------------------------------------------------------------*/ +static void +init_panel(void) +{ + register int y, x; + + for (y = 0; y < LINES - 1; y++) { + for (x = 0; x < COLS; x++) + wprintw(stdscr, "%d", (y + x) % 10); + } +} + static void fill_panel(PANEL * pan) { @@ -4016,217 +4031,214 @@ fill_panel(PANEL * pan) waddch(win, UChar(num)); } } -} /* end of fill_panel */ +} +#if USE_WIDEC_SUPPORT static void -demo_panels(void) +make_fullwidth_digit(cchar_t *target, int digit) { - int itmp; - register int y, x; + wchar_t source[2]; - refresh(); + source[0] = digit + 0xff10; + source[1] = 0; + setcchar(target, source, A_NORMAL, 0, 0); +} - for (y = 0; y < LINES - 1; y++) { - for (x = 0; x < COLS; x++) - wprintw(stdscr, "%d", (y + x) % 10); - } - for (y = 0; y < 5; y++) { - PANEL *p1; - PANEL *p2; - PANEL *p3; - PANEL *p4; - PANEL *p5; - - p1 = mkpanel(COLOR_RED, - LINES / 2 - 2, - COLS / 8 + 1, - 0, - 0); - set_panel_userptr(p1, (NCURSES_CONST void *) "p1"); - - p2 = mkpanel(COLOR_GREEN, - LINES / 2 + 1, - COLS / 7, - LINES / 4, - COLS / 10); - set_panel_userptr(p2, (NCURSES_CONST void *) "p2"); - - p3 = mkpanel(COLOR_YELLOW, - LINES / 4, - COLS / 10, - LINES / 2, - COLS / 9); - set_panel_userptr(p3, (NCURSES_CONST void *) "p3"); - - p4 = mkpanel(COLOR_BLUE, - LINES / 2 - 2, - COLS / 8, - LINES / 2 - 2, - COLS / 3); - set_panel_userptr(p4, (NCURSES_CONST void *) "p4"); - - p5 = mkpanel(COLOR_MAGENTA, - LINES / 2 - 2, - COLS / 8, - LINES / 2, - COLS / 2 - 2); - set_panel_userptr(p5, (NCURSES_CONST void *) "p5"); - - fill_panel(p1); - fill_panel(p2); - fill_panel(p3); - fill_panel(p4); - fill_panel(p5); - hide_panel(p4); - hide_panel(p5); - pflush(); - saywhat("press any key to continue"); - wait_a_while(nap_msec); +static void +init_wide_panel(void) +{ + int digit; + cchar_t temp[10]; - saywhat("h3 s1 s2 s4 s5; press any key to continue"); - move_panel(p1, 0, 0); - hide_panel(p3); - show_panel(p1); - show_panel(p2); - show_panel(p4); - show_panel(p5); - pflush(); - wait_a_while(nap_msec); + for (digit = 0; digit < 10; ++digit) + make_fullwidth_digit(&temp[digit], digit); - saywhat("s1; press any key to continue"); - show_panel(p1); - pflush(); - wait_a_while(nap_msec); + do { + int y, x; + getyx(stdscr, y, x); + digit = (y + x / 2) % 10; + } while (add_wch(&temp[digit]) != ERR); +} - saywhat("s2; press any key to continue"); - show_panel(p2); - pflush(); - wait_a_while(nap_msec); +static void +fill_wide_panel(PANEL * pan) +{ + WINDOW *win = panel_window(pan); + int num = ((const char *) panel_userptr(pan))[1]; + int y, x; - saywhat("m2; press any key to continue"); - move_panel(p2, LINES / 3 + 1, COLS / 8); - pflush(); - wait_a_while(nap_msec); + wmove(win, 1, 1); + wprintw(win, "-pan%c-", num); + wclrtoeol(win); + box(win, 0, 0); + for (y = 2; y < getmaxy(win) - 1; y++) { + for (x = 1; x < getmaxx(win) - 1; x++) { + wmove(win, y, x); + waddch(win, UChar(num)); + } + } +} +#endif - saywhat("s3;"); - show_panel(p3); - pflush(); - wait_a_while(nap_msec); +#define MAX_PANELS 5 - saywhat("m3; press any key to continue"); - move_panel(p3, LINES / 4 + 1, COLS / 15); - pflush(); - wait_a_while(nap_msec); +static void +canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd) +{ + int which = cmd[1] - '0'; - saywhat("b3; press any key to continue"); - bottom_panel(p3); - pflush(); - wait_a_while(nap_msec); + saywhat(cmd); + switch (*cmd) { + case 'h': + hide_panel(px[which]); + break; + case 's': + show_panel(px[which]); + break; + case 't': + top_panel(px[which]); + break; + case 'b': + bottom_panel(px[which]); + break; + case 'd': + rmpanel(px[which]); + break; + } + pflush(); + wait_a_while(nap_msec); +} - saywhat("s4; press any key to continue"); - show_panel(p4); - pflush(); - wait_a_while(nap_msec); +static void +demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *)) +{ + int count; + int itmp; + PANEL *px[MAX_PANELS + 1]; - saywhat("s5; press any key to continue"); - show_panel(p5); - pflush(); - wait_a_while(nap_msec); + scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */ + refresh(); - saywhat("t3; press any key to continue"); - top_panel(p3); + InitPanel(); + for (count = 0; count < 5; count++) { + px[1] = mkpanel(COLOR_RED, + LINES / 2 - 2, + COLS / 8 + 1, + 0, + 0); + set_panel_userptr(px[1], (NCURSES_CONST void *) "p1"); + + px[2] = mkpanel(COLOR_GREEN, + LINES / 2 + 1, + COLS / 7, + LINES / 4, + COLS / 10); + set_panel_userptr(px[2], (NCURSES_CONST void *) "p2"); + + px[3] = mkpanel(COLOR_YELLOW, + LINES / 4, + COLS / 10, + LINES / 2, + COLS / 9); + set_panel_userptr(px[3], (NCURSES_CONST void *) "p3"); + + px[4] = mkpanel(COLOR_BLUE, + LINES / 2 - 2, + COLS / 8, + LINES / 2 - 2, + COLS / 3); + set_panel_userptr(px[4], (NCURSES_CONST void *) "p4"); + + px[5] = mkpanel(COLOR_MAGENTA, + LINES / 2 - 2, + COLS / 8, + LINES / 2, + COLS / 2 - 2); + set_panel_userptr(px[5], (NCURSES_CONST void *) "p5"); + + FillPanel(px[1]); + FillPanel(px[2]); + FillPanel(px[3]); + FillPanel(px[4]); + FillPanel(px[5]); + + hide_panel(px[4]); + hide_panel(px[5]); pflush(); + saywhat(""); wait_a_while(nap_msec); - saywhat("t1; press any key to continue"); - top_panel(p1); + saywhat("h3 s1 s2 s4 s5"); + move_panel(px[1], 0, 0); + hide_panel(px[3]); + show_panel(px[1]); + show_panel(px[2]); + show_panel(px[4]); + show_panel(px[5]); pflush(); wait_a_while(nap_msec); - saywhat("t2; press any key to continue"); - top_panel(p2); - pflush(); - wait_a_while(nap_msec); + canned_panel(px, "s1"); + canned_panel(px, "s2"); - saywhat("t3; press any key to continue"); - top_panel(p3); + saywhat("m2"); + move_panel(px[2], LINES / 3 + 1, COLS / 8); pflush(); wait_a_while(nap_msec); - saywhat("t4; press any key to continue"); - top_panel(p4); + canned_panel(px, "s3"); + + saywhat("m3"); + move_panel(px[3], LINES / 4 + 1, COLS / 15); pflush(); wait_a_while(nap_msec); + canned_panel(px, "b3"); + canned_panel(px, "s4"); + canned_panel(px, "s5"); + canned_panel(px, "t3"); + canned_panel(px, "t1"); + canned_panel(px, "t2"); + canned_panel(px, "t3"); + canned_panel(px, "t4"); + for (itmp = 0; itmp < 6; itmp++) { - WINDOW *w4 = panel_window(p4); - WINDOW *w5 = panel_window(p5); + WINDOW *w4 = panel_window(px[4]); + WINDOW *w5 = panel_window(px[5]); - saywhat("m4; press any key to continue"); + saywhat("m4"); wmove(w4, LINES / 8, 1); waddstr(w4, mod[itmp]); - move_panel(p4, LINES / 6, itmp * (COLS / 8)); + move_panel(px[4], LINES / 6, itmp * (COLS / 8)); wmove(w5, LINES / 6, 1); waddstr(w5, mod[itmp]); pflush(); wait_a_while(nap_msec); - saywhat("m5; press any key to continue"); + saywhat("m5"); wmove(w4, LINES / 6, 1); waddstr(w4, mod[itmp]); - move_panel(p5, LINES / 3 - 1, (itmp * 10) + 6); + move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6); wmove(w5, LINES / 8, 1); waddstr(w5, mod[itmp]); pflush(); wait_a_while(nap_msec); } - saywhat("m4; press any key to continue"); - move_panel(p4, LINES / 6, itmp * (COLS / 8)); - pflush(); - wait_a_while(nap_msec); - - saywhat("t5; press any key to continue"); - top_panel(p5); + saywhat("m4"); + move_panel(px[4], LINES / 6, itmp * (COLS / 8)); pflush(); wait_a_while(nap_msec); - saywhat("t2; press any key to continue"); - top_panel(p2); - pflush(); - wait_a_while(nap_msec); - - saywhat("t1; press any key to continue"); - top_panel(p1); - pflush(); - wait_a_while(nap_msec); - - saywhat("d2; press any key to continue"); - rmpanel(p2); - pflush(); - wait_a_while(nap_msec); - - saywhat("h3; press any key to continue"); - hide_panel(p3); - pflush(); - wait_a_while(nap_msec); - - saywhat("d1; press any key to continue"); - rmpanel(p1); - pflush(); - wait_a_while(nap_msec); - - saywhat("d4; press any key to continue"); - rmpanel(p4); - pflush(); - wait_a_while(nap_msec); - - saywhat("d5; press any key to continue"); - rmpanel(p5); - pflush(); - - rmpanel(p3); - pflush(); + canned_panel(px, "t5"); + canned_panel(px, "t2"); + canned_panel(px, "t1"); + canned_panel(px, "d2"); + canned_panel(px, "h3"); + canned_panel(px, "d1"); + canned_panel(px, "d4"); + canned_panel(px, "d5"); + canned_panel(px, "d3"); wait_a_while(nap_msec); if (nap_msec == 1) @@ -5886,7 +5898,13 @@ do_single_test(const char c) #if USE_LIBPANEL case 'o': - demo_panels(); + demo_panels(init_panel, fill_panel); + break; +#endif + +#if USE_WIDEC_SUPPORT + case 'O': + demo_panels(init_wide_panel, fill_wide_panel); break; #endif @@ -6054,9 +6072,12 @@ main_menu(bool top) #endif #if USE_LIBPANEL (void) puts("o = exercise panels library"); +#if USE_WIDEC_SUPPORT + (void) puts("O = exercise panels with wide-characters"); +#endif +#endif (void) puts("p = exercise pad features"); (void) puts("q = quit"); -#endif #if USE_LIBFORM (void) puts("r = exercise forms code"); #endif -- 2.44.0