/*
* 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 2003 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"
#ifdef EUC
#ifdef NROFF
#include <stdlib.h>
#include <widec.h>
#include <limits.h>
#endif /* NROFF */
#endif /* EUC */
#include "tdef.h"
#ifdef NROFF
#include "tw.h"
#endif
#ifdef NROFF
#endif
#ifndef NROFF
#endif
/*
* troff7.c
*
* text
*/
#include <ctype.h>
#ifdef EUC
#ifdef NROFF
#include <wctype.h>
#endif /* NROFF */
#endif /* EUC */
#include "ext.h"
#ifdef EUC
#ifdef NROFF
int pendmb = 0;
#endif /* NROFF */
#endif /* EUC */
int brflg;
int
tbreak()
{
int pad, k;
tchar *i, j;
int resol = 0;
#ifdef EUC
#ifdef NROFF
tchar l;
#endif /* NROFF */
#endif /* EUC */
trap = 0;
if (nb)
return (0);
newline(1);
return (0);
}
if (!nc) {
setnel();
if (!wch)
return (0);
if (pendw)
getword(1);
movword();
getword(1);
movword();
}
#ifdef NROFF
if (dip == d)
#endif
if (lnmod)
donum();
if (brflg != 1) {
totout = 0;
} else if (ad) {
}
if (admod == 1)
else if (admod == 2)
}
totout++;
brflg = 0;
#ifdef NROFF
else
#else
#endif
#ifndef EUC
if ((cbits(j = *i++)) == ' ') {
#else
#ifndef NROFF
if ((cbits(j = *i++)) == ' ') {
#else
#endif /* NROFF */
#endif /* EUC */
pad = 0;
do {
nc--;
#ifndef EUC
} while ((cbits(j = *i++)) == ' ');
#else
#ifndef NROFF
} while ((cbits(j = *i++)) == ' ');
#else
#endif /* NROFF */
#endif /* EUC */
i--;
--nwd;
if (adrem) {
if (adrem < 0) {
}
}
} else {
pchar(j);
nc--;
}
}
if (ic) {
horiz(k);
}
if (icf)
icf++;
else
ic = 0;
setnel();
newline(0);
if (dip != d) {
} else {
}
newline(0);
spread = 0;
return (0);
}
int
donum()
{
int i, nw;
extern int pchar();
if (nn) {
nn--;
goto d1;
}
d1:
return (0);
}
i = 0;
i++;
i++;
nform = 0;
return (0);
}
extern int logf;
int
text()
{
tchar i;
static int spcnt;
nflush++;
newline(1);
return (0);
}
setnel();
nofill();
return (0);
}
if (pendw)
goto t4;
if (pendt)
if (spcnt)
goto t2;
else
goto t3;
pendt++;
if (spcnt)
goto t2;
spcnt++;
}
if (nlflg) {
t1:
callsp();
return (0);
}
ch = i;
if (spcnt) {
t2:
tbreak();
goto rtn;
spcnt = 0;
setnel();
if (trap)
goto rtn;
if (nlflg)
goto t1;
}
t3:
if (spread)
goto t5;
t4:
if (getword(0))
goto t6;
if (!movword())
goto t3;
t5:
if (nlflg)
pendt = 0;
if (ad) {
if (nwd == 1)
else
}
brflg = 1;
tbreak();
spread = 0;
if (!trap)
goto t3;
if (!nlflg)
goto rtn;
t6:
pendt = 0;
ckul();
rtn:
nflush = 0;
return (0);
}
int
nofill()
{
int j;
tchar i;
if (!pendnf) {
over = 0;
tbreak();
if (trap)
goto rtn;
if (nlflg) {
callsp();
return (0);
}
nwd = 10000;
}
if (j == ohc)
continue;
if (j == CONT) {
pendnf++;
nflush = 0;
flushi();
ckul();
return (0);
}
j = width(i);
widthp = j;
storeline(i, j);
}
if (ce) {
ce--;
un += i;
}
if (!nc)
brflg = 2;
tbreak();
ckul();
rtn:
return (0);
}
int
callsp()
{
int i;
if (flss)
i = flss;
else
i = lss;
flss = 0;
casesp(i);
return (0);
}
int
ckul()
{
cu = 0;
mchbits();
}
return (0);
}
int
storeline(c, w)
tchar c;
{
if (!over) {
flusho();
over++;
c = LEFTHAND;
w = -1;
goto s1;
}
return (0);
}
s1:
if (w == -1)
w = width(c);
ne += w;
nel -= w;
*linep++ = c;
nc++;
return (0);
}
int
newline(a)
int a;
{
int i, j, nlss;
int opn;
if (a)
goto nl1;
if (dip != d) {
j = lss;
if (flss)
lss = j;
}
trap++;
}
return (0);
}
j = lss;
if (flss)
#ifndef NROFF
if (ascii) {
}
#endif
flss = 0;
lss = j;
goto nl2;
nl1:
if (donef) {
done1(0);
ndone++;
donef = 0;
nflush++;
}
if (npnflg) {
}
nlpn:
print++;
pfrom = -1;
print = 0;
opn = -1;
chkpn();
goto nlpn;
}
if (print)
dpn++;
dpn = 0;
dostop();
}
}
nl2:
trap = 0;
flusho();
done2(-5);
}
}
return (0);
}
int
findn1(a)
int a;
{
int i, j;
for (i = 0; i < NTRAP; i++) {
if (mlist[i]) {
if ((j = nlist[i]) < 0)
j += pl;
if (j == a)
break;
}
}
return(i);
}
int
chkpn()
{
if (pto == -32767) {
flusho();
done1(0);
}
if (pto < 0) {
print++;
pfrom = 0;
}
return (0);
}
int
findt(a)
int a;
{
int i, j, k;
k = 32767;
if (dip != d) {
k = i;
return(k);
}
for (i = 0; i < NTRAP; i++) {
if (mlist[i]) {
if ((j = nlist[i]) < 0)
j += pl;
if ((j -= a) <= 0)
continue;
if (j < k)
k = j;
}
}
i = pl - a;
if (k > i)
k = i;
return(k);
}
int
findt1()
{
int i;
if (dip != d)
else
return(findt(i));
}
int
eject(a)
struct s *a;
{
int savlss;
if (dip != d)
return (0);
ejf++;
if (a)
ejl = a;
else
if (trap)
return (0);
e1:
newline(0);
goto e1;
return (0);
}
int
movword()
{
int w;
over = 0;
if (!nwd) {
#ifndef EUC
#else
#ifndef NROFF
#else
#endif /* NROFF */
#endif /* EUC */
wch--;
}
wp--;
}
nhyp = 0;
hyp++;
while (wch) {
hyp++;
nhyp++;
}
}
i = *wp++;
w = width(i);
wne -= w;
wch--;
storeline(i, w);
}
if (nel >= 0) {
nwd++;
return(0); /* line didn't fill up */
}
#ifndef NROFF
#endif
m1:
if (!nhyp) {
if (!nwd)
goto m3;
goto m4;
}
goto m5;
if (!(--nhyp))
if (!nwd)
goto m2;
nc--;
goto m1;
}
m2:
nel -= w;
ne += w;
linep++;
}
m3:
nwd++;
m4:
return(1); /* line filled up */
m5:
nc--;
ne -= w;
nel += w;
wne += w;
wch++;
wp--;
goto m1;
}
int
horiz(i)
int i;
{
vflag = 0;
if (i)
return (0);
}
int
setnel()
{
if (!nc) {
if (un1 >= 0) {
un1 = -1;
}
}
return (0);
}
int
getword(x)
int x;
{
int j, k;
int noword;
#ifdef EUC
#ifdef NROFF
char *mbbuf3p;
int wbf, n;
tchar m;
#endif /* NROFF */
#endif /* EUC */
noword = 0;
if (x)
if (pendw) {
*pendw = 0;
goto rtn;
}
goto g1;
hyoff = 0;
#ifdef EUC
#ifdef NROFF
if (pendmb) {
while(*mtbufp) {
case LASTOFMB:
case BYTE_CHR:
break;
default:
}
}
pendmb = 0;
goto g1;
}
#endif /* NROFF */
#endif /* EUC */
while (1) { /* picks up 1st char of word */
#ifdef EUC
#ifdef NROFF
if (multi_locale)
if (collectmb(i))
continue;
#endif /* NROFF */
#endif /* EUC */
if (j == '\n') {
noword = 1;
goto rtn;
}
if (j == ohc) {
continue;
}
if (j == ' ') {
continue;
}
break;
}
#ifdef EUC
#ifdef NROFF
if (!multi_locale)
goto a0;
wceoll = 0;
if (*wddelim != ' ') {
if (!*wddelim) {
} else {
while (*wddelim) {
> 0) {
mbbuf3[n] = 0;
n--;
while(n) {
m = *(mbbuf3p-- - n--) &
0xff | MIDDLEOFMB |
ZBIT;
storeword(m, 0);
}
storeword(m, -1);
} else {
break;
}
}
}
spflg = 0;
goto g0;
}
}
a0:
#endif /* NROFF */
#endif /* EUC */
if (spflg) {
spflg = 0;
}
g0:
if (j == CONT) {
nflush = 0;
flushi();
return(1);
}
if (hyoff != 1) {
if (j == ohc) {
hyoff = 2;
goto g1;
}
if (j == '-' || j == EMDASH)
hyoff = 2;
}
}
j = width(i);
#ifndef EUC
storeword(i, j);
#else
#ifndef NROFF
storeword(i, j);
#else
if (multi_locale) {
while(*mtbufp) {
case LASTOFMB:
case BYTE_CHR:
break;
default:
}
}
} else {
storeword(i, j);
}
#endif /* NROFF */
#endif /* EUC */
g1:
#ifdef EUC
#ifdef NROFF
if (multi_locale)
if (collectmb(i))
goto g1;
#endif /* NROFF */
#endif /* EUC */
if (j != ' ') {
if (j != '\n')
#ifdef EUC
#ifdef NROFF
if (!multi_locale)
#endif /* NROFF */
#endif /* EUC */
goto g0;
#ifdef EUC
#ifdef NROFF
else {
goto g0;
pendmb++;
ZWDELIM(2), 0);
*wordp = 0;
goto rtn;
} else goto g0;
}
#endif /* NROFF */
#endif /* EUC */
continue;
for (k = 0; sentchar[k]; k++)
if (j == sentchar[k]) {
spflg++;
break;
}
break;
}
}
#ifdef EUC
#ifdef NROFF
#endif /* NROFF */
#endif /* EUC */
*wordp = 0;
rtn:
if (j == ' ')
continue;
break;
}
if (*wp == 0) /* all numbers, so don't hyphenate */
hyoff = 1;
wdstart = 0;
pendw = 0;
*hyp++ = 0;
setnel();
return(noword);
}
int
storeword(c, w)
tchar c;
int w;
{
if (!over) {
flusho();
over++;
c = LEFTHAND;
w = -1;
goto s1;
}
return (0);
}
s1:
if (w == -1)
w = width(c);
widthp = w;
wne += w;
*wordp++ = c;
wch++;
return (0);
}
#ifdef NROFF
{
extern int c_isalnum;
tchar i;
int j;
i = getch();
j = cbits(i);
return(i);
if (cu) {
if (trtab[j] == ' ') {
setcbits(i, '_');
}
return(i);
}
/* should test here for characters that ought to be underlined */
/* in the old nroff, that was the 200 bit on the width! */
/* for now, just do letters, digits and certain special chars */
if (j <= 127) {
if (!isalnum(j))
} else {
if (j < c_isalnum)
}
return(i);
}
#endif
#ifdef EUC
#ifdef NROFF
int
collectmb(i)
tchar i;
{
int busy;
*mtbufp++ = i;
if (ismot(i)) {
owc = 0;
cwc = 0;
return(busy = 0);
}
if ((i & MBMASK) == MIDDLEOFMB) {
busy = 1;
} else {
goto gotmb;
}
} else {
while (*mtbufp) {
mtbufp++;
}
}
busy = 0;
}
return(busy);
}
#endif /* NROFF */
#endif /* EUC */