|
|
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 the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef COHERENT
19: #ifndef lint
20: static uchar sccsid[] = "@(#)addbytes.c 5.3 (Berkeley) 6/30/88";
21: #endif /* not lint */
22: #endif /* not COHERENT */
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 uchar *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 uchar blanks[] = " ";
47:
48: c = *bytes++;
49: switch (c) {
50: case '\t':
51: SYNCH_OUT();
52: if (waddbytes(win, blanks, 8-(x%8)) == ERR) {
53: return ERR;
54: }
55: SYNCH_IN();
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.