xref: /onnv-gate/usr/src/cmd/vi/port/ex_subr.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1996 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #include <sys/stropts.h>
36*0Sstevel@tonic-gate #include <sys/eucioctl.h>
37*0Sstevel@tonic-gate #ifndef PRESUNEUC
38*0Sstevel@tonic-gate #include <locale.h>
39*0Sstevel@tonic-gate /* Undef putchar/getchar if they're defined. */
40*0Sstevel@tonic-gate #ifdef putchar
41*0Sstevel@tonic-gate #	undef putchar
42*0Sstevel@tonic-gate #endif
43*0Sstevel@tonic-gate #ifdef getchar
44*0Sstevel@tonic-gate #	undef getchar
45*0Sstevel@tonic-gate #endif
46*0Sstevel@tonic-gate #endif /* PRESUNEUC */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #include "ex.h"
49*0Sstevel@tonic-gate #include "ex_re.h"
50*0Sstevel@tonic-gate #include "ex_tty.h"
51*0Sstevel@tonic-gate #include "ex_vis.h"
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate /*
54*0Sstevel@tonic-gate  * Random routines, in alphabetical order.
55*0Sstevel@tonic-gate  */
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate any(c, s)
58*0Sstevel@tonic-gate 	int c;
59*0Sstevel@tonic-gate 	register unsigned char *s;
60*0Sstevel@tonic-gate {
61*0Sstevel@tonic-gate 	register int x;
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate 	while (x = *s++)
64*0Sstevel@tonic-gate 		if (x == c)
65*0Sstevel@tonic-gate 			return (1);
66*0Sstevel@tonic-gate 	return (0);
67*0Sstevel@tonic-gate }
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate backtab(i)
70*0Sstevel@tonic-gate 	register int i;
71*0Sstevel@tonic-gate {
72*0Sstevel@tonic-gate 	register int j;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	j = i % value(vi_SHIFTWIDTH);
75*0Sstevel@tonic-gate 	if (j == 0)
76*0Sstevel@tonic-gate 		j = value(vi_SHIFTWIDTH);
77*0Sstevel@tonic-gate 	i -= j;
78*0Sstevel@tonic-gate 	if (i < 0)
79*0Sstevel@tonic-gate 		i = 0;
80*0Sstevel@tonic-gate 	return (i);
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate change()
84*0Sstevel@tonic-gate {
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 	tchng++;
87*0Sstevel@tonic-gate 	chng = tchng;
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate  * Column returns the number of
92*0Sstevel@tonic-gate  * columns occupied by printing the
93*0Sstevel@tonic-gate  * characters through position cp of the
94*0Sstevel@tonic-gate  * current line.
95*0Sstevel@tonic-gate  */
96*0Sstevel@tonic-gate column(cp)
97*0Sstevel@tonic-gate 	register unsigned char *cp;
98*0Sstevel@tonic-gate {
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate 	if (cp == 0)
101*0Sstevel@tonic-gate 		cp = &linebuf[LBSIZE - 2];
102*0Sstevel@tonic-gate 	return (qcolumn(cp, (char *) 0));
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate /* lcolumn is same as column except it returns number of columns
106*0Sstevel@tonic-gate  * occupied by characters before position
107*0Sstevel@tonic-gate  * cp of the current line
108*0Sstevel@tonic-gate  */
109*0Sstevel@tonic-gate lcolumn(cp)
110*0Sstevel@tonic-gate 	register unsigned char *cp;
111*0Sstevel@tonic-gate {
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate 	if (cp == 0)
114*0Sstevel@tonic-gate 		cp = &linebuf[LBSIZE - 2];
115*0Sstevel@tonic-gate 	return(nqcolumn(lastchr(linebuf, cp), (char *)0));
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate /*
119*0Sstevel@tonic-gate  * Ignore a comment to the end of the line.
120*0Sstevel@tonic-gate  * This routine eats the trailing newline so don't call donewline().
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate comment()
123*0Sstevel@tonic-gate {
124*0Sstevel@tonic-gate 	register int c;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	do {
127*0Sstevel@tonic-gate 		c = getchar();
128*0Sstevel@tonic-gate 	} while (c != '\n' && c != EOF);
129*0Sstevel@tonic-gate 	if (c == EOF)
130*0Sstevel@tonic-gate 		ungetchar(c);
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate Copy(to, from, size)
134*0Sstevel@tonic-gate 	register unsigned char *from, *to;
135*0Sstevel@tonic-gate 	register int size;
136*0Sstevel@tonic-gate {
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 	if (size > 0)
139*0Sstevel@tonic-gate 		do
140*0Sstevel@tonic-gate 			*to++ = *from++;
141*0Sstevel@tonic-gate 		while (--size > 0);
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate copyw(to, from, size)
145*0Sstevel@tonic-gate 	register line *from, *to;
146*0Sstevel@tonic-gate 	register int size;
147*0Sstevel@tonic-gate {
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 	if (size > 0)
150*0Sstevel@tonic-gate 		do
151*0Sstevel@tonic-gate 			*to++ = *from++;
152*0Sstevel@tonic-gate 		while (--size > 0);
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate copywR(to, from, size)
156*0Sstevel@tonic-gate 	register line *from, *to;
157*0Sstevel@tonic-gate 	register int size;
158*0Sstevel@tonic-gate {
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	while (--size >= 0)
161*0Sstevel@tonic-gate 		to[size] = from[size];
162*0Sstevel@tonic-gate }
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate ctlof(c)
165*0Sstevel@tonic-gate 	int c;
166*0Sstevel@tonic-gate {
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate 	return (c == DELETE ? '?' : c | ('A' - 1));
169*0Sstevel@tonic-gate }
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate dingdong()
172*0Sstevel@tonic-gate {
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate 	if (flash_screen && value(vi_FLASH))
175*0Sstevel@tonic-gate 		putpad(flash_screen);
176*0Sstevel@tonic-gate 	else if (value(vi_ERRORBELLS))
177*0Sstevel@tonic-gate 		putpad(bell);
178*0Sstevel@tonic-gate }
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate fixindent(indent)
181*0Sstevel@tonic-gate 	int indent;
182*0Sstevel@tonic-gate {
183*0Sstevel@tonic-gate 	register int i;
184*0Sstevel@tonic-gate 	register unsigned char *cp;
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	i = whitecnt(genbuf);
187*0Sstevel@tonic-gate 	cp = vpastwh(genbuf);
188*0Sstevel@tonic-gate 	if (*cp == 0 && i == indent && linebuf[0] == 0) {
189*0Sstevel@tonic-gate 		genbuf[0] = 0;
190*0Sstevel@tonic-gate 		return (i);
191*0Sstevel@tonic-gate 	}
192*0Sstevel@tonic-gate 	CP(genindent(i), cp);
193*0Sstevel@tonic-gate 	return (i);
194*0Sstevel@tonic-gate }
195*0Sstevel@tonic-gate 
196*0Sstevel@tonic-gate filioerr(cp)
197*0Sstevel@tonic-gate 	unsigned char *cp;
198*0Sstevel@tonic-gate {
199*0Sstevel@tonic-gate 	register int oerrno = errno;
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate 	lprintf("\"%s\"", cp);
202*0Sstevel@tonic-gate 	errno = oerrno;
203*0Sstevel@tonic-gate 	syserror(1);
204*0Sstevel@tonic-gate }
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate unsigned char *
207*0Sstevel@tonic-gate genindent(indent)
208*0Sstevel@tonic-gate 	register int indent;
209*0Sstevel@tonic-gate {
210*0Sstevel@tonic-gate 	register unsigned char *cp;
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate 	for (cp = genbuf; indent >= value(vi_TABSTOP); indent -= value(vi_TABSTOP))
213*0Sstevel@tonic-gate 		*cp++ = '\t';
214*0Sstevel@tonic-gate 	for (; indent > 0; indent--)
215*0Sstevel@tonic-gate 		*cp++ = ' ';
216*0Sstevel@tonic-gate 	return (cp);
217*0Sstevel@tonic-gate }
218*0Sstevel@tonic-gate 
219*0Sstevel@tonic-gate getDOT()
220*0Sstevel@tonic-gate {
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 	getline(*dot);
223*0Sstevel@tonic-gate }
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate line *
226*0Sstevel@tonic-gate getmark(c)
227*0Sstevel@tonic-gate 	register int c;
228*0Sstevel@tonic-gate {
229*0Sstevel@tonic-gate 	register line *addr;
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate 	for (addr = one; addr <= dol; addr++)
232*0Sstevel@tonic-gate 		if (names[c - 'a'] == (*addr &~ 01)) {
233*0Sstevel@tonic-gate 			return (addr);
234*0Sstevel@tonic-gate 		}
235*0Sstevel@tonic-gate 	return (0);
236*0Sstevel@tonic-gate }
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate getn(cp)
239*0Sstevel@tonic-gate 	register unsigned char *cp;
240*0Sstevel@tonic-gate {
241*0Sstevel@tonic-gate 	register int i = 0;
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	while (isdigit(*cp))
244*0Sstevel@tonic-gate 		i = i * 10 + *cp++ - '0';
245*0Sstevel@tonic-gate 	if (*cp)
246*0Sstevel@tonic-gate 		return (0);
247*0Sstevel@tonic-gate 	return (i);
248*0Sstevel@tonic-gate }
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate ignnEOF()
251*0Sstevel@tonic-gate {
252*0Sstevel@tonic-gate 	register int c = getchar();
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate 	if (c == EOF)
255*0Sstevel@tonic-gate 		ungetchar(c);
256*0Sstevel@tonic-gate 	else if (c=='"')
257*0Sstevel@tonic-gate 		comment();
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate 
260*0Sstevel@tonic-gate iswhite(c)
261*0Sstevel@tonic-gate 	int c;
262*0Sstevel@tonic-gate {
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 	return (c == ' ' || c == '\t');
265*0Sstevel@tonic-gate }
266*0Sstevel@tonic-gate 
267*0Sstevel@tonic-gate junk(c)
268*0Sstevel@tonic-gate 	register wchar_t c;
269*0Sstevel@tonic-gate {
270*0Sstevel@tonic-gate 
271*0Sstevel@tonic-gate 	if (c && !value(vi_BEAUTIFY))
272*0Sstevel@tonic-gate 		return (0);
273*0Sstevel@tonic-gate 	if (c >= ' ' && c != DELETE)
274*0Sstevel@tonic-gate 		return (0);
275*0Sstevel@tonic-gate 	switch (c) {
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate 	case '\t':
278*0Sstevel@tonic-gate 	case '\n':
279*0Sstevel@tonic-gate 	case '\f':
280*0Sstevel@tonic-gate 		return (0);
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate 	default:
283*0Sstevel@tonic-gate 		return (1);
284*0Sstevel@tonic-gate 	}
285*0Sstevel@tonic-gate }
286*0Sstevel@tonic-gate 
287*0Sstevel@tonic-gate killed()
288*0Sstevel@tonic-gate {
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 	killcnt(addr2 - addr1 + 1);
291*0Sstevel@tonic-gate }
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate killcnt(cnt)
294*0Sstevel@tonic-gate 	register int cnt;
295*0Sstevel@tonic-gate {
296*0Sstevel@tonic-gate 	extern char *verbalize();
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate 	if (inopen) {
299*0Sstevel@tonic-gate 		notecnt = cnt;
300*0Sstevel@tonic-gate 		notenam = notesgn = (unsigned char *)"";
301*0Sstevel@tonic-gate 		return;
302*0Sstevel@tonic-gate 	}
303*0Sstevel@tonic-gate 	if (!notable(cnt))
304*0Sstevel@tonic-gate 		return;
305*0Sstevel@tonic-gate 	if (value(vi_TERSE) == 0) {
306*0Sstevel@tonic-gate 		verbalize(cnt, Command, "");
307*0Sstevel@tonic-gate 	} else {
308*0Sstevel@tonic-gate 		if (cnt == 1) {
309*0Sstevel@tonic-gate 			printf(gettext("1 line"), cnt);
310*0Sstevel@tonic-gate 		} else {
311*0Sstevel@tonic-gate 			printf(gettext("%d lines"), cnt);
312*0Sstevel@tonic-gate 		}
313*0Sstevel@tonic-gate 	}
314*0Sstevel@tonic-gate 	putNFL();
315*0Sstevel@tonic-gate }
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate lineno(a)
318*0Sstevel@tonic-gate 	line *a;
319*0Sstevel@tonic-gate {
320*0Sstevel@tonic-gate 
321*0Sstevel@tonic-gate 	return (a - zero);
322*0Sstevel@tonic-gate }
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate lineDOL()
325*0Sstevel@tonic-gate {
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate 	return (lineno(dol));
328*0Sstevel@tonic-gate }
329*0Sstevel@tonic-gate 
330*0Sstevel@tonic-gate lineDOT()
331*0Sstevel@tonic-gate {
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate 	return (lineno(dot));
334*0Sstevel@tonic-gate }
335*0Sstevel@tonic-gate 
336*0Sstevel@tonic-gate markDOT()
337*0Sstevel@tonic-gate {
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	markpr(dot);
340*0Sstevel@tonic-gate }
341*0Sstevel@tonic-gate 
342*0Sstevel@tonic-gate markpr(which)
343*0Sstevel@tonic-gate 	line *which;
344*0Sstevel@tonic-gate {
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate 	if ((inglobal == 0 || inopen) && which <= endcore) {
347*0Sstevel@tonic-gate 		names['z'-'a'+1] = *which & ~01;
348*0Sstevel@tonic-gate 		if (inopen)
349*0Sstevel@tonic-gate 			ncols['z'-'a'+1] = cursor;
350*0Sstevel@tonic-gate 	}
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate markreg(c)
354*0Sstevel@tonic-gate 	register int c;
355*0Sstevel@tonic-gate {
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	if (c == '\'' || c == '`')
358*0Sstevel@tonic-gate 		return ('z' + 1);
359*0Sstevel@tonic-gate 	if (c >= 'a' && c <= 'z')
360*0Sstevel@tonic-gate 		return (c);
361*0Sstevel@tonic-gate 	return (0);
362*0Sstevel@tonic-gate }
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate /*
365*0Sstevel@tonic-gate  * Mesg decodes the terse/verbose strings. Thus
366*0Sstevel@tonic-gate  *	'xxx@yyy' -> 'xxx' if terse, else 'xxx yyy'
367*0Sstevel@tonic-gate  *	'xxx|yyy' -> 'xxx' if terse, else 'yyy'
368*0Sstevel@tonic-gate  * All others map to themselves.
369*0Sstevel@tonic-gate  */
370*0Sstevel@tonic-gate /*
371*0Sstevel@tonic-gate  * The feature described above was disabled for localizable messaging.
372*0Sstevel@tonic-gate  */
373*0Sstevel@tonic-gate unsigned char *
374*0Sstevel@tonic-gate mesg(str)
375*0Sstevel@tonic-gate 	register unsigned char *str;
376*0Sstevel@tonic-gate {
377*0Sstevel@tonic-gate 	register unsigned char *cp;
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate 	str = (unsigned char *)strcpy(genbuf, str);
380*0Sstevel@tonic-gate 	/* commented out for localizable messaging */
381*0Sstevel@tonic-gate /*	for (cp = str; *cp; cp++)
382*0Sstevel@tonic-gate 		switch (*cp) {
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate 		case '@':
385*0Sstevel@tonic-gate 			if (value(vi_TERSE))
386*0Sstevel@tonic-gate 				*cp = 0;
387*0Sstevel@tonic-gate 			else
388*0Sstevel@tonic-gate 				*cp = ' ';
389*0Sstevel@tonic-gate 			break;
390*0Sstevel@tonic-gate 
391*0Sstevel@tonic-gate 		case '|':
392*0Sstevel@tonic-gate 			if (value(vi_TERSE) == 0)
393*0Sstevel@tonic-gate 				return (cp + 1);
394*0Sstevel@tonic-gate 			*cp = 0;
395*0Sstevel@tonic-gate 			break;
396*0Sstevel@tonic-gate 		}	*/
397*0Sstevel@tonic-gate 	return (str);
398*0Sstevel@tonic-gate }
399*0Sstevel@tonic-gate 
400*0Sstevel@tonic-gate /*VARARGS2*/
401*0Sstevel@tonic-gate merror(seekpt, i)
402*0Sstevel@tonic-gate 	unsigned char *seekpt;
403*0Sstevel@tonic-gate 	int i;
404*0Sstevel@tonic-gate {
405*0Sstevel@tonic-gate 	register unsigned char *cp = linebuf;
406*0Sstevel@tonic-gate 
407*0Sstevel@tonic-gate 	if (seekpt == 0)
408*0Sstevel@tonic-gate 		return;
409*0Sstevel@tonic-gate 	merror1(seekpt);
410*0Sstevel@tonic-gate 	if (*cp == '\n')
411*0Sstevel@tonic-gate 		putnl(), cp++;
412*0Sstevel@tonic-gate 	if (inopen > 0 && clr_eol)
413*0Sstevel@tonic-gate 		vclreol();
414*0Sstevel@tonic-gate 	if (enter_standout_mode && exit_bold)
415*0Sstevel@tonic-gate 		putpad(enter_standout_mode);
416*0Sstevel@tonic-gate #ifdef PRESUNEUC
417*0Sstevel@tonic-gate 	printf(mesg(cp), i);
418*0Sstevel@tonic-gate #else
419*0Sstevel@tonic-gate 	printf((char *)mesg(cp), i);
420*0Sstevel@tonic-gate #endif /* PRESUNEUC */
421*0Sstevel@tonic-gate 	if (enter_standout_mode && exit_bold)
422*0Sstevel@tonic-gate 		putpad(exit_bold);
423*0Sstevel@tonic-gate }
424*0Sstevel@tonic-gate 
425*0Sstevel@tonic-gate merror1(seekpt)
426*0Sstevel@tonic-gate 	unsigned char *seekpt;
427*0Sstevel@tonic-gate {
428*0Sstevel@tonic-gate 
429*0Sstevel@tonic-gate 	strcpy(linebuf, seekpt);
430*0Sstevel@tonic-gate }
431*0Sstevel@tonic-gate 
432*0Sstevel@tonic-gate #define MAXDATA (56*1024)
433*0Sstevel@tonic-gate morelines()
434*0Sstevel@tonic-gate {
435*0Sstevel@tonic-gate 	register unsigned char *end;
436*0Sstevel@tonic-gate 
437*0Sstevel@tonic-gate 	if ((int) sbrk(1024 * sizeof (line)) == -1) {
438*0Sstevel@tonic-gate 		if (endcore >= (line *) MAXDATA)
439*0Sstevel@tonic-gate 			return -1;
440*0Sstevel@tonic-gate 		end = (unsigned char *) MAXDATA;
441*0Sstevel@tonic-gate 		/*
442*0Sstevel@tonic-gate 		 * Ask for end+2 sice we want end to be the last used location.
443*0Sstevel@tonic-gate 		 */
444*0Sstevel@tonic-gate 		while (brk(end+2) == -1)
445*0Sstevel@tonic-gate 			end -= 64;
446*0Sstevel@tonic-gate 		if (end <= (unsigned char *) endcore)
447*0Sstevel@tonic-gate 			return -1;
448*0Sstevel@tonic-gate 		endcore = (line *) end;
449*0Sstevel@tonic-gate 	} else {
450*0Sstevel@tonic-gate 		endcore += 1024;
451*0Sstevel@tonic-gate 	}
452*0Sstevel@tonic-gate 	return (0);
453*0Sstevel@tonic-gate }
454*0Sstevel@tonic-gate 
455*0Sstevel@tonic-gate nonzero()
456*0Sstevel@tonic-gate {
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate 	if (addr1 == zero) {
459*0Sstevel@tonic-gate 		notempty();
460*0Sstevel@tonic-gate 		error(value(vi_TERSE) ? gettext("Nonzero address required") :
461*0Sstevel@tonic-gate gettext("Nonzero address required on this command"));
462*0Sstevel@tonic-gate 	}
463*0Sstevel@tonic-gate }
464*0Sstevel@tonic-gate 
465*0Sstevel@tonic-gate notable(i)
466*0Sstevel@tonic-gate 	int i;
467*0Sstevel@tonic-gate {
468*0Sstevel@tonic-gate 
469*0Sstevel@tonic-gate 	return (hush == 0 && !inglobal && i > value(vi_REPORT));
470*0Sstevel@tonic-gate }
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate 
473*0Sstevel@tonic-gate notempty()
474*0Sstevel@tonic-gate {
475*0Sstevel@tonic-gate 
476*0Sstevel@tonic-gate 	if (dol == zero)
477*0Sstevel@tonic-gate 		error(value(vi_TERSE) ? gettext("No lines") :
478*0Sstevel@tonic-gate gettext("No lines in the buffer"));
479*0Sstevel@tonic-gate }
480*0Sstevel@tonic-gate 
481*0Sstevel@tonic-gate 
482*0Sstevel@tonic-gate netchHAD(cnt)
483*0Sstevel@tonic-gate 	int cnt;
484*0Sstevel@tonic-gate {
485*0Sstevel@tonic-gate 
486*0Sstevel@tonic-gate 	netchange(lineDOL() - cnt);
487*0Sstevel@tonic-gate }
488*0Sstevel@tonic-gate 
489*0Sstevel@tonic-gate netchange(i)
490*0Sstevel@tonic-gate 	register int i;
491*0Sstevel@tonic-gate {
492*0Sstevel@tonic-gate 	register unsigned char *cp;
493*0Sstevel@tonic-gate 
494*0Sstevel@tonic-gate 	if (i > 0)
495*0Sstevel@tonic-gate 		notesgn = cp = (unsigned char *)"more ";
496*0Sstevel@tonic-gate 	else
497*0Sstevel@tonic-gate 		notesgn = cp = (unsigned char *)"fewer ", i = -i;
498*0Sstevel@tonic-gate 	if (inopen) {
499*0Sstevel@tonic-gate 		notecnt = i;
500*0Sstevel@tonic-gate 		notenam = (unsigned char *)"";
501*0Sstevel@tonic-gate 		return;
502*0Sstevel@tonic-gate 	}
503*0Sstevel@tonic-gate 	if (!notable(i))
504*0Sstevel@tonic-gate 		return;
505*0Sstevel@tonic-gate 	if (*cp == 'm')	/* for ease of messge localization */
506*0Sstevel@tonic-gate #ifdef PRESUNEUC
507*0Sstevel@tonic-gate 		printf(mesg(value(vi_TERSE) ?
508*0Sstevel@tonic-gate #else
509*0Sstevel@tonic-gate 		printf((char *)mesg(value(vi_TERSE) ?
510*0Sstevel@tonic-gate #endif /* PRESUNEUC */
511*0Sstevel@tonic-gate gettext("%d more lines") :
512*0Sstevel@tonic-gate 		/*
513*0Sstevel@tonic-gate 		 * TRANSLATION_NOTE
514*0Sstevel@tonic-gate 		 *	Reference order of arguments must not
515*0Sstevel@tonic-gate 		 *	be changed using '%digit$', since vi's
516*0Sstevel@tonic-gate 		 *	printf() does not support it.
517*0Sstevel@tonic-gate 		 */
518*0Sstevel@tonic-gate gettext("%d more lines in file after %s")), i, Command);
519*0Sstevel@tonic-gate 	else
520*0Sstevel@tonic-gate #ifdef PRESUNEUC
521*0Sstevel@tonic-gate 		printf(mesg(value(vi_TERSE) ?
522*0Sstevel@tonic-gate #else
523*0Sstevel@tonic-gate 		printf((char *)mesg(value(vi_TERSE) ?
524*0Sstevel@tonic-gate #endif /* PRESUNEUC */
525*0Sstevel@tonic-gate gettext("%d fewer lines") :
526*0Sstevel@tonic-gate 		/*
527*0Sstevel@tonic-gate 		 * TRANSLATION_NOTE
528*0Sstevel@tonic-gate 		 *	Reference order of arguments must not
529*0Sstevel@tonic-gate 		 *	be changed using '%digit$', since vi's
530*0Sstevel@tonic-gate 		 *	printf() does not support it.
531*0Sstevel@tonic-gate 		 */
532*0Sstevel@tonic-gate gettext("%d fewer lines in file after %s")), i, Command);
533*0Sstevel@tonic-gate 	putNFL();
534*0Sstevel@tonic-gate }
535*0Sstevel@tonic-gate 
536*0Sstevel@tonic-gate putmark(addr)
537*0Sstevel@tonic-gate 	line *addr;
538*0Sstevel@tonic-gate {
539*0Sstevel@tonic-gate 
540*0Sstevel@tonic-gate 	putmk1(addr, putline());
541*0Sstevel@tonic-gate }
542*0Sstevel@tonic-gate 
543*0Sstevel@tonic-gate putmk1(addr, n)
544*0Sstevel@tonic-gate 	register line *addr;
545*0Sstevel@tonic-gate 	int n;
546*0Sstevel@tonic-gate {
547*0Sstevel@tonic-gate 	register line *markp;
548*0Sstevel@tonic-gate 	register oldglobmk;
549*0Sstevel@tonic-gate 
550*0Sstevel@tonic-gate 	oldglobmk = *addr & 1;
551*0Sstevel@tonic-gate 	*addr &= ~1;
552*0Sstevel@tonic-gate 	for (markp = (anymarks ? names : &names['z'-'a'+1]);
553*0Sstevel@tonic-gate 	  markp <= &names['z'-'a'+1]; markp++)
554*0Sstevel@tonic-gate 		if (*markp == *addr)
555*0Sstevel@tonic-gate 			*markp = n;
556*0Sstevel@tonic-gate 	*addr = n | oldglobmk;
557*0Sstevel@tonic-gate }
558*0Sstevel@tonic-gate 
559*0Sstevel@tonic-gate unsigned char *
560*0Sstevel@tonic-gate plural(i)
561*0Sstevel@tonic-gate 	long i;
562*0Sstevel@tonic-gate {
563*0Sstevel@tonic-gate 
564*0Sstevel@tonic-gate 	return (i == 1 ? (unsigned char *)"" : (unsigned char *)"s");
565*0Sstevel@tonic-gate }
566*0Sstevel@tonic-gate 
567*0Sstevel@tonic-gate int	qcount();
568*0Sstevel@tonic-gate short	vcntcol;
569*0Sstevel@tonic-gate 
570*0Sstevel@tonic-gate qcolumn(lim, gp)
571*0Sstevel@tonic-gate 	register unsigned char *lim, *gp;
572*0Sstevel@tonic-gate {
573*0Sstevel@tonic-gate 	register int x, length;
574*0Sstevel@tonic-gate 	int	col;
575*0Sstevel@tonic-gate 	wchar_t wchar;
576*0Sstevel@tonic-gate 	int (*OO)();
577*0Sstevel@tonic-gate 
578*0Sstevel@tonic-gate 	OO = Outchar;
579*0Sstevel@tonic-gate 	Outchar = qcount;
580*0Sstevel@tonic-gate 	vcntcol = 0;
581*0Sstevel@tonic-gate 	if (lim != NULL) {
582*0Sstevel@tonic-gate 		if(lim == linebuf - 1 || lim == &linebuf[LBSIZE-2])
583*0Sstevel@tonic-gate 			length = 1;
584*0Sstevel@tonic-gate 		else
585*0Sstevel@tonic-gate 			length = mbtowc(&wchar, (char *)lim, MULTI_BYTE_MAX);
586*0Sstevel@tonic-gate 		if(length < 0)
587*0Sstevel@tonic-gate 			length = 1;
588*0Sstevel@tonic-gate 		x = lim[length];
589*0Sstevel@tonic-gate 		lim[length] = 0;
590*0Sstevel@tonic-gate 	}
591*0Sstevel@tonic-gate 	pline(0);
592*0Sstevel@tonic-gate 	if (lim != NULL)
593*0Sstevel@tonic-gate 		lim[length] = x;
594*0Sstevel@tonic-gate 	if(length > 1 && !gp) {
595*0Sstevel@tonic-gate 		/* put cursor at beginning of multibyte character */
596*0Sstevel@tonic-gate 		if ((col = wcwidth(wchar)) < 0)
597*0Sstevel@tonic-gate 			col = 0;
598*0Sstevel@tonic-gate 		vcntcol = vcntcol - col + 1;
599*0Sstevel@tonic-gate 	}
600*0Sstevel@tonic-gate  	if (gp)
601*0Sstevel@tonic-gate 		while (*gp) {
602*0Sstevel@tonic-gate 			length = mbtowc(&wchar, (char *)gp, MULTI_BYTE_MAX);
603*0Sstevel@tonic-gate 			if(length < 0) {
604*0Sstevel@tonic-gate 				putoctal = 1;
605*0Sstevel@tonic-gate 				putchar(*gp++);
606*0Sstevel@tonic-gate 				putoctal = 0;
607*0Sstevel@tonic-gate 			} else {
608*0Sstevel@tonic-gate 				putchar(wchar);
609*0Sstevel@tonic-gate 				gp += length;
610*0Sstevel@tonic-gate 			}
611*0Sstevel@tonic-gate 		}
612*0Sstevel@tonic-gate 	Outchar = OO;
613*0Sstevel@tonic-gate 	return (vcntcol);
614*0Sstevel@tonic-gate }
615*0Sstevel@tonic-gate 
616*0Sstevel@tonic-gate /* This routine puts cursor after multibyte character */
617*0Sstevel@tonic-gate nqcolumn(lim, gp)
618*0Sstevel@tonic-gate 	register unsigned char *lim, *gp;
619*0Sstevel@tonic-gate {
620*0Sstevel@tonic-gate 	register int x, length;
621*0Sstevel@tonic-gate 	wchar_t wchar;
622*0Sstevel@tonic-gate 	int (*OO)();
623*0Sstevel@tonic-gate 
624*0Sstevel@tonic-gate 	OO = Outchar;
625*0Sstevel@tonic-gate 	Outchar = qcount;
626*0Sstevel@tonic-gate 	vcntcol = 0;
627*0Sstevel@tonic-gate 	if (lim != NULL) {
628*0Sstevel@tonic-gate 		if(lim == linebuf - 1 || lim == &linebuf[LBSIZE-2])
629*0Sstevel@tonic-gate 			length = 1;
630*0Sstevel@tonic-gate 		else
631*0Sstevel@tonic-gate 			length = mbtowc(&wchar, (char *)lim, MULTI_BYTE_MAX);
632*0Sstevel@tonic-gate 		if(length < 0)
633*0Sstevel@tonic-gate 			length = 1;
634*0Sstevel@tonic-gate 		x = lim[length];
635*0Sstevel@tonic-gate 		lim[length] = 0;
636*0Sstevel@tonic-gate 	}
637*0Sstevel@tonic-gate 	pline(0);
638*0Sstevel@tonic-gate 	if (lim != NULL)
639*0Sstevel@tonic-gate 		lim[length] = x;
640*0Sstevel@tonic-gate  	if (gp)
641*0Sstevel@tonic-gate 		while (*gp) {
642*0Sstevel@tonic-gate 			length = mbtowc(&wchar, (char *)gp, MULTI_BYTE_MAX);
643*0Sstevel@tonic-gate 			if(length < 0) {
644*0Sstevel@tonic-gate 				putoctal = 1;
645*0Sstevel@tonic-gate 				putchar(*gp++);
646*0Sstevel@tonic-gate 				putoctal = 0;
647*0Sstevel@tonic-gate 			} else {
648*0Sstevel@tonic-gate 				putchar(wchar);
649*0Sstevel@tonic-gate 				gp += length;
650*0Sstevel@tonic-gate 			}
651*0Sstevel@tonic-gate 		}
652*0Sstevel@tonic-gate 	Outchar = OO;
653*0Sstevel@tonic-gate 	return (vcntcol);
654*0Sstevel@tonic-gate }
655*0Sstevel@tonic-gate 
656*0Sstevel@tonic-gate int
657*0Sstevel@tonic-gate qcount(c)
658*0Sstevel@tonic-gate wchar_t c;
659*0Sstevel@tonic-gate {
660*0Sstevel@tonic-gate 	register int cols;
661*0Sstevel@tonic-gate #ifndef PRESUNEUC
662*0Sstevel@tonic-gate 	register int remcols;
663*0Sstevel@tonic-gate 	register short OWCOLS;
664*0Sstevel@tonic-gate #endif /* PRESUNEUC */
665*0Sstevel@tonic-gate 
666*0Sstevel@tonic-gate 	if (c == '\t') {
667*0Sstevel@tonic-gate 		vcntcol += value(vi_TABSTOP) - vcntcol % value(vi_TABSTOP);
668*0Sstevel@tonic-gate 		return;
669*0Sstevel@tonic-gate 	}
670*0Sstevel@tonic-gate #ifdef PRESUNEUC
671*0Sstevel@tonic-gate 	if ((cols = wcwidth(c)) > 0)
672*0Sstevel@tonic-gate 		vcntcol += cols;
673*0Sstevel@tonic-gate #else
674*0Sstevel@tonic-gate 	if ((cols = wcwidth(c)) < 0)
675*0Sstevel@tonic-gate 		cols = 0;
676*0Sstevel@tonic-gate 	OWCOLS = WCOLS;
677*0Sstevel@tonic-gate 	if (WCOLS == 0)
678*0Sstevel@tonic-gate 		WCOLS = columns;
679*0Sstevel@tonic-gate 	if ((mc_wrap) == 1 && (remcols = (WCOLS - (vcntcol % WCOLS))) < cols)
680*0Sstevel@tonic-gate 		vcntcol += remcols;
681*0Sstevel@tonic-gate 	WCOLS = OWCOLS;
682*0Sstevel@tonic-gate 	vcntcol += cols;
683*0Sstevel@tonic-gate #endif /* PRESUNEUC */
684*0Sstevel@tonic-gate }
685*0Sstevel@tonic-gate 
686*0Sstevel@tonic-gate reverse(a1, a2)
687*0Sstevel@tonic-gate 	register line *a1, *a2;
688*0Sstevel@tonic-gate {
689*0Sstevel@tonic-gate 	register line t;
690*0Sstevel@tonic-gate 
691*0Sstevel@tonic-gate 	for (;;) {
692*0Sstevel@tonic-gate 		t = *--a2;
693*0Sstevel@tonic-gate 		if (a2 <= a1)
694*0Sstevel@tonic-gate 			return;
695*0Sstevel@tonic-gate 		*a2 = *a1;
696*0Sstevel@tonic-gate 		*a1++ = t;
697*0Sstevel@tonic-gate 	}
698*0Sstevel@tonic-gate }
699*0Sstevel@tonic-gate 
700*0Sstevel@tonic-gate save(a1, a2)
701*0Sstevel@tonic-gate 	line *a1;
702*0Sstevel@tonic-gate 	register line *a2;
703*0Sstevel@tonic-gate {
704*0Sstevel@tonic-gate 	register int more;
705*0Sstevel@tonic-gate 
706*0Sstevel@tonic-gate 	if (!FIXUNDO)
707*0Sstevel@tonic-gate 		return;
708*0Sstevel@tonic-gate #ifdef UNDOTRACE
709*0Sstevel@tonic-gate 	if (trace)
710*0Sstevel@tonic-gate 		vudump("before save");
711*0Sstevel@tonic-gate #endif
712*0Sstevel@tonic-gate 	undkind = UNDNONE;
713*0Sstevel@tonic-gate 	undadot = dot;
714*0Sstevel@tonic-gate 	more = (a2 - a1 + 1) - (unddol - dol);
715*0Sstevel@tonic-gate 	while (more > (endcore - truedol))
716*0Sstevel@tonic-gate 		if (morelines() < 0)
717*0Sstevel@tonic-gate 			error(value(vi_TERSE) ? gettext("Out of memory") :
718*0Sstevel@tonic-gate gettext("Out of memory saving lines for undo - try using ed"));
719*0Sstevel@tonic-gate 	if (more)
720*0Sstevel@tonic-gate 		(*(more > 0 ? copywR : copyw))(unddol + more + 1, unddol + 1,
721*0Sstevel@tonic-gate 		    (truedol - unddol));
722*0Sstevel@tonic-gate 	unddol += more;
723*0Sstevel@tonic-gate 	truedol += more;
724*0Sstevel@tonic-gate 	copyw(dol + 1, a1, a2 - a1 + 1);
725*0Sstevel@tonic-gate 	undkind = UNDALL;
726*0Sstevel@tonic-gate 	unddel = a1 - 1;
727*0Sstevel@tonic-gate 	undap1 = a1;
728*0Sstevel@tonic-gate 	undap2 = a2 + 1;
729*0Sstevel@tonic-gate #ifdef UNDOTRACE
730*0Sstevel@tonic-gate 	if (trace)
731*0Sstevel@tonic-gate 		vudump("after save");
732*0Sstevel@tonic-gate #endif
733*0Sstevel@tonic-gate }
734*0Sstevel@tonic-gate 
735*0Sstevel@tonic-gate save12()
736*0Sstevel@tonic-gate {
737*0Sstevel@tonic-gate 
738*0Sstevel@tonic-gate 	save(addr1, addr2);
739*0Sstevel@tonic-gate }
740*0Sstevel@tonic-gate 
741*0Sstevel@tonic-gate saveall()
742*0Sstevel@tonic-gate {
743*0Sstevel@tonic-gate 
744*0Sstevel@tonic-gate 	save(one, dol);
745*0Sstevel@tonic-gate }
746*0Sstevel@tonic-gate 
747*0Sstevel@tonic-gate span()
748*0Sstevel@tonic-gate {
749*0Sstevel@tonic-gate 
750*0Sstevel@tonic-gate 	return (addr2 - addr1 + 1);
751*0Sstevel@tonic-gate }
752*0Sstevel@tonic-gate 
753*0Sstevel@tonic-gate sync()
754*0Sstevel@tonic-gate {
755*0Sstevel@tonic-gate 
756*0Sstevel@tonic-gate 	chng = 0;
757*0Sstevel@tonic-gate 	tchng = 0;
758*0Sstevel@tonic-gate 	xchng = 0;
759*0Sstevel@tonic-gate }
760*0Sstevel@tonic-gate 
761*0Sstevel@tonic-gate 
762*0Sstevel@tonic-gate skipwh()
763*0Sstevel@tonic-gate {
764*0Sstevel@tonic-gate 	register int wh;
765*0Sstevel@tonic-gate 
766*0Sstevel@tonic-gate 	wh = 0;
767*0Sstevel@tonic-gate 	while (iswhite(peekchar())) {
768*0Sstevel@tonic-gate 		wh++;
769*0Sstevel@tonic-gate 		ignchar();
770*0Sstevel@tonic-gate 	}
771*0Sstevel@tonic-gate 	return (wh);
772*0Sstevel@tonic-gate }
773*0Sstevel@tonic-gate 
774*0Sstevel@tonic-gate /*VARARGS2*/
775*0Sstevel@tonic-gate smerror(seekpt, cp)
776*0Sstevel@tonic-gate 	unsigned char *seekpt;
777*0Sstevel@tonic-gate 	unsigned char *cp;
778*0Sstevel@tonic-gate {
779*0Sstevel@tonic-gate 
780*0Sstevel@tonic-gate 	errcnt++;
781*0Sstevel@tonic-gate 	merror1(seekpt);
782*0Sstevel@tonic-gate 	if (inopen && clr_eol)
783*0Sstevel@tonic-gate 		vclreol();
784*0Sstevel@tonic-gate 	if (enter_standout_mode && exit_bold)
785*0Sstevel@tonic-gate 		putpad(enter_standout_mode);
786*0Sstevel@tonic-gate 	lprintf(mesg(linebuf), cp);
787*0Sstevel@tonic-gate 	if (enter_standout_mode && exit_bold)
788*0Sstevel@tonic-gate 		putpad(exit_bold);
789*0Sstevel@tonic-gate }
790*0Sstevel@tonic-gate 
791*0Sstevel@tonic-gate unsigned char *
792*0Sstevel@tonic-gate strend(cp)
793*0Sstevel@tonic-gate 	register unsigned char *cp;
794*0Sstevel@tonic-gate {
795*0Sstevel@tonic-gate 
796*0Sstevel@tonic-gate 	while (*cp)
797*0Sstevel@tonic-gate 		cp++;
798*0Sstevel@tonic-gate 	return (cp);
799*0Sstevel@tonic-gate }
800*0Sstevel@tonic-gate 
801*0Sstevel@tonic-gate strcLIN(dp)
802*0Sstevel@tonic-gate 	unsigned char *dp;
803*0Sstevel@tonic-gate {
804*0Sstevel@tonic-gate 
805*0Sstevel@tonic-gate 	CP(linebuf, dp);
806*0Sstevel@tonic-gate }
807*0Sstevel@tonic-gate 
808*0Sstevel@tonic-gate /*
809*0Sstevel@tonic-gate  * A system error has occurred that we need to perror.
810*0Sstevel@tonic-gate  * danger is true if we are unsure of the contents of
811*0Sstevel@tonic-gate  * the file or our buffer, e.g. a write error in the
812*0Sstevel@tonic-gate  * middle of a write operation, or a temp file error.
813*0Sstevel@tonic-gate  */
814*0Sstevel@tonic-gate syserror(danger)
815*0Sstevel@tonic-gate int danger;
816*0Sstevel@tonic-gate {
817*0Sstevel@tonic-gate 	register int e = errno;
818*0Sstevel@tonic-gate 	char *errstr;
819*0Sstevel@tonic-gate 	extern char *strerror();
820*0Sstevel@tonic-gate 
821*0Sstevel@tonic-gate 	dirtcnt = 0;
822*0Sstevel@tonic-gate 	putchar(' ');
823*0Sstevel@tonic-gate 	if (danger)
824*0Sstevel@tonic-gate 		edited = 0;	/* for temp file errors, for example */
825*0Sstevel@tonic-gate 	if ((errstr = strerror(e)) != NULL)
826*0Sstevel@tonic-gate 		error(errstr);
827*0Sstevel@tonic-gate 	else
828*0Sstevel@tonic-gate 		error(gettext("System error %d"), e);
829*0Sstevel@tonic-gate }
830*0Sstevel@tonic-gate 
831*0Sstevel@tonic-gate /*
832*0Sstevel@tonic-gate  * Return the column number that results from being in column col and
833*0Sstevel@tonic-gate  * hitting a tab, where tabs are set every ts columns.  Work right for
834*0Sstevel@tonic-gate  * the case where col > columns, even if ts does not divide columns.
835*0Sstevel@tonic-gate  */
836*0Sstevel@tonic-gate tabcol(col, ts)
837*0Sstevel@tonic-gate int col, ts;
838*0Sstevel@tonic-gate {
839*0Sstevel@tonic-gate 	int offset, result;
840*0Sstevel@tonic-gate 
841*0Sstevel@tonic-gate 	if (col >= columns) {
842*0Sstevel@tonic-gate 		offset = columns * (col/columns);
843*0Sstevel@tonic-gate 		col -= offset;
844*0Sstevel@tonic-gate 	} else
845*0Sstevel@tonic-gate 		offset = 0;
846*0Sstevel@tonic-gate 	result = col + ts - (col % ts) + offset;
847*0Sstevel@tonic-gate 	return (result);
848*0Sstevel@tonic-gate }
849*0Sstevel@tonic-gate 
850*0Sstevel@tonic-gate unsigned char *
851*0Sstevel@tonic-gate vfindcol(i)
852*0Sstevel@tonic-gate 	int i;
853*0Sstevel@tonic-gate {
854*0Sstevel@tonic-gate 	register unsigned char *cp, *oldcp;
855*0Sstevel@tonic-gate 	register int (*OO)() = Outchar;
856*0Sstevel@tonic-gate 	register int length;
857*0Sstevel@tonic-gate 	unsigned char x;
858*0Sstevel@tonic-gate 	wchar_t wchar;
859*0Sstevel@tonic-gate 
860*0Sstevel@tonic-gate 	Outchar = qcount;
861*0Sstevel@tonic-gate 	(void)qcolumn(linebuf - 1, NOSTR);
862*0Sstevel@tonic-gate 	for (cp = linebuf; *cp && vcntcol < i; ) {
863*0Sstevel@tonic-gate 		oldcp = cp;
864*0Sstevel@tonic-gate 		length = mbtowc(&wchar, (char *)cp, MULTI_BYTE_MAX);
865*0Sstevel@tonic-gate 		if(length < 0) {
866*0Sstevel@tonic-gate 			putoctal = 1;
867*0Sstevel@tonic-gate 			putchar(*cp++);
868*0Sstevel@tonic-gate 			putoctal = 0;
869*0Sstevel@tonic-gate 		} else {
870*0Sstevel@tonic-gate 			putchar(wchar);
871*0Sstevel@tonic-gate 			cp += length;
872*0Sstevel@tonic-gate 		}
873*0Sstevel@tonic-gate 	}
874*0Sstevel@tonic-gate 	if (cp != linebuf)
875*0Sstevel@tonic-gate 		cp = oldcp;
876*0Sstevel@tonic-gate 	Outchar = OO;
877*0Sstevel@tonic-gate 	return (cp);
878*0Sstevel@tonic-gate }
879*0Sstevel@tonic-gate 
880*0Sstevel@tonic-gate unsigned char *
881*0Sstevel@tonic-gate vskipwh(cp)
882*0Sstevel@tonic-gate 	register unsigned char *cp;
883*0Sstevel@tonic-gate {
884*0Sstevel@tonic-gate 
885*0Sstevel@tonic-gate 	while (iswhite(*cp) && cp[1])
886*0Sstevel@tonic-gate 		cp++;
887*0Sstevel@tonic-gate 	return (cp);
888*0Sstevel@tonic-gate }
889*0Sstevel@tonic-gate 
890*0Sstevel@tonic-gate 
891*0Sstevel@tonic-gate unsigned char *
892*0Sstevel@tonic-gate vpastwh(cp)
893*0Sstevel@tonic-gate 	register unsigned char *cp;
894*0Sstevel@tonic-gate {
895*0Sstevel@tonic-gate 
896*0Sstevel@tonic-gate 	while (iswhite(*cp))
897*0Sstevel@tonic-gate 		cp++;
898*0Sstevel@tonic-gate 	return (cp);
899*0Sstevel@tonic-gate }
900*0Sstevel@tonic-gate 
901*0Sstevel@tonic-gate whitecnt(cp)
902*0Sstevel@tonic-gate 	register unsigned char *cp;
903*0Sstevel@tonic-gate {
904*0Sstevel@tonic-gate 	register int i;
905*0Sstevel@tonic-gate 
906*0Sstevel@tonic-gate 	i = 0;
907*0Sstevel@tonic-gate 	for (;;)
908*0Sstevel@tonic-gate 		switch (*cp++) {
909*0Sstevel@tonic-gate 
910*0Sstevel@tonic-gate 		case '\t':
911*0Sstevel@tonic-gate 			i += value(vi_TABSTOP) - i % value(vi_TABSTOP);
912*0Sstevel@tonic-gate 			break;
913*0Sstevel@tonic-gate 
914*0Sstevel@tonic-gate 		case ' ':
915*0Sstevel@tonic-gate 			i++;
916*0Sstevel@tonic-gate 			break;
917*0Sstevel@tonic-gate 
918*0Sstevel@tonic-gate 		default:
919*0Sstevel@tonic-gate 			return (i);
920*0Sstevel@tonic-gate 		}
921*0Sstevel@tonic-gate }
922*0Sstevel@tonic-gate 
923*0Sstevel@tonic-gate markit(addr)
924*0Sstevel@tonic-gate 	line *addr;
925*0Sstevel@tonic-gate {
926*0Sstevel@tonic-gate 
927*0Sstevel@tonic-gate 	if (addr != dot && addr >= one && addr <= dol)
928*0Sstevel@tonic-gate 		markDOT();
929*0Sstevel@tonic-gate }
930*0Sstevel@tonic-gate 
931*0Sstevel@tonic-gate /*
932*0Sstevel@tonic-gate  * The following code is defensive programming against a bug in the
933*0Sstevel@tonic-gate  * pdp-11 overlay implementation.  Sometimes it goes nuts and asks
934*0Sstevel@tonic-gate  * for an overlay with some garbage number, which generates an emt
935*0Sstevel@tonic-gate  * trap.  This is a less than elegant solution, but it is somewhat
936*0Sstevel@tonic-gate  * better than core dumping and losing your work, leaving your tty
937*0Sstevel@tonic-gate  * in a weird state, etc.
938*0Sstevel@tonic-gate  */
939*0Sstevel@tonic-gate int _ovno;
940*0Sstevel@tonic-gate 
941*0Sstevel@tonic-gate /*ARGSUSED*/
942*0Sstevel@tonic-gate void
943*0Sstevel@tonic-gate onemt(sig)
944*0Sstevel@tonic-gate int sig;
945*0Sstevel@tonic-gate {
946*0Sstevel@tonic-gate 	int oovno;
947*0Sstevel@tonic-gate 
948*0Sstevel@tonic-gate 	signal(SIGEMT, onemt);
949*0Sstevel@tonic-gate 	oovno = _ovno;
950*0Sstevel@tonic-gate 	/* 2 and 3 are valid on 11/40 type vi, so */
951*0Sstevel@tonic-gate 	if (_ovno < 0 || _ovno > 3)
952*0Sstevel@tonic-gate 		_ovno = 0;
953*0Sstevel@tonic-gate 	error(value(vi_TERSE) ? gettext("emt trap, _ovno is %d ") :
954*0Sstevel@tonic-gate gettext("emt trap, _ovno is %d   - try again"));
955*0Sstevel@tonic-gate }
956*0Sstevel@tonic-gate 
957*0Sstevel@tonic-gate /*
958*0Sstevel@tonic-gate  * When a hangup occurs our actions are similar to a preserve
959*0Sstevel@tonic-gate  * command.  If the buffer has not been [Modified], then we do
960*0Sstevel@tonic-gate  * nothing but remove the temporary files and exit.
961*0Sstevel@tonic-gate  * Otherwise, we sync the temp file and then attempt a preserve.
962*0Sstevel@tonic-gate  * If the preserve succeeds, we unlink our temp files.
963*0Sstevel@tonic-gate  * If the preserve fails, we leave the temp files as they are
964*0Sstevel@tonic-gate  * as they are a backup even without preservation if they
965*0Sstevel@tonic-gate  * are not removed.
966*0Sstevel@tonic-gate  */
967*0Sstevel@tonic-gate 
968*0Sstevel@tonic-gate /*ARGSUSED*/
969*0Sstevel@tonic-gate void
970*0Sstevel@tonic-gate onhup(sig)
971*0Sstevel@tonic-gate int sig;
972*0Sstevel@tonic-gate {
973*0Sstevel@tonic-gate 
974*0Sstevel@tonic-gate 	/*
975*0Sstevel@tonic-gate 	 * USG tty driver can send multiple HUP's!!
976*0Sstevel@tonic-gate 	 */
977*0Sstevel@tonic-gate 	signal(SIGINT, SIG_IGN);
978*0Sstevel@tonic-gate 	signal(SIGHUP, SIG_IGN);
979*0Sstevel@tonic-gate 	if (chng == 0) {
980*0Sstevel@tonic-gate 		cleanup(1);
981*0Sstevel@tonic-gate 		exit(++errcnt);
982*0Sstevel@tonic-gate 	}
983*0Sstevel@tonic-gate 	if (setexit() == 0) {
984*0Sstevel@tonic-gate 		if (preserve()) {
985*0Sstevel@tonic-gate 			cleanup(1);
986*0Sstevel@tonic-gate 			exit(++errcnt);
987*0Sstevel@tonic-gate 		}
988*0Sstevel@tonic-gate 	}
989*0Sstevel@tonic-gate 	if (kflag)
990*0Sstevel@tonic-gate 		crypt_close(perm);
991*0Sstevel@tonic-gate 	if (xtflag)
992*0Sstevel@tonic-gate 		crypt_close(tperm);
993*0Sstevel@tonic-gate 	exit(++errcnt);
994*0Sstevel@tonic-gate }
995*0Sstevel@tonic-gate 
996*0Sstevel@tonic-gate /*
997*0Sstevel@tonic-gate  * Similar to onhup.  This happens when any random core dump occurs,
998*0Sstevel@tonic-gate  * e.g. a bug in vi.  We preserve the file and then generate a core.
999*0Sstevel@tonic-gate  */
1000*0Sstevel@tonic-gate void oncore(sig)
1001*0Sstevel@tonic-gate int sig;
1002*0Sstevel@tonic-gate {
1003*0Sstevel@tonic-gate 	static int timescalled = 0;
1004*0Sstevel@tonic-gate 	char *messagep;	/* for message localization */
1005*0Sstevel@tonic-gate 
1006*0Sstevel@tonic-gate 	/*
1007*0Sstevel@tonic-gate 	 * USG tty driver can send multiple HUP's!!
1008*0Sstevel@tonic-gate 	 */
1009*0Sstevel@tonic-gate 	signal(SIGINT, SIG_IGN);
1010*0Sstevel@tonic-gate 	signal(SIGHUP, SIG_IGN);
1011*0Sstevel@tonic-gate 	signal(sig, SIG_DFL);	/* Insure that we don't catch it again */
1012*0Sstevel@tonic-gate 	messagep = (char *)gettext("\r\nYour file has been preserved\r\n");
1013*0Sstevel@tonic-gate 	if (timescalled++ == 0 && chng && setexit() == 0) {
1014*0Sstevel@tonic-gate 		if (inopen)
1015*0Sstevel@tonic-gate 			vsave();
1016*0Sstevel@tonic-gate 		preserve();
1017*0Sstevel@tonic-gate 		write(1, messagep, strlen(messagep));
1018*0Sstevel@tonic-gate 	}
1019*0Sstevel@tonic-gate 	if (timescalled < 2) {
1020*0Sstevel@tonic-gate 		normal(normf);
1021*0Sstevel@tonic-gate 		cleanup(2);
1022*0Sstevel@tonic-gate 		kill(getpid(), sig);	/* Resend ourselves the same signal */
1023*0Sstevel@tonic-gate 		/* We won't get past here */
1024*0Sstevel@tonic-gate 	}
1025*0Sstevel@tonic-gate 	if (kflag)
1026*0Sstevel@tonic-gate 		crypt_close(perm);
1027*0Sstevel@tonic-gate 	if (xtflag)
1028*0Sstevel@tonic-gate 		crypt_close(tperm);
1029*0Sstevel@tonic-gate 	exit(++errcnt);
1030*0Sstevel@tonic-gate }
1031*0Sstevel@tonic-gate 
1032*0Sstevel@tonic-gate /*
1033*0Sstevel@tonic-gate  * An interrupt occurred.  Drain any output which
1034*0Sstevel@tonic-gate  * is still in the output buffering pipeline.
1035*0Sstevel@tonic-gate  * Catch interrupts again.  Unless we are in visual
1036*0Sstevel@tonic-gate  * reset the output state (out of -nl mode, e.g).
1037*0Sstevel@tonic-gate  * Then like a normal error (with the \n before Interrupt
1038*0Sstevel@tonic-gate  * suppressed in visual mode).
1039*0Sstevel@tonic-gate  */
1040*0Sstevel@tonic-gate 
1041*0Sstevel@tonic-gate /*ARGSUSED*/
1042*0Sstevel@tonic-gate void
1043*0Sstevel@tonic-gate onintr(sig)
1044*0Sstevel@tonic-gate int sig;
1045*0Sstevel@tonic-gate {
1046*0Sstevel@tonic-gate #ifndef CBREAK
1047*0Sstevel@tonic-gate 	signal(SIGINT, onintr);
1048*0Sstevel@tonic-gate #else
1049*0Sstevel@tonic-gate 	signal(SIGINT, inopen ? vintr : onintr);
1050*0Sstevel@tonic-gate #endif
1051*0Sstevel@tonic-gate 	cancelalarm();
1052*0Sstevel@tonic-gate 	draino();
1053*0Sstevel@tonic-gate 	if (!inopen) {
1054*0Sstevel@tonic-gate 		pstop();
1055*0Sstevel@tonic-gate 		setlastchar('\n');
1056*0Sstevel@tonic-gate #ifdef CBREAK
1057*0Sstevel@tonic-gate 	}
1058*0Sstevel@tonic-gate #else
1059*0Sstevel@tonic-gate 	} else
1060*0Sstevel@tonic-gate 		vraw();
1061*0Sstevel@tonic-gate #endif
1062*0Sstevel@tonic-gate 	error(gettext("\nInterrupt") + (inopen!=0));
1063*0Sstevel@tonic-gate }
1064*0Sstevel@tonic-gate 
1065*0Sstevel@tonic-gate /*
1066*0Sstevel@tonic-gate  * If we are interruptible, enable interrupts again.
1067*0Sstevel@tonic-gate  * In some critical sections we turn interrupts off,
1068*0Sstevel@tonic-gate  * but not very often.
1069*0Sstevel@tonic-gate  */
1070*0Sstevel@tonic-gate setrupt()
1071*0Sstevel@tonic-gate {
1072*0Sstevel@tonic-gate 
1073*0Sstevel@tonic-gate 	if (ruptible) {
1074*0Sstevel@tonic-gate #ifndef CBREAK
1075*0Sstevel@tonic-gate 		signal(SIGINT, onintr);
1076*0Sstevel@tonic-gate #else
1077*0Sstevel@tonic-gate 		signal(SIGINT, inopen ? vintr : onintr);
1078*0Sstevel@tonic-gate #endif
1079*0Sstevel@tonic-gate #ifdef SIGTSTP
1080*0Sstevel@tonic-gate 		if (dosusp)
1081*0Sstevel@tonic-gate 			signal(SIGTSTP, onsusp);
1082*0Sstevel@tonic-gate #endif
1083*0Sstevel@tonic-gate 	}
1084*0Sstevel@tonic-gate }
1085*0Sstevel@tonic-gate 
1086*0Sstevel@tonic-gate preserve()
1087*0Sstevel@tonic-gate {
1088*0Sstevel@tonic-gate 
1089*0Sstevel@tonic-gate #ifdef VMUNIX
1090*0Sstevel@tonic-gate 	tflush();
1091*0Sstevel@tonic-gate #endif
1092*0Sstevel@tonic-gate 	synctmp();
1093*0Sstevel@tonic-gate 	pid = fork();
1094*0Sstevel@tonic-gate 	if (pid < 0)
1095*0Sstevel@tonic-gate 		return (0);
1096*0Sstevel@tonic-gate 	if (pid == 0) {
1097*0Sstevel@tonic-gate 		close(0);
1098*0Sstevel@tonic-gate 		dup(tfile);
1099*0Sstevel@tonic-gate 		execlp(EXPRESERVE, "expreserve", (char *) 0);
1100*0Sstevel@tonic-gate 		exit(++errcnt);
1101*0Sstevel@tonic-gate 	}
1102*0Sstevel@tonic-gate 	waitfor();
1103*0Sstevel@tonic-gate 	if (rpid == pid && status == 0)
1104*0Sstevel@tonic-gate 		return (1);
1105*0Sstevel@tonic-gate 	return (0);
1106*0Sstevel@tonic-gate }
1107*0Sstevel@tonic-gate 
1108*0Sstevel@tonic-gate #ifndef V6
1109*0Sstevel@tonic-gate void exit(i)
1110*0Sstevel@tonic-gate 	int i;
1111*0Sstevel@tonic-gate {
1112*0Sstevel@tonic-gate 
1113*0Sstevel@tonic-gate #ifdef TRACE
1114*0Sstevel@tonic-gate 	if (trace)
1115*0Sstevel@tonic-gate 		fclose(trace);
1116*0Sstevel@tonic-gate #endif
1117*0Sstevel@tonic-gate 	_exit(i);
1118*0Sstevel@tonic-gate }
1119*0Sstevel@tonic-gate #endif
1120*0Sstevel@tonic-gate 
1121*0Sstevel@tonic-gate #ifdef SIGTSTP
1122*0Sstevel@tonic-gate /*
1123*0Sstevel@tonic-gate  * We have just gotten a susp.  Suspend and prepare to resume.
1124*0Sstevel@tonic-gate  */
1125*0Sstevel@tonic-gate extern void redraw();
1126*0Sstevel@tonic-gate 
1127*0Sstevel@tonic-gate /*ARGSUSED*/
1128*0Sstevel@tonic-gate void
1129*0Sstevel@tonic-gate onsusp(sig)
1130*0Sstevel@tonic-gate int sig;
1131*0Sstevel@tonic-gate {
1132*0Sstevel@tonic-gate 	ttymode f;
1133*0Sstevel@tonic-gate 	int savenormtty;
1134*0Sstevel@tonic-gate 
1135*0Sstevel@tonic-gate 	f = setty(normf);
1136*0Sstevel@tonic-gate 	vnfl();
1137*0Sstevel@tonic-gate 	putpad(exit_ca_mode);
1138*0Sstevel@tonic-gate 	flush();
1139*0Sstevel@tonic-gate 	resetterm();
1140*0Sstevel@tonic-gate 	savenormtty = normtty;
1141*0Sstevel@tonic-gate 	normtty = 0;
1142*0Sstevel@tonic-gate 
1143*0Sstevel@tonic-gate 	signal(SIGTSTP, SIG_DFL);
1144*0Sstevel@tonic-gate 	kill(0, SIGTSTP);
1145*0Sstevel@tonic-gate 
1146*0Sstevel@tonic-gate 	/* the pc stops here */
1147*0Sstevel@tonic-gate 
1148*0Sstevel@tonic-gate 	signal(SIGTSTP, onsusp);
1149*0Sstevel@tonic-gate 	normtty = savenormtty;
1150*0Sstevel@tonic-gate 	vcontin(0);
1151*0Sstevel@tonic-gate 	flush();
1152*0Sstevel@tonic-gate 	setty(f);
1153*0Sstevel@tonic-gate 	if (!inopen)
1154*0Sstevel@tonic-gate 		error(0);
1155*0Sstevel@tonic-gate 	else {
1156*0Sstevel@tonic-gate 		if(vcnt < 0) {
1157*0Sstevel@tonic-gate 			vcnt = -vcnt;
1158*0Sstevel@tonic-gate 			if(state == VISUAL)
1159*0Sstevel@tonic-gate 				vclear();
1160*0Sstevel@tonic-gate 			else if(state == CRTOPEN)
1161*0Sstevel@tonic-gate 				vcnt = 0;
1162*0Sstevel@tonic-gate 		}
1163*0Sstevel@tonic-gate 		vdirty(0, lines);
1164*0Sstevel@tonic-gate 		if (sig)
1165*0Sstevel@tonic-gate 			vrepaint(cursor);
1166*0Sstevel@tonic-gate 	}
1167*0Sstevel@tonic-gate }
1168*0Sstevel@tonic-gate #endif
1169*0Sstevel@tonic-gate 
1170*0Sstevel@tonic-gate unsigned char *nextchr(cursor)
1171*0Sstevel@tonic-gate unsigned char *cursor;
1172*0Sstevel@tonic-gate {
1173*0Sstevel@tonic-gate 
1174*0Sstevel@tonic-gate 	wchar_t wchar;
1175*0Sstevel@tonic-gate 	int length;
1176*0Sstevel@tonic-gate 	length = mbtowc(&wchar, (char *)cursor, MULTI_BYTE_MAX);
1177*0Sstevel@tonic-gate 	if(length <= 0)
1178*0Sstevel@tonic-gate 		return(++cursor);
1179*0Sstevel@tonic-gate 	return(cursor + length);
1180*0Sstevel@tonic-gate }
1181*0Sstevel@tonic-gate 
1182*0Sstevel@tonic-gate unsigned char *lastchr(linebuf, cursor)
1183*0Sstevel@tonic-gate unsigned char *linebuf, *cursor;
1184*0Sstevel@tonic-gate {
1185*0Sstevel@tonic-gate 	wchar_t wchar;
1186*0Sstevel@tonic-gate 	int length;
1187*0Sstevel@tonic-gate 	unsigned char *ccursor, *ocursor;
1188*0Sstevel@tonic-gate 	if(cursor == linebuf)
1189*0Sstevel@tonic-gate 		return(linebuf - 1);
1190*0Sstevel@tonic-gate 	ccursor = ocursor = linebuf;
1191*0Sstevel@tonic-gate 	while(ccursor < cursor) {
1192*0Sstevel@tonic-gate 		length = mbtowc(&wchar, (char *)ccursor, MULTI_BYTE_MAX);
1193*0Sstevel@tonic-gate 		ocursor =  ccursor;
1194*0Sstevel@tonic-gate 		if(length <= 0)
1195*0Sstevel@tonic-gate 			ccursor++;
1196*0Sstevel@tonic-gate 		else
1197*0Sstevel@tonic-gate 			ccursor += length;
1198*0Sstevel@tonic-gate 	}
1199*0Sstevel@tonic-gate 	return(ocursor);
1200*0Sstevel@tonic-gate }
1201*0Sstevel@tonic-gate 
1202*0Sstevel@tonic-gate ixlatctl(flag)
1203*0Sstevel@tonic-gate 	int flag;
1204*0Sstevel@tonic-gate {
1205*0Sstevel@tonic-gate 	static struct strioctl sb = {0, 0, 0, 0};
1206*0Sstevel@tonic-gate 
1207*0Sstevel@tonic-gate 	if (!(MULTI_BYTE_MAX > 1))
1208*0Sstevel@tonic-gate 		return (0);
1209*0Sstevel@tonic-gate 
1210*0Sstevel@tonic-gate 	switch (flag) {
1211*0Sstevel@tonic-gate 	case 0:
1212*0Sstevel@tonic-gate 		sb.ic_cmd = EUC_MSAVE;
1213*0Sstevel@tonic-gate 		sb.ic_len = 0;
1214*0Sstevel@tonic-gate 		sb.ic_dp = 0;
1215*0Sstevel@tonic-gate 		if (ioctl(0, I_STR, &sb) < 0)
1216*0Sstevel@tonic-gate 			return (-1);
1217*0Sstevel@tonic-gate 		return (0);
1218*0Sstevel@tonic-gate 	case 1:
1219*0Sstevel@tonic-gate 		sb.ic_cmd = EUC_MREST;
1220*0Sstevel@tonic-gate 		sb.ic_len = 0;
1221*0Sstevel@tonic-gate 		sb.ic_dp = 0;
1222*0Sstevel@tonic-gate 		if (ioctl(0, I_STR, &sb) < 0)
1223*0Sstevel@tonic-gate 			return (-1);
1224*0Sstevel@tonic-gate 		return (0);
1225*0Sstevel@tonic-gate 	case 11:
1226*0Sstevel@tonic-gate 		return (0);
1227*0Sstevel@tonic-gate 	default:
1228*0Sstevel@tonic-gate 		return (-1);
1229*0Sstevel@tonic-gate 	}
1230*0Sstevel@tonic-gate }
1231*0Sstevel@tonic-gate #ifndef PRESUNEUC
1232*0Sstevel@tonic-gate 
1233*0Sstevel@tonic-gate /* locale specific initialization */
1234*0Sstevel@tonic-gate int localize()
1235*0Sstevel@tonic-gate {
1236*0Sstevel@tonic-gate 	wchar_t fillerchar;
1237*0Sstevel@tonic-gate 	extern int	wdchkind();
1238*0Sstevel@tonic-gate 	extern int	wdbindf();
1239*0Sstevel@tonic-gate 	extern wchar_t	*wddelim();
1240*0Sstevel@tonic-gate 	extern wchar_t	mcfiller();
1241*0Sstevel@tonic-gate 
1242*0Sstevel@tonic-gate 	wdwc = wdchkind;
1243*0Sstevel@tonic-gate 	wdbdg = wdbindf;
1244*0Sstevel@tonic-gate 	wddlm = wddelim;
1245*0Sstevel@tonic-gate 	mcfllr = mcfiller;
1246*0Sstevel@tonic-gate 	mc_wrap = 1;
1247*0Sstevel@tonic-gate 	fillerchar = mcfiller();
1248*0Sstevel@tonic-gate 	mc_filler = isascii(fillerchar) ? (fillerchar & 0x7f) : '~';
1249*0Sstevel@tonic-gate }
1250*0Sstevel@tonic-gate #endif /* PRESUNEUC */
1251