ptx [-t] [-i ignore] [-o only] [-w num] [-f] [input] [output]
Ptx reads the input file and permutes on words in it.
It excludes all words in the ignore file.
Alternately it includes words in the only file.
if neither is given it excludes the words in /usr/lib/eign.
The width of the output line can be changed to num
characters. If omitted 72 is default unless troff than 100.
the -f flag tells the program to fold the output
the -t flag says the output is for troff and the
#define DEFLTX "/usr/lib/eign"
#define SORT "/usr/bin/sort"
#define isabreak(c) (btable[c])
extern char *calloc(), *mktemp();
char *strtbufp
, *endbufp
;
char *sortfile
; /* output of sort program */
char nofold
[] = {'-', 'd', 't', TILDE
, 0};
char fold
[] = {'-', 'd', 'f', 't', TILDE
, 0};
char *bfile
; /*contains user supplied break chars */
if(signal(SIGHUP
,onintr
)==SIG_IGN
)
if(signal(SIGINT
,onintr
)==SIG_IGN
)
while(argc
>1 && **argv
== '-') {
diag("Wrong width:",*argv
);
msg("Lines truncated to 200 chars.",empty
);
gap
= gutter
= atoi(*++argv
);
diag("Only file already given.",empty
);
diag("Ignore file already given",empty
);
msg("Illegal argument:",*argv
);
diag("Too many filenames",empty
);
if((outptr
= fopen(outfile
,"w")) == NULL
)
diag("Cannot open output file:",outfile
);
/* Default breaks of blank, tab and newline */
if((bptr
= fopen(bfile
,"r")) == NULL
)
diag("Cannot open break char file",bfile
);
while((c
= getc(bptr
)) != EOF
)
/* Allocate space for a buffer. If only or ignore file present
read it into buffer. Else read in default ignore file
and put resulting words in buffer.
if((strtbufp
= calloc(N
,BUFSIZ
)) == NULL
)
diag("Out of memory space",empty
);
if((xptr
= fopen(xfile
,"r")) == NULL
)
diag("Cannot open file",xfile
);
while(bufp
< endbufp
&& (c
= getc(xptr
)) != EOF
) {
if(storeh(hash(strtbufp
,bufp
),strtbufp
))
diag("Too many words",xfile
);
*bufp
++ = (isupper(c
)?tolower(c
):c
);
diag("Too many words in file",xfile
);
/* open output file for sorting */
sortfile
= mktemp("/tmp/ptxsXXXXX");
if((sortptr
= fopen(sortfile
, "w")) == NULL
)
diag("Cannot open output for sorting:",sortfile
);
/* get a line of data and compare each word for
inclusion or exclusion in the sort phase
if (infile
!=0 && (inptr
= fopen(infile
,"r")) == NULL
)
diag("Cannot open data: ",infile
);
case -1: /* cannot fork */
diag("Cannot fork",empty
);
execl(SORT
, SORT
, sortopt
, "+0", "-1", "+1",
sortfile
, "-o", sortfile
, 0);
while(wait(&status
) != pid
);
fprintf(stderr
,"%s %s\n",s
,arg
);
/* Throw away leading white space */
while(isspace(c
=getc(inptr
)))
while(( c
=getc(inptr
)) != EOF
) {
while(isspace(*--linep
));
char *pstrt
, *pchar
, *cp
;
while(pchar
<pend
&&!isspace(*pchar
))
/* eliminate white space */
hp
= &hasht
[hash(pstrt
,pchar
)];
if(cmpword(pstrt
,pchar
,cp
)){
if((isupper(c
)?tolower(c
):c
) != *hpp
++)
if(--cpp
== pend
) return(1);
for(cp
=strt
; cp
<end
; cp
++)
/* Add extra blank before TILDE to sort correctly
for (cp
=line
; cp
<strt
; cp
++)
register char *tilde
, *linep
, *ref
;
char *p1a
,*p1b
,*p2a
,*p2b
,*p3a
,*p3b
,*p4a
,*p4b
;
if((sortptr
= fopen(sortfile
,"r")) == NULL
)
diag("Cannot open sorted data:",sortfile
);
halflen
= (llen
-gutter
)/2;
while((c
= getc(sortptr
)) != EOF
) {
while(isspace(linep
[-1]))
while(ref
<linep
&&!isspace(*ref
))
/* the -1 is an overly conservative test to leave
space for the / that signifies truncation*/
p3b
= rtrim(p3a
=line
,tilde
,halflen
-1);
p2a
= ltrim(ref
,p2b
=linep
,halflen
-1);
p1b
= rtrim(p1a
=p3b
+(isspace(p3b
[0])!=0),tilde
,
w
=halflen
-(p2b
-p2a
)-gap
);
p4a
= ltrim(ref
,p4b
=p2a
-(isspace(p2a
[-1])!=0),
w
=halflen
-(p3b
-p3a
)-gap
);
fprintf(outptr
,".xx \"");
/* tilde-1 to account for extra space before TILDE */
if(p1b
!=(tilde
-1) && p1a
!=p1b
)
if(p4a
==p4b
&& p2a
!=ref
&& p2a
!=p2b
)
/* ++p3b to account for extra blank after TILDE */
/* ++p3b to account for extra space before TILDE */
if(p1a
==p1b
&& ++p3b
!=tilde
)
if(p1a
==p1b
&& p4a
!=ref
&& p4a
!=p4b
)
fprintf(outptr
,"\" %s\n",tilde
);
for(x
=a
+1; x
<=c
&&x
-a
<=d
; x
++)
if((x
==c
||isspace(x
[0]))&&!isspace(x
[-1]))
for(x
=b
-1; x
>=c
&&b
-x
<=d
; x
--)
if(!isspace(x
[0])&&(x
==c
||isspace(x
[-1])))
for(cp
=strt
; cp
<end
; cp
++) {
/* Return zero hash number for single letter words */
i
= (isupper(c
)?tolower(c
):c
);
j
= (isupper(c
)?tolower(c
):c
);
k
= (isupper(c
)?tolower(c
):c
);
j
= (isupper(c
)?tolower(c
):c
);
for(i
=num
; i
<MAXT
; i
++) {