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