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