n1.c revision e5190c108bde19ca4d7c03b1d1eab7b00bd3a1ed
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* n1.c
*
* consume options, initialization, main loop,
* input routines, escape function calling
*/
#include <ctype.h>
#include <signal.h>
#include <setjmp.h>
#include <time.h>
#include <stdarg.h>
#include <locale.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#ifdef EUC
#ifdef NROFF
#include <stddef.h>
#include <limits.h>
#endif /* NROFF */
#endif /* EUC */
#include "tdef.h"
#include "ext.h"
#ifdef NROFF
#include "tw.h"
#endif
#define MAX_RECURSION_DEPTH 512
extern void fdprintf(int, char *, ...);
extern char *roff_sprintf(char *, char *, ...);
long ioff;
char *ttyp;
char *progname; /* program name (troff) */
#ifdef EUC
#ifdef NROFF
#endif /* NROFF */
#endif /* EUC */
#ifdef DEBUG
int debug = 0; /*debug flag*/
#endif /* DEBUG */
static char *sprintn(char *, long, int);
static int printn(long, int);
int
{
char *p, *q;
int j;
tchar i;
int eileenct; /*count to test for "Eileen's loop"*/
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void)textdomain(TEXT_DOMAIN);
}
mrehash();
nrehash();
init0();
#ifdef EUC
#ifdef NROFF
(void)localize();
#endif /* NROFF */
#endif /* EUC */
if ((p = getenv("TYPESETTER")) != 0)
switch (argv[0][1]) {
case 'F': /* switch font tables from default */
} else {
if (argv[0] != '\0') {
} else
}
continue;
case 0:
goto start;
case 'i':
stdi++;
continue;
case 'q':
#ifdef NROFF
quiet++;
save_tty();
#else
#endif /* NROFF */
continue;
case 'n':
continue;
case 'u': /* set emboldening amount */
bdtab[3] = 0;
continue;
case 's':
stop++;
continue;
case 't':
ptid = 1;
continue;
case 'r':
else
continue;
case 'c':
case 'm':
argv[0]);
continue;
}
done(02);
}
nmfi++;
} else
nmfi++;
else {
argv[0]);
done(02);
}
continue;
case 'o':
continue;
case 'T':
dotT++;
continue;
#ifdef NROFF
case 'h':
hflg++;
continue;
case 'z':
no_out++;
continue;
case 'e':
eqflg++;
continue;
#endif
#ifndef NROFF
case 'z':
no_out++;
case 'a':
ascii = 1;
nofeed++;
continue;
case 'f':
nofeed++;
continue;
#endif
case '#':
#ifdef DEBUG
#else
errprint("DEBUG not enabled");
#endif /* DEBUG */
continue;
default:
done(02);
}
nmfi = 0;
init2();
eileenct = 0; /*reset count for "Eileen's loop"*/
loop:
nflush++;
trap = 0;
eject((struct s *)0);
#ifdef DEBUG
#endif /* DEBUG */
if (eileenct > 20) {
ejf = 0; /*try to break Eileen's loop*/
eileenct = 0;
} else
eileenct++;
goto loop;
}
eileenct = 0; /*reset count for "Eileen's loop"*/
i = getch();
if (pendt)
goto Lt;
copyf++;
tflg++;
while (cbits(i) != '\n')
tflg = 0;
copyf--;
goto loop;
}
if (j == c2)
nb++;
copyf++;
;
ch = i;
copyf--;
flushi();
goto loop;
}
Lt:
ch = i;
text();
if (nlflg)
goto loop;
}
int
int idx;
{
return(0);
else return(1);
}
void catch()
{
done3(01);
}
void kcatch()
{
done3(01);
}
int
init0()
{
ibuf[0] = 0;
return (0);
}
int
init1(a)
char a;
{
char *p;
int i;
p = tmp_name;
if (a == 'a')
p = &p[9];
exit(-1);
}
unlkp = p;
for (i = NTRTAB; --i; )
trtab[i] = i;
return (0);
}
int
init2()
{
int i, j;
extern char *setbrk();
extern char *ttyname();
ttyod = 2;
;
else
ttyp = "notty";
iflg = j;
if (ascii)
mesg(0);
ptinit();
mchbits();
cvtime();
ioff = 0;
nfo = 0;
ifile = 0;
dip = &d[0];
#ifdef INCORE
for (i = 0; i < NEV; i++) {
}
#else
for (i = NEV; i--; )
#endif
return (0);
}
int
cvtime()
{
return (0);
}
int
ctoi(s)
char *s;
{
int n;
while (*s == ' ')
s++;
n = 0;
while (isdigit((unsigned char)*s))
n = 10 * n + *s++ - '0';
return n;
}
int
mesg(f)
int f;
{
static int mode;
if (!f) {
} else {
}
return (0);
}
int
{
stackdump();
#ifdef DEBUG
if (debug)
abort();
#endif /* DEBUG */
return (0);
}
/*
* Scaled down version of C Library printf.
* Only %s %u %d (==%u) %o %c %x %D are recognized.
*/
void
{
int c;
char *s;
int i;
loop:
while ((c = *fmt++) != '%') {
if (c == '\0') {
else {
*pfbp = 0;
while (*pfbp) {
flusho();
}
}
return;
}
putchar(c);
}
c = *fmt++;
if (c == 'd') {
if (i < 0) {
putchar('-');
i = -i;
}
printn((long)i, 10);
} else if (c == 'u' || c == 'o' || c == 'x')
else if (c == 'c') {
if (c > 0177 || c < 040)
putchar('\\');
} else if (c == 's') {
while (c = *s++)
putchar(c);
} else if (c == 'D') {
} else if (c == 'O') {
}
goto loop;
}
/*
* Print an unsigned integer in base b.
*/
static int
printn(n, b)
long n;
int b;
{
long a;
if (n < 0) { /* shouldn't happen */
putchar('-');
n = -n;
}
if (a = n / b)
printn(a, b);
putchar("0123456789ABCDEF"[(int)(n%b)]);
return (0);
}
/* scaled down version of library roff_sprintf */
/* same limits as fdprintf */
/* returns pointer to \0 that ends the string */
/* VARARGS2 */
{
int c;
char *s;
int i;
loop:
while ((c = *fmt++) != '%') {
if (c == '\0') {
*str = 0;
return str;
}
*str++ = c;
}
c = *fmt++;
if (c == 'd') {
if (i < 0) {
*str++ = '-';
i = -i;
}
} else if (c == 'u' || c == 'o' || c == 'x')
else if (c == 'c') {
if (c > 0177 || c < 040)
*str++ = '\\';
} else if (c == 's') {
while (c = *s++)
*str++ = c;
} else if (c == 'D') {
} else if (c == 'O') {
}
goto loop;
}
/*
* Print an unsigned integer in base b.
*/
static char *sprintn(s, n, b)
char *s;
long n;
int b;
{
long a;
if (n < 0) { /* shouldn't happen */
*s++ = '-';
n = -n;
}
if (a = n / b)
s = sprintn(s, a, b);
*s++ = "0123456789ABCDEF"[(int)(n%b)];
return s;
}
int
control(a, b)
int a, b;
{
int j;
if (a == 0 || (j = findmn(a)) == -1)
return(0);
/*
* Attempt to find endless recursion at runtime. Arbitrary
* recursion limit of MAX_RECURSION_DEPTH was chosen as
* invocation would exceed this value.
*/
int frame_cnt = 0;
struct s *p;
frame_cnt++;
if (frame_cnt > MAX_RECURSION_DEPTH) {
gettext("Exceeded maximum stack size (%d) when "
"executing macro %c%c. Stack dump follows"),
edone(02);
}
}
#ifdef DEBUG
#endif /* DEBUG */
if (contab[j].f == 0) {
if (b)
collect();
flushi();
} else if (b)
return((*contab[j].f)(0));
else
return(0);
}
int
getrq()
{
int i, j;
goto rtn;
i = PAIR(i, j);
rtn:
return(i);
}
/*
* table encodes some special characters, to speed up tests
* in getchar, viz FLSS, RPT, f, \b, \n, fc, tabch, ldrch
*/
char
gchtab[] = {
000,004,000,000,010,000,000,000, /* fc, ldr */
001,002,001,000,001,000,000,000, /* \b, tab, nl, RPT */
000,000,000,000,000,000,000,000,
000,001,000,000,000,000,000,000, /* FLSS */
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,001,000, /* f */
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
000,000,000,000,000,000,000,000,
};
getch()
{
int k;
tchar i, j;
g0:
if (i = ch) {
#ifdef DEBUG
#endif /* DEBUG */
if (cbits(i) == '\n')
nlflg++;
ch = 0;
return(i);
}
#ifdef DEBUG
if (nlflg)
#endif /* DEBUG */
if (nlflg)
return('\n');
i = getch0();
#ifdef DEBUG
i, (i&0177) < 040 ? 0177 : i&0177);
#endif /* DEBUG */
if (ismot(i))
return(i);
k = cbits(i);
if (k != ESC) {
/*
* gchtab[] has only 128 entries
* if k is out of the range, it should be
* handled as gchtab[k] == 0
*/
return(i);
if (k == '\n') {
if (cbits(i) == '\n') {
nlflg++;
if (ip == 0)
}
return(k);
}
if (k == FLSS) {
copyf++;
raw++;
i = getch0();
if (!fi)
flss = i;
copyf--;
raw--;
goto g0;
}
if (k == RPT) {
setrpt();
goto g0;
}
if (!copyf) {
i = getlg(i);
return(i);
}
if ((i = setfield(k)) == 0)
goto g0;
else
return(i);
}
if (k == '\b') {
return(i);
}
}
return(i);
}
if (ismot(j))
return(j);
switch (k) {
case 'X': /* \X'...' for copy through */
setxon();
goto g0;
case '\n': /* concealed newline */
goto g0;
case 'n': /* number register */
setn();
goto g0;
case '*': /* string indicator */
setstr();
goto g0;
case '$': /* argument indicator */
seta();
goto g0;
case '{': /* LEFT */
i = LEFT;
goto gx;
case '}': /* RIGHT */
i = RIGHT;
goto gx;
case '"': /* comment */
;
nlflg++;
if (ip == 0)
return(i);
case ESC: /* double backslash */
i = eschar;
goto gx;
case 'e': /* printable version of current eschar */
i = PRESC;
goto gx;
case ' ': /* unpaddable space */
i = UNPAD;
goto gx;
case '\'': /* \(aa */
i = ACUTE;
goto gx;
case '`': /* \(ga */
i = GRAVE;
goto gx;
case '_': /* \(ul */
i = UNDERLINE;
goto gx;
case '-': /* current font minus */
i = MINUS;
goto gx;
case '&': /* filler */
i = FILLER;
goto gx;
case 'c': /* to be continued */
i = CONT;
goto gx;
case '!': /* transparent indicator */
i = XPAR;
goto gx;
case 't': /* tab */
i = '\t';
return(i);
case 'a': /* leader (SOH) */
i = LEADER;
return(i);
case '%': /* ohc */
i = OHC;
return(i);
case 'g': /* return format of a number register */
setaf();
goto g0;
case 'N': /* absolute character number */
i = setabs();
goto gx;
case '.': /* . */
i = '.';
gx:
return(i);
}
if (copyf) {
*pbp++ = j;
return(eschar);
}
switch (k) {
case 'p': /* spread */
spread++;
goto g0;
case '(': /* special char name */
if ((i = setch()) == 0)
goto g0;
return(i);
case 's': /* size indicator */
setps();
goto g0;
case 'H': /* character height */
return(setht());
case 'S': /* slant */
return(setslant());
case 'f': /* font indicator */
setfont(0);
goto g0;
case 'w': /* width function */
setwd();
goto g0;
case 'v': /* vert mot */
if (i = vmot())
return(i);
goto g0;
case 'h': /* horiz mot */
if (i = hmot())
return(i);
goto g0;
case 'z': /* zero with char */
return(setz());
case 'l': /* hor line */
setline();
goto g0;
case 'L': /* vert line */
setvline();
goto g0;
case 'D': /* drawing function */
setdraw();
goto g0;
case 'b': /* bracket */
setbra();
goto g0;
case 'o': /* overstrike */
setov();
goto g0;
case 'k': /* mark hor place */
}
goto g0;
case '0': /* number space */
#ifdef NROFF
case '|':
case '^':
goto g0;
#else
case '|': /* narrow space */
case '^': /* half narrow space */
#endif
case 'x': /* extra line space */
if (i = xlss())
return(i);
goto g0;
case 'u': /* half em up */
case 'r': /* full em up */
case 'd': /* half em down */
return(sethl(k));
default:
return(j);
}
/* NOTREACHED */
}
int
setxon() /* \X'...' for copy through */
{
tchar *i;
tchar c;
int delim, k;
return (0);
i = xbuf;
*i++ = XON;
if (k == ' ')
*i++ = c | ZBIT;
}
*i++ = XOFF;
*i = 0;
return (0);
}
char ifilt[32] = {
0, 001, 002, 003, 0, 005, 006, 007, 010, 011, 012};
{
int j;
tchar i;
#ifdef EUC
#ifdef NROFF
int n;
int col_index;
#endif /* NROFF */
#endif /* EUC */
i = *--pbp;
else if (ip) {
#ifdef INCORE
if (i == 0)
i = rbf();
else {
--ip;
(void)rbf();
}
}
#else
i = rbf();
#endif
} else {
done(0);
if (nfo==0) {
g0:
if (nextfile()) {
if (ip)
goto again;
goto g2;
}
}
nx = 0;
goto g0;
if (ip)
goto again;
}
g2:
#ifndef EUC
i = *ibufp++ & 0177;
ioff++;
if (i >= 040 && i < 0177)
#else
#ifndef NROFF
i = *ibufp++ & 0177;
ioff++;
if (i >= 040 && i < 0177)
#else
i = *ibufp++ & 0377;
*mbbuf1p++ = i;
*mbbuf1p = 0;
if (!multi_locale) {
twc = 0;
twc = 0;
*mbbuf1p = 0;
} else {
i |= (MIDDLEOFMB);
}
} else {
if (n > 1)
i |= (LASTOFMB);
else
i |= (BYTE_CHR);
col_index = 0;
} else {
col_index = 0;
}
twc = 0;
}
ioff++;
if (i >= 040 && i != 0177)
#endif /* NROFF */
#endif /* EUC */
goto g4;
if (i != 0177)
i = ifilt[i];
}
goto again;
goto again;
}
g4:
#ifndef EUC
#else
#ifndef NROFF
#else
#endif /* NROFF */
#endif /* EUC */
i |= chbits;
#ifdef EUC
#ifdef NROFF
if (multi_locale)
if (i & MBMASK1)
i |= ZBIT;
#endif /* NROFF */
#endif /* EUC */
return(i);
}
int
pushback(b)
tchar *b;
{
while (*b++)
;
b--;
*pbp++ = *--b;
done(2);
}
return (0);
}
int
cpushback(b)
char *b;
{
char *ob = b;
while (*b++)
;
b--;
*pbp++ = *--b;
done(2);
}
return (0);
}
int
nextfile()
{
char *p;
n0:
if (ifile)
if (*p != 0)
goto n1;
}
if (ifi > 0) {
if (popf())
goto n0; /* popf error */
return(1); /* popf ok */
}
if (rargc-- <= 0) {
done(0);
nfo++;
ioff = 0;
return(0);
}
p = (argp++)[0];
n1:
if (p[0] == '-' && p[1] == 0) {
ifile = 0;
done(02);
} else
nfo++;
ioff = 0;
return(0);
}
int
popf()
{
int i;
char *p, *q;
extern char *ttyname();
p = xbuf;
q = ibuf;
while (q < eibuf)
*q++ = *p++;
return(0);
}
return(1);
/* was >= ... */
return(1);
return(0);
}
int
flushi()
{
if (nflush)
return (0);
ch = 0;
copyf++;
while (!nlflg) {
break;
getch();
}
copyf--;
return (0);
}
int
getach()
{
tchar i;
int j;
lgf++;
#ifndef EUC
#else
#ifndef NROFF
#else
#endif /* NROFF */
#endif /* EUC */
ch = i;
j = 0;
}
lgf--;
return(j & 0177);
}
int
casenx()
{
lgf++;
skip();
getname();
nx++;
if (nmfi > 0)
nmfi--;
nextfile();
nlflg++;
ip = 0;
pendt = 0;
return (0);
}
int
getname()
{
int j, k;
tchar i;
lgf++;
for (k = 0; k < (NS - 1); k++) {
#ifndef EUC
#else
#ifndef NROFF
#else
#endif /* NROFF */
#endif /* EUC */
break;
}
nextf[k] = 0;
ch = i;
lgf--;
return((int)nextf[0]);
}
int
caseso()
{
int i;
char *p, *q;
lgf++;
nextf[0] = 0;
done(02);
}
flushi();
ifile = i;
ioff = 0;
ip = 0;
nx++;
nflush++;
p = ibuf;
q = xbuf;
while (p < eibuf)
*q++ = *p++;
}
return (0);
}
int
caself() /* set line number and file */
{
int n;
if (skip())
return (0);
n = atoi();
if (skip())
return (0);
if (getname())
return (0);
}
int
casecf()
{ /* copy file without change */
#ifndef NROFF
int fd, n;
char buf[512];
nextf[0] = 0;
done(02);
}
tbreak();
/* make it into a clean state, be sure that everything is out */
ptesc();
ptlead();
ptps();
ptfont();
flusho();
#endif
return (0);
}
int
casesy() /* call system */
{
int i;
lgf++;
copyf++;
skip();
for (i = 0; i < NTM - 2; i++)
break;
sybuf[i] = 0;
copyf--;
lgf--;
return (0);
}
int
getpn(a)
char *a;
{
int n, neg;
if (*a == 0)
return (0);
neg = 0;
for ( ; *a; a++)
switch (*a) {
case '+':
case ',':
continue;
case '-':
neg = 1;
continue;
default:
n = 0;
if (isdigit((unsigned char)*a)) {
do
n = 10 * n + *a++ - '0';
while (isdigit((unsigned char)*a));
a--;
} else
n = 9999;
neg = 0;
done3(-3);
}
}
if (neg)
*pnp++ = -9999;
*pnp = -32767;
print = 0;
if (*pnp != -32767)
chkpn();
return (0);
}
int
setrpt()
{
tchar i, j;
copyf++;
raw++;
i = getch0();
copyf--;
raw--;
return (0);
i &= BYTEMASK;
i--;
*pbp++ = j;
}
return (0);
}
int
casedb()
{
#ifdef DEBUG
debug = 0;
if (skip())
return (0);
noscale++;
noscale = 0;
#endif /* DEBUG */
return (0);
}