bug-ncurses
[Top][All Lists]
Advanced

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

Reply to Mr Verdoolaege about wide chars


From: philippe blain
Subject: Reply to Mr Verdoolaege about wide chars
Date: Thu, 27 Sep 2001 06:18:55 +0200

>From Philippe Blain, Bordeaux, FRANCE
My old computer : P133 - 8,4Go - 32 Mo       Red Hat Linux 7.0

To the maintainers of 'ncurses'. (and to Mr Dickey)
Subject : Corrections for ncurses-5.2-20010922+

###  Problems about WIDE CHARS and functions
Here are some problems I found :

--------------------------------------------------------------------------------
Mr Verdoolaege wrote :
>> It should be defined simply something like      NCURSES_CH_T _bkgrnd;
>No. Backward compatibility.

>> 2) Double definition of '_nc_background()', 'wgetbkgrnd(win,wch)'
>>     which should normaly return both the current background char (or struct).
>I don't know about this one. Maybe legibility.

>> 3) _nc_background() not correct for wide chars :
>How so ?

--------------------------------------------------------------------------------
First, I would like to say that it's very hard and complicated for me
to get the meaning of some portions of code. The more ncurses moves forward,
the more code become complicated with tons of #define, #ifdef, special cases
for a particular system, modifications not documented in source, etc, etc....
Sometimes, when i'm in front of my monitor, I really need aspirin.
That's not good. Is there an end to the ncurses project ?
--------------------------------------------------------------------------------
EXPLANATION :
Support for wide characters starts by a definition in 'curses.h.in' :

#define CCHARW_MAX 5
typedef struct
{
    attr_t attr;
    wchar_t chars[CCHARW_MAX];
}
cchar_t;


Then ,'configure' sets these shell variables by default :
 NCURSES_CH_T=chtype
 NCURSES_getbkgd_gen=generated
 NCURSES_getbkgd_def="#define getbkgd(win)    ((win)->_bkgd)"
 NCURSES_bkgd_field="chtype  _bkgd;"

When "--enable-widec" is turned on, these are :
 #define USE_WIDEC_SUPPORT 1
 NCURSES_CH_T=cchar_t
 NCURSES_getbkgd_gen=implemented
 NCURSES_getbkgd_def=""
 NCURSES_bkgd_field=""

'configure' makes then some substitutions in 'curses.h.in':

#define NCURSES_CH_T @NCURSES_CH_T@     <==== becomes chtype or cchar_t
......................
struct _win_st
{
 NCURSES_SIZE_T _cury, _curx; /* current cursor position */
 ......................
 @NCURSES_bkgd_field@ /* current background char/attribute pair */
 ......................
#ifdef _XOPEN_SOURCE_EXTENDED
 NCURSES_CH_T  _bkgrnd; /* current background char/attribute pair */
#endif
};

_XOPEN_SOURCE_EXTENDED is defined when USE_WIDEC_SUPPORT is TRUE (curses.priv.h)

#if USE_WIDEC_SUPPORT
 #ifndef _XOPEN_SOURCE_EXTENDED
  #define _XOPEN_SOURCE_EXTENDED
 #endif
#else
 #undef _XOPEN_SOURCE_EXTENDED
 #define _bkgrnd     _bkgd
 #define wgetbkgrnd(win, wch) *wch = win->_bkgd
 #define wbkgrnd     wbkgd
#endif

So, I don't see why the double definition of _bkgd and _bkgrnd in _win_st ?
You said 'backward compatibility', but when
1) USE_WIDEC_SUPPORT is TRUE
 we have   NCURSES_CH_T  _bkgrnd;

2) USE_WIDEC_SUPPORT is FALSE
 NCURSES_bkgd_field="chtype  _bkgd;"
 we have   chtype  _bkgd;   and  #define _bkgrnd     _bkgd

Why not a simplification here by choosing _bkgrnd ONLY ???

--------------------------------------------------------------------------------
####  WIDE CHARS AND FUNCTIONS

In lib_addch.c, there is the _nc_background() function :

NCURSES_EXPORT(NCURSES_CH_T) _nc_background(WINDOW *win)
{
    return (win->_bkgrnd);
}

This function is used in many files :
    lib_addch.c:    _nc_background(WINDOW *win)
    lib_addstr.c:   line->text[x - 1] = _nc_background(win);
    lib_addstr.c:   line->text[x - 1] = _nc_background(win);
    lib_addstr.c:   line->text[x] = _nc_background(win);
    lib_clrbot.c:   NCURSES_CH_T blank = _nc_background(win);
    lib_clreol.c:   blank = _nc_background(win);
    lib_delch.c:    NCURSES_CH_T blank = _nc_background(win);
    lib_erase.c:    blank = _nc_background(win);
    lib_insdel.c:   _nc_background(win));
    lib_scroll.c:   _nc_scroll_window(win, n, win->_regtop, win->_regbottom,
                                      _nc_background(win));
    wresize.c:      blank = _nc_background(win);

The problem I see there, is about its return value when used with wide chars.
There is restrictions when using structures and functions in C.
A function CANNOT return a structure, only a pointer on a structure
or have a pointer as one parameter.
A function CANNOT have a structure as parameter also, only a pointer to this
structure, you write 'f(WINDOW *win)' and not 'f(WINDOW win)'.
Writing      NCURSES_CH_T blank = _nc_background(win);
is false when blank is a structure.

There is also another function (correct) doing same thing
 #define wgetbkgrnd(win, wch) *wch = win->_bkgd
but defined when USE_WIDEC_SUPPORT is **** FALSE ****(why ?? should be TRUE):
==> You should unify that. <===

Same thing for '_nc_render()' :
 NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
Cannot return a structure.


As you see, the wide char support introduce many, many problems.
You need to verify each function which have a parameter of 'NCURSES_CH_T'
or return a 'NCURSES_CH_T'

--------------------------------------------------------------------------------
------ Philippe (need gnu-aspirin after writing that).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]