File: bw-lgen.inc

package info (click to toggle)
jupp 3.1.38-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,420 kB
  • sloc: ansic: 31,382; sh: 4,199; makefile: 431
file content (211 lines) | stat: -rw-r--r-- 4,178 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 *	Edit buffer single line update core loop (twice)
 *	Copyright © 1992 Joseph H. Allen
 *	Copyright © 2018 mirabilos
 *
 *	This file is part of jupp (Joe’s Own Editor fork)
 */

#ifdef LGEN_Q
__IDSTRING(rcsid_bw_lgen_inc, "$MirOS: contrib/code/jupp/bw-lgen.inc,v 1.5 2018/06/28 03:11:18 tg Exp $");
#define XCOL col
#else
#define XCOL (scr + x - ox)
#endif

 LGEN_LABEL(loop):
	/* Display next character */
	if (!amnt)
		goto LGEN_LABEL(noamnt);
	do {
		if (ungetit == -1)
			bc = *bp++;
		else {
			bc = ungetit;
			ungetit = -1;
		}
		if (st != -1)
			atr = syn[idx++];
		if (utf8_sm.state && !(bc & 0x80))
			goto LGEN_LABEL(ilseq);
		if (p->b->o.crlf && bc == '\r') {
			++byte;
			if (!--amnt) {
 LGEN_LABEL(pl):
				if (bp == p->ptr + SEGSIZ) {
					if (pnext(p)) {
						bp = p->ptr;
						amnt = p->hdr->hole;
					} else
						goto LGEN_LABEL(nl);
				} else {
					bp = p->ptr + p->hdr->ehole;
					amnt = SEGSIZ - p->hdr->ehole;
					if (!amnt)
						goto LGEN_LABEL(pl);
				}
			}
			if (*bp == '\n') {
				++bp;
				++byte;
				++amnt;
				goto eobl;
			}
 LGEN_LABEL(nl):
			--byte;
			++amnt;
		}
		if (square)
			if (bc == '\t') {
				long tcol = XCOL + p->b->o.tab -
				    (XCOL % p->b->o.tab);

				if (tcol > from && tcol <= to)
					c1 = INVERSE;
				else
					c1 = 0;
			} else if (XCOL >= from && XCOL < to)
				c1 = INVERSE;
			else
				c1 = 0;
		else if (byte >= from && byte < to)
			c1 = INVERSE;
		else
			c1 = 0;
		++byte;
		if (bc == '\t') {
			ta = p->b->o.tab - (XCOL % p->b->o.tab);
#ifdef LGEN_Q
			if (ta + col > scr) {
				ta -= scr - col;
				goto dota_tab;
			}
			if ((col += ta) == scr) {
				--amnt;
				goto v_loop;
			}
#else
 dota_tab:
			tach1 = tach = ' ';
			if (bw->o.vispace)
				tach = 0x2192;
			goto dota_gen;
 dota_loop:
			tach = tach1;
 dota_gen:
			outatr(utf8_map, t, screen + x, attr + x,
			    x, y, tach, c1 | atr);
			if (have)
				goto bye;
			if (++x == w)
				goto eosl;
			if (--ta)
				goto dota_loop;
#endif
		} else if (bc == '\n') {
			goto eobl;
		} else {
			int wid = -1;

			/*
			 * should be p->b->o.charmap->type logically
			 * but they are identical here, and it helps
			 * static analysers like Coverity
			 */
			if (bw->b->o.charmap->type) {
				/* UTF-8 */
				c = utf8_decode(&utf8_sm, bc);

				if (c >= 0) {
					/* Normal decoded character */
					wid = joe_wcwidth(c);
				} else if (c == -1) {
					/* Character taken */
					wid = -1;
				} else if (c == -2) {
					/* Incomplete sequence */
					--byte;
 LGEN_LABEL(ilseq):
					++amnt;
					ungetit = bc;
					c = 0x1000FFFE;
					wid = utf8_sm.ptr;
					utf8_init(&utf8_sm);
				} else if (c == -3) {
					/* Invalid byte */
					c = 0x1000FFFE;
					wid = 1;
				}
			} else {
				/* 8-bit charmap */
				c = bc;
				wid = 1;
			}

			if (wid >= 0) {
#ifdef LGEN_Q
				col += wid;
				if (col == scr) {
					--amnt;
					goto v_loop;
				} else if (col > scr) {
					ta = col - scr;
					tach1 = tach = '<';
					goto dota_gen;
				}
#else
				if (x + wid > w) {
					/* Character hits rightmost column */
					while (x < w) {
						/* Display offscreen marker */
						outatr(bw->b->o.charmap,
						    t, screen + x, attr + x,
						    x, y, '>', c1 | atr);
						x++;
					}
				} else if (c == 0x1000FFFE) while (wid--) {
					outatr(bw->b->o.charmap, t,
					    screen + x, attr + x,
					    x, y, 0xFFFD,
					    (c1 | atr | UNDERLINE) ^ INVERSE);
					x++;
				} else if (c == 0x20 && bw->o.vispace) {
					outatr(utf8_map, t,
					    screen + x, attr + x,
					    x, y, 0xB7, c1 | atr);
					x++;
				} else {
					outatr(bw->b->o.charmap, t,
					    screen + x, attr + x,
					    x, y, c, c1 | atr);
					x += wid;
				}
#endif
			} else
				/* Get highlighting character again */
				--idx;
#ifndef LGEN_Q
			if (have)
				goto bye;
			if (x >= w)
				goto eosl;
#endif
		}
	} while (--amnt);
 LGEN_LABEL(noamnt):
	if (bp == p->ptr + SEGSIZ) {
		if (pnext(p)) {
			bp = p->ptr;
			amnt = p->hdr->hole;
			goto LGEN_LABEL(loop);
		}
	} else {
		bp = p->ptr + p->hdr->ehole;
		amnt = SEGSIZ - p->hdr->ehole;
		goto LGEN_LABEL(loop);
	}
	if (utf8_sm.state)
		goto LGEN_LABEL(ilseq);
	goto eof;

#undef XCOL