#ifndef lint static char *sccsid = "@(#)what2.c 4.1 (Berkeley) 5/6/83"; #endif #include "stdio.h" #include "ctype.h" #define NS 5 struct sf { char *text; int olap; } sents[NS]; struct sf *sp; char stext[NS][500]; describe (file, argc, argv, rf) char *file, *argv[]; FILE *rf; { int ns 0; char linbuf[BUFSIZ], *line, *p; int i, wrflg 0, wrote 0, ln 0; FILE *fi; fi = fopen(file, "r"); if (fi==NULL) return; for(i=1; itext, 0, rf); } int state 0; int oldc '\n'; gsent(buf, bsize, fi) char *buf; FILE *fi; { char *s; int c, leng 0; /* state 0: looking for '.' 1: looking for nl or space aftter '.' 2: looking for nl after line with dot. */ s=buf; if (state==2) *s++='.'; while ( (c = getc(fi)) > 0 ) { switch(state) { case 0: /* normal */ if (c=='.' && oldc == '\n') { *s=0; state=2; oldc='\n'; return(1); } *s++ = (c=='\n'? ' ': c); if (s>=buf+bsize) { *--s = 0; return(1); } if (c=='.' || c == '?' || c=='!') if (leng>1) state=1; leng = (isalpha(c) ? leng+1 : 0); break; case 1: /* found ., want nl or space */ if (c==' ' || c == '\n') { *s=0; state=0; oldc=c; return(1); } *s++ = (c=='\n' ? ' ' : c); state=0; leng = 0; break; case 2: /* found trof line, want nl */ if (c == '\n') { *s=0; state=0; oldc='\n'; return(1); } *s++ = c; break; } oldc=c; } *s=0; return(0); } prefix( p, s) char *p, *s; { int c; while ( (c= *p++) == *s++) if (c==0) return(1); return(c==0); } output (s, ln, rf) char *s; FILE *rf; { char *t; int more 1; t=s; while (more) { while (t(s+25)) t--; *t=0; more=1; } else more=0; printf("%s%s\n",ln++ ? " " : " ", s); if (rf!=NULL) fprintf(rf, "%s\n", s); s= ++t; } } count(isent, nw, wds) char *wds[], *isent; { int saw[50], ct; char sb[BUFSIZ], *s sb; int i, c; for(i=1; itext = stext[ns], line); sp->olap = kov; return(ns+1); } for(sp=sents+ns-1; sp>=sents; sp--) { if (sp->olap < lval) { least = sp; lval = sp->olap; } } if (kov <= lval) return(ns); ob = least->text; while (++least < sents+NS) { (least-1)->text = least->text; (least-1)->olap = least->olap; } sp = sents+NS-1; strcpy (sp->text=ob, line); sp->olap = kov; return(NS); }