diff options
| author | alm <alm@NetBSD.org> | 1993-07-09 05:34:14 +0000 |
|---|---|---|
| committer | alm <alm@NetBSD.org> | 1993-07-09 05:34:14 +0000 |
| commit | 75de25bb937aed7d7fbdbd3a822fbc03d8bf6a08 (patch) | |
| tree | a8a314f717e88a1f7fb1700d111d7263e416f95a /lib/libcurses | |
| parent | cb880ccb9480246e8ba2026db43f12f1f2e8dde8 (diff) | |
added Andrew Chernov's patch set:
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.
Diffstat (limited to 'lib/libcurses')
| -rw-r--r-- | lib/libcurses/addbytes.c | 31 | ||||
| -rw-r--r-- | lib/libcurses/addch.c | 5 | ||||
| -rw-r--r-- | lib/libcurses/addstr.c | 11 | ||||
| -rw-r--r-- | lib/libcurses/box.c | 8 | ||||
| -rw-r--r-- | lib/libcurses/clrtobot.c | 2 | ||||
| -rw-r--r-- | lib/libcurses/clrtoeol.c | 4 | ||||
| -rw-r--r-- | lib/libcurses/cr_put.c | 7 | ||||
| -rw-r--r-- | lib/libcurses/curses.h | 12 | ||||
| -rw-r--r-- | lib/libcurses/delch.c | 5 | ||||
| -rw-r--r-- | lib/libcurses/deleteln.c | 8 | ||||
| -rw-r--r-- | lib/libcurses/erase.c | 2 | ||||
| -rw-r--r-- | lib/libcurses/getch.c | 8 | ||||
| -rw-r--r-- | lib/libcurses/getstr.c | 9 | ||||
| -rw-r--r-- | lib/libcurses/insch.c | 8 | ||||
| -rw-r--r-- | lib/libcurses/insertln.c | 6 | ||||
| -rw-r--r-- | lib/libcurses/newwin.c | 6 | ||||
| -rw-r--r-- | lib/libcurses/overlay.c | 5 | ||||
| -rw-r--r-- | lib/libcurses/overwrite.c | 3 | ||||
| -rw-r--r-- | lib/libcurses/printw.c | 2 | ||||
| -rw-r--r-- | lib/libcurses/refresh.c | 24 |
20 files changed, 95 insertions, 71 deletions
diff --git a/lib/libcurses/addbytes.c b/lib/libcurses/addbytes.c index 0ddc5f084cb..3d47b326acf 100644 --- a/lib/libcurses/addbytes.c +++ b/lib/libcurses/addbytes.c @@ -37,13 +37,29 @@ static char sccsid[] = "@(#)addbytes.c 5.4 (Berkeley) 6/1/90"; # include "curses.ext" +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 * */ -waddbytes(win, bytes, count) +_waddbytes(win, bytes, count) reg WINDOW *win; -reg char *bytes; +reg chtype *bytes; reg int count; { #define SYNCH_OUT() {win->_cury = y; win->_curx = x;} @@ -52,18 +68,15 @@ reg int count; reg int newx; SYNCH_IN(); -# ifdef FULLDEBUG - fprintf(outf, "ADDBYTES('%c') at (%d, %d)\n", c, y, x); -# endif while (count--) { - register int c; - static char blanks[] = " "; + register chtype c; + static chtype blanks[] = {' ',' ',' ',' ',' ',' ',' ',' '}; c = *bytes++; switch (c) { case '\t': SYNCH_OUT(); - if (waddbytes(win, blanks, 8-(x%8)) == ERR) { + if (_waddbytes(win, blanks, 8-(x%8)) == ERR) { return ERR; } SYNCH_IN(); @@ -102,10 +115,10 @@ reg int count; newline: if (++y >= win->_maxy) if (win->_scroll) { + --y; SYNCH_OUT(); scroll(win); SYNCH_IN(); - --y; } else return ERR; diff --git a/lib/libcurses/addch.c b/lib/libcurses/addch.c index 897660a9849..027c4bf9447 100644 --- a/lib/libcurses/addch.c +++ b/lib/libcurses/addch.c @@ -43,7 +43,8 @@ static char sccsid[] = "@(#)addch.c 5.5 (Berkeley) 6/1/90"; */ waddch(win, c) WINDOW *win; -char c; +char c; { - return waddbytes(win, &c, 1); + chtype ch = (unsigned char) c; + return _waddbytes(win, &ch, 1); } diff --git a/lib/libcurses/addstr.c b/lib/libcurses/addstr.c index 0d442672d48..025fd43d4a0 100644 --- a/lib/libcurses/addstr.c +++ b/lib/libcurses/addstr.c @@ -43,10 +43,17 @@ static char sccsid[] = "@(#)addstr.c 5.5 (Berkeley) 6/1/90"; */ waddstr(win,str) reg WINDOW *win; -reg char *str; +char *str; { + chtype c; + reg char *s; # 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; } diff --git a/lib/libcurses/box.c b/lib/libcurses/box.c index 7c6532ae4c0..983ed66621c 100644 --- a/lib/libcurses/box.c +++ b/lib/libcurses/box.c @@ -44,21 +44,21 @@ static char sccsid[] = "@(#)box.c 5.4 (Berkeley) 6/1/90"; */ box(win, vert, hor) reg WINDOW *win; -char vert, hor; { +char vert, hor; { reg int i; reg int endy, endx; - reg char *fp, *lp; + reg chtype *fp, *lp; 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] = hor; + fp[i] = lp[i] = (unsigned char) hor; 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); diff --git a/lib/libcurses/clrtobot.c b/lib/libcurses/clrtobot.c index e2635ba356f..86324389956 100644 --- a/lib/libcurses/clrtobot.c +++ b/lib/libcurses/clrtobot.c @@ -45,7 +45,7 @@ wclrtobot(win) reg WINDOW *win; { reg int y; - reg char *sp, *end, *maxx; + reg chtype *sp, *end, *maxx; reg int startx, minx; startx = win->_curx; diff --git a/lib/libcurses/clrtoeol.c b/lib/libcurses/clrtoeol.c index 472652e4cd1..6af2bfceded 100644 --- a/lib/libcurses/clrtoeol.c +++ b/lib/libcurses/clrtoeol.c @@ -44,9 +44,9 @@ static char sccsid[] = "@(#)clrtoeol.c 5.4 (Berkeley) 6/1/90"; wclrtoeol(win) reg WINDOW *win; { - reg char *sp, *end; + reg chtype *sp, *end; reg int y, x; - reg char *maxx; + reg chtype *maxx; reg int minx; y = win->_cury; diff --git a/lib/libcurses/cr_put.c b/lib/libcurses/cr_put.c index 26c1f89384b..c9d0e79134f 100644 --- a/lib/libcurses/cr_put.c +++ b/lib/libcurses/cr_put.c @@ -180,6 +180,7 @@ plod(cnt) { register int i, j, k; register int soutcol, soutline; + chtype ch; plodcnt = plodflg = cnt; soutcol = outcol; @@ -373,9 +374,9 @@ dontcr: 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); else goto nondes; } diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index 3c71191029d..e845bb22878 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -44,6 +44,8 @@ #define bool char #define reg register +typedef unsigned short chtype; + #define TRUE (1) #define FALSE (0) #define ERR (0) @@ -55,7 +57,7 @@ #define _FLUSH 010 #define _FULLLINE 020 #define _IDLINE 040 -#define _STANDOUT 0200 +#define _STANDOUT 0400 #define _NOCHANGE -1 #define _puts(s) tputs(s, 0, _putchar) @@ -92,7 +94,7 @@ struct _win_st { bool _clear; bool _leave; bool _scroll; - char **_y; + chtype **_y; short *_firstch; short *_lastch; struct _win_st *_nextp, *_orig; @@ -127,7 +129,7 @@ int __void__; #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)) @@ -151,7 +153,7 @@ int __void__; #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)) @@ -174,7 +176,7 @@ int __void__; #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)) diff --git a/lib/libcurses/delch.c b/lib/libcurses/delch.c index 2347549db3d..23499eb5549 100644 --- a/lib/libcurses/delch.c +++ b/lib/libcurses/delch.c @@ -45,9 +45,8 @@ static char sccsid[] = "@(#)delch.c 5.4 (Berkeley) 6/1/90"; 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]; diff --git a/lib/libcurses/deleteln.c b/lib/libcurses/deleteln.c index d5cb57dd0df..ba5d4819743 100644 --- a/lib/libcurses/deleteln.c +++ b/lib/libcurses/deleteln.c @@ -45,9 +45,9 @@ static char sccsid[] = "@(#)deleteln.c 5.4 (Berkeley) 6/1/90"; wdeleteln(win) reg WINDOW *win; { - reg char *temp; + reg chtype *temp; reg int y; - reg char *end; + reg chtype *end; reg int x; # ifdef DEBUG @@ -58,7 +58,7 @@ reg WINDOW *win; 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) @@ -67,7 +67,7 @@ reg WINDOW *win; 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; diff --git a/lib/libcurses/erase.c b/lib/libcurses/erase.c index c700ef272bb..9cbd79e7fd4 100644 --- a/lib/libcurses/erase.c +++ b/lib/libcurses/erase.c @@ -45,7 +45,7 @@ werase(win) reg WINDOW *win; { reg int y; - reg char *sp, *end, *start, *maxx; + reg chtype *sp, *end, *start, *maxx; reg int minx; # ifdef DEBUG diff --git a/lib/libcurses/getch.c b/lib/libcurses/getch.c index 95b3875243f..d3e04d08f66 100644 --- a/lib/libcurses/getch.c +++ b/lib/libcurses/getch.c @@ -45,7 +45,7 @@ wgetch(win) reg WINDOW *win; { reg bool weset = FALSE; - reg char inp; + reg int inp; if (!win->_scroll && (win->_flags&_FULLWIN) && win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1) @@ -58,13 +58,15 @@ reg WINDOW *win; { weset++; } inp = getchar(); + if (inp != EOF) { # 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); + } } if (weset) nocbreak(); diff --git a/lib/libcurses/getstr.c b/lib/libcurses/getstr.c index ff09e8dd79a..ec3af26fe7a 100644 --- a/lib/libcurses/getstr.c +++ b/lib/libcurses/getstr.c @@ -44,13 +44,12 @@ static char sccsid[] = "@(#)getstr.c 5.4 (Berkeley) 6/1/90"; wgetstr(win,str) reg WINDOW *win; reg char *str; { + int c; - while ((*str = wgetch(win)) != ERR && *str != '\n') - str++; - if (*str == ERR) { + while ((c = wgetch(win)) != ERR && c != EOF && c != '\n') + *str++ = c; *str = '\0'; + if (c == ERR) return ERR; - } - *str = '\0'; return OK; } diff --git a/lib/libcurses/insch.c b/lib/libcurses/insch.c index d4e160e33c7..5ec1c9a7d86 100644 --- a/lib/libcurses/insch.c +++ b/lib/libcurses/insch.c @@ -44,17 +44,17 @@ static char sccsid[] = "@(#)insch.c 5.4 (Berkeley) 6/1/90"; */ winsch(win, c) reg WINDOW *win; -char c; { +char c; { - 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--; - *temp1 = c; + *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) { diff --git a/lib/libcurses/insertln.c b/lib/libcurses/insertln.c index 7c9d528e743..09b8b435303 100644 --- a/lib/libcurses/insertln.c +++ b/lib/libcurses/insertln.c @@ -45,9 +45,9 @@ static char sccsid[] = "@(#)insertln.c 5.4 (Berkeley) 6/1/90"; winsertln(win) reg WINDOW *win; { - reg char *temp; + reg chtype *temp; reg int y; - reg char *end; + reg chtype *end; reg int x; #ifdef DEBUG @@ -59,7 +59,7 @@ reg WINDOW *win; { 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) diff --git a/lib/libcurses/newwin.c b/lib/libcurses/newwin.c index fc1ae4a2478..dfa7e75e63b 100644 --- a/lib/libcurses/newwin.c +++ b/lib/libcurses/newwin.c @@ -55,7 +55,7 @@ newwin(num_lines, num_cols, begy, begx) int num_lines, num_cols, begy, begx; { reg WINDOW *win; - reg char *sp; + reg chtype *sp; reg int i, by, bx, nl, nc; reg int j; @@ -87,7 +87,7 @@ int num_lines, num_cols, begy, begx; 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); @@ -188,7 +188,7 @@ int num_lines, num_cols, begy, begx; { # 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; } diff --git a/lib/libcurses/overlay.c b/lib/libcurses/overlay.c index 0340d9ea89d..d272c7ba6da 100644 --- a/lib/libcurses/overlay.c +++ b/lib/libcurses/overlay.c @@ -36,7 +36,6 @@ static char sccsid[] = "@(#)overlay.c 5.6 (Berkeley) 6/1/90"; #endif /* not lint */ # include "curses.ext" -# include <ctype.h> # define min(a,b) (a < b ? a : b) # define max(a,b) (a > b ? a : b) @@ -48,7 +47,7 @@ static char sccsid[] = "@(#)overlay.c 5.6 (Berkeley) 6/1/90"; overlay(win1, win2) reg WINDOW *win1, *win2; { - reg char *sp, *end; + reg chtype *sp, *end; reg int x, y, endy, endx, starty, startx; reg int y1,y2; @@ -70,7 +69,7 @@ reg WINDOW *win1, *win2; { end = &win1->_y[y1][endx - win1->_begx]; x = startx - win2->_begx; for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) { - if (!isspace(*sp)) + if (*sp != ' ') mvwaddch(win2, y2, x, *sp); x++; } diff --git a/lib/libcurses/overwrite.c b/lib/libcurses/overwrite.c index c885ab34652..655f923ab26 100644 --- a/lib/libcurses/overwrite.c +++ b/lib/libcurses/overwrite.c @@ -48,7 +48,6 @@ static char sccsid[] = "@(#)overwrite.c 5.4 (Berkeley) 6/1/90"; overwrite(win1, win2) reg WINDOW *win1, *win2; { - reg char *sp, *end; reg int x, y, endy, endx, starty, startx; # ifdef DEBUG @@ -66,7 +65,7 @@ reg WINDOW *win1, *win2; { 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); } } diff --git a/lib/libcurses/printw.c b/lib/libcurses/printw.c index 069b1c64db2..4568c5f4b87 100644 --- a/lib/libcurses/printw.c +++ b/lib/libcurses/printw.c @@ -111,7 +111,7 @@ _winwrite(cookie, buf, n) register int c = n; while (--c >= 0) { - if (waddch(win, *buf++) == ERR) + if (waddch(win, (unsigned char) *buf++) == ERR) return (-1); } return n; diff --git a/lib/libcurses/refresh.c b/lib/libcurses/refresh.c index a4937c56fbc..62673d2f879 100644 --- a/lib/libcurses/refresh.c +++ b/lib/libcurses/refresh.c @@ -169,9 +169,11 @@ makech(win, 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 */ + char *ce_tcap; + static chtype blank[] = {' ','\0'}; wx = win->_firstch[wy] - win->_ch_off; if (wx >= win->_maxx) @@ -186,7 +188,7 @@ short wy; y = wy + win->_begy; if (curwin) - csp = " "; + csp = blank; else csp = &curscr->_y[wy + win->_begy][wx + win->_begx]; @@ -199,9 +201,9 @@ short wy; } if (!curwin) - ce = CE; + ce_tcap = CE; else - ce = NULL; + ce_tcap = NULL; while (wx <= lch) { if (*nsp != *csp) { @@ -212,7 +214,7 @@ short wy; 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 */ @@ -235,7 +237,7 @@ short wy; *csp++ = ' '; return OK; } - ce = NULL; + ce_tcap = NULL; } /* * enter/exit standout mode as appropriate @@ -260,9 +262,9 @@ short wy; curscr->_flags &= ~_STANDOUT; } if (!curwin) - _putchar((*csp = *nsp) & 0177); + _putchar((*csp = *nsp)); else - _putchar(*nsp & 0177); + _putchar(*nsp); if (win->_flags&_FULLWIN && !curwin) scroll(curscr); ly = win->_begy+win->_cury; @@ -274,12 +276,12 @@ short wy; return ERR; } if (!curwin) - _putchar((*csp++ = *nsp) & 0177); + _putchar((*csp++ = *nsp)); else - _putchar(*nsp & 0177); + _putchar(*nsp); # ifdef FULLDEBUG fprintf(outf, - "MAKECH:putchar(%c)\n", *nsp & 0177); + "MAKECH:putchar(%c)\n", *nsp); # endif if (UC && (*nsp & _STANDOUT)) { _putchar('\b'); |
