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