static char SccsId
[] = "@(#)ul.c 4.3 (Berkeley) %G%";
#define ALTSET 001 /* Reverse */
#define SUPERSC 002 /* Dim */
#define SUBSC 004 /* Dim | Ul */
#define UNDERL 010 /* Ul */
#define BOLD 020 /* Bold */
int must_use_uc
, must_overstrike
;
char *CURS_UP
, *CURS_RIGHT
, *CURS_LEFT
,
*ENTER_STANDOUT
, *EXIT_STANDOUT
, *ENTER_UNDERLINE
, *EXIT_UNDERLINE
,
*ENTER_DIM
, *ENTER_BOLD
, *ENTER_REVERSE
, *UNDER_CHAR
, *EXIT_ATTRIBUTES
;
struct CHAR obuf
[MAXBUF
];
termtype
= getenv("TERM");
if (termtype
== NULL
|| (argv
[0][0] == 'c' && !isatty(1)))
while ((c
=getopt(argc
, argv
, "it:T:")) != EOF
)
case 'T': /* for nroff compatibility */
"Usage: %s [ -i ] [ -tTerm ] file...\n",
switch(tgetent(termcap
, termtype
)) {
fprintf(stderr
,"trouble reading termcap");
/* fall through to ... */
/* No such terminal type - assume dumb */
strcpy(termcap
, "dumb:os:col#80:cr=^M:sf=^J:am:");
if ( (tgetflag("os") && ENTER_BOLD
==NULL
) ||
(tgetflag("ul") && ENTER_UNDERLINE
==NULL
&& UNDER_CHAR
==NULL
))
else for (; optind
<argc
; optind
++) {
f
= fopen(argv
[optind
],"r");
while((c
= getc(f
)) != EOF
) switch(c
) {
} else if (halfpos
> 0) {
} else if (halfpos
< 0) {
"Unknown escape sequence in input: %o, %o\n",
obuf
[col
].c_mode
|= UNDERL
| mode
;
if (c
< ' ') /* non printing */
if (obuf
[col
].c_char
== '\0') {
} else if (obuf
[col
].c_char
== '_') {
obuf
[col
].c_mode
|= UNDERL
|mode
;
obuf
[col
].c_mode
|= BOLD
|mode
;
for (i
=0; i
<maxcol
; i
++) {
if (obuf
[i
].c_mode
!= lastmode
) {
lastmode
= obuf
[i
].c_mode
;
if (obuf
[i
].c_char
== '\0') {
if (lastmode
!= NORMAL
) {
if (must_overstrike
&& hadmodes
)
* For terminals that can overstrike, overstrike underlines and bolds.
* We don't do anything with halfline ups and downs, or Greek.
register char *cp
= lbuf
;
/* Set up overstrike buffer */
switch (obuf
[i
].c_mode
) {
for (*cp
=' '; *cp
==' '; cp
--)
putchar(*cp
=='_' ? ' ' : *cp
);
putchar(*cp
=='_' ? ' ' : *cp
);
register char *cp
= lbuf
;
switch (obuf
[i
].c_mode
) {
case NORMAL
: *cp
++ = ' '; break;
case ALTSET
: *cp
++ = 'g'; break;
case SUPERSC
: *cp
++ = '^'; break;
case SUBSC
: *cp
++ = 'v'; break;
case UNDERL
: *cp
++ = '_'; break;
case BOLD
: *cp
++ = '!'; break;
default: *cp
++ = 'X'; break;
for (*cp
=' '; *cp
==' '; cp
--)
for (i
=0; i
<MAXBUF
; i
++) {
static char tcapbuf
[512];
char *getenv(), *tgetstr();
/* This nonsense attempts to work with both old and new termcap */
CURS_UP
= tgetstr("up", &bp
);
CURS_RIGHT
= tgetstr("ri", &bp
);
CURS_RIGHT
= tgetstr("nd", &bp
);
CURS_LEFT
= tgetstr("le", &bp
);
CURS_LEFT
= tgetstr("bc", &bp
);
if (CURS_LEFT
== NULL
&& tgetflag("bs"))
ENTER_STANDOUT
= tgetstr("so", &bp
);
EXIT_STANDOUT
= tgetstr("se", &bp
);
ENTER_UNDERLINE
= tgetstr("us", &bp
);
EXIT_UNDERLINE
= tgetstr("ue", &bp
);
ENTER_DIM
= tgetstr("mh", &bp
);
ENTER_BOLD
= tgetstr("md", &bp
);
ENTER_REVERSE
= tgetstr("mr", &bp
);
EXIT_ATTRIBUTES
= tgetstr("me", &bp
);
if (!ENTER_BOLD
&& ENTER_REVERSE
)
ENTER_BOLD
= ENTER_REVERSE
;
if (!ENTER_BOLD
&& ENTER_STANDOUT
)
ENTER_BOLD
= ENTER_STANDOUT
;
if (!ENTER_UNDERLINE
&& ENTER_STANDOUT
) {
ENTER_UNDERLINE
= ENTER_STANDOUT
;
EXIT_UNDERLINE
= EXIT_STANDOUT
;
if (!ENTER_DIM
&& ENTER_STANDOUT
)
ENTER_DIM
= ENTER_STANDOUT
;
if (!ENTER_REVERSE
&& ENTER_STANDOUT
)
ENTER_REVERSE
= ENTER_STANDOUT
;
if (!EXIT_ATTRIBUTES
&& EXIT_STANDOUT
)
EXIT_ATTRIBUTES
= EXIT_STANDOUT
;
* Note that we use REVERSE for the alternate character set,
* not the as/ae capabilities. This is because we are modelling
* the model 37 teletype (since that's what nroff outputs) and
* the typical as/ae is more of a graphics set, not the greek
printf("so %s se %s us %s ue %s me %s\n",
ENTER_STANDOUT
, EXIT_STANDOUT
, ENTER_UNDERLINE
,
EXIT_UNDERLINE
, EXIT_ATTRIBUTES
);
UNDER_CHAR
= tgetstr("uc", &bp
);
must_use_uc
= (UNDER_CHAR
&& !ENTER_UNDERLINE
);
if (must_use_uc
&& (curmode
&UNDERL
)) {
if (curmode
!= NORMAL
&& newmode
!= NORMAL
)
/* This includes standout */
* This only works on a few terminals.
* We should have some provision here for multiple modes
* on at once. This will have to come later.
#define ERR(s, c) if(opterr){\
getopt (argc
, argv
, opts
)
argv
[optind
][0] != '-' || argv
[optind
][1] == '\0')
else if (strcmp(argv
[optind
], "--") == NULL
) {
else if (strcmp(argv
[optind
], "-?") == NULL
) {
if (c
== ':' || (cp
=index(opts
, c
)) == NULL
) {
ERR (": illegal option -- ", c
);
if (argv
[optind
][++sp
] == '\0') {
if (argv
[optind
][2] != '\0')
optarg
= &argv
[optind
++][sp
+1];
else if (++optind
>= argc
) {
ERR (": option requires an argument -- ", c
);
else if (argv
[optind
][++sp
] == '\0') {