1 /*- 2 * %sccs.include.proprietary.c% 3 */ 4 5 #ifndef lint 6 static char sccsid[] = "@(#)flagger.c 4.2 (Berkeley) 04/18/91"; 7 #endif /* not lint */ 8 9 #include <stdio.h> 10 11 char wds[100][40]; 12 int synwd[100]; 13 int mark[100]; 14 int justw = 0; 15 extern int comcount; 16 int blank[100]; 17 int wdp, wdf; 18 int bl; 19 int sargc; 20 char **sargv; 21 FILE *inf; 22 23 main(argc,argv) 24 char *argv[]; 25 { 26 int i; 27 while (--argc && **++argv== '-') 28 switch(argv[0][1]) 29 { 30 case 'w': 31 justw=1; 32 break; 33 case 'c': 34 comcount=atoi(argv[0]+2); 35 break; 36 } 37 wdp=wdf=0; 38 if (argc>0) 39 { 40 argc--; 41 inf = fopen(argv[0], "r"); 42 if (inf==NULL) exit(0); 43 argv++; 44 } 45 else 46 inf=stdin; 47 sargc=argc; 48 sargv= argv; 49 while ( gw (wds[wdp = next(wdp)], &bl)) 50 { 51 blank[wdp] = bl; 52 mark[wdp]=0; 53 synwd[wdp] = common(upcase(wds[wdp])); 54 if (common(sstrip(upcase(wds[wdp])))) 55 synwd[wdp]=1; 56 if (allpunct(wds[wdp])) 57 synwd[wdp]=1; 58 if (strlen(wds[wdp])<3) 59 synwd[wdp]=1; 60 if (synwd[wdp]==1) 61 { 62 for(i=wdp; i!=wdf; i=prev(i)) 63 { 64 if (synwd[i]>0) 65 continue; 66 mark[i]=1; 67 break; 68 } 69 } 70 } 71 if (wdp<0) return(0); 72 i=wdf -1; 73 i = next(i); 74 while (i != wdp) 75 i= next(i); 76 } 77 78 next(i) 79 { 80 int j; 81 j = (i+1) % 100; 82 if (j==wdf) 83 { 84 if (justw==0) 85 { 86 if (mark[j] ) putchar('*'); 87 printf("%s",wds[j]); 88 if (blank[j]) putchar(' '); 89 } 90 else 91 if (mark[j]) printf("%s\n", wds[j]); 92 wdf = (wdf+1)%100; 93 } 94 return(j); 95 } 96 97 prev(i) 98 { 99 i = (i-1)%100; 100 return(i); 101 } 102 103 allpunct(s) 104 char *s; 105 { 106 int c; 107 while (c = *s++) 108 if (isalpha(c)) 109 return(0); 110 return(1); 111 } 112 113 gw(s, b) 114 char *s; 115 int *b; 116 { 117 int c, type, nt; 118 c = getc(inf); 119 while (c==EOF) 120 { 121 fclose(inf); 122 inf=NULL; 123 if (sargc-->0) 124 { 125 inf = fopen ( *sargv++, "r"); 126 } 127 if (inf==NULL) return(0); 128 c = getc(inf); 129 } 130 *s++ = c; 131 type = isalpha(c) || isdigit(c); 132 while ( (c = getc(inf)) != EOF ) 133 { 134 nt = isalpha(c) || isdigit(c); 135 if (nt==type) 136 *s++= c; 137 else 138 break; 139 } 140 *s=0; 141 if (c== ' ') 142 { 143 *b = 1; 144 return(1); 145 } 146 while (c==EOF) 147 { 148 fclose(inf); 149 inf=NULL; 150 if (sargc-- > 0) 151 { 152 inf= fopen( *sargv++, "r"); 153 } 154 if (inf==NULL) return(0); 155 c = getc(inf); 156 } 157 ungetc(c, inf); 158 *b=0; 159 return(1); 160 } 161 162 trimnl(s) 163 char *s; 164 { 165 while (*s) s++; 166 if (*--s=='\n') *s=0; 167 } 168 169 upcase(s) 170 char *s; 171 { 172 static char buf[100]; 173 strcpy (buf, s); 174 for(s=buf; *s; s++) 175 if (isupper(*s)) 176 *s = *s-'A'+'a'; 177 return(buf); 178 } 179 180 sstrip(s) 181 char *s; 182 { 183 char *p ; 184 p=s; 185 while (*s) s++; 186 if (*--s=='s') *s=0; 187 return(p); 188 } 189