Standard curses library use eight bit for standout mode, so
8-bit characters displays like highlighted 7-bit characters.
This patch produce library which is fully compatible with all curses
programs and add 8-bit chars to all input/display functions.
---
I don't think, that any programs wish to use internal curses
attribute _STANDOUT directly, in expressions like:
addch( ch | _STANDOUT );
Normal interface use standout() and standend() functions instead.
Many programs use 'char' type (with sign extention) for input characters
and sign extention becomes _STANDOUT mode in this case.
So, I refuse this future and allow 8-bit characters for programs,
which is designed for 7-bit only ('char' type using instead of
'unsigned char').
---
This small patch fix unpleasant standard curses bug:
curses can't expand TAB at all (but tries).
A man who wrote this curses misplace SYNC_IN and SYNCH_OUT,
this patch exchange macro calls.
This patch useful for standard 7-bit curses too, for this
you must delete '_' symbol before waddbytes and apply patch.
---
Oh, NO! This curses are really buggy!
This small patch fix following problem:
[ assumed scrollok(stdscr, TRUE) ]
when addch(ch) at lower right corner of screen, curses are realy
gone mad instead if simple scrolling... Curses code assumed that
this will be done correctly, but implement it with two bugs.
20 files changed:
+waddbytes(win, bytes, count)
+reg WINDOW *win;
+reg char *bytes;
+int count;
+{
+ chtype c;
+ reg int i;
+
+ for (i = 0; i < count; i++) {
+ c = (unsigned char) *bytes++;
+ if (_waddbytes(win, &c, 1) == ERR)
+ return ERR;
+ }
+ return OK;
+}
+
/*
* This routine adds the character to the current position
*
*/
/*
* This routine adds the character to the current position
*
*/
-waddbytes(win, bytes, count)
+_waddbytes(win, bytes, count)
reg int count;
{
#define SYNCH_OUT() {win->_cury = y; win->_curx = x;}
reg int count;
{
#define SYNCH_OUT() {win->_cury = y; win->_curx = x;}
reg int newx;
SYNCH_IN();
reg int newx;
SYNCH_IN();
-# ifdef FULLDEBUG
- fprintf(outf, "ADDBYTES('%c') at (%d, %d)\n", c, y, x);
-# endif
- register int c;
- static char blanks[] = " ";
+ register chtype c;
+ static chtype blanks[] = {' ',' ',' ',' ',' ',' ',' ',' '};
c = *bytes++;
switch (c) {
case '\t':
c = *bytes++;
switch (c) {
case '\t':
- SYNCH_IN();
- if (waddbytes(win, blanks, 8-(x%8)) == ERR) {
+ SYNCH_OUT();
+ if (_waddbytes(win, blanks, 8-(x%8)) == ERR) {
newline:
if (++y >= win->_maxy)
if (win->_scroll) {
newline:
if (++y >= win->_maxy)
if (win->_scroll) {
SYNCH_OUT();
scroll(win);
SYNCH_IN();
SYNCH_OUT();
scroll(win);
SYNCH_IN();
*/
waddch(win, c)
WINDOW *win;
*/
waddch(win, c)
WINDOW *win;
- return waddbytes(win, &c, 1);
+ chtype ch = (unsigned char) c;
+ return _waddbytes(win, &ch, 1);
*/
waddstr(win,str)
reg WINDOW *win;
*/
waddstr(win,str)
reg WINDOW *win;
+ chtype c;
+ reg char *s;
# ifdef DEBUG
fprintf(outf, "WADDSTR(\"%s\")\n", str);
# endif
# ifdef DEBUG
fprintf(outf, "WADDSTR(\"%s\")\n", str);
# endif
- return waddbytes(win, str, strlen(str));
+ for (s = str; *s;) {
+ c = (unsigned char) *s++;
+ if (_waddbytes(win, &c, 1) == ERR)
+ return ERR;
+ }
+ return OK;
*/
box(win, vert, hor)
reg WINDOW *win;
*/
box(win, vert, hor)
reg WINDOW *win;
reg int i;
reg int endy, endx;
reg int i;
reg int endy, endx;
endx = win->_maxx;
endy = win->_maxy - 1;
fp = win->_y[0];
lp = win->_y[endy];
for (i = 0; i < endx; i++)
endx = win->_maxx;
endy = win->_maxy - 1;
fp = win->_y[0];
lp = win->_y[endy];
for (i = 0; i < endx; i++)
+ fp[i] = lp[i] = (unsigned char) hor;
endx--;
for (i = 0; i <= endy; i++)
endx--;
for (i = 0; i <= endy; i++)
- win->_y[i][0] = (win->_y[i][endx] = vert);
+ win->_y[i][0] = (win->_y[i][endx] = (unsigned char) vert);
if (!win->_scroll && (win->_flags&_SCROLLWIN))
fp[0] = fp[endx] = lp[0] = lp[endx] = ' ';
touchwin(win);
if (!win->_scroll && (win->_flags&_SCROLLWIN))
fp[0] = fp[endx] = lp[0] = lp[endx] = ' ';
touchwin(win);
reg WINDOW *win; {
reg int y;
reg WINDOW *win; {
reg int y;
- reg char *sp, *end, *maxx;
+ reg chtype *sp, *end, *maxx;
reg int startx, minx;
startx = win->_curx;
reg int startx, minx;
startx = win->_curx;
wclrtoeol(win)
reg WINDOW *win; {
wclrtoeol(win)
reg WINDOW *win; {
reg int minx;
y = win->_cury;
reg int minx;
y = win->_cury;
{
register int i, j, k;
register int soutcol, soutline;
{
register int i, j, k;
register int soutcol, soutline;
plodcnt = plodflg = cnt;
soutcol = outcol;
plodcnt = plodflg = cnt;
soutcol = outcol;
if (plodflg) /* avoid a complex calculation */
plodcnt--;
else {
if (plodflg) /* avoid a complex calculation */
plodcnt--;
else {
- i = curscr->_y[outline][outcol];
- if ((i&_STANDOUT) == (curscr->_flags&_STANDOUT))
- _putchar(i & 0177);
+ ch = curscr->_y[outline][outcol];
+ if ((ch&_STANDOUT) == (curscr->_flags&_STANDOUT))
+ _putchar(ch);
#define bool char
#define reg register
#define bool char
#define reg register
+typedef unsigned short chtype;
+
#define TRUE (1)
#define FALSE (0)
#define ERR (0)
#define TRUE (1)
#define FALSE (0)
#define ERR (0)
#define _FLUSH 010
#define _FULLLINE 020
#define _IDLINE 040
#define _FLUSH 010
#define _FULLLINE 020
#define _IDLINE 040
#define _NOCHANGE -1
#define _puts(s) tputs(s, 0, _putchar)
#define _NOCHANGE -1
#define _puts(s) tputs(s, 0, _putchar)
bool _clear;
bool _leave;
bool _scroll;
bool _clear;
bool _leave;
bool _scroll;
short *_firstch;
short *_lastch;
struct _win_st *_nextp, *_orig;
short *_firstch;
short *_lastch;
struct _win_st *_nextp, *_orig;
#define addch(ch) VOID(waddch(stdscr, ch))
#define getch() VOID(wgetch(stdscr))
#define addbytes(da,co) VOID(waddbytes(stdscr, da,co))
#define addch(ch) VOID(waddch(stdscr, ch))
#define getch() VOID(wgetch(stdscr))
#define addbytes(da,co) VOID(waddbytes(stdscr, da,co))
-#define addstr(str) VOID(waddbytes(stdscr, str, strlen(str)))
+#define addstr(str) VOID(waddstr(stdscr, str))
#define getstr(str) VOID(wgetstr(stdscr, str))
#define move(y, x) VOID(wmove(stdscr, y, x))
#define clear() VOID(wclear(stdscr))
#define getstr(str) VOID(wgetstr(stdscr, str))
#define move(y, x) VOID(wmove(stdscr, y, x))
#define clear() VOID(wclear(stdscr))
#define mvwaddbytes(win,y,x,da,co) \
VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
#define mvwaddstr(win,y,x,str) \
#define mvwaddbytes(win,y,x,da,co) \
VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
#define mvwaddstr(win,y,x,str) \
- VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,str,strlen(str)))
+ VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str))
#define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
#define mvwinch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
#define mvwdelch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
#define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
#define mvwinch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
#define mvwdelch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
#define scrollok(win,bf) (win->_scroll = bf)
#define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
#define getyx(win,y,x) y = win->_cury, x = win->_curx
#define scrollok(win,bf) (win->_scroll = bf)
#define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
#define getyx(win,y,x) y = win->_cury, x = win->_curx
-#define winch(win) (win->_y[win->_cury][win->_curx] & 0177)
+#define winch(win) (win->_y[win->_cury][win->_curx] & 0xFF)
#define raw() (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, \
ioctl(_tty_ch, TIOCSETP, &_tty))
#define raw() (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, \
ioctl(_tty_ch, TIOCSETP, &_tty))
wdelch(win)
reg WINDOW *win; {
wdelch(win)
reg WINDOW *win; {
- reg char *temp1, *temp2;
- reg char *end;
- reg int lch;
+ reg chtype *temp1, *temp2;
+ reg chtype *end;
end = &win->_y[win->_cury][win->_maxx - 1];
temp1 = &win->_y[win->_cury][win->_curx];
end = &win->_y[win->_cury][win->_maxx - 1];
temp1 = &win->_y[win->_cury][win->_curx];
wdeleteln(win)
reg WINDOW *win;
{
wdeleteln(win)
reg WINDOW *win;
{
if (win->_orig == NULL)
win->_y[y] = win->_y[y + 1];
else
if (win->_orig == NULL)
win->_y[y] = win->_y[y + 1];
else
- bcopy(win->_y[y + 1], win->_y[y], win->_maxx);
+ bcopy(win->_y[y + 1], win->_y[y], win->_maxx * sizeof(chtype));
touchline(win, y, 0, win->_maxx - 1);
}
if (win->_orig == NULL)
touchline(win, y, 0, win->_maxx - 1);
}
if (win->_orig == NULL)
temp = win->_y[y];
for (end = &temp[win->_maxx]; temp < end; )
*temp++ = ' ';
temp = win->_y[y];
for (end = &temp[win->_maxx]; temp < end; )
*temp++ = ' ';
- touchline(win, win->_cury, 0, win->_maxx - 1);
+ touchline(win, y, 0, win->_maxx - 1);
if (win->_orig == NULL)
_id_subwins(win);
return OK;
if (win->_orig == NULL)
_id_subwins(win);
return OK;
reg WINDOW *win; {
reg int y;
reg WINDOW *win; {
reg int y;
- reg char *sp, *end, *start, *maxx;
+ reg chtype *sp, *end, *start, *maxx;
reg int minx;
# ifdef DEBUG
reg int minx;
# ifdef DEBUG
reg WINDOW *win; {
reg bool weset = FALSE;
reg WINDOW *win; {
reg bool weset = FALSE;
if (!win->_scroll && (win->_flags&_FULLWIN)
&& win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1)
if (!win->_scroll && (win->_flags&_FULLWIN)
&& win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1)
weset++;
}
inp = getchar();
weset++;
}
inp = getchar();
# ifdef DEBUG
fprintf(outf,"WGETCH got '%s'\n",unctrl(inp));
# endif
if (_echoit) {
mvwaddch(curscr, win->_cury + win->_begy,
# ifdef DEBUG
fprintf(outf,"WGETCH got '%s'\n",unctrl(inp));
# endif
if (_echoit) {
mvwaddch(curscr, win->_cury + win->_begy,
- win->_curx + win->_begx, inp);
- waddch(win, inp);
+ win->_curx + win->_begx, (unsigned char) inp);
+ waddch(win, (unsigned char) inp);
+ }
wgetstr(win,str)
reg WINDOW *win;
reg char *str; {
wgetstr(win,str)
reg WINDOW *win;
reg char *str; {
- while ((*str = wgetch(win)) != ERR && *str != '\n')
- str++;
- if (*str == ERR) {
+ while ((c = wgetch(win)) != ERR && c != EOF && c != '\n')
+ *str++ = c;
*/
winsch(win, c)
reg WINDOW *win;
*/
winsch(win, c)
reg WINDOW *win;
- reg char *temp1, *temp2;
- reg char *end;
+ reg chtype *temp1, *temp2;
+ reg chtype *end;
end = &win->_y[win->_cury][win->_curx];
temp1 = &win->_y[win->_cury][win->_maxx - 1];
temp2 = temp1 - 1;
while (temp1 > end)
*temp1-- = *temp2--;
end = &win->_y[win->_cury][win->_curx];
temp1 = &win->_y[win->_cury][win->_maxx - 1];
temp2 = temp1 - 1;
while (temp1 > end)
*temp1-- = *temp2--;
+ *temp1 = (unsigned char) c;
touchline(win, win->_cury, win->_curx, win->_maxx - 1);
if (win->_cury == LINES - 1 && win->_y[LINES-1][COLS-1] != ' ')
if (win->_scroll) {
touchline(win, win->_cury, win->_curx, win->_maxx - 1);
if (win->_cury == LINES - 1 && win->_y[LINES-1][COLS-1] != ' ')
if (win->_scroll) {
winsertln(win)
reg WINDOW *win; {
winsertln(win)
reg WINDOW *win; {
if (win->_orig == NULL)
win->_y[y] = win->_y[y - 1];
else
if (win->_orig == NULL)
win->_y[y] = win->_y[y - 1];
else
- bcopy(win->_y[y - 1], win->_y[y], win->_maxx);
+ bcopy(win->_y[y - 1], win->_y[y], win->_maxx * sizeof(chtype));
touchline(win, y, 0, win->_maxx - 1);
}
if (win->_orig == NULL)
touchline(win, y, 0, win->_maxx - 1);
}
if (win->_orig == NULL)
int num_lines, num_cols, begy, begx;
{
reg WINDOW *win;
int num_lines, num_cols, begy, begx;
{
reg WINDOW *win;
reg int i, by, bx, nl, nc;
reg int j;
reg int i, by, bx, nl, nc;
reg int j;
win->_lastch[i] = _NOCHANGE;
}
for (i = 0; i < nl; i++)
win->_lastch[i] = _NOCHANGE;
}
for (i = 0; i < nl; i++)
- if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) {
+ if ((win->_y[i] = (chtype *) malloc(nc * sizeof(chtype))) == NULL) {
for (j = 0; j < i; j++)
free(win->_y[j]);
free(win->_firstch);
for (j = 0; j < i; j++)
free(win->_y[j]);
free(win->_firstch);
# ifdef DEBUG
fprintf(outf, "MAKENEW: nl = %d\n", nl);
# endif
# ifdef DEBUG
fprintf(outf, "MAKENEW: nl = %d\n", nl);
# endif
- if ((win->_y = (char **) malloc(nl * sizeof win->_y[0])) == NULL) {
+ if ((win->_y = (chtype **) malloc(nl * sizeof(chtype *))) == NULL) {
free(win);
return NULL;
}
free(win);
return NULL;
}
#endif /* not lint */
# include "curses.ext"
#endif /* not lint */
# include "curses.ext"
# define min(a,b) (a < b ? a : b)
# define max(a,b) (a > b ? a : b)
# define min(a,b) (a < b ? a : b)
# define max(a,b) (a > b ? a : b)
overlay(win1, win2)
reg WINDOW *win1, *win2; {
overlay(win1, win2)
reg WINDOW *win1, *win2; {
reg int x, y, endy, endx, starty, startx;
reg int y1,y2;
reg int x, y, endy, endx, starty, startx;
reg int y1,y2;
end = &win1->_y[y1][endx - win1->_begx];
x = startx - win2->_begx;
for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) {
end = &win1->_y[y1][endx - win1->_begx];
x = startx - win2->_begx;
for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) {
mvwaddch(win2, y2, x, *sp);
x++;
}
mvwaddch(win2, y2, x, *sp);
x++;
}
overwrite(win1, win2)
reg WINDOW *win1, *win2; {
overwrite(win1, win2)
reg WINDOW *win1, *win2; {
reg int x, y, endy, endx, starty, startx;
# ifdef DEBUG
reg int x, y, endy, endx, starty, startx;
# ifdef DEBUG
x = endx - startx;
for (y = starty; y < endy; y++) {
bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
x = endx - startx;
for (y = starty; y < endy; y++) {
bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
- &win2->_y[y - win2->_begy][startx - win2->_begx], x);
+ &win2->_y[y - win2->_begy][startx - win2->_begx], x * sizeof(chtype));
touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
}
}
touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
}
}
register int c = n;
while (--c >= 0) {
register int c = n;
while (--c >= 0) {
- if (waddch(win, *buf++) == ERR)
+ if (waddch(win, (unsigned char) *buf++) == ERR)
reg WINDOW *win;
short wy;
{
reg WINDOW *win;
short wy;
{
- reg char *nsp, *csp, *ce;
+ reg chtype *nsp, *csp, *ce;
reg short wx, lch, y;
reg int nlsp, clsp; /* last space in lines */
reg short wx, lch, y;
reg int nlsp, clsp; /* last space in lines */
+ char *ce_tcap;
+ static chtype blank[] = {' ','\0'};
wx = win->_firstch[wy] - win->_ch_off;
if (wx >= win->_maxx)
wx = win->_firstch[wy] - win->_ch_off;
if (wx >= win->_maxx)
y = wy + win->_begy;
if (curwin)
y = wy + win->_begy;
if (curwin)
else
csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
else
csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
while (wx <= lch) {
if (*nsp != *csp) {
while (wx <= lch) {
if (*nsp != *csp) {
ly = y;
lx = wx + win->_begx;
while (*nsp != *csp && wx <= lch) {
ly = y;
lx = wx + win->_begx;
while (*nsp != *csp && wx <= lch) {
- if (ce != NULL && wx >= nlsp && *nsp == ' ') {
+ if (ce_tcap != NULL && wx >= nlsp && *nsp == ' ') {
/*
* check for clear to end-of-line
*/
/*
* check for clear to end-of-line
*/
*csp++ = ' ';
return OK;
}
*csp++ = ' ';
return OK;
}
}
/*
* enter/exit standout mode as appropriate
}
/*
* enter/exit standout mode as appropriate
curscr->_flags &= ~_STANDOUT;
}
if (!curwin)
curscr->_flags &= ~_STANDOUT;
}
if (!curwin)
- _putchar((*csp = *nsp) & 0177);
+ _putchar((*csp = *nsp));
if (win->_flags&_FULLWIN && !curwin)
scroll(curscr);
ly = win->_begy+win->_cury;
if (win->_flags&_FULLWIN && !curwin)
scroll(curscr);
ly = win->_begy+win->_cury;
return ERR;
}
if (!curwin)
return ERR;
}
if (!curwin)
- _putchar((*csp++ = *nsp) & 0177);
+ _putchar((*csp++ = *nsp));
# ifdef FULLDEBUG
fprintf(outf,
# ifdef FULLDEBUG
fprintf(outf,
- "MAKECH:putchar(%c)\n", *nsp & 0177);
+ "MAKECH:putchar(%c)\n", *nsp);
# endif
if (UC && (*nsp & _STANDOUT)) {
_putchar('\b');
# endif
if (UC && (*nsp & _STANDOUT)) {
_putchar('\b');