|
|
1.1 root 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: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)addbytes.c 5.4 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: # include "curses.ext"
25:
26: /*
27: * This routine adds the character to the current position
28: *
29: */
30: waddbytes(win, bytes, count)
31: reg WINDOW *win;
32: reg char *bytes;
33: reg int count;
34: {
35: #define SYNCH_OUT() {win->_cury = y; win->_curx = x;}
36: #define SYNCH_IN() {y = win->_cury; x = win->_curx;}
37: reg int x, y;
38: reg int newx;
39:
40: SYNCH_IN();
41: # ifdef FULLDEBUG
42: fprintf(outf, "ADDBYTES('%c') at (%d, %d)\n", c, y, x);
43: # endif
44: while (count--) {
45: register int c;
46: static char blanks[] = " ";
47:
48: c = *bytes++;
49: switch (c) {
50: case '\t':
51: SYNCH_IN();
52: if (waddbytes(win, blanks, 8-(x%8)) == ERR) {
53: return ERR;
54: }
55: SYNCH_OUT();
56: break;
57:
58: default:
59: # ifdef FULLDEBUG
60: fprintf(outf, "ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
61: # endif
62: if (win->_flags & _STANDOUT)
63: c |= _STANDOUT;
64: {
65: # ifdef FULLDEBUG
66: fprintf(outf, "ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
67: # endif
68: if (win->_y[y][x] != c) {
69: newx = x + win->_ch_off;
70: if (win->_firstch[y] == _NOCHANGE) {
71: win->_firstch[y] =
72: win->_lastch[y] = newx;
73: } else if (newx < win->_firstch[y])
74: win->_firstch[y] = newx;
75: else if (newx > win->_lastch[y])
76: win->_lastch[y] = newx;
77: # ifdef FULLDEBUG
78: fprintf(outf, "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
79: win->_firstch[y], win->_lastch[y],
80: win->_firstch[y] - win->_ch_off,
81: win->_lastch[y] - win->_ch_off);
82: # endif
83: }
84: }
85: win->_y[y][x++] = c;
86: if (x >= win->_maxx) {
87: x = 0;
88: newline:
89: if (++y >= win->_maxy)
90: if (win->_scroll) {
91: SYNCH_OUT();
92: scroll(win);
93: SYNCH_IN();
94: --y;
95: }
96: else
97: return ERR;
98: }
99: # ifdef FULLDEBUG
100: fprintf(outf, "ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
101: # endif
102: break;
103: case '\n':
104: SYNCH_OUT();
105: wclrtoeol(win);
106: SYNCH_IN();
107: if (!NONL)
108: x = 0;
109: goto newline;
110: case '\r':
111: x = 0;
112: break;
113: case '\b':
114: if (--x < 0)
115: x = 0;
116: break;
117: }
118: }
119: SYNCH_OUT();
120: return OK;
121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.