Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Curses(3) inch(3) seems broken in NetBSD 5



Hi,

> > Up to NetBSD 4.0, this worked fine. In 5.0.1, it seems that it has
> > broken. I put ACS_PLUS on the screen, and I get back a different value,
> > seemingly ACS_PLUS & 0xFF.

Yes.  inch() seems to be broken.

> If, for whatever reason, wide characters get mangled that way, they
> could not have been placed on the screen with addch() in the first
> place, so inch() mishandling them would not be a problem.

The interaction between wide and non-wide characters isn't well defined, so
I agree that adding as wide and viewing as non-wide (or vice versa) shouldn't
necessarily work.

> Something like this (untested) (wich, on reflection, makes both parts of
> the #ifdef essentially identical):

As far as I can see, both parts can be identical.  The attached patch does
that and also fixes a default colour pair bug.  I've also attached a small
test program.  Note that the patch is for -current, which has changed
'lines' to 'alines'.

Thanks,

J

-- 
  My other computer also runs NetBSD    /        Sailing at Newbiggin
        http://www.netbsd.org/        /   http://www.newbigginsailingclub.org/
Index: inch.c
===================================================================
RCS file: /cvsroot/src/lib/libcurses/inch.c,v
retrieving revision 1.9
diff -u -r1.9 inch.c
--- inch.c      22 Jul 2009 16:57:14 -0000      1.9
+++ inch.c      14 Sep 2009 17:22:35 -0000
@@ -81,13 +81,14 @@
 chtype
 winch(WINDOW *win)
 {
-#ifndef HAVE_WCHAR
-       chtype   ch;
+       chtype  ch;
+       attr_t  attr;
 
-       ch = (chtype) (((win)->alines[(win)->cury]->line[(win)->curx].ch & 
__CHARTEXT) |
-         (chtype) ((win)->alines[(win)->cury]->line[(win)->curx].attr & 
__ATTRIBUTES));
-       return (ch);
-#else
-       return ( chtype )win->alines[ win->cury ]->line[ win->curx ].ch;
-#endif /* HAVE_WCHAR */
+       ch = (chtype) ((win)->alines[(win)->cury]->line[(win)->curx].ch &
+           __CHARTEXT);
+       attr = (attr_t) ((win)->alines[(win)->cury]->line[(win)->curx].attr &
+           __ATTRIBUTES);
+       if (__using_color && ((attr & __COLOR) == __default_color))
+               attr &= ~__default_color;
+       return (ch | attr);
 }
#include <curses.h>
#include <stdlib.h>

main ()
{
        char    *term;
        chtype  c;

        /* Initialisation */
        term = getenv("TERM");
        if (initscr() == NULL) {
                fprintf(stderr, "Failed to initialise terminal (%s)\n",
                    getenv("TERM"));
                exit(1);
        }

        if (has_colors() == FALSE || start_color() == ERR) {
                move(0, 0);
                printw("Terminal (%s) does not support colour", term);
                getch();
                endwin();
                exit(1);
        }

        init_pair(1, COLOR_BLUE, COLOR_CYAN);

        use_default_colors();

        move(2, 1);
        addch(ACS_PLUS);
        attrset(COLOR_PAIR(1));
        move(4, 1);
        addch(ACS_PLUS);
        getch();

        attroff(COLOR_PAIR(1));
        move(0, 4);
        addstr("Char/attributes(  colour  /pair)");
        move(2, 1);
        c = inch();
        move(2, 4);
        printw("0x%0x/0x%08x(0x%08x/%4d)", c & A_CHARTEXT, c & A_ATTRIBUTES,
            c & A_COLOR, PAIR_NUMBER(c & A_COLOR));
        move(4, 1);
        c = inch();
        move(4, 4);
        printw("0x%0x/0x%08x(0x%08x/%4d)", c & A_CHARTEXT, c & A_ATTRIBUTES,
            c & A_COLOR, PAIR_NUMBER(c & A_COLOR));
        getch();

        endwin();
}


Home | Main Index | Thread Index | Old Index