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