char *xxxvers
= "\nDeroff Version 1.02 24 July 1978\n";
/* Deroff command -- strip troff, eqn, and Tbl sequences from
a file. Has one flag argument, -w, to cause output one word per line
rather than in the original format.
Deroff follows .so and .nx commands, removes contents of macro
definitions, equations (both .EQ ... .EN and $...$),
Tbl command sequences, and Troff backslash constructions.
All input is through the C macro; the most recently read character is in c.
#define C ( (c=getc(infile)) == EOF ? eof() : ((c==ldelim)&&(filesp==files) ? skeqn() : c) )
#define C1 ( (c=getc(infile)) == EOF ? eof() : c)
#define SKIP while(C != '\n')
char chars
[128]; /* SPECIAL, APOS, DIGIT, or LETTER */
static char onechar
[2] = "X";
while(argc
>0 && argv
[0][0]=='-' && argv
[0][1]!='\0')
for(p
=argv
[0]+1; *p
; ++p
) switch(*p
)
fatal("Invalid flag %s\n", onechar
);
while((c
= getc(infile
)) != rdelim
)
while( (c
= getc(infile
)) != '"')
if((c
= getc(infile
)) == EOF
)
if(p
[0]=='-' && p
[1]=='\0')
else if( (fd
= fopen(p
, "r")) == NULL
)
fatal("Cannot open file %s\n", p
);
struct chain
{ struct chain
*nextp
; char *datap
; } *chainblock
;
register struct chain
*q
;
static struct chain
*namechain
= NULL
;
for(p
= fname
; (*p
=c
)!= '\n' && c
!=' ' && c
!='\t' && c
!='\\' ; ++p
)
/* see if this name has already been used */
for(q
= namechain
; q
; q
= q
->nextp
)
if( ! strcmp(fname
, q
->datap
))
q
= (struct chain
*) calloc(1, sizeof(*chainblock
));
fprintf(stderr
, "Deroff: ");
if(C
== '.' || c
== '\'')
while(*s
==' ' || *s
=='\t')
for(t
= s
; *t
!=' ' && *t
!='\t' && *t
!='\0' ; ++t
)
if(t
>s
+2 && chars
[ s
[0] ]==LETTER
&& chars
[ s
[1] ]==LETTER
)
putwords(macline
) /* break into words for -w option */
/* skip initial specials ampersands and apostrophes */
while( chars
[*p1
] < DIGIT
)
if(*p1
++ == '\0') return;
for(p
= p1
; (i
=chars
[*p
]) != SPECIAL
; ++p
)
if( (!macline
&& nlet
>1) /* MDM definition of word */
|| (macline
&& nlet
>2 && chars
[ p1
[0] ]==LETTER
&& chars
[ p1
[1] ]==LETTER
) )
/* delete trailing ampersands and apostrophes */
while(p
[-1]=='\'' || p
[-1]=='&')
while(p1
< p
) putchar(*p1
++);
if(c1
=='E' && c2
=='Q' && filesp
==files
)
else if(c1
=='T' && (c2
=='S' || c2
=='C' || c2
=='&') && filesp
==files
)
else if(c1
=='T' && c2
=='E')
else if(!inmacro
&& c1
=='d' && c2
=='e')
else if(!inmacro
&& c1
=='i' && c2
=='g')
else if(!inmacro
&& c1
=='a' && c2
== 'm')
else if(c1
=='s' && c2
=='o')
infile
= *++filesp
= opn( fname
);
else if(c1
=='n' && c2
=='x')
if(fname
[0] == '\0') exit(0);
infile
= *filesp
= opn(fname
);
else if(c1
=='h' && c2
=='w')
while(C!='.' || C!='.'); /* look for .EN */
if(C
== '.' || c
== '\'')
else if(c
== 'd') /* look for delim */
if((c1
=c
)=='\n' || (c2
=C1
)=='\n'
|| (c1
=='o' && c2
=='f' && C1
=='f') )
backsl() /* skip over a complete backslash construction */
while(C
>='0' && c
<='9') ;
C
; /* discard argument number */
while(C
!='\n' && c
!=bdelim
)
if( (t0
= t
= calloc( strlen(s
)+1, sizeof(*t
) ) ) == NULL
)
fatal("Cannot allocate memory", (char *) NULL
);