only look at stdin, stdout and stderr
[unix-history] / usr / src / lib / libcurses / addch.c
CommitLineData
8b28dacd
KA
1# include "curses.ext"
2
3/*
4 * This routine adds the character to the current position
5 *
f6b7be61 6 * @(#)addch.c 1.6 (Berkeley) %G%
8b28dacd
KA
7 */
8waddch(win, c)
9reg WINDOW *win;
10char c;
11{
12 reg int x, y;
60d72089 13 reg WINDOW *wp;
8b28dacd
KA
14
15 x = win->_curx;
16 y = win->_cury;
17# ifdef FULLDEBUG
18 fprintf(outf, "ADDCH('%c') at (%d, %d)\n", c, y, x);
19# endif
20 if (y >= win->_maxy || x >= win->_maxx || y < 0 || x < 0)
21 return ERR;
22 switch (c) {
23 case '\t':
24 {
25 reg int newx;
26
b7b377b8 27 for (newx = x + (8 - (x & 07)); x < newx; x++)
8b28dacd
KA
28 if (waddch(win, ' ') == ERR)
29 return ERR;
30 return OK;
31 }
60d72089 32
8b28dacd
KA
33 default:
34# ifdef FULLDEBUG
35 fprintf(outf, "ADDCH: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
36# endif
37 if (win->_flags & _STANDOUT)
38 c |= _STANDOUT;
9fcd8c35 39 set_ch(win, y, x, c, NULL);
60d72089 40 for (wp = win->_nextp; wp != win; wp = wp->_nextp)
9fcd8c35 41 set_ch(wp, y, x, c, win);
8b28dacd
KA
42 win->_y[y][x++] = c;
43 if (x >= win->_maxx) {
8b28dacd 44 x = 0;
4ce7bc0f
KA
45newline:
46 if (++y >= win->_maxy)
8b28dacd
KA
47 if (win->_scroll) {
48 wrefresh(win);
49 scroll(win);
50 --y;
51 }
52 else
53 return ERR;
54 }
55# ifdef FULLDEBUG
56 fprintf(outf, "ADDCH: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
57# endif
58 break;
59 case '\n':
60 wclrtoeol(win);
4ce7bc0f
KA
61 if (!NONL)
62 x = 0;
63 goto newline;
8b28dacd
KA
64 case '\r':
65 x = 0;
66 break;
67 case '\b':
68 if (--x < 0)
69 x = 0;
70 break;
71 }
72 win->_curx = x;
73 win->_cury = y;
74 return OK;
75}
60d72089
KA
76
77/*
78 * set_ch:
79 * Set the first and last change flags for this window.
80 */
81static
9fcd8c35 82set_ch(win, y, x, ch, orig)
60d72089 83reg WINDOW *win;
9fcd8c35
KA
84int y, x;
85WINDOW *orig; {
60d72089 86
9fcd8c35
KA
87 if (orig != NULL) {
88 y -= win->_begy - orig->_begy;
89 x -= win->_begx - orig->_begx;
60d72089 90 }
9fcd8c35
KA
91 if (y < 0 || y >= win->_maxy || x < 0 || x >= win->_maxx)
92 return;
60d72089
KA
93 if (win->_y[y][x] != ch) {
94 if (win->_firstch[y] == _NOCHANGE)
f6b7be61 95 win->_firstch[y] = win->_lastch[y] = x + win->_ch_off;
60d72089 96 else if (x < win->_firstch[y])
f6b7be61 97 win->_firstch[y] = x + win->_ch_off;
60d72089 98 else if (x > win->_lastch[y])
f6b7be61 99 win->_lastch[y] = x + win->_ch_off;
60d72089
KA
100 }
101}