summaryrefslogtreecommitdiff
path: root/editors/mflteco/patches/patch-te__window.c
blob: b204def8a542e782ba47fede6a2046d2d03c2259 (plain)
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
$NetBSD: patch-te__window.c,v 1.1 2012/12/27 06:13:20 dholland Exp $

- remove unused variables
- fix signed/unsigned issues
- use static for local functions
- declare own functions
- declare void functions void
- use c89
- don't index arrays with (signed) char
- patch up two uninitialized variables
- silence warnings about assignments in conditionals
- #if out unused function putchar_d()
- silence unnecessary pointer width warning

--- te_window.c.orig	1995-04-25 15:02:41.000000000 +0000
+++ te_window.c
@@ -78,16 +78,37 @@ char win_dlyc[] =   { 0, 2, 1, 0, 0, 0, 
 int rate[]  = { 0, 0, 9600, 4800, 2400, 1800, 1200, 600, 300, 200, 150, 134, 110 };
 #define NSPEEDS (sizeof(win_speeds) / sizeof(char))
 #endif
-int real_win_speed = 0;
+static unsigned real_win_speed = 0;
 #define win_speed  ((ez_val & EZ_NOFILL) ? 0: real_win_speed)
-static int brate = 0;
+
+static VOID window0(int num);
+static VOID window1_both(void);
+static VOID window1(void);
+static VOID window1_abs(void);
+static VOID window1_inc(int wd);
+static VOID window1_after(void);
+static VOID w_rmcurs(void);
+static VOID window2(int arg);
+static VOID vtm(int arg);
+static VOID w_makecurs(char wc, short crflag);
+static int w_overflow(int wd);
+static VOID w_type(char c, int m);
+static VOID w_init(void);
+static VOID w_separators(void);
+static VOID w_move(short y, short x);
+static VOID w_scroll(int count);
+static VOID w_ebol(void);
+static int w_setptr(struct bh *pbuff, register int loc,
+		    register struct qp *pp);
+static int w_lines(int n, register struct qp *ps, register struct qp *pd);
+
 /* routine to perform simple scope operations */
 /* (an attempt to concentrate VT-100 specific things in one place) */
 
-vt(func)
+VOID vt(func)
 	int func;
 {
-	short t;
+	unsigned t;
 	switch (func)
 	{
 		case VT_CLEAR:			/* clear screen */
@@ -141,7 +162,7 @@ int win_min[]  = { 4,  20,		4,		 0, 0,	 
 int win_max[]  = { 4,  W_MAX_H,	W_MAX_V, 3, MAX, 12, -1,  20,	20,	-1,	-1 } ;	/* max values */
 int win_data[] = { 4,  132,		24,		 0, 0,	  0,  0,   0,	 0,	 0,	 0 } ;	/* window parameters	*/
 
-do_window(ref_flag)
+VOID do_window(ref_flag)
 	int ref_flag;					/* nonzero forces "refresh" operation */
 {
 	int i;
@@ -149,7 +170,7 @@ do_window(ref_flag)
 	if (colonflag && !ref_flag)
 	{
 		i = get_value(0);	/* get sub-function */
-		if ((i < 0) || (i > (sizeof(win_data)/sizeof(int)))) ERROR(E_IWA);
+		if ((i < 0) || (i > (int)(sizeof(win_data)/sizeof(int)))) ERROR(E_IWA);
 		if (!esp->flag2)	/* it's a "get" */
 		{
 			esp->val1 = win_data[i];
@@ -205,7 +226,7 @@ do_window(ref_flag)
 /* routine to update screen size with numbers obtained from environment	*/
 /* (called by main program's initialization)							*/
 
-set_term_par(lines, cols)
+VOID set_term_par(lines, cols)
 	int lines, cols;
 {
 	if ((lines >= win_min[2]) && (lines <= win_max[2])) win_1.size = win_data[2] = lines, win_1.end = lines - 1;
@@ -223,7 +244,7 @@ set_term_par(lines, cols)
 /* WIN_LINE:	does WIN_REFR unless that wouldn't do anything, in which case		*/
 /*				it does effective 1EV output										*/
 
-window(arg)
+VOID window(arg)
 	int arg;
 {
 	int i;
@@ -308,8 +329,7 @@ window(arg)
 /* used for ev, es, and <BS> or <LF> as immediate commands					*/
 /* starting char position is in w_p1; argument is number of lines			*/
 
-window0(num)
-int num; 
+static VOID window0(int num)
 {
 	int wi;
 	char wc;			/* temp char */
@@ -319,7 +339,7 @@ int num; 
 	{
 		wc = w_p1.p->ch[w_p1.c];		/* get character */
 
-		if ((char_count >= WN_width) && (wc != CR) && !(spec_chars[wc] & A_L))	/* if about to exceed width */
+		if ((char_count >= WN_width) && (wc != CR) && !(spec_chars[(unsigned char)wc] & A_L))	/* if about to exceed width */
 		{
 			if (et_val & ET_TRUNC) goto w0_noprint;			/* truncate: don't print this */
 			else
@@ -383,7 +403,7 @@ int num; 
 
 struct bh *old_pbuff;
 
-window1_both()
+static VOID window1_both(void)
 {
 	pw0 = &win_1;
 	pb0 = &buffs[0];
@@ -414,12 +434,14 @@ window1_both()
 /* if scroll mode is enabled, the VT100 screen is split and only the upper part */
 /* is used by this routine; else the whole screen is used.						*/
 
-window1()
+static VOID window1(void)
 {
 	int i, j, m, lflag;
 	register struct bh *pb = pb0;
 	register struct w_data *pw = pw0;
 
+	lflag = 0; /* XXX is this right? */
+
 	/* return if nothing has changed */
 	if (!redraw_sw && (pbuff == old_pbuff) && (pb->dot == pw->last_dot) && (pb->buff_mod == MAX)) return;
 
@@ -514,7 +536,7 @@ window1()
 }
 /* routine to redraw screen absolutely */
 
-window1_abs()
+static VOID window1_abs(void)
 {
 	int i, j;
 	struct bh *save_pbuff;								/* save old pbuff during set_pointer call */
@@ -545,8 +567,8 @@ window1_abs()
 
 /* redraw screen incrementally */
 
-window1_inc(wd)
-	int wd;						/* argument is earliest change */
+static VOID window1_inc(int wd)
+			/* argument is earliest change */
 {
 	short temp_y;
 	register struct bh *pb = pb0;
@@ -572,12 +594,14 @@ window1_inc(wd)
 }
 /* routine to move window downwards: scroll up or redraw as appropriate */
 
-window1_after()
+static VOID window1_after(void)
 {
 	int i, lflag;
 	register struct bh *pb = pb0;
 	register struct w_data *pw = pw0;
 
+	lflag = 0; /* XXX: is this right? */
+
 	w_rmcurs();						/* remove old cursor */
 	w_setptr(pb, wlp[pw->end]->start, &w_p1);		/* set pointer to start of last line on screen */
 
@@ -604,7 +628,7 @@ window1_after()
 
 /* routine to remove the existing cursor */
 
-w_rmcurs()
+static VOID w_rmcurs(void)
 {
 	register struct w_data *pw = pw0;
 
@@ -621,8 +645,7 @@ w_rmcurs()
 /* called with w_p1 at starting char, curr_y, curr_x at starting coordinate			*/
 /* rewrites to end of screen if arg = 0, or only until line with cursor if arg = 1	*/
 
-window2(arg)
-	int arg;
+static VOID window2(int arg)
 {
 	register struct bh *pb = pb0;
 	register struct w_data *pw = pw0;
@@ -635,7 +658,7 @@ window2(arg)
 	for (wdot = w_p1.dot; (curr_y <= pw->end) && (wdot < pb->z); wdot++)		/* for each character */
 	{
 		wc = w_p1.p->ch[w_p1.c] & 0177;		/* get character */
-		if (dflag = (wdot == pb->dot)) if (arg) arg = -1;		/* save "this is char at dot", "on line with dot" */
+		if ((dflag = (wdot == pb->dot)) != 0) if (arg) arg = -1;		/* save "this is char at dot", "on line with dot" */
 
 		if (wc < ' ') switch (wc)				/* dispatch control characters */
 		{
@@ -821,7 +844,7 @@ window2(arg)
 			wc = 'c';     /* get character */
 		else
 			wc = '`';     /* get character */
-		if (dflag = (wdot == pb->dot)) if (arg) arg = -1;		/* save "this is char at dot", "on line with dot" */
+		if ((dflag = (wdot == pb->dot)) != 0) if (arg) arg = -1;		/* save "this is char at dot", "on line with dot" */
 		if (curr_x >= WN_width)
 		{
 			if (et_val & ET_TRUNC) goto noprint;
@@ -856,8 +879,7 @@ window2(arg)
 }
 /* routine to move cursor to current location and then call vt */
 
-vtm(arg)
-	int arg;
+static VOID vtm(int arg)
 {
 	w_move(curr_y, curr_x);
 	vt(arg);
@@ -869,9 +891,7 @@ vtm(arg)
 /* routine to set reverse video and save cursor location */
 /* first argument is char at cursor, 2nd is value for curs_crflag */
 
-w_makecurs(wc, crflag)
-	char wc;
-	short crflag;
+static VOID w_makecurs(char wc, short crflag)
 {
 	register struct w_data *pw = pw0;
 
@@ -888,7 +908,7 @@ w_makecurs(wc, crflag)
 /* returns nonzero if at end of screen, zero otherwise */
 /* arg is current character position */
 
-int w_overflow(wd)
+static int w_overflow(int wd)
 {
 	register struct w_data *pw = pw0;
 
@@ -912,12 +932,11 @@ int w_overflow(wd)
 /* routine to type one character:  arguments are char and a */
 /* "mark" bit.  If mark is set, the char is always retyped  */
 
-w_type(c, m)
+static VOID w_type(c, m)
 	char c;
 	int m;
 {
 	register char *p;
-	register struct w_data *pw = pw0;
 
 	p = &wlp[curr_y]->ch[curr_x];		/* pointer to char image */
 	if ((c != *p) || (m) || (redraw_sw) || (curr_x >= wlp[curr_y]->n))
@@ -936,7 +955,7 @@ w_type(c, m)
 
 /* initialize display image */
 
-w_init()
+static VOID w_init(void)
 {
 	short i, j;
 
@@ -968,7 +987,7 @@ w_init()
 
 /* write separator lines between windows on screen */
 
-w_separators()
+static VOID w_separators(void)
 {
 	int i;
 
@@ -990,29 +1009,30 @@ w_separators()
 /* put character followed by appropriate number of nulls for "other control function" */
 /* if argument is 0, output filler chars only */
 
-putchar_d(c)
-	char c;
+#if 0 /* not used */
+static VOID putchar_d(char c)
 {
-	int i;
+	unsigned i;
 
 	if (c) putchar(c);												/* output character */
 	for (i = 0; i < win_dlyc[win_speed]; i++) putchar('\0');		/* output filler */
 }
+#endif
 
 
 
 /* put out appropriate number of filler chars for display function that scrolls (LF, etc.) */
 
-scroll_dly()
+VOID scroll_dly(void)
 {
-	int i;
+	unsigned i;
 
 	for (i = 0; i < win_dlys[win_speed]; i++) putchar('\0');		/* output filler */
 }
 /* move terminal cursor to stated y, x position */
 /* uses incremental moves or absolute cursor position, whichever is shorter */
 
-w_move(y, x)
+static VOID w_move(y, x)
 	short y, x;
 {
 	register short i;
@@ -1052,10 +1072,9 @@ w_move(y, x)
 }
 /* scroll screen: argument is count: + up, - down */
 
-w_scroll(count)
-	int count;
+static VOID w_scroll(int count)
 {
-	register int i, ic;
+	register int i;
 	struct w_line *p[W_MAX_V];					/* temp copy of pointer array */
 	register struct w_data *pw = pw0;
 
@@ -1084,10 +1103,9 @@ w_scroll(count)
 /* clear line to left of curr_x */
 /* if some chars nonblank, does erase from start of line */
 
-w_ebol()
+static VOID w_ebol(void)
 {
 	short i, j;
-	register struct w_data *pw = pw0;
 
 	for (j = i = 0; i < curr_x; i++) if (wlp[curr_y]->ch[i] != ' ') wlp[curr_y]->ch[i] = ' ', j++;
 	if (j || redraw_sw) w_move(curr_y, curr_x-1), vt(VT_EBOL);
@@ -1098,7 +1116,7 @@ w_ebol()
 /* routine to set a pointer to a given location (like set_pointer) */
 /* returns nonzero if a text buffer exists, otherwise 0 */
 
-int w_setptr(pbuff, loc, pp)
+static int w_setptr(pbuff, loc, pp)
 	struct bh *pbuff;				/* current buffer header */
 	register int loc;				/* location */
 	register struct qp *pp;			/* address of pointer */
@@ -1111,7 +1129,7 @@ int w_setptr(pbuff, loc, pp)
 		pp->c = loc % CELLSIZE;
 		pp->dot = loc;
 	}
-	return( (int) pbuff->f);
+	return( pbuff->f != NULL );
 }
 /* routine to move N lines (back, forward, or 0)				*/
 /* w_lines(n, &source, &dest) where n is the line count, source	*/
@@ -1121,7 +1139,7 @@ int w_setptr(pbuff, loc, pp)
 
 struct qp w_lines_p;				/* to compute # of display lines in -N lines */
 
-int w_lines(n, ps, pd)
+static int w_lines(n, ps, pd)
 	int n;							/* number of lines */
 	register struct qp *ps, *pd;	/* source, destination qp's */
 {
@@ -1138,7 +1156,7 @@ int w_lines(n, ps, pd)
 	{
 		for (tcnt = tl = tn = 0; (tn < n) && (tdot < pb0->z); tdot++)	/* forward over N line separators */
 		{
-			if (spec_chars[ tch = tp->ch[tc] ] & A_L) ++tl, ++tn;		/* count separators */
+			if (spec_chars[ (unsigned char)(tch = tp->ch[tc]) ] & A_L) ++tl, ++tn;		/* count separators */
 			else if (!(et_val & ET_TRUNC))		/* if text lines can overflow screen lines */
 			{
 				if (!(tch & 0140))				/* if character is a control char */
@@ -1166,7 +1184,7 @@ int w_lines(n, ps, pd)
 		{
 			--tdot;
 			if (--tc < 0) tp = tp->b, tc = CELLSIZE -1;
-			if (spec_chars[tp->ch[tc]] & A_L) --tn;
+			if (spec_chars[(unsigned char)tp->ch[tc]] & A_L) --tn;
 		}
 		if (tn < n)			/* if stopped on a line sep, fwd over it */
 		{
@@ -1187,8 +1205,7 @@ int w_lines(n, ps, pd)
 }
 /* routine to move n chars on line */
 /* call with # of columns, return new dot value */
-int x_to_dot(x)
-	int x;
+static int x_to_dot(int x)
 {
 	struct qp m_dot;
 	int m_count;
@@ -1227,7 +1244,7 @@ int last_dis_buff;
 int last_dis_x;
 int last_dis_wrap;
 
-VOID display_lines()
+VOID display_lines(void)
 {
 	int dis_buff = (pbuff == &buffs[0]) ? 0 : 1 ;		/* current buffer */
 	struct w_data *pw = dis_buff ? &win_2 : &win_1 ;