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

Defined functions

allpunct defined in line 99; used 1 times
  • in line 52
gw defined in line 109; used 1 times
  • in line 45
main defined in line 19; never used
next defined in line 74; used 3 times
prev defined in line 93; used 1 times
  • in line 58
sstrip defined in line 176; used 1 times
  • in line 50
trimnl defined in line 158; never used
upcase defined in line 165; used 2 times

Defined variables

bl defined in line 14; used 2 times
blank defined in line 12; used 2 times
justw defined in line 10; used 2 times
mark defined in line 9; used 4 times
sargc defined in line 15; used 3 times
sargv defined in line 16; used 3 times
sccsid defined in line 2; never used
synwd defined in line 8; used 6 times
wdf defined in line 13; used 6 times
wdp defined in line 13; used 17 times
wds defined in line 7; used 7 times
Last modified: 1983-05-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1100
Valid CSS Valid XHTML 1.0 Strict