/*
* 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"
/*
* troff3.c
*
* macro and string routines, storage allocation
*/
#include "tdef.h"
#ifdef NROFF
#include "tw.h"
#endif
#include "ext.h"
int strflg;
#ifdef INCORE
#else
#endif
int
caseig()
{
int i;
offset = 0;
i = copyb();
if (i != '.')
control(i, 1);
return (0);
}
int
casern()
{
int i, j;
lgf++;
skip();
return (0);
skip();
if (j) {
}
return (0);
}
int
{
return (0);
return (0);
}
int
{
struct contab *p;
return (0);
p = *lp;
while (p) {
if (p == mp) {
p->link = 0;
return (0);
}
p = p->link;
}
return (0);
}
int
mrehash()
{
struct contab *p;
int i;
for (i=0; i<128; i++)
mhash[i] = 0;
p->link = 0;
if (p->rq == 0)
continue;
mhash[i] = p;
}
return (0);
}
int
caserm()
{
int j;
lgf++;
lgf--;
return (0);
}
int
caseas()
{
app++;
caseds();
return (0);
}
int
caseds()
{
ds++;
casede();
return (0);
}
int
caseam()
{
app++;
casede();
return (0);
}
int
casede()
{
int i, req;
if (dip != d)
wbfl();
req = '.';
lgf++;
skip();
if ((i = getrq()) == 0)
goto de1;
goto de1;
if (ds)
copys();
else
wbfl();
if (newmn) {
}
if (apptr) {
}
if (req != '.')
de1:
return (0);
}
int
findmn(i)
int i;
{
struct contab *p;
if (i == p->rq)
return(p - contab);
return(-1);
}
int
clrmn(i)
int i;
{
if (i >= 0) {
contab[i].f = 0;
}
return (0);
}
int mn;
{
int i;
newmn = 0;
oldmn = -1;
while ((i = rbf()) != 0)
;
if (!diflg)
} else {
for (i = 0; i < NM; i++) {
break;
}
app = 0;
if (macerr++ > 1)
done2(02);
NM);
edone(04);
return(offset = 0);
}
if (!diflg) {
newmn = i;
if (oldmn == -1)
} else {
}
}
app = 0;
}
int
{
tchar i;
;
ch = i;
return(nlflg);
}
int
copyb()
{
int i, j, state;
int req, k;
j = '.';
req = j;
k = j >> BYTE;
j &= BYTEMASK;
copyf++;
flushi();
nlflg = 0;
state = 1;
/* state 0 eat up
* state 1 look for .
* state 2 look for first char of end macro
* state 3 look for second char of end macro
*/
while (1) {
if (state == 3) {
if (i == k)
break;
if (!k) {
i = getach();
if (!i)
break;
}
state = 0;
goto c0;
}
if (i == '\n') {
state = 1;
nlflg = 0;
goto c0;
}
state++;
goto c0;
}
if ((state == 2) && (i == j)) {
state++;
goto c0;
}
state = 0;
c0:
if (offset)
}
if (offset) {
wbfl();
}
copyf--;
return(req);
}
int
copys()
{
tchar i;
copyf++;
if (skip())
goto c0;
wbf(i);
wbf(i);
c0:
copyf--;
return (0);
}
{
int i;
filep j;
for (i = 0; i < NBLIST; i++) {
if (blist[i] == 0)
break;
}
if (i == NBLIST) {
j = 0;
} else {
blist[i] = -1;
}
#ifdef DEBUG
cc2 = ' ';
}
}
#endif /* DEBUG */
return(nextb = j);
}
int
filep i;
{
int j;
blist[j] = 0;
}
blist[j] = 0;
return (0);
}
int
wbt(i)
tchar i;
{
wbf(i);
wbfl();
return (0);
}
int
tchar i;
{
int j;
if (!offset)
return (0);
if (!woff) {
#ifdef INCORE
#endif
wbfi = 0;
}
wbfl();
if (j < 0 || j >= NBLIST) {
done2(01);
}
if (blist[j] == (unsigned) ~0) {
if (alloc() == 0) {
done2(01);
}
}
}
wbfl();
return (0);
}
int
{
if (woff == 0)
return (0);
#ifndef INCORE
#endif
roff = -1;
woff = 0;
return (0);
}
{
tchar i;
filep j, p;
if (j = rdtty())
return(j);
else
return(popi());
}
/* this is an inline expansion of rbf0: dirty! */
#ifndef INCORE
if (j != roff) {
roff = j;
i = 0;
else
} else
#else
#endif
/* end of rbf0 */
if (i == 0) {
if (!app)
i = popi();
return(i);
}
/* this is an inline expansion of incoff: also dirty */
p = ++ip;
if ((p & (BLK - 1)) == 0) {
ip = 0;
done2(-5);
}
/* this was meant to protect against people removing
* the macro they were standing on, but it's too
* sensitive to block boundaries.
* if (ip == 0) {
* errprint(gettext("Block removed while in use"));
* done2(-6);
* }
*/
}
return(i);
}
filep p;
{
#ifndef INCORE
filep i;
roff = i;
return(0);
}
#else
return(corebuf[p]);
#endif
}
filep p;
{
p++;
if ((p & (BLK - 1)) == 0) {
done2(-5);
}
}
return(p);
}
{
struct s *p;
return(0);
if (strflg)
strflg--;
p->nargs = 0;
return(p->pch);
}
/*
* test that the end of the allocation is above a certain location
* in memory
*/
int
int mname;
{
struct s *p;
extern char *setbrk();
p = nxf;
nxf += 1;
else
}
char *setbrk(x)
int x;
{
char *i, *k;
int j;
char *sbrk();
if ((i = sbrk(x)) == (char *) -1) {
edone(0100);
}
if (j = (unsigned)i % sizeof(int)) { /*check alignment for 3B*/
j = sizeof(int) - j; /*only init calls should need this*/
if ((k = sbrk(j)) == (char *) -1) {
errprint("Core limit reached");
edone(0100);
}
if (k != i + x) { /*there must have been an intervening sbrk*/
errprint ("internal error in setbrk: i=%x, j=%d, k=%x",
i, j, k);
edone(0100);
}
i += j;
}
enda = i + x;
return(i);
}
int
getsn()
{
int i;
if ((i = getach()) == 0)
return(0);
if (i == '(')
return(getrq());
else
return(i);
}
int
setstr()
{
int i, j;
lgf++;
lgf--;
return(0);
} else {
strflg++;
lgf--;
}
}
int
collect()
{
int j;
tchar i;
int quote;
struct s *savnxf;
copyf++;
if (skip())
goto rtn;
{
char *memp;
/*
* 1 s structure for the macro descriptor
* APERMAC tchar *'s for pointers into the strings
* space for the tchar's themselves
*/
memp += sizeof(struct s);
/*
* CPERMAC (the total # of characters for ALL arguments)
* to a macros, has been carefully chosen
* so that the distance between stack frames is < DELTA
*/
}
/*
* Zero out all the string pointers before filling them in.
*/
for (j = 0; j < APERMAC; j++){
}
#if 0
errprint("savnxf=0x%x,nxf=0x%x,argpp=0x%x,strp=argppend=0x%x,lim=0x%x,enda=0x%x",
#endif
strflg = 0;
quote = 0;
quote++;
else
ch = i;
while (1) {
i = getch();
break;
if ( quote
&& (cbits(i) == '"')
ch = i;
break;
}
*strp++ = i;
#if 0
errprint("strp=0x%x, lim = 0x%x",
#endif
copyf--;
edone(004);
}
}
*strp++ = 0;
}
rtn:
copyf--;
return (0);
}
int
seta()
{
int i;
return (0);
}
int
caseda()
{
app++;
casedi();
return (0);
}
int
casedi()
{
int i, j;
int *k;
lgf++;
if (dip != d)
if (dilev > 0) {
}
goto rtn;
}
--dilev;
edone(02);
}
if (dip != d)
diflg++;
for (j = 0; j < 10; j++)
k[j] = 0; /*not op and curd*/
rtn:
app = 0;
diflg = 0;
return (0);
}
int
casedt()
{
lgf++;
skip();
if (nonumb)
return (0);
skip();
return (0);
}
int
casetl()
{
int j;
int w[3];
skip();
delim = '\'';
} else
w[0] = w[1] = w[2] = 0;
j = 0;
if (j < 3)
j++;
*tp++ = 0;
} else {
i&SFMASK);
continue;
}
*tp++ = i;
}
}
if (j<3)
*tp++ = 0;
*tp++ = 0;
*tp++ = 0;
#ifdef NROFF
#endif
while (i = *tp++)
pchar(i);
if (w[1] || w[2])
while (i = *tp++)
pchar(i);
if (w[2]) {
while (i = *tp++)
pchar(i);
}
newline(0);
if (dip != d) {
} else {
}
return (0);
}
int
casepc()
{
return (0);
}
int
casepm()
{
int i, k;
char *p;
filep j;
for (i = 0; i < NM; i++) {
continue;
tcnt++;
p = pmline;
k = 1;
k++;
}
cnt++;
kk += k;
if (!tot) {
*p++ = xx & 0177;
*(p - 1) = ' ';
*p++ = 0;
}
}
return (0);
}
int
{
struct s *p;
}
return (0);
}