Annotation of 41BSD/cmd/refer/flagger.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.