Commit | Line | Data |
---|---|---|
15637ed4 | 1 | /* |
b80b8de3 AC |
2 | * Copyright (c) 1987, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
15637ed4 RG |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
b80b8de3 AC |
35 | static char sccsid[] = "@(#)addbytes.c 8.2 (Berkeley) 1/9/94"; |
36 | #endif /* not lint */ | |
15637ed4 | 37 | |
b80b8de3 | 38 | #include <curses.h> |
15637ed4 | 39 | |
b80b8de3 AC |
40 | #define SYNCH_IN {y = win->cury; x = win->curx;} |
41 | #define SYNCH_OUT {win->cury = y; win->curx = x;} | |
5b37262a | 42 | |
15637ed4 | 43 | /* |
b80b8de3 AC |
44 | * waddbytes -- |
45 | * Add the character to the current position in the given window. | |
15637ed4 | 46 | */ |
b80b8de3 AC |
47 | int |
48 | __waddbytes(win, bytes, count, so) | |
49 | register WINDOW *win; | |
50 | register const char *bytes; | |
51 | register int count; | |
52 | int so; | |
15637ed4 | 53 | { |
b80b8de3 AC |
54 | static char blanks[] = " "; |
55 | register int c, newx, x, y; | |
56 | char stand; | |
57 | __LINE *lp; | |
15637ed4 | 58 | |
b80b8de3 | 59 | SYNCH_IN; |
15637ed4 | 60 | |
b80b8de3 AC |
61 | #ifdef DEBUG |
62 | __CTRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x); | |
63 | #endif | |
64 | while (count--) { | |
65 | c = *bytes++; | |
66 | switch (c) { | |
67 | case '\t': | |
68 | SYNCH_OUT; | |
69 | if (waddbytes(win, blanks, 8 - (x % 8)) == ERR) | |
70 | return (ERR); | |
71 | SYNCH_IN; | |
72 | break; | |
15637ed4 | 73 | |
b80b8de3 AC |
74 | default: |
75 | #ifdef DEBUG | |
76 | __CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x); | |
77 | #endif | |
78 | ||
79 | lp = win->lines[y]; | |
80 | if (lp->flags & __ISPASTEOL) { | |
81 | lp->flags &= ~__ISPASTEOL; | |
82 | newline: if (y == win->maxy - 1) { | |
83 | if (win->flags & __SCROLLOK) { | |
84 | SYNCH_OUT; | |
85 | scroll(win); | |
86 | SYNCH_IN; | |
87 | lp = win->lines[y]; | |
88 | x = 0; | |
89 | } | |
90 | else | |
91 | return ERR; | |
92 | } else { | |
93 | y++; | |
94 | lp = win->lines[y]; | |
95 | x = 0; | |
96 | } | |
97 | if (c == '\n') | |
98 | break; | |
99 | } | |
100 | ||
101 | stand = '\0'; | |
102 | if (win->flags & __WSTANDOUT || so) | |
103 | stand |= __STANDOUT; | |
104 | #ifdef DEBUG | |
105 | __CTRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", | |
106 | y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp); | |
107 | #endif | |
108 | if (lp->line[x].ch != c || | |
109 | !(lp->line[x].attr & stand)) { | |
110 | newx = x + win->ch_off; | |
111 | if (!(lp->flags & __ISDIRTY)) { | |
112 | lp->flags |= __ISDIRTY; | |
113 | *lp->firstchp = *lp->lastchp = newx; | |
114 | } | |
115 | else if (newx < *lp->firstchp) | |
116 | *lp->firstchp = newx; | |
117 | else if (newx > *lp->lastchp) | |
118 | *lp->lastchp = newx; | |
119 | #ifdef DEBUG | |
120 | __CTRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n", | |
121 | *lp->firstchp, *lp->lastchp, | |
122 | *lp->firstchp - win->ch_off, | |
123 | *lp->lastchp - win->ch_off); | |
124 | #endif | |
125 | } | |
126 | lp->line[x].ch = c; | |
127 | if (stand) | |
128 | lp->line[x].attr |= __STANDOUT; | |
129 | else | |
130 | lp->line[x].attr &= ~__STANDOUT; | |
131 | if (x == win->maxx - 1) | |
132 | lp->flags |= __ISPASTEOL; | |
133 | else | |
134 | x++; | |
135 | #ifdef DEBUG | |
136 | __CTRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", | |
137 | y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp); | |
138 | #endif | |
139 | break; | |
140 | case '\n': | |
141 | SYNCH_OUT; | |
142 | wclrtoeol(win); | |
143 | SYNCH_IN; | |
144 | if (!NONL) | |
145 | x = 0; | |
146 | goto newline; | |
147 | case '\r': | |
148 | x = 0; | |
149 | break; | |
150 | case '\b': | |
151 | if (--x < 0) | |
152 | x = 0; | |
153 | break; | |
154 | } | |
155 | } | |
156 | SYNCH_OUT; | |
157 | return (OK); | |
15637ed4 | 158 | } |