/* words ... extract the words from the document */ /* there are various glitches in this algorithm... /* in particular, it would be polite to recognize troff escapes */ int vflag 0; /* verbose flag */ char t1[20], t2[20]; /* tempfile names */ char *s1 { "/lib/spell1" }; char *s2 { "/lib/spell2" }; char *s3 { "/lib/spell3" }; main( argc, argv ) char *argv[]; { int c, fno; char sybuf[200]; extern int cin, cout, getout(); if( (signal(1,1)&01) == 0 ) signal( 1, getout ); if( (signal(2,1)&01) == 0 ) signal( 2, getout ); tmpnam(t1); tmpnam(t2); if( (cout=copen( t1, 'w' )) < 0) { printf( 2, "cannot open tempfile\n" ); getout(); } if( argv[1][0] == '-' ){ /* verbose option */ vflag = 1; ++argv; --argc; } fno = 0; filebeg: /* beginning of new input file */ if( ++fno > 1 && cin != 0 ) cclose(cin); if( fno >= argc && fno>1 ) goto proceed; /* get on with the rest */ if( argc <= 1 ) cin = 0; /* use standard input */ else if( (cin=copen( argv[fno], 'r' )) < 0 ){ printf( 2, "cannot open %s\n", argv[fno] ); goto filebeg; } linebeg: /* beginning of a line; check for roff control */ c = getchar(); if( c == '.' || c == '\'' ){ /* delete the line */ while((c = getchar()) != '\n' && c != '\0') ; goto linebeg; /* try the next line */ } check: while( brkch(c) ){ /* delete break characters */ if( c == '\n' || c == '\14' ) goto linebeg; if( ceof(cin) ) goto filebeg; if( c == '\0' ) goto linebeg; c = getchar(); } /* we have the beginning of a word now */ wloop: while( !brkch(c) ){ putchar(c|' '); c = getchar(); } if( c == '-' ) { c = getchar(); if( c == '\n' ) { c = getchar(); while( c == ' ' || c == '\t' || c == '\n' ) c = getchar(); goto wloop; } putchar( '\n' ); goto check; } if( c == '\'' ) { c = getchar(); goto wloop; } if( c == '' ) { /* backspace */ c = getchar(); c = getchar(); goto wloop; } /* end of word */ putchar( '\n' ); goto check; proceed: /* do the rest of the job */ cclose(cout); printf( -1, sybuf, "sort -d %s | uniq | comm -23 - /lib/w2006 >%s", t1, t2 ); system( sybuf ); printf( -1, sybuf, "%s <%s | sort -d | %s | sort -d | %s %s %s",s1,t2,s2,s3,t2,vflag?"-v":"" ); system( sybuf ); getout(); } brkch(c){ /* is c a break character */ if( c>='a' && c <='z' ) return(0); if( c>='A' && c<='Z' ) return(0); return(1); } getout(){ /* remove temps and stop */ unlink( t1 ); unlink( t2 ); cexit(0); }