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