ul.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, 2000 Sun Microsystems, Inc.
* All Rights Reserved.
*/
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
#include <stdio.h>
#include <locale.h>
#include <wctype.h>
#include <widec.h>
#include <euc.h>
#include <limits.h>
#include <stdlib.h>
#define IESC L'\033'
#define SO L'\016'
#define SI L'\017'
#define HFWD L'9'
#define HREV L'8'
#define FREV L'7'
#define CDUMMY -1
#define NORMAL 000
#define MEMFCT 16
/*
* MEMFCT is a number that is likely to be large enough as a factor for
* allocating more memory and to be small enough so as not wasting memory
*/
int must_use_uc, must_overstrike;
struct CHAR {
char c_mode;
};
int mode;
int halfpos;
int upln;
int iflag;
int scrw[4];
int argc;
char **argv;
{
int c;
FILE *f;
char termcap[1024];
char *getenv();
extern int optind;
extern char *optarg;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
scrw[0] = 1;
termtype = "lpr";
switch (c) {
case 't':
case 'T': /* for nroff compatibility */
break;
case 'i':
iflag = 1;
break;
default:
gettext("\
Usage: %s [ -i ] [ -t terminal ] [ filename...]\n"),
argv[0]);
exit(1);
}
case 1:
break;
default:
/* fall through to ... */
case 0:
/* No such terminal type - assume dumb */
break;
}
initcap();
must_overstrike = 1;
initbuf();
if (f == NULL) {
exit(1);
} else
filter(f);
}
exit(0);
}
filter(f)
FILE *f;
{
register wchar_t c;
register i;
{
exit(1);
}
switch (c) {
case L'\b':
if (col > 0)
col--;
continue;
case L'\t':
continue;
case L'\r':
col = 0;
continue;
case SO:
continue;
case SI:
continue;
case IESC:
switch (c = getwc(f)) {
case HREV:
if (halfpos == 0) {
halfpos--;
} else if (halfpos > 0) {
halfpos--;
} else {
halfpos = 0;
reverse();
}
continue;
case HFWD:
if (halfpos == 0) {
halfpos++;
} else if (halfpos < 0) {
halfpos++;
} else {
halfpos = 0;
fwd();
}
continue;
case FREV:
reverse();
continue;
default:
gettext("Unknown escape sequence in input: %o, %o\n"),
IESC, c);
exit(1);
}
continue;
case L'_':
else
case L' ':
col++;
continue;
case L'\n':
flushln();
continue;
default:
if (c < L' ') /* non printing */
continue;
while (--i > 0)
while (--i > 0)
else {
}
col++;
continue;
}
}
if (maxcol)
flushln();
}
flushln()
{
register lastmode;
register i;
int hadmodes = 0;
for (i=0; i<maxcol; i++) {
hadmodes++;
}
if (upln) {
} else
outc(L' ');
} else
}
setmode(0);
}
if (must_overstrike && hadmodes)
overstrike();
putwchar(L'\n');
iattr();
if (upln)
upln--;
initbuf();
}
/*
* For terminals that can overstrike, overstrike underlines and bolds.
* We don't do anything with halfline ups and downs, or Greek.
*/
{
register int i, n;
int hadbold=0;
if (!scp) {
/* this kind of message need not to be gettext'ed */
exit(1);
}
#ifdef DEBUG
/*
* to allocate a memory after the chunk of the current scp
* and to make sure the following realloc() allocates
* memory from different chunks.
*/
#endif
/* Set up overstrike buffer */
for (i=0; i<maxcol; i++) {
if (tszbf <= n) {
/* may not enough buffer for this char */
/* obtain the offset of cp */
/* reallocate another (n * MEMFCT) * sizeof (wchar_t) */
if (!scp) {
exit(1);
}
/* get the new address of cp */
}
case NORMAL:
default:
tszbf -= n;
*cp++ = L' ';
while (--n > 0) {
*cp++ = L' ';
i++;
}
break;
case UNDERL:
tszbf -= n;
*cp++ = L'_';
while (--n > 0) {
*cp++ = L'_';
i++;
}
break;
case BOLD:
tszbf--;
hadbold=1;
break;
}
}
putwchar(L'\r');
*cp = L'\0';
if (hadbold) {
putwchar(L'\r');
putwchar(L'\r');
}
}
iattr()
{
register int i, n;
if (!scp) {
/* this kind of message need not to be gettext'ed */
exit(1);
}
#ifdef DEBUG
/*
* to allocate a memory after the chunk of the current scp
* and to make sure the following realloc() allocates
* memory from different chunks.
*/
#endif
for (i=0; i<maxcol; i++) {
default: cx = 'X'; break;
}
if (tszbf <= n) {
/* may not enough buffer for this char */
/* obtain the offset of cp */
/* reallocate another (n * MEMFCT) * sizeof (wchar_t) */
if (!scp) {
exit(1);
}
/* get the new address of cp */
}
tszbf -= n;
while (--n > 0) {
i++;
}
}
*cp = L'\0';
putwchar(L'\n');
}
initbuf()
{
register i;
/* following depends on NORMAL == 000 */
for (i = 0; i < LINE_MAX; i++)
col = 0;
maxcol = 0;
}
fwd()
{
flushln();
}
reverse()
{
upln++;
fwd();
upln++;
}
initcap()
{
static char tcapbuf[512];
char *termtype;
/* This nonsense attempts to work with both old and new termcap */
if (CURS_RIGHT == NULL)
CURS_LEFT = "\b";
if (!ENTER_BOLD && ENTER_REVERSE)
if (!ENTER_BOLD && ENTER_STANDOUT)
if (!ENTER_UNDERLINE && ENTER_STANDOUT) {
}
if (!ENTER_DIM && ENTER_STANDOUT)
if (!ENTER_REVERSE && ENTER_STANDOUT)
if (!EXIT_ATTRIBUTES && EXIT_STANDOUT)
/*
* Note that we use REVERSE for the alternate character set,
* the model 37 teletype (since that's what nroff outputs) and
* letters the 37 has.
*/
#ifdef notdef
printf("so %s se %s us %s ue %s me %s\n",
#endif
}
outchar(c)
char c;
{
putchar(c&0177);
}
const char *str;
{
if (str)
}
static curmode = 0;
outc(c)
wchar_t c;
{
register int m, n;
if (c == CDUMMY)
return;
putwchar(c);
while (--m > 0)
while (--n > 0)
}
}
int newmode;
{
if (!iflag)
{
switch (newmode) {
case NORMAL:
switch (curmode) {
case NORMAL:
break;
case UNDERL:
break;
default:
/* This includes standout */
break;
}
break;
case ALTSET:
break;
case SUPERSC:
/*
* This only works on a few terminals.
* It should be fixed.
*/
break;
case SUBSC:
break;
case UNDERL:
break;
case BOLD:
break;
default:
/*
* We should have some provision here for multiple modes
* on at once. This will have to come later.
*/
break;
}
}
}