1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3*0Sstevel@tonic-gate * Use is subject to license terms.
4*0Sstevel@tonic-gate */
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7*0Sstevel@tonic-gate /* All Rights Reserved */
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate /*
10*0Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
11*0Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
12*0Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
13*0Sstevel@tonic-gate */
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate #ifndef lint
18*0Sstevel@tonic-gate static char
19*0Sstevel@tonic-gate sccsid[] = "@(#)addch.c 1.6 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
20*0Sstevel@tonic-gate #endif /* not lint */
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gate #include "curses.ext"
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gate /* forward declaration */
25*0Sstevel@tonic-gate static void set_ch(WINDOW *, int, int, int);
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate * This routine adds the character to the current position
29*0Sstevel@tonic-gate */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate int
waddch(WINDOW * win,char c)32*0Sstevel@tonic-gate waddch(WINDOW *win, char c)
33*0Sstevel@tonic-gate {
34*0Sstevel@tonic-gate int x, y;
35*0Sstevel@tonic-gate int newx;
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate x = win->_curx;
38*0Sstevel@tonic-gate y = win->_cury;
39*0Sstevel@tonic-gate #ifdef FULLDEBUG
40*0Sstevel@tonic-gate fprintf(outf, "ADDCH('%c') at (%d, %d)\n", c, y, x);
41*0Sstevel@tonic-gate #endif
42*0Sstevel@tonic-gate switch (c) {
43*0Sstevel@tonic-gate case '\t':
44*0Sstevel@tonic-gate for (newx = x + (8 - (x & 07)); x < newx; x++)
45*0Sstevel@tonic-gate if (waddch(win, ' ') == ERR)
46*0Sstevel@tonic-gate return (ERR);
47*0Sstevel@tonic-gate return (OK);
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate default:
50*0Sstevel@tonic-gate #ifdef FULLDEBUG
51*0Sstevel@tonic-gate fprintf(outf, "ADDCH: 1: y = %d, x = %d, firstch = %d,"
52*0Sstevel@tonic-gate " lastch = %d\n", y, x, win->_firstch[y],
53*0Sstevel@tonic-gate win->_lastch[y]);
54*0Sstevel@tonic-gate #endif
55*0Sstevel@tonic-gate if (win->_flags & _STANDOUT)
56*0Sstevel@tonic-gate c |= _STANDOUT;
57*0Sstevel@tonic-gate set_ch(win, y, x, c);
58*0Sstevel@tonic-gate win->_y[y][x++] = c;
59*0Sstevel@tonic-gate if (x >= win->_maxx) {
60*0Sstevel@tonic-gate x = 0;
61*0Sstevel@tonic-gate newline:
62*0Sstevel@tonic-gate if (++y >= win->_maxy)
63*0Sstevel@tonic-gate if (win->_scroll) {
64*0Sstevel@tonic-gate (void) scroll(win);
65*0Sstevel@tonic-gate --y;
66*0Sstevel@tonic-gate }
67*0Sstevel@tonic-gate else
68*0Sstevel@tonic-gate return (ERR);
69*0Sstevel@tonic-gate }
70*0Sstevel@tonic-gate #ifdef FULLDEBUG
71*0Sstevel@tonic-gate fprintf(outf, "ADDCH: 2: y = %d, x = %d, firstch = %d,"
72*0Sstevel@tonic-gate " lastch = %d\n", y, x, win->_firstch[y],
73*0Sstevel@tonic-gate win->_lastch[y]);
74*0Sstevel@tonic-gate #endif
75*0Sstevel@tonic-gate break;
76*0Sstevel@tonic-gate case '\n':
77*0Sstevel@tonic-gate (void) wclrtoeol(win);
78*0Sstevel@tonic-gate if (!NONL)
79*0Sstevel@tonic-gate x = 0;
80*0Sstevel@tonic-gate goto newline;
81*0Sstevel@tonic-gate case '\r':
82*0Sstevel@tonic-gate x = 0;
83*0Sstevel@tonic-gate break;
84*0Sstevel@tonic-gate case '\b':
85*0Sstevel@tonic-gate if (--x < 0)
86*0Sstevel@tonic-gate x = 0;
87*0Sstevel@tonic-gate break;
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate win->_curx = (short)x;
90*0Sstevel@tonic-gate win->_cury = (short)y;
91*0Sstevel@tonic-gate return (OK);
92*0Sstevel@tonic-gate }
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate /*
95*0Sstevel@tonic-gate * set_ch:
96*0Sstevel@tonic-gate * Set the first and last change flags for this window.
97*0Sstevel@tonic-gate */
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate static void
set_ch(WINDOW * win,int y,int x,int ch)100*0Sstevel@tonic-gate set_ch(WINDOW *win, int y, int x, int ch)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate #ifdef FULLDEBUG
103*0Sstevel@tonic-gate fprintf(outf, "SET_CH(%0.2o, %d, %d)\n", win, y, x);
104*0Sstevel@tonic-gate #endif
105*0Sstevel@tonic-gate if (win->_y[y][x] != ch) {
106*0Sstevel@tonic-gate x += win->_ch_off;
107*0Sstevel@tonic-gate if (win->_firstch[y] == _NOCHANGE)
108*0Sstevel@tonic-gate win->_firstch[y] = win->_lastch[y] = (short)x;
109*0Sstevel@tonic-gate else if (x < win->_firstch[y])
110*0Sstevel@tonic-gate win->_firstch[y] = (short)x;
111*0Sstevel@tonic-gate else if (x > win->_lastch[y])
112*0Sstevel@tonic-gate win->_lastch[y] = (short)x;
113*0Sstevel@tonic-gate #ifdef FULLDEBUG
114*0Sstevel@tonic-gate fprintf(outf, "SET_CH: change gives f/l: %d/%d [%d/%d]\n",
115*0Sstevel@tonic-gate win->_firstch[y], win->_lastch[y],
116*0Sstevel@tonic-gate win->_firstch[y] - win->_ch_off,
117*0Sstevel@tonic-gate win->_lastch[y] - win->_ch_off);
118*0Sstevel@tonic-gate #endif
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate }
121