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 * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 301590Srgrimes#ifndef lint 3128454Scharnierstatic const char copyright[] = 321590Srgrimes"@(#) Copyright (c) 1980, 1993\n\ 331590Srgrimes The Regents of the University of California. All rights reserved.\n"; 341590Srgrimes#endif /* not lint */ 351590Srgrimes 361590Srgrimes#ifndef lint 3728454Scharnier#if 0 381590Srgrimesstatic char sccsid[] = "@(#)ul.c 8.1 (Berkeley) 6/6/93"; 3928454Scharnier#endif 4028454Scharnierstatic const char rcsid[] = 4150477Speter "$FreeBSD: releng/10.2/usr.bin/ul/ul.c 245093 2013-01-06 03:08:27Z andrew $"; 421590Srgrimes#endif /* not lint */ 431590Srgrimes 4428454Scharnier#include <err.h> 45132858Stjr#include <locale.h> 461590Srgrimes#include <stdio.h> 4728454Scharnier#include <stdlib.h> 4828454Scharnier#include <string.h> 4928454Scharnier#include <termcap.h> 5028454Scharnier#include <unistd.h> 51132858Stjr#include <wchar.h> 52200462Sdelphij#include <wctype.h> 531590Srgrimes 541590Srgrimes#define IESC '\033' 551590Srgrimes#define SO '\016' 561590Srgrimes#define SI '\017' 571590Srgrimes#define HFWD '9' 581590Srgrimes#define HREV '8' 591590Srgrimes#define FREV '7' 601590Srgrimes#define MAXBUF 512 611590Srgrimes 621590Srgrimes#define NORMAL 000 631590Srgrimes#define ALTSET 001 /* Reverse */ 641590Srgrimes#define SUPERSC 002 /* Dim */ 651590Srgrimes#define SUBSC 004 /* Dim | Ul */ 661590Srgrimes#define UNDERL 010 /* Ul */ 671590Srgrimes#define BOLD 020 /* Bold */ 681590Srgrimes 69227190Sedstatic int must_use_uc, must_overstrike; 70227190Sedstatic const char 7187303Sdwmalone *CURS_UP, *CURS_RIGHT, *CURS_LEFT, 721590Srgrimes *ENTER_STANDOUT, *EXIT_STANDOUT, *ENTER_UNDERLINE, *EXIT_UNDERLINE, 731590Srgrimes *ENTER_DIM, *ENTER_BOLD, *ENTER_REVERSE, *UNDER_CHAR, *EXIT_ATTRIBUTES; 741590Srgrimes 751590Srgrimesstruct CHAR { 761590Srgrimes char c_mode; 77132858Stjr wchar_t c_char; 78132858Stjr int c_width; /* width or -1 if multi-column char. filler */ 791590Srgrimes} ; 801590Srgrimes 81227190Sedstatic struct CHAR obuf[MAXBUF]; 82227190Sedstatic int col, maxcol; 83227190Sedstatic int mode; 84227190Sedstatic int halfpos; 85227190Sedstatic int upln; 86227190Sedstatic int iflag; 871590Srgrimes 8892922Simpstatic void usage(void); 89227190Sedstatic void setnewmode(int); 90227190Sedstatic void initcap(void); 91227190Sedstatic void reverse(void); 92227190Sedstatic int outchar(int); 93227190Sedstatic void fwd(void); 94227190Sedstatic void initbuf(void); 95227190Sedstatic void iattr(void); 96227190Sedstatic void overstrike(void); 97227190Sedstatic void flushln(void); 98227190Sedstatic void filter(FILE *); 99227190Sedstatic void outc(wint_t, int); 10028454Scharnier 1011590Srgrimes#define PRINT(s) if (s == NULL) /* void */; else tputs(s, 1, outchar) 1021590Srgrimes 10328789Scharnierint 104102944Sdwmalonemain(int argc, char **argv) 1051590Srgrimes{ 1061590Srgrimes int c; 10787303Sdwmalone const char *termtype; 1081590Srgrimes FILE *f; 1091590Srgrimes char termcap[1024]; 1101590Srgrimes 111132858Stjr setlocale(LC_ALL, ""); 112132858Stjr 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"); 137102412Scharnier /* FALLTHROUGH */ 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 162102944Sdwmaloneusage(void) 16328454Scharnier{ 164146466Sru fprintf(stderr, "usage: ul [-i] [-t terminal] [file ...]\n"); 16528454Scharnier exit(1); 16628454Scharnier} 16728454Scharnier 168227190Sedstatic void 169102944Sdwmalonefilter(FILE *f) 1701590Srgrimes{ 171132858Stjr wint_t c; 172132858Stjr int i, w; 1731590Srgrimes 174132858Stjr while ((c = getwc(f)) != WEOF && 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: 200132858Stjr switch (c = getwc(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 '_': 238132858Stjr if (obuf[col].c_char || obuf[col].c_width < 0) { 239132858Stjr while (col > 0 && obuf[col].c_width < 0) 240132858Stjr col--; 241132858Stjr w = obuf[col].c_width; 242132858Stjr for (i = 0; i < w; i++) 243132858Stjr obuf[col++].c_mode |= UNDERL | mode; 244132858Stjr if (col > maxcol) 245132858Stjr maxcol = col; 246132858Stjr continue; 247132858Stjr } 248132858Stjr obuf[col].c_char = '_'; 249132858Stjr obuf[col].c_width = 1; 250132858Stjr /* FALLTHROUGH */ 2511590Srgrimes case ' ': 2521590Srgrimes col++; 2531590Srgrimes if (col > maxcol) 2541590Srgrimes maxcol = col; 2551590Srgrimes continue; 2561590Srgrimes 2571590Srgrimes case '\n': 2581590Srgrimes flushln(); 2591590Srgrimes continue; 2601590Srgrimes 2611590Srgrimes case '\f': 2621590Srgrimes flushln(); 263132858Stjr putwchar('\f'); 2641590Srgrimes continue; 2651590Srgrimes 2661590Srgrimes default: 267132858Stjr if ((w = wcwidth(c)) <= 0) /* non printing */ 2681590Srgrimes continue; 2691590Srgrimes if (obuf[col].c_char == '\0') { 2701590Srgrimes obuf[col].c_char = c; 271132858Stjr for (i = 0; i < w; i++) 272132858Stjr obuf[col + i].c_mode = mode; 273132858Stjr obuf[col].c_width = w; 274132858Stjr for (i = 1; i < w; i++) 275132858Stjr obuf[col + i].c_width = -1; 2761590Srgrimes } else if (obuf[col].c_char == '_') { 2771590Srgrimes obuf[col].c_char = c; 278132858Stjr for (i = 0; i < w; i++) 279132858Stjr obuf[col + i].c_mode |= UNDERL|mode; 280132858Stjr obuf[col].c_width = w; 281132858Stjr for (i = 1; i < w; i++) 282132858Stjr obuf[col + i].c_width = -1; 283245093Sandrew } else if ((wint_t)obuf[col].c_char == c) { 284132858Stjr for (i = 0; i < w; i++) 285132858Stjr obuf[col + i].c_mode |= BOLD|mode; 286132858Stjr } else { 287132858Stjr w = obuf[col].c_width; 288132858Stjr for (i = 0; i < w; i++) 289132858Stjr obuf[col + i].c_mode = mode; 290132858Stjr } 291132858Stjr col += w; 2921590Srgrimes if (col > maxcol) 2931590Srgrimes maxcol = col; 2941590Srgrimes continue; 2951590Srgrimes } 296132882Stjr if (ferror(f)) 297132882Stjr err(1, NULL); 2981590Srgrimes if (maxcol) 2991590Srgrimes flushln(); 3001590Srgrimes} 3011590Srgrimes 302227190Sedstatic void 303102944Sdwmaloneflushln(void) 3041590Srgrimes{ 30587303Sdwmalone int lastmode; 30687303Sdwmalone int i; 3071590Srgrimes int hadmodes = 0; 3081590Srgrimes 3091590Srgrimes lastmode = NORMAL; 3101590Srgrimes for (i=0; i<maxcol; i++) { 3111590Srgrimes if (obuf[i].c_mode != lastmode) { 3121590Srgrimes hadmodes++; 31328454Scharnier setnewmode(obuf[i].c_mode); 3141590Srgrimes lastmode = obuf[i].c_mode; 3151590Srgrimes } 3161590Srgrimes if (obuf[i].c_char == '\0') { 3171590Srgrimes if (upln) 3181590Srgrimes PRINT(CURS_RIGHT); 3191590Srgrimes else 320132858Stjr outc(' ', 1); 3211590Srgrimes } else 322132858Stjr outc(obuf[i].c_char, obuf[i].c_width); 323132858Stjr if (obuf[i].c_width > 1) 324132858Stjr i += obuf[i].c_width - 1; 3251590Srgrimes } 3261590Srgrimes if (lastmode != NORMAL) { 32728454Scharnier setnewmode(0); 3281590Srgrimes } 3291590Srgrimes if (must_overstrike && hadmodes) 3301590Srgrimes overstrike(); 331132858Stjr putwchar('\n'); 3321590Srgrimes if (iflag && hadmodes) 3331590Srgrimes iattr(); 3341590Srgrimes (void)fflush(stdout); 3351590Srgrimes if (upln) 3361590Srgrimes upln--; 3371590Srgrimes initbuf(); 3381590Srgrimes} 3391590Srgrimes 3401590Srgrimes/* 3411590Srgrimes * For terminals that can overstrike, overstrike underlines and bolds. 3421590Srgrimes * We don't do anything with halfline ups and downs, or Greek. 3431590Srgrimes */ 344227190Sedstatic void 345102944Sdwmaloneoverstrike(void) 3461590Srgrimes{ 347102944Sdwmalone int i; 348132858Stjr wchar_t lbuf[256]; 349132858Stjr wchar_t *cp = lbuf; 3501590Srgrimes int hadbold=0; 3511590Srgrimes 3521590Srgrimes /* Set up overstrike buffer */ 3531590Srgrimes for (i=0; i<maxcol; i++) 3541590Srgrimes switch (obuf[i].c_mode) { 3551590Srgrimes case NORMAL: 3561590Srgrimes default: 3571590Srgrimes *cp++ = ' '; 3581590Srgrimes break; 3591590Srgrimes case UNDERL: 3601590Srgrimes *cp++ = '_'; 3611590Srgrimes break; 3621590Srgrimes case BOLD: 3631590Srgrimes *cp++ = obuf[i].c_char; 364132858Stjr if (obuf[i].c_width > 1) 365132858Stjr i += obuf[i].c_width - 1; 3661590Srgrimes hadbold=1; 3671590Srgrimes break; 3681590Srgrimes } 369132858Stjr putwchar('\r'); 3701590Srgrimes for (*cp=' '; *cp==' '; cp--) 3711590Srgrimes *cp = 0; 3721590Srgrimes for (cp=lbuf; *cp; cp++) 373132858Stjr putwchar(*cp); 3741590Srgrimes if (hadbold) { 375132858Stjr putwchar('\r'); 3761590Srgrimes for (cp=lbuf; *cp; cp++) 377132858Stjr putwchar(*cp=='_' ? ' ' : *cp); 378132858Stjr putwchar('\r'); 3791590Srgrimes for (cp=lbuf; *cp; cp++) 380132858Stjr putwchar(*cp=='_' ? ' ' : *cp); 3811590Srgrimes } 3821590Srgrimes} 3831590Srgrimes 384227190Sedstatic void 385102944Sdwmaloneiattr(void) 3861590Srgrimes{ 387102944Sdwmalone int i; 388132858Stjr wchar_t lbuf[256]; 389132858Stjr wchar_t *cp = lbuf; 3901590Srgrimes 3911590Srgrimes for (i=0; i<maxcol; i++) 3921590Srgrimes switch (obuf[i].c_mode) { 3931590Srgrimes case NORMAL: *cp++ = ' '; break; 3941590Srgrimes case ALTSET: *cp++ = 'g'; break; 3951590Srgrimes case SUPERSC: *cp++ = '^'; break; 3961590Srgrimes case SUBSC: *cp++ = 'v'; break; 3971590Srgrimes case UNDERL: *cp++ = '_'; break; 3981590Srgrimes case BOLD: *cp++ = '!'; break; 3991590Srgrimes default: *cp++ = 'X'; break; 4001590Srgrimes } 4011590Srgrimes for (*cp=' '; *cp==' '; cp--) 4021590Srgrimes *cp = 0; 4031590Srgrimes for (cp=lbuf; *cp; cp++) 404132858Stjr putwchar(*cp); 405132858Stjr putwchar('\n'); 4061590Srgrimes} 4071590Srgrimes 408227190Sedstatic void 409102944Sdwmaloneinitbuf(void) 4101590Srgrimes{ 4111590Srgrimes 4121590Srgrimes bzero((char *)obuf, sizeof (obuf)); /* depends on NORMAL == 0 */ 4131590Srgrimes col = 0; 4141590Srgrimes maxcol = 0; 4151590Srgrimes mode &= ALTSET; 4161590Srgrimes} 4171590Srgrimes 418227190Sedstatic void 419102944Sdwmalonefwd(void) 4201590Srgrimes{ 42187303Sdwmalone int oldcol, oldmax; 4221590Srgrimes 4231590Srgrimes oldcol = col; 4241590Srgrimes oldmax = maxcol; 4251590Srgrimes flushln(); 4261590Srgrimes col = oldcol; 4271590Srgrimes maxcol = oldmax; 4281590Srgrimes} 4291590Srgrimes 430227190Sedstatic void 431102944Sdwmalonereverse(void) 4321590Srgrimes{ 4331590Srgrimes upln++; 4341590Srgrimes fwd(); 4351590Srgrimes PRINT(CURS_UP); 4361590Srgrimes PRINT(CURS_UP); 4371590Srgrimes upln++; 4381590Srgrimes} 4391590Srgrimes 440227190Sedstatic void 441102944Sdwmaloneinitcap(void) 4421590Srgrimes{ 4431590Srgrimes static char tcapbuf[512]; 4441590Srgrimes char *bp = tcapbuf; 4451590Srgrimes 4461590Srgrimes /* This nonsense attempts to work with both old and new termcap */ 4471590Srgrimes CURS_UP = tgetstr("up", &bp); 4481590Srgrimes CURS_RIGHT = tgetstr("ri", &bp); 4491590Srgrimes if (CURS_RIGHT == NULL) 4501590Srgrimes CURS_RIGHT = tgetstr("nd", &bp); 4511590Srgrimes CURS_LEFT = tgetstr("le", &bp); 4521590Srgrimes if (CURS_LEFT == NULL) 4531590Srgrimes CURS_LEFT = tgetstr("bc", &bp); 4541590Srgrimes if (CURS_LEFT == NULL && tgetflag("bs")) 4551590Srgrimes CURS_LEFT = "\b"; 4561590Srgrimes 4571590Srgrimes ENTER_STANDOUT = tgetstr("so", &bp); 4581590Srgrimes EXIT_STANDOUT = tgetstr("se", &bp); 4591590Srgrimes ENTER_UNDERLINE = tgetstr("us", &bp); 4601590Srgrimes EXIT_UNDERLINE = tgetstr("ue", &bp); 4611590Srgrimes ENTER_DIM = tgetstr("mh", &bp); 4621590Srgrimes ENTER_BOLD = tgetstr("md", &bp); 4631590Srgrimes ENTER_REVERSE = tgetstr("mr", &bp); 4641590Srgrimes EXIT_ATTRIBUTES = tgetstr("me", &bp); 4651590Srgrimes 4661590Srgrimes if (!ENTER_BOLD && ENTER_REVERSE) 4671590Srgrimes ENTER_BOLD = ENTER_REVERSE; 4681590Srgrimes if (!ENTER_BOLD && ENTER_STANDOUT) 4691590Srgrimes ENTER_BOLD = ENTER_STANDOUT; 4701590Srgrimes if (!ENTER_UNDERLINE && ENTER_STANDOUT) { 4711590Srgrimes ENTER_UNDERLINE = ENTER_STANDOUT; 4721590Srgrimes EXIT_UNDERLINE = EXIT_STANDOUT; 4731590Srgrimes } 4741590Srgrimes if (!ENTER_DIM && ENTER_STANDOUT) 4751590Srgrimes ENTER_DIM = ENTER_STANDOUT; 4761590Srgrimes if (!ENTER_REVERSE && ENTER_STANDOUT) 4771590Srgrimes ENTER_REVERSE = ENTER_STANDOUT; 4781590Srgrimes if (!EXIT_ATTRIBUTES && EXIT_STANDOUT) 4791590Srgrimes EXIT_ATTRIBUTES = EXIT_STANDOUT; 4808874Srgrimes 4811590Srgrimes /* 4821590Srgrimes * Note that we use REVERSE for the alternate character set, 4831590Srgrimes * not the as/ae capabilities. This is because we are modelling 4841590Srgrimes * the model 37 teletype (since that's what nroff outputs) and 4851590Srgrimes * the typical as/ae is more of a graphics set, not the greek 4861590Srgrimes * letters the 37 has. 4871590Srgrimes */ 4881590Srgrimes 4891590Srgrimes UNDER_CHAR = tgetstr("uc", &bp); 4901590Srgrimes must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE); 4911590Srgrimes} 4921590Srgrimes 493227190Sedstatic int 494102944Sdwmaloneoutchar(int c) 4951590Srgrimes{ 496132858Stjr return (putwchar(c) != WEOF ? c : EOF); 4971590Srgrimes} 4981590Srgrimes 4991590Srgrimesstatic int curmode = 0; 5001590Srgrimes 501227190Sedstatic void 502132858Stjroutc(wint_t c, int width) 5031590Srgrimes{ 504132858Stjr int i; 505132858Stjr 506132858Stjr putwchar(c); 5071590Srgrimes if (must_use_uc && (curmode&UNDERL)) { 508132858Stjr for (i = 0; i < width; i++) 509132858Stjr PRINT(CURS_LEFT); 510132858Stjr for (i = 0; i < width; i++) 511132858Stjr PRINT(UNDER_CHAR); 5121590Srgrimes } 5131590Srgrimes} 5141590Srgrimes 515227190Sedstatic void 516102944Sdwmalonesetnewmode(int newmode) 5171590Srgrimes{ 5181590Srgrimes if (!iflag) { 5191590Srgrimes if (curmode != NORMAL && newmode != NORMAL) 52028454Scharnier setnewmode(NORMAL); 5211590Srgrimes switch (newmode) { 5221590Srgrimes case NORMAL: 5231590Srgrimes switch(curmode) { 5241590Srgrimes case NORMAL: 5251590Srgrimes break; 5261590Srgrimes case UNDERL: 5271590Srgrimes PRINT(EXIT_UNDERLINE); 5281590Srgrimes break; 5291590Srgrimes default: 5301590Srgrimes /* This includes standout */ 5311590Srgrimes PRINT(EXIT_ATTRIBUTES); 5321590Srgrimes break; 5331590Srgrimes } 5341590Srgrimes break; 5351590Srgrimes case ALTSET: 5361590Srgrimes PRINT(ENTER_REVERSE); 5371590Srgrimes break; 5381590Srgrimes case SUPERSC: 5391590Srgrimes /* 5401590Srgrimes * This only works on a few terminals. 5411590Srgrimes * It should be fixed. 5421590Srgrimes */ 5431590Srgrimes PRINT(ENTER_UNDERLINE); 5441590Srgrimes PRINT(ENTER_DIM); 5451590Srgrimes break; 5461590Srgrimes case SUBSC: 5471590Srgrimes PRINT(ENTER_DIM); 5481590Srgrimes break; 5491590Srgrimes case UNDERL: 5501590Srgrimes PRINT(ENTER_UNDERLINE); 5511590Srgrimes break; 5521590Srgrimes case BOLD: 5531590Srgrimes PRINT(ENTER_BOLD); 5541590Srgrimes break; 5551590Srgrimes default: 5561590Srgrimes /* 5571590Srgrimes * We should have some provision here for multiple modes 5581590Srgrimes * on at once. This will have to come later. 5591590Srgrimes */ 5601590Srgrimes PRINT(ENTER_STANDOUT); 5611590Srgrimes break; 5621590Srgrimes } 5631590Srgrimes } 5641590Srgrimes curmode = newmode; 5651590Srgrimes} 566