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