[ Previous |
Next |
Contents |
Glossary |
Home |
Search ]
AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs
Use of the libcur Package
Programs that use the libcur package (extension to AT&T's libcurses package) need to make the following changes:
- Remove the assumption that the number of bytes need to represent a character in a code set also represents the display column width of the character. Use the wcwidth subroutine to determine the number of display columns needed by the wide character code of a character.
- NLSCHAR is redefined to be wchar_t.
- The win->_y [y][x]
has wchar_t encodings.
- Programs should not assume any particular encodings on the wchar_t.
- Programs should use the addstr, waddstr, mvaddstr, and mvwaddstr subroutines rather than the addch family of subroutines. All string arguments are in multibyte form.
- The addch and waddch subroutines accept a wchar_t encoding of the character. Programs that use these subroutines should ensure that wchar_t are used in calling these functions. The (x,y) are incremented by the number of columns occupied by the wchar_t passed to these subroutines.
- The delch, wdelch, mvdelch, and mvwdelch subroutines support delete and backspace on multibyte characters depending on the current position of (x,y). If the current (x,y) column position points to either the first or second column of a two-column character, the delch subroutine deletes both columns and shifts the rest of the line by the number of columns deleted.
- The insch, winsch, mvinsch, and mvwinsch subroutines can be used to insert a wchar_t encoding of a character at the current (x,y) position. The line is shifted by the number of columns needed by the wchar_t.
- The libcur package is modified to support box drawing characters as defined in the terminfo database and not assume the graphic characters in the IBM-850 code set. The libcur package supports drawing of primary and alternate box characters as defined in the box_chars_1 and box_chars_2 entries in the terminfo database. To use this, programs should be modified in the following fashion:
Drawing Primary box characters:
wcolorout(win, Bxa);
cbox(win);
wcolorend(win);
or,
wcolorout(win, Bxa);
drawbox(win, y,x, height, width);
wcolorend(win);
Drawing Alternate box characters:
wcolorout(win, Bya)
cboxalt(win);
wcolorend(win);
or,
wcolorout(win, Bya);
drawbox(win, y, x, height, width);
wcolorend(win);
Bxa
and Bya
refer to the primary and alternate attributes defined in the terminfo database.
The following macros are added in the cur01.h file:
cboxalt(win)
drawboxalt(win, y,x, height, width)
- Programs that need to support input of multibyte characters should not set _extended to TRUE by a call to extended(TRUE). When the _extended flag is true, the wgetch subroutine returns wchar_t encodings of the character. With multibyte characters, this encoding of wchar_t may conflict with predefined values for escape sequences or function keys. Avoid this conflict when using multibyte code sets by setting extended to off (extended(FALSE)) before input. (The default is TRUE.)
Programs that do multibyte character input should do the following:
Input routine:
Example:
int c, count;
char buf[];
extended(FALSE); /* obtain one byte at a time */
count =0;
while(1){
c = wgetch(); /* get one byte at a time */
buf[count++] = c;
if(count <=MB_CUR_MAX)
if(mblen(buf, count) != -1)
break; /* character found* /
else
/*Error. No character can be found */
/* Handle this case appropriately */
break;
}
/* buf contains the input multibyte sequence */
/* Now handle PF keys, or any escape sequence here */
- The inch, winch, mvinch, and mvwinch subroutines return the wchar_t at the current (x,y) position. Note that in the case of a double column width character, if the (x,y) point is at the first column, the wchar_t code of the double column width character is returned. If the (x,y) point is at the second column, WEOF is returned.
Related Information
National Language Support Overview for Programming.
The addch and waddch subroutines, addstr, waddstr, mvaddstr, and mvwaddstr subroutines, delch, wdelch, mvdelch, and mvwdelch subroutines, inch, insch, winsch, mvinsch, and mvwinsch subroutines, winch, mvinch, and mvwinch subroutines, wcwidth subroutine, wgetch subroutine.
[ Previous |
Next |
Contents |
Glossary |
Home |
Search ]