ul.c revision 87303
11590Srgrimes/*
21590Srgrimes * Copyright (c) 1980, 1993
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * Redistribution and use in source and binary forms, with or without
61590Srgrimes * modification, are permitted provided that the following conditions
71590Srgrimes * are met:
81590Srgrimes * 1. Redistributions of source code must retain the above copyright
91590Srgrimes *    notice, this list of conditions and the following disclaimer.
101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer in the
121590Srgrimes *    documentation and/or other materials provided with the distribution.
131590Srgrimes * 3. All advertising materials mentioning features or use of this software
141590Srgrimes *    must display the following acknowledgement:
151590Srgrimes *	This product includes software developed by the University of
161590Srgrimes *	California, Berkeley and its contributors.
171590Srgrimes * 4. Neither the name of the University nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
321590Srgrimes */
331590Srgrimes
341590Srgrimes#ifndef lint
3528454Scharnierstatic const char copyright[] =
361590Srgrimes"@(#) Copyright (c) 1980, 1993\n\
371590Srgrimes	The Regents of the University of California.  All rights reserved.\n";
381590Srgrimes#endif /* not lint */
391590Srgrimes
401590Srgrimes#ifndef lint
4128454Scharnier#if 0
421590Srgrimesstatic char sccsid[] = "@(#)ul.c	8.1 (Berkeley) 6/6/93";
4328454Scharnier#endif
4428454Scharnierstatic const char rcsid[] =
4550477Speter  "$FreeBSD: head/usr.bin/ul/ul.c 87303 2001-12-03 21:37:35Z dwmalone $";
461590Srgrimes#endif /* not lint */
471590Srgrimes
4828454Scharnier#include <err.h>
491590Srgrimes#include <stdio.h>
5028454Scharnier#include <stdlib.h>
5128454Scharnier#include <string.h>
5228454Scharnier#include <termcap.h>
5328454Scharnier#include <unistd.h>
541590Srgrimes
551590Srgrimes#define	IESC	'\033'
561590Srgrimes#define	SO	'\016'
571590Srgrimes#define	SI	'\017'
581590Srgrimes#define	HFWD	'9'
591590Srgrimes#define	HREV	'8'
601590Srgrimes#define	FREV	'7'
611590Srgrimes#define	MAXBUF	512
621590Srgrimes
631590Srgrimes#define	NORMAL	000
641590Srgrimes#define	ALTSET	001	/* Reverse */
651590Srgrimes#define	SUPERSC	002	/* Dim */
661590Srgrimes#define	SUBSC	004	/* Dim | Ul */
671590Srgrimes#define	UNDERL	010	/* Ul */
681590Srgrimes#define	BOLD	020	/* Bold */
691590Srgrimes
701590Srgrimesint	must_use_uc, must_overstrike;
7187303Sdwmaloneconst char
7287303Sdwmalone	*CURS_UP, *CURS_RIGHT, *CURS_LEFT,
731590Srgrimes	*ENTER_STANDOUT, *EXIT_STANDOUT, *ENTER_UNDERLINE, *EXIT_UNDERLINE,
741590Srgrimes	*ENTER_DIM, *ENTER_BOLD, *ENTER_REVERSE, *UNDER_CHAR, *EXIT_ATTRIBUTES;
751590Srgrimes
761590Srgrimesstruct	CHAR	{
771590Srgrimes	char	c_mode;
781590Srgrimes	char	c_char;
791590Srgrimes} ;
801590Srgrimes
811590Srgrimesstruct	CHAR	obuf[MAXBUF];
821590Srgrimesint	col, maxcol;
831590Srgrimesint	mode;
841590Srgrimesint	halfpos;
851590Srgrimesint	upln;
861590Srgrimesint	iflag;
871590Srgrimes
8828454Scharnierstatic void usage __P((void));
8928454Scharniervoid setnewmode __P((int));
9028454Scharniervoid initcap __P((void));
9128454Scharniervoid reverse __P((void));
9228454Scharnierint outchar __P((int));
9328454Scharniervoid fwd __P((void));
9428454Scharniervoid initbuf __P((void));
9528454Scharniervoid iattr __P((void));
9628454Scharniervoid overstrike __P((void));
9728454Scharniervoid flushln __P((void));
9828454Scharniervoid filter __P((FILE *));
9928454Scharniervoid outc __P((int));
10028454Scharnier
1011590Srgrimes#define	PRINT(s)	if (s == NULL) /* void */; else tputs(s, 1, outchar)
1021590Srgrimes
10328789Scharnierint
1041590Srgrimesmain(argc, argv)
1051590Srgrimes	int argc;
1061590Srgrimes	char **argv;
1071590Srgrimes{
1081590Srgrimes	int c;
10987303Sdwmalone	const char *termtype;
1101590Srgrimes	FILE *f;
1111590Srgrimes	char termcap[1024];
1121590Srgrimes
1131590Srgrimes	termtype = getenv("TERM");
1141590Srgrimes	if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
1151590Srgrimes		termtype = "lpr";
11624360Simp	while ((c=getopt(argc, argv, "it:T:")) != -1)
1171590Srgrimes		switch(c) {
1181590Srgrimes
1191590Srgrimes		case 't':
1201590Srgrimes		case 'T': /* for nroff compatibility */
12187303Sdwmalone			termtype = optarg;
1221590Srgrimes			break;
1231590Srgrimes		case 'i':
1241590Srgrimes			iflag = 1;
1251590Srgrimes			break;
1261590Srgrimes		default:
12728454Scharnier			usage();
1281590Srgrimes		}
1291590Srgrimes
1301590Srgrimes	switch(tgetent(termcap, termtype)) {
1311590Srgrimes
1321590Srgrimes	case 1:
1331590Srgrimes		break;
1341590Srgrimes
1351590Srgrimes	default:
13628454Scharnier		warnx("trouble reading termcap");
1371590Srgrimes		/* fall through to ... */
1381590Srgrimes
1391590Srgrimes	case 0:
1401590Srgrimes		/* No such terminal type - assume dumb */
1411590Srgrimes		(void)strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:");
1421590Srgrimes		break;
1431590Srgrimes	}
1441590Srgrimes	initcap();
1451590Srgrimes	if (    (tgetflag("os") && ENTER_BOLD==NULL ) ||
1461590Srgrimes		(tgetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
1471590Srgrimes			must_overstrike = 1;
1481590Srgrimes	initbuf();
1491590Srgrimes	if (optind == argc)
1501590Srgrimes		filter(stdin);
1511590Srgrimes	else for (; optind<argc; optind++) {
1521590Srgrimes		f = fopen(argv[optind],"r");
15328454Scharnier		if (f == NULL)
15428454Scharnier			err(1, "%s", argv[optind]);
15528454Scharnier		else
1561590Srgrimes			filter(f);
1571590Srgrimes	}
1581590Srgrimes	exit(0);
1591590Srgrimes}
1601590Srgrimes
16128454Scharnierstatic void
16228454Scharnierusage()
16328454Scharnier{
16428454Scharnier	fprintf(stderr, "usage: ul [-i] [-t terminal] file...\n");
16528454Scharnier	exit(1);
16628454Scharnier}
16728454Scharnier
16828454Scharniervoid
1691590Srgrimesfilter(f)
1701590Srgrimes	FILE *f;
1711590Srgrimes{
17287303Sdwmalone	int c;
1731590Srgrimes
17464052Skris	while ((c = getc(f)) != EOF && col < MAXBUF) switch(c) {
1751590Srgrimes
1761590Srgrimes	case '\b':
1771590Srgrimes		if (col > 0)
1781590Srgrimes			col--;
1791590Srgrimes		continue;
1801590Srgrimes
1811590Srgrimes	case '\t':
1821590Srgrimes		col = (col+8) & ~07;
1831590Srgrimes		if (col > maxcol)
1841590Srgrimes			maxcol = col;
1851590Srgrimes		continue;
1861590Srgrimes
1871590Srgrimes	case '\r':
1881590Srgrimes		col = 0;
1891590Srgrimes		continue;
1901590Srgrimes
1911590Srgrimes	case SO:
1921590Srgrimes		mode |= ALTSET;
1931590Srgrimes		continue;
1941590Srgrimes
1951590Srgrimes	case SI:
1961590Srgrimes		mode &= ~ALTSET;
1971590Srgrimes		continue;
1981590Srgrimes
1991590Srgrimes	case IESC:
2001590Srgrimes		switch (c = getc(f)) {
2011590Srgrimes
2021590Srgrimes		case HREV:
2031590Srgrimes			if (halfpos == 0) {
2041590Srgrimes				mode |= SUPERSC;
2051590Srgrimes				halfpos--;
2061590Srgrimes			} else if (halfpos > 0) {
2071590Srgrimes				mode &= ~SUBSC;
2081590Srgrimes				halfpos--;
2091590Srgrimes			} else {
2101590Srgrimes				halfpos = 0;
2111590Srgrimes				reverse();
2121590Srgrimes			}
2131590Srgrimes			continue;
2141590Srgrimes
2151590Srgrimes		case HFWD:
2161590Srgrimes			if (halfpos == 0) {
2171590Srgrimes				mode |= SUBSC;
2181590Srgrimes				halfpos++;
2191590Srgrimes			} else if (halfpos < 0) {
2201590Srgrimes				mode &= ~SUPERSC;
2211590Srgrimes				halfpos++;
2221590Srgrimes			} else {
2231590Srgrimes				halfpos = 0;
2241590Srgrimes				fwd();
2251590Srgrimes			}
2261590Srgrimes			continue;
2271590Srgrimes
2281590Srgrimes		case FREV:
2291590Srgrimes			reverse();
2301590Srgrimes			continue;
2311590Srgrimes
2321590Srgrimes		default:
23328454Scharnier			errx(1, "unknown escape sequence in input: %o, %o", IESC, c);
2341590Srgrimes		}
2351590Srgrimes		continue;
2361590Srgrimes
2371590Srgrimes	case '_':
2381590Srgrimes		if (obuf[col].c_char)
2391590Srgrimes			obuf[col].c_mode |= UNDERL | mode;
2401590Srgrimes		else
2411590Srgrimes			obuf[col].c_char = '_';
2421590Srgrimes	case ' ':
2431590Srgrimes		col++;
2441590Srgrimes		if (col > maxcol)
2451590Srgrimes			maxcol = col;
2461590Srgrimes		continue;
2471590Srgrimes
2481590Srgrimes	case '\n':
2491590Srgrimes		flushln();
2501590Srgrimes		continue;
2511590Srgrimes
2521590Srgrimes	case '\f':
2531590Srgrimes		flushln();
2541590Srgrimes		putchar('\f');
2551590Srgrimes		continue;
2561590Srgrimes
2571590Srgrimes	default:
2581590Srgrimes		if (c < ' ')	/* non printing */
2591590Srgrimes			continue;
2601590Srgrimes		if (obuf[col].c_char == '\0') {
2611590Srgrimes			obuf[col].c_char = c;
2621590Srgrimes			obuf[col].c_mode = mode;
2631590Srgrimes		} else if (obuf[col].c_char == '_') {
2641590Srgrimes			obuf[col].c_char = c;
2651590Srgrimes			obuf[col].c_mode |= UNDERL|mode;
2661590Srgrimes		} else if (obuf[col].c_char == c)
2671590Srgrimes			obuf[col].c_mode |= BOLD|mode;
2681590Srgrimes		else
2691590Srgrimes			obuf[col].c_mode = mode;
2701590Srgrimes		col++;
2711590Srgrimes		if (col > maxcol)
2721590Srgrimes			maxcol = col;
2731590Srgrimes		continue;
2741590Srgrimes	}
2751590Srgrimes	if (maxcol)
2761590Srgrimes		flushln();
2771590Srgrimes}
2781590Srgrimes
27928454Scharniervoid
2801590Srgrimesflushln()
2811590Srgrimes{
28287303Sdwmalone	int lastmode;
28387303Sdwmalone	int i;
2841590Srgrimes	int hadmodes = 0;
2851590Srgrimes
2861590Srgrimes	lastmode = NORMAL;
2871590Srgrimes	for (i=0; i<maxcol; i++) {
2881590Srgrimes		if (obuf[i].c_mode != lastmode) {
2891590Srgrimes			hadmodes++;
29028454Scharnier			setnewmode(obuf[i].c_mode);
2911590Srgrimes			lastmode = obuf[i].c_mode;
2921590Srgrimes		}
2931590Srgrimes		if (obuf[i].c_char == '\0') {
2941590Srgrimes			if (upln)
2951590Srgrimes				PRINT(CURS_RIGHT);
2961590Srgrimes			else
2971590Srgrimes				outc(' ');
2981590Srgrimes		} else
2991590Srgrimes			outc(obuf[i].c_char);
3001590Srgrimes	}
3011590Srgrimes	if (lastmode != NORMAL) {
30228454Scharnier		setnewmode(0);
3031590Srgrimes	}
3041590Srgrimes	if (must_overstrike && hadmodes)
3051590Srgrimes		overstrike();
3061590Srgrimes	putchar('\n');
3071590Srgrimes	if (iflag && hadmodes)
3081590Srgrimes		iattr();
3091590Srgrimes	(void)fflush(stdout);
3101590Srgrimes	if (upln)
3111590Srgrimes		upln--;
3121590Srgrimes	initbuf();
3131590Srgrimes}
3141590Srgrimes
3151590Srgrimes/*
3161590Srgrimes * For terminals that can overstrike, overstrike underlines and bolds.
3171590Srgrimes * We don't do anything with halfline ups and downs, or Greek.
3181590Srgrimes */
31928454Scharniervoid
3201590Srgrimesoverstrike()
3211590Srgrimes{
3221590Srgrimes	register int i;
3231590Srgrimes	char lbuf[256];
3241590Srgrimes	register char *cp = lbuf;
3251590Srgrimes	int hadbold=0;
3261590Srgrimes
3271590Srgrimes	/* Set up overstrike buffer */
3281590Srgrimes	for (i=0; i<maxcol; i++)
3291590Srgrimes		switch (obuf[i].c_mode) {
3301590Srgrimes		case NORMAL:
3311590Srgrimes		default:
3321590Srgrimes			*cp++ = ' ';
3331590Srgrimes			break;
3341590Srgrimes		case UNDERL:
3351590Srgrimes			*cp++ = '_';
3361590Srgrimes			break;
3371590Srgrimes		case BOLD:
3381590Srgrimes			*cp++ = obuf[i].c_char;
3391590Srgrimes			hadbold=1;
3401590Srgrimes			break;
3411590Srgrimes		}
3421590Srgrimes	putchar('\r');
3431590Srgrimes	for (*cp=' '; *cp==' '; cp--)
3441590Srgrimes		*cp = 0;
3451590Srgrimes	for (cp=lbuf; *cp; cp++)
3461590Srgrimes		putchar(*cp);
3471590Srgrimes	if (hadbold) {
3481590Srgrimes		putchar('\r');
3491590Srgrimes		for (cp=lbuf; *cp; cp++)
3501590Srgrimes			putchar(*cp=='_' ? ' ' : *cp);
3511590Srgrimes		putchar('\r');
3521590Srgrimes		for (cp=lbuf; *cp; cp++)
3531590Srgrimes			putchar(*cp=='_' ? ' ' : *cp);
3541590Srgrimes	}
3551590Srgrimes}
3561590Srgrimes
35728454Scharniervoid
3581590Srgrimesiattr()
3591590Srgrimes{
3601590Srgrimes	register int i;
3611590Srgrimes	char lbuf[256];
3621590Srgrimes	register char *cp = lbuf;
3631590Srgrimes
3641590Srgrimes	for (i=0; i<maxcol; i++)
3651590Srgrimes		switch (obuf[i].c_mode) {
3661590Srgrimes		case NORMAL:	*cp++ = ' '; break;
3671590Srgrimes		case ALTSET:	*cp++ = 'g'; break;
3681590Srgrimes		case SUPERSC:	*cp++ = '^'; break;
3691590Srgrimes		case SUBSC:	*cp++ = 'v'; break;
3701590Srgrimes		case UNDERL:	*cp++ = '_'; break;
3711590Srgrimes		case BOLD:	*cp++ = '!'; break;
3721590Srgrimes		default:	*cp++ = 'X'; break;
3731590Srgrimes		}
3741590Srgrimes	for (*cp=' '; *cp==' '; cp--)
3751590Srgrimes		*cp = 0;
3761590Srgrimes	for (cp=lbuf; *cp; cp++)
3771590Srgrimes		putchar(*cp);
3781590Srgrimes	putchar('\n');
3791590Srgrimes}
3801590Srgrimes
38128454Scharniervoid
3821590Srgrimesinitbuf()
3831590Srgrimes{
3841590Srgrimes
3851590Srgrimes	bzero((char *)obuf, sizeof (obuf));	/* depends on NORMAL == 0 */
3861590Srgrimes	col = 0;
3871590Srgrimes	maxcol = 0;
3881590Srgrimes	mode &= ALTSET;
3891590Srgrimes}
3901590Srgrimes
39128454Scharniervoid
3921590Srgrimesfwd()
3931590Srgrimes{
39487303Sdwmalone	int oldcol, oldmax;
3951590Srgrimes
3961590Srgrimes	oldcol = col;
3971590Srgrimes	oldmax = maxcol;
3981590Srgrimes	flushln();
3991590Srgrimes	col = oldcol;
4001590Srgrimes	maxcol = oldmax;
4011590Srgrimes}
4021590Srgrimes
40328454Scharniervoid
4041590Srgrimesreverse()
4051590Srgrimes{
4061590Srgrimes	upln++;
4071590Srgrimes	fwd();
4081590Srgrimes	PRINT(CURS_UP);
4091590Srgrimes	PRINT(CURS_UP);
4101590Srgrimes	upln++;
4111590Srgrimes}
4121590Srgrimes
41328454Scharniervoid
4141590Srgrimesinitcap()
4151590Srgrimes{
4161590Srgrimes	static char tcapbuf[512];
4171590Srgrimes	char *bp = tcapbuf;
4181590Srgrimes
4191590Srgrimes	/* This nonsense attempts to work with both old and new termcap */
4201590Srgrimes	CURS_UP =		tgetstr("up", &bp);
4211590Srgrimes	CURS_RIGHT =		tgetstr("ri", &bp);
4221590Srgrimes	if (CURS_RIGHT == NULL)
4231590Srgrimes		CURS_RIGHT =	tgetstr("nd", &bp);
4241590Srgrimes	CURS_LEFT =		tgetstr("le", &bp);
4251590Srgrimes	if (CURS_LEFT == NULL)
4261590Srgrimes		CURS_LEFT =	tgetstr("bc", &bp);
4271590Srgrimes	if (CURS_LEFT == NULL && tgetflag("bs"))
4281590Srgrimes		CURS_LEFT =	"\b";
4291590Srgrimes
4301590Srgrimes	ENTER_STANDOUT =	tgetstr("so", &bp);
4311590Srgrimes	EXIT_STANDOUT =		tgetstr("se", &bp);
4321590Srgrimes	ENTER_UNDERLINE =	tgetstr("us", &bp);
4331590Srgrimes	EXIT_UNDERLINE =	tgetstr("ue", &bp);
4341590Srgrimes	ENTER_DIM =		tgetstr("mh", &bp);
4351590Srgrimes	ENTER_BOLD =		tgetstr("md", &bp);
4361590Srgrimes	ENTER_REVERSE =		tgetstr("mr", &bp);
4371590Srgrimes	EXIT_ATTRIBUTES =	tgetstr("me", &bp);
4381590Srgrimes
4391590Srgrimes	if (!ENTER_BOLD && ENTER_REVERSE)
4401590Srgrimes		ENTER_BOLD = ENTER_REVERSE;
4411590Srgrimes	if (!ENTER_BOLD && ENTER_STANDOUT)
4421590Srgrimes		ENTER_BOLD = ENTER_STANDOUT;
4431590Srgrimes	if (!ENTER_UNDERLINE && ENTER_STANDOUT) {
4441590Srgrimes		ENTER_UNDERLINE = ENTER_STANDOUT;
4451590Srgrimes		EXIT_UNDERLINE = EXIT_STANDOUT;
4461590Srgrimes	}
4471590Srgrimes	if (!ENTER_DIM && ENTER_STANDOUT)
4481590Srgrimes		ENTER_DIM = ENTER_STANDOUT;
4491590Srgrimes	if (!ENTER_REVERSE && ENTER_STANDOUT)
4501590Srgrimes		ENTER_REVERSE = ENTER_STANDOUT;
4511590Srgrimes	if (!EXIT_ATTRIBUTES && EXIT_STANDOUT)
4521590Srgrimes		EXIT_ATTRIBUTES = EXIT_STANDOUT;
4538874Srgrimes
4541590Srgrimes	/*
4551590Srgrimes	 * Note that we use REVERSE for the alternate character set,
4561590Srgrimes	 * not the as/ae capabilities.  This is because we are modelling
4571590Srgrimes	 * the model 37 teletype (since that's what nroff outputs) and
4581590Srgrimes	 * the typical as/ae is more of a graphics set, not the greek
4591590Srgrimes	 * letters the 37 has.
4601590Srgrimes	 */
4611590Srgrimes
4621590Srgrimes	UNDER_CHAR =		tgetstr("uc", &bp);
4631590Srgrimes	must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
4641590Srgrimes}
4651590Srgrimes
46628454Scharnierint
4671590Srgrimesoutchar(c)
4681590Srgrimes	int c;
4691590Srgrimes{
47028454Scharnier	return(putchar(c & 0177));
4711590Srgrimes}
4721590Srgrimes
4731590Srgrimesstatic int curmode = 0;
4741590Srgrimes
47528454Scharniervoid
4761590Srgrimesoutc(c)
4771590Srgrimes	int c;
4781590Srgrimes{
4791590Srgrimes	putchar(c);
4801590Srgrimes	if (must_use_uc && (curmode&UNDERL)) {
4811590Srgrimes		PRINT(CURS_LEFT);
4821590Srgrimes		PRINT(UNDER_CHAR);
4831590Srgrimes	}
4841590Srgrimes}
4851590Srgrimes
48628454Scharniervoid
48728454Scharniersetnewmode(newmode)
4881590Srgrimes	int newmode;
4891590Srgrimes{
4901590Srgrimes	if (!iflag) {
4911590Srgrimes		if (curmode != NORMAL && newmode != NORMAL)
49228454Scharnier			setnewmode(NORMAL);
4931590Srgrimes		switch (newmode) {
4941590Srgrimes		case NORMAL:
4951590Srgrimes			switch(curmode) {
4961590Srgrimes			case NORMAL:
4971590Srgrimes				break;
4981590Srgrimes			case UNDERL:
4991590Srgrimes				PRINT(EXIT_UNDERLINE);
5001590Srgrimes				break;
5011590Srgrimes			default:
5021590Srgrimes				/* This includes standout */
5031590Srgrimes				PRINT(EXIT_ATTRIBUTES);
5041590Srgrimes				break;
5051590Srgrimes			}
5061590Srgrimes			break;
5071590Srgrimes		case ALTSET:
5081590Srgrimes			PRINT(ENTER_REVERSE);
5091590Srgrimes			break;
5101590Srgrimes		case SUPERSC:
5111590Srgrimes			/*
5121590Srgrimes			 * This only works on a few terminals.
5131590Srgrimes			 * It should be fixed.
5141590Srgrimes			 */
5151590Srgrimes			PRINT(ENTER_UNDERLINE);
5161590Srgrimes			PRINT(ENTER_DIM);
5171590Srgrimes			break;
5181590Srgrimes		case SUBSC:
5191590Srgrimes			PRINT(ENTER_DIM);
5201590Srgrimes			break;
5211590Srgrimes		case UNDERL:
5221590Srgrimes			PRINT(ENTER_UNDERLINE);
5231590Srgrimes			break;
5241590Srgrimes		case BOLD:
5251590Srgrimes			PRINT(ENTER_BOLD);
5261590Srgrimes			break;
5271590Srgrimes		default:
5281590Srgrimes			/*
5291590Srgrimes			 * We should have some provision here for multiple modes
5301590Srgrimes			 * on at once.  This will have to come later.
5311590Srgrimes			 */
5321590Srgrimes			PRINT(ENTER_STANDOUT);
5331590Srgrimes			break;
5341590Srgrimes		}
5351590Srgrimes	}
5361590Srgrimes	curmode = newmode;
5371590Srgrimes}
538