xref: /minix3/usr.bin/ul/ul.c (revision a501098bf5c6aa07e28212d21c5d9ff8546caef5)
1*a501098bSThomas Cort /*	$NetBSD: ul.c,v 1.16 2012/03/20 20:34:59 matt Exp $	*/
2*a501098bSThomas Cort 
3*a501098bSThomas Cort /*
4*a501098bSThomas Cort  * Copyright (c) 1980, 1993
5*a501098bSThomas Cort  *	The Regents of the University of California.  All rights reserved.
6*a501098bSThomas Cort  *
7*a501098bSThomas Cort  * Redistribution and use in source and binary forms, with or without
8*a501098bSThomas Cort  * modification, are permitted provided that the following conditions
9*a501098bSThomas Cort  * are met:
10*a501098bSThomas Cort  * 1. Redistributions of source code must retain the above copyright
11*a501098bSThomas Cort  *    notice, this list of conditions and the following disclaimer.
12*a501098bSThomas Cort  * 2. Redistributions in binary form must reproduce the above copyright
13*a501098bSThomas Cort  *    notice, this list of conditions and the following disclaimer in the
14*a501098bSThomas Cort  *    documentation and/or other materials provided with the distribution.
15*a501098bSThomas Cort  * 3. Neither the name of the University nor the names of its contributors
16*a501098bSThomas Cort  *    may be used to endorse or promote products derived from this software
17*a501098bSThomas Cort  *    without specific prior written permission.
18*a501098bSThomas Cort  *
19*a501098bSThomas Cort  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*a501098bSThomas Cort  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*a501098bSThomas Cort  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*a501098bSThomas Cort  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*a501098bSThomas Cort  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*a501098bSThomas Cort  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*a501098bSThomas Cort  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*a501098bSThomas Cort  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*a501098bSThomas Cort  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*a501098bSThomas Cort  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*a501098bSThomas Cort  * SUCH DAMAGE.
30*a501098bSThomas Cort  */
31*a501098bSThomas Cort 
32*a501098bSThomas Cort #include <sys/cdefs.h>
33*a501098bSThomas Cort #ifndef lint
34*a501098bSThomas Cort __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
35*a501098bSThomas Cort  The Regents of the University of California.  All rights reserved.");
36*a501098bSThomas Cort #endif /* not lint */
37*a501098bSThomas Cort 
38*a501098bSThomas Cort #ifndef lint
39*a501098bSThomas Cort #if 0
40*a501098bSThomas Cort static char sccsid[] = "@(#)ul.c	8.1 (Berkeley) 6/6/93";
41*a501098bSThomas Cort #endif
42*a501098bSThomas Cort __RCSID("$NetBSD: ul.c,v 1.16 2012/03/20 20:34:59 matt Exp $");
43*a501098bSThomas Cort #endif /* not lint */
44*a501098bSThomas Cort 
45*a501098bSThomas Cort #include <stdio.h>
46*a501098bSThomas Cort #include <stdlib.h>
47*a501098bSThomas Cort #include <string.h>
48*a501098bSThomas Cort #include <term.h>
49*a501098bSThomas Cort #include <unistd.h>
50*a501098bSThomas Cort 
51*a501098bSThomas Cort #define	IESC	'\033'
52*a501098bSThomas Cort #define	SO	'\016'
53*a501098bSThomas Cort #define	SI	'\017'
54*a501098bSThomas Cort #define	HFWD	'9'
55*a501098bSThomas Cort #define	HREV	'8'
56*a501098bSThomas Cort #define	FREV	'7'
57*a501098bSThomas Cort #define	MAXBUF	512
58*a501098bSThomas Cort 
59*a501098bSThomas Cort #define	NORMAL	000
60*a501098bSThomas Cort #define	ALTSET	001	/* Reverse */
61*a501098bSThomas Cort #define	SUPERSC	002	/* Dim */
62*a501098bSThomas Cort #define	SUBSC	004	/* Dim | Ul */
63*a501098bSThomas Cort #define	UNDERL	010	/* Ul */
64*a501098bSThomas Cort #define	BOLD	020	/* Bold */
65*a501098bSThomas Cort 
66*a501098bSThomas Cort struct tinfo *info;
67*a501098bSThomas Cort int	must_overstrike;
68*a501098bSThomas Cort const char *CURS_UP, *CURS_RIGHT, *CURS_LEFT,
69*a501098bSThomas Cort 	*ENTER_STANDOUT, *EXIT_STANDOUT, *ENTER_UNDERLINE, *EXIT_UNDERLINE,
70*a501098bSThomas Cort 	*ENTER_DIM, *ENTER_BOLD, *ENTER_REVERSE, *UNDER_CHAR, *EXIT_ATTRIBUTES;
71*a501098bSThomas Cort 
72*a501098bSThomas Cort struct	CHAR	{
73*a501098bSThomas Cort 	char	c_mode;
74*a501098bSThomas Cort 	char	c_char;
75*a501098bSThomas Cort } ;
76*a501098bSThomas Cort 
77*a501098bSThomas Cort struct	CHAR	obuf[MAXBUF];
78*a501098bSThomas Cort int	col, maxcol;
79*a501098bSThomas Cort int	mode;
80*a501098bSThomas Cort int	halfpos;
81*a501098bSThomas Cort int	upln;
82*a501098bSThomas Cort int	iflag;
83*a501098bSThomas Cort 
84*a501098bSThomas Cort int	main __P((int, char **));
85*a501098bSThomas Cort void	filter __P((FILE *));
86*a501098bSThomas Cort void	flushln __P((void));
87*a501098bSThomas Cort void	fwd __P((void));
88*a501098bSThomas Cort void	iattr __P((void));
89*a501098bSThomas Cort void	initbuf __P((void));
90*a501098bSThomas Cort void	initcap __P((void));
91*a501098bSThomas Cort void	outc __P((int));
92*a501098bSThomas Cort int	outchar __P((int));
93*a501098bSThomas Cort void	overstrike __P((void));
94*a501098bSThomas Cort void	reverse __P((void));
95*a501098bSThomas Cort void	setulmode __P((int));
96*a501098bSThomas Cort 
97*a501098bSThomas Cort 
98*a501098bSThomas Cort #define	PRINT(s)	if (s == NULL) /* void */; else tputs(s, 1, outchar)
99*a501098bSThomas Cort 
100*a501098bSThomas Cort int
main(int argc,char ** argv)101*a501098bSThomas Cort main(int argc, char **argv)
102*a501098bSThomas Cort {
103*a501098bSThomas Cort 	int c;
104*a501098bSThomas Cort 	const char *termtype;
105*a501098bSThomas Cort 	FILE *f;
106*a501098bSThomas Cort 
107*a501098bSThomas Cort 	termtype = getenv("TERM");
108*a501098bSThomas Cort 	if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
109*a501098bSThomas Cort 		termtype = "lpr";
110*a501098bSThomas Cort 	while ((c=getopt(argc, argv, "it:T:")) != -1)
111*a501098bSThomas Cort 		switch(c) {
112*a501098bSThomas Cort 
113*a501098bSThomas Cort 		case 't':
114*a501098bSThomas Cort 		case 'T': /* for nroff compatibility */
115*a501098bSThomas Cort 				termtype = optarg;
116*a501098bSThomas Cort 			break;
117*a501098bSThomas Cort 		case 'i':
118*a501098bSThomas Cort 			iflag = 1;
119*a501098bSThomas Cort 			break;
120*a501098bSThomas Cort 
121*a501098bSThomas Cort 		default:
122*a501098bSThomas Cort 			fprintf(stderr,
123*a501098bSThomas Cort 				"usage: %s [ -i ] [ -tTerm ] file...\n",
124*a501098bSThomas Cort 				argv[0]);
125*a501098bSThomas Cort 			exit(1);
126*a501098bSThomas Cort 		}
127*a501098bSThomas Cort 
128*a501098bSThomas Cort 	setupterm(termtype, 0, NULL);
129*a501098bSThomas Cort 	if ((over_strike && enter_bold_mode == NULL) ||
130*a501098bSThomas Cort 	    (transparent_underline && enter_underline_mode == NULL &&
131*a501098bSThomas Cort 	     underline_char == NULL))
132*a501098bSThomas Cort 	initbuf();
133*a501098bSThomas Cort 	if (optind == argc)
134*a501098bSThomas Cort 		filter(stdin);
135*a501098bSThomas Cort 	else for (; optind<argc; optind++) {
136*a501098bSThomas Cort 		f = fopen(argv[optind],"r");
137*a501098bSThomas Cort 		if (f == NULL) {
138*a501098bSThomas Cort 			perror(argv[optind]);
139*a501098bSThomas Cort 			exit(1);
140*a501098bSThomas Cort 		}
141*a501098bSThomas Cort 
142*a501098bSThomas Cort 		filter(f);
143*a501098bSThomas Cort 		fclose(f);
144*a501098bSThomas Cort 	}
145*a501098bSThomas Cort 	exit(0);
146*a501098bSThomas Cort }
147*a501098bSThomas Cort 
148*a501098bSThomas Cort void
filter(FILE * f)149*a501098bSThomas Cort filter(FILE *f)
150*a501098bSThomas Cort {
151*a501098bSThomas Cort 	int c;
152*a501098bSThomas Cort 
153*a501098bSThomas Cort 	while ((c = getc(f)) != EOF) switch(c) {
154*a501098bSThomas Cort 
155*a501098bSThomas Cort 	case '\b':
156*a501098bSThomas Cort 		if (col > 0)
157*a501098bSThomas Cort 			col--;
158*a501098bSThomas Cort 		continue;
159*a501098bSThomas Cort 
160*a501098bSThomas Cort 	case '\t':
161*a501098bSThomas Cort 		col = (col+8) & ~07;
162*a501098bSThomas Cort 		if (col > maxcol)
163*a501098bSThomas Cort 			maxcol = col;
164*a501098bSThomas Cort 		continue;
165*a501098bSThomas Cort 
166*a501098bSThomas Cort 	case '\r':
167*a501098bSThomas Cort 		col = 0;
168*a501098bSThomas Cort 		continue;
169*a501098bSThomas Cort 
170*a501098bSThomas Cort 	case SO:
171*a501098bSThomas Cort 		mode |= ALTSET;
172*a501098bSThomas Cort 		continue;
173*a501098bSThomas Cort 
174*a501098bSThomas Cort 	case SI:
175*a501098bSThomas Cort 		mode &= ~ALTSET;
176*a501098bSThomas Cort 		continue;
177*a501098bSThomas Cort 
178*a501098bSThomas Cort 	case IESC:
179*a501098bSThomas Cort 		switch (c = getc(f)) {
180*a501098bSThomas Cort 
181*a501098bSThomas Cort 		case HREV:
182*a501098bSThomas Cort 			if (halfpos == 0) {
183*a501098bSThomas Cort 				mode |= SUPERSC;
184*a501098bSThomas Cort 				halfpos--;
185*a501098bSThomas Cort 			} else if (halfpos > 0) {
186*a501098bSThomas Cort 				mode &= ~SUBSC;
187*a501098bSThomas Cort 				halfpos--;
188*a501098bSThomas Cort 			} else {
189*a501098bSThomas Cort 				halfpos = 0;
190*a501098bSThomas Cort 				reverse();
191*a501098bSThomas Cort 			}
192*a501098bSThomas Cort 			continue;
193*a501098bSThomas Cort 
194*a501098bSThomas Cort 		case HFWD:
195*a501098bSThomas Cort 			if (halfpos == 0) {
196*a501098bSThomas Cort 				mode |= SUBSC;
197*a501098bSThomas Cort 				halfpos++;
198*a501098bSThomas Cort 			} else if (halfpos < 0) {
199*a501098bSThomas Cort 				mode &= ~SUPERSC;
200*a501098bSThomas Cort 				halfpos++;
201*a501098bSThomas Cort 			} else {
202*a501098bSThomas Cort 				halfpos = 0;
203*a501098bSThomas Cort 				fwd();
204*a501098bSThomas Cort 			}
205*a501098bSThomas Cort 			continue;
206*a501098bSThomas Cort 
207*a501098bSThomas Cort 		case FREV:
208*a501098bSThomas Cort 			reverse();
209*a501098bSThomas Cort 			continue;
210*a501098bSThomas Cort 
211*a501098bSThomas Cort 		default:
212*a501098bSThomas Cort 			fprintf(stderr,
213*a501098bSThomas Cort 				"Unknown escape sequence in input: %o, %o\n",
214*a501098bSThomas Cort 				IESC, c);
215*a501098bSThomas Cort 			exit(1);
216*a501098bSThomas Cort 		}
217*a501098bSThomas Cort 		continue;
218*a501098bSThomas Cort 
219*a501098bSThomas Cort 	case '_':
220*a501098bSThomas Cort 		if (obuf[col].c_char)
221*a501098bSThomas Cort 			obuf[col].c_mode |= UNDERL | mode;
222*a501098bSThomas Cort 		else
223*a501098bSThomas Cort 			obuf[col].c_char = '_';
224*a501098bSThomas Cort 	case ' ':
225*a501098bSThomas Cort 		col++;
226*a501098bSThomas Cort 		if (col > maxcol)
227*a501098bSThomas Cort 			maxcol = col;
228*a501098bSThomas Cort 		continue;
229*a501098bSThomas Cort 
230*a501098bSThomas Cort 	case '\n':
231*a501098bSThomas Cort 		flushln();
232*a501098bSThomas Cort 		continue;
233*a501098bSThomas Cort 
234*a501098bSThomas Cort 	case '\f':
235*a501098bSThomas Cort 		flushln();
236*a501098bSThomas Cort 		putchar('\f');
237*a501098bSThomas Cort 		continue;
238*a501098bSThomas Cort 
239*a501098bSThomas Cort 	default:
240*a501098bSThomas Cort 		if (c < ' ')	/* non printing */
241*a501098bSThomas Cort 			continue;
242*a501098bSThomas Cort 		if (obuf[col].c_char == '\0') {
243*a501098bSThomas Cort 			obuf[col].c_char = c;
244*a501098bSThomas Cort 			obuf[col].c_mode = mode;
245*a501098bSThomas Cort 		} else if (obuf[col].c_char == '_') {
246*a501098bSThomas Cort 			obuf[col].c_char = c;
247*a501098bSThomas Cort 			obuf[col].c_mode |= UNDERL|mode;
248*a501098bSThomas Cort 		} else if (obuf[col].c_char == c)
249*a501098bSThomas Cort 			obuf[col].c_mode |= BOLD|mode;
250*a501098bSThomas Cort 		else
251*a501098bSThomas Cort 			obuf[col].c_mode = mode;
252*a501098bSThomas Cort 		col++;
253*a501098bSThomas Cort 		if (col > maxcol)
254*a501098bSThomas Cort 			maxcol = col;
255*a501098bSThomas Cort 		continue;
256*a501098bSThomas Cort 	}
257*a501098bSThomas Cort 	if (maxcol)
258*a501098bSThomas Cort 		flushln();
259*a501098bSThomas Cort }
260*a501098bSThomas Cort 
261*a501098bSThomas Cort void
flushln(void)262*a501098bSThomas Cort flushln(void)
263*a501098bSThomas Cort {
264*a501098bSThomas Cort 	int lastmode;
265*a501098bSThomas Cort 	int i;
266*a501098bSThomas Cort 	int hadmodes = 0;
267*a501098bSThomas Cort 
268*a501098bSThomas Cort 	lastmode = NORMAL;
269*a501098bSThomas Cort 	for (i=0; i<maxcol; i++) {
270*a501098bSThomas Cort 		if (obuf[i].c_mode != lastmode) {
271*a501098bSThomas Cort 			hadmodes++;
272*a501098bSThomas Cort 			setulmode(obuf[i].c_mode);
273*a501098bSThomas Cort 			lastmode = obuf[i].c_mode;
274*a501098bSThomas Cort 		}
275*a501098bSThomas Cort 		if (obuf[i].c_char == '\0') {
276*a501098bSThomas Cort 			if (upln) {
277*a501098bSThomas Cort 				PRINT(cursor_right);
278*a501098bSThomas Cort 			}
279*a501098bSThomas Cort 			else {
280*a501098bSThomas Cort 				outc(' ');
281*a501098bSThomas Cort 			}
282*a501098bSThomas Cort 		} else
283*a501098bSThomas Cort 			outc(obuf[i].c_char);
284*a501098bSThomas Cort 	}
285*a501098bSThomas Cort 	if (lastmode != NORMAL) {
286*a501098bSThomas Cort 		setulmode(0);
287*a501098bSThomas Cort 	}
288*a501098bSThomas Cort 	if (must_overstrike && hadmodes)
289*a501098bSThomas Cort 		overstrike();
290*a501098bSThomas Cort 	putchar('\n');
291*a501098bSThomas Cort 	if (iflag && hadmodes)
292*a501098bSThomas Cort 		iattr();
293*a501098bSThomas Cort 	(void)fflush(stdout);
294*a501098bSThomas Cort 	if (upln)
295*a501098bSThomas Cort 		upln--;
296*a501098bSThomas Cort 	initbuf();
297*a501098bSThomas Cort }
298*a501098bSThomas Cort 
299*a501098bSThomas Cort /*
300*a501098bSThomas Cort  * For terminals that can overstrike, overstrike underlines and bolds.
301*a501098bSThomas Cort  * We don't do anything with halfline ups and downs, or Greek.
302*a501098bSThomas Cort  */
303*a501098bSThomas Cort void
overstrike(void)304*a501098bSThomas Cort overstrike(void)
305*a501098bSThomas Cort {
306*a501098bSThomas Cort 	int i;
307*a501098bSThomas Cort 	char lbuf[256];
308*a501098bSThomas Cort 	char *cp = lbuf;
309*a501098bSThomas Cort 	int hadbold=0;
310*a501098bSThomas Cort 
311*a501098bSThomas Cort 	/* Set up overstrike buffer */
312*a501098bSThomas Cort 	for (i=0; i<maxcol; i++)
313*a501098bSThomas Cort 		switch (obuf[i].c_mode) {
314*a501098bSThomas Cort 		case NORMAL:
315*a501098bSThomas Cort 		default:
316*a501098bSThomas Cort 			*cp++ = ' ';
317*a501098bSThomas Cort 			break;
318*a501098bSThomas Cort 		case UNDERL:
319*a501098bSThomas Cort 			*cp++ = '_';
320*a501098bSThomas Cort 			break;
321*a501098bSThomas Cort 		case BOLD:
322*a501098bSThomas Cort 			*cp++ = obuf[i].c_char;
323*a501098bSThomas Cort 			hadbold=1;
324*a501098bSThomas Cort 			break;
325*a501098bSThomas Cort 		}
326*a501098bSThomas Cort 	putchar('\r');
327*a501098bSThomas Cort 	for (*cp=' '; *cp==' '; cp--)
328*a501098bSThomas Cort 		*cp = 0;
329*a501098bSThomas Cort 	for (cp=lbuf; *cp; cp++)
330*a501098bSThomas Cort 		putchar(*cp);
331*a501098bSThomas Cort 	if (hadbold) {
332*a501098bSThomas Cort 		putchar('\r');
333*a501098bSThomas Cort 		for (cp=lbuf; *cp; cp++)
334*a501098bSThomas Cort 			putchar(*cp=='_' ? ' ' : *cp);
335*a501098bSThomas Cort 		putchar('\r');
336*a501098bSThomas Cort 		for (cp=lbuf; *cp; cp++)
337*a501098bSThomas Cort 			putchar(*cp=='_' ? ' ' : *cp);
338*a501098bSThomas Cort 	}
339*a501098bSThomas Cort }
340*a501098bSThomas Cort 
341*a501098bSThomas Cort void
iattr(void)342*a501098bSThomas Cort iattr(void)
343*a501098bSThomas Cort {
344*a501098bSThomas Cort 	int i;
345*a501098bSThomas Cort 	char lbuf[256];
346*a501098bSThomas Cort 	char *cp = lbuf;
347*a501098bSThomas Cort 
348*a501098bSThomas Cort 	for (i=0; i<maxcol; i++)
349*a501098bSThomas Cort 		switch (obuf[i].c_mode) {
350*a501098bSThomas Cort 		case NORMAL:	*cp++ = ' '; break;
351*a501098bSThomas Cort 		case ALTSET:	*cp++ = 'g'; break;
352*a501098bSThomas Cort 		case SUPERSC:	*cp++ = '^'; break;
353*a501098bSThomas Cort 		case SUBSC:	*cp++ = 'v'; break;
354*a501098bSThomas Cort 		case UNDERL:	*cp++ = '_'; break;
355*a501098bSThomas Cort 		case BOLD:	*cp++ = '!'; break;
356*a501098bSThomas Cort 		default:	*cp++ = 'X'; break;
357*a501098bSThomas Cort 		}
358*a501098bSThomas Cort 	for (*cp=' '; *cp==' '; cp--)
359*a501098bSThomas Cort 		*cp = 0;
360*a501098bSThomas Cort 	for (cp=lbuf; *cp; cp++)
361*a501098bSThomas Cort 		putchar(*cp);
362*a501098bSThomas Cort 	putchar('\n');
363*a501098bSThomas Cort }
364*a501098bSThomas Cort 
365*a501098bSThomas Cort void
initbuf(void)366*a501098bSThomas Cort initbuf(void)
367*a501098bSThomas Cort {
368*a501098bSThomas Cort 
369*a501098bSThomas Cort 	memset((char *)obuf, 0, sizeof (obuf));	/* depends on NORMAL == 0 */
370*a501098bSThomas Cort 	col = 0;
371*a501098bSThomas Cort 	maxcol = 0;
372*a501098bSThomas Cort 	mode &= ALTSET;
373*a501098bSThomas Cort }
374*a501098bSThomas Cort 
375*a501098bSThomas Cort void
fwd(void)376*a501098bSThomas Cort fwd(void)
377*a501098bSThomas Cort {
378*a501098bSThomas Cort 	int oldcol, oldmax;
379*a501098bSThomas Cort 
380*a501098bSThomas Cort 	oldcol = col;
381*a501098bSThomas Cort 	oldmax = maxcol;
382*a501098bSThomas Cort 	flushln();
383*a501098bSThomas Cort 	col = oldcol;
384*a501098bSThomas Cort 	maxcol = oldmax;
385*a501098bSThomas Cort }
386*a501098bSThomas Cort 
387*a501098bSThomas Cort void
reverse(void)388*a501098bSThomas Cort reverse(void)
389*a501098bSThomas Cort {
390*a501098bSThomas Cort 	upln++;
391*a501098bSThomas Cort 	fwd();
392*a501098bSThomas Cort 	PRINT(cursor_up);
393*a501098bSThomas Cort 	PRINT(cursor_up);
394*a501098bSThomas Cort 	upln++;
395*a501098bSThomas Cort }
396*a501098bSThomas Cort 
397*a501098bSThomas Cort int
outchar(int c)398*a501098bSThomas Cort outchar(int c)
399*a501098bSThomas Cort {
400*a501098bSThomas Cort 	return (putchar(c & 0177));
401*a501098bSThomas Cort }
402*a501098bSThomas Cort 
403*a501098bSThomas Cort static int curmode = 0;
404*a501098bSThomas Cort 
405*a501098bSThomas Cort void
outc(int c)406*a501098bSThomas Cort outc(int c)
407*a501098bSThomas Cort {
408*a501098bSThomas Cort 	putchar(c);
409*a501098bSThomas Cort 	if (underline_char && !enter_underline_mode && (curmode & UNDERL)) {
410*a501098bSThomas Cort 		if (cursor_left)
411*a501098bSThomas Cort 			PRINT(cursor_left);
412*a501098bSThomas Cort 		else
413*a501098bSThomas Cort 			putchar('\b');
414*a501098bSThomas Cort 		PRINT(underline_char);
415*a501098bSThomas Cort 	}
416*a501098bSThomas Cort }
417*a501098bSThomas Cort 
418*a501098bSThomas Cort void
setulmode(int newmode)419*a501098bSThomas Cort setulmode(int newmode)
420*a501098bSThomas Cort {
421*a501098bSThomas Cort 	if (!iflag) {
422*a501098bSThomas Cort 		if (curmode != NORMAL && newmode != NORMAL)
423*a501098bSThomas Cort 			setulmode(NORMAL);
424*a501098bSThomas Cort 		switch (newmode) {
425*a501098bSThomas Cort 		case NORMAL:
426*a501098bSThomas Cort 			switch(curmode) {
427*a501098bSThomas Cort 			case NORMAL:
428*a501098bSThomas Cort 				break;
429*a501098bSThomas Cort 			case UNDERL:
430*a501098bSThomas Cort 				if (enter_underline_mode)
431*a501098bSThomas Cort 					PRINT(exit_underline_mode);
432*a501098bSThomas Cort 				else
433*a501098bSThomas Cort 					PRINT(exit_standout_mode);
434*a501098bSThomas Cort 				break;
435*a501098bSThomas Cort 			default:
436*a501098bSThomas Cort 				/* This includes standout */
437*a501098bSThomas Cort 				if (exit_attribute_mode)
438*a501098bSThomas Cort 					PRINT(exit_attribute_mode);
439*a501098bSThomas Cort 				else
440*a501098bSThomas Cort 					PRINT(exit_standout_mode);
441*a501098bSThomas Cort 				break;
442*a501098bSThomas Cort 			}
443*a501098bSThomas Cort 			break;
444*a501098bSThomas Cort 		case ALTSET:
445*a501098bSThomas Cort 			if (enter_reverse_mode)
446*a501098bSThomas Cort 				PRINT(enter_reverse_mode);
447*a501098bSThomas Cort 			else
448*a501098bSThomas Cort 				PRINT(enter_standout_mode);
449*a501098bSThomas Cort 			break;
450*a501098bSThomas Cort 		case SUPERSC:
451*a501098bSThomas Cort 			/*
452*a501098bSThomas Cort 			 * This only works on a few terminals.
453*a501098bSThomas Cort 			 * It should be fixed.
454*a501098bSThomas Cort 			 */
455*a501098bSThomas Cort 			PRINT(enter_underline_mode);
456*a501098bSThomas Cort 			PRINT(enter_dim_mode);
457*a501098bSThomas Cort 			break;
458*a501098bSThomas Cort 		case SUBSC:
459*a501098bSThomas Cort 			if (enter_dim_mode)
460*a501098bSThomas Cort 				PRINT(enter_dim_mode);
461*a501098bSThomas Cort 			else
462*a501098bSThomas Cort 				PRINT(enter_standout_mode);
463*a501098bSThomas Cort 			break;
464*a501098bSThomas Cort 		case UNDERL:
465*a501098bSThomas Cort 			if (enter_underline_mode)
466*a501098bSThomas Cort 				PRINT(enter_underline_mode);
467*a501098bSThomas Cort 			else
468*a501098bSThomas Cort 				PRINT(enter_standout_mode);
469*a501098bSThomas Cort 			break;
470*a501098bSThomas Cort 		case BOLD:
471*a501098bSThomas Cort 			if (enter_bold_mode)
472*a501098bSThomas Cort 				PRINT(enter_bold_mode);
473*a501098bSThomas Cort 			else
474*a501098bSThomas Cort 				PRINT(enter_reverse_mode);
475*a501098bSThomas Cort 			break;
476*a501098bSThomas Cort 		default:
477*a501098bSThomas Cort 			/*
478*a501098bSThomas Cort 			 * We should have some provision here for multiple modes
479*a501098bSThomas Cort 			 * on at once.  This will have to come later.
480*a501098bSThomas Cort 			 */
481*a501098bSThomas Cort 			PRINT(enter_standout_mode);
482*a501098bSThomas Cort 			break;
483*a501098bSThomas Cort 		}
484*a501098bSThomas Cort 	}
485*a501098bSThomas Cort 	curmode = newmode;
486*a501098bSThomas Cort }
487