# 2.11BSD#431 - /usr/src/usr.bin/refer/what1.c

##### Functions

    comp              X
    exch              X
    lfind             X
    main              X
    str6cmp           X
    wrdoc             X

##### Variables

    files             X
    fnames            X
    rb                X
    rbb               X
    rbp               X
    relfeed           X

       1: #if !defined(lint) && defined(DOSCCS)
       2: static char *sccsid = "@(#)what1.c	4.1.1 (2.11BSD GTE) 1/21/95";
       3: #endif
       4:
       5: #include "what..c"
       6: #include <pwd.h>
       7:
       8: struct filans files[NFILES];
       9: char fnames[NAMES];
      10: int relfeed 0;
      11: char *rb[NFEED];
      12: char rbb[200], *rbp rbb;
      13: ;
      14:
      15: main(argc,argv)
      16: char *argv[];
      17: {
      18:     char *s, *t, *xargv[50], *wd[50];
      19:     struct filans *af;
      20:     int xargc 0, nw, nf, i;
      21:     while (argc>1 && argv[1][0]=='-')
      22:     {
      23:         switch(argv[1][1])
      24:         {
      25:         case 'r':
      26:             relfeed=1;
      27:             break;
      28:         }
      29:         argc--;
      30:         argv++;
      31:     }
      32:     if (argc<=1)
      33:     {
      34:         printf("No query.\n");
      35:         return(0);
      36:     }
      37:     nf = doclook(argc,argv,0);
      38:     printf("   %d files\n",nf);
      39:     if (relfeed && nf>NFEED)
      40:     {
      41:         wrdoc(NFEED, argc, argv, 1);
      42:         nw = freqwd (rb, wd, argc);
      43:         for(i=0; rb[i]; i++)
      44:             unlink(rb[i]);
      45:     }
      46:     for(i=0; i<argc; i++)
      47:         xargv[xargc++]=argv[i];
      48:     if (relfeed)
      49:     {
      50:         printf("Adding: ");
      51:         for(i=0; i<nw; i++)
      52:             if (!lfind(wd[i], xargc, xargv))
      53:                 printf("%s ", xargv[xargc++]=wd[i]);
      54:         printf("\n");
      55:         nf = doclook(xargc, xargv, relfeed? xargc/4 : 0);
      56:         printf("  %d files\n",nf);
      57:     }
      58:     shell (nf, comp, exch);
      59:     wrdoc(nf, xargc, xargv, 0);
      60:     return(0);
      61: }
      62:
      63: exch( i1, i2 )
      64: {
      65:     struct filans *p1, *p2;
      66:     struct filans xt;
      67:     p1=files+i1;
      68:     p2=files+i2;
      69:     xt = *p1;
      70:     *p1 = *p2;
      71:     *p2 = xt;
      72: }
      73:
      74: comp(i1, i2)
      75: {
      76:     struct filans *p1, *p2;
      77:     p1 = files+i1;
      78:     p2= files+i2;
      79:     if (p1->fdate != p2->fdate)
      80:         return(p2->fdate > p1->fdate);
      81:     return(p2->uid >= p1->uid);
      82: }
      83:
      84: wrdoc ( np, argc, argv, relfeed )
      85: {
      86:     struct filans *af;
      87:     char *s, *t, buf[200];
      88:     int eval, k, pid;
      89:     FILE *rf NULL;
      90:     FILE *ans NULL;
      91:     struct passwd *pw;
      92:
      93:     pid=getpid();
      94:     for(af=files; af<files+np; af++)
      95:     {
      96:         t = ctime(&af->fdate);
      97:         pw = getpwuid(af->uid);
      98:         if (!pw)
      99:            buf[0] = '\0';
     100:         else
     101:            strcpy(buf, pw->pw_name);
     102:         printf("%s (%.20s)  %s, %ld bytes\n",af->nm,t+4,buf,af->size);
     103:         endpwent();
     104:         if (relfeed)
     105:         {
     106:             k=af-files;
     107:             _assert (k<NFEED);
     108:             sprintf(rb[k]=rbp, "rf%d.%d",pid, k);
     109:             rf = fopen(rb[k], "w");
     110:             while (*rbp++);
     111:         }
     112:         describe(af->nm, argc,argv, rf);
     113:         if (relfeed)
     114:         {
     115:             printf("You like that one?");
     116:             fflush(stdout);
     117:             fgets(buf, 100, stdin);
     118:             switch(buf[0])
     119:             {
     120:             case 'y':
     121:             case 'Y':
     122:                 eval=1;
     123:                 break;
     124:             case 'n':
     125:             case 'N':
     126:                 eval = -1;
     127:                 break;
     128:             default:
     129:                 eval=0;
     130:                 break;
     131:             }
     132:             fclose(rf);
     133:             if (eval<=0)
     134:             {
     135:                 unlink(rb[k]);
     136:                 rb[k][0]=0;
     137:             }
     138:         }
     139:     }
     140:     if (relfeed) rb[np]=0;
     141: }
     142:
     143: lfind( wl, n, wds)
     144: char *wl, *wds[];
     145: {
     146:     int i;
     147:     for(i=0; i<n; i++)
     148:         if (str6cmp(wl, wds[i])==0)
     149:             return(1);
     150:     return(0);
     151: }
     152:
     153: str6cmp(s, t)
     154: char *s, *t;
     155: {
     156:     int i 0, c;
     157:     while ( (c= *s++ ) == ( *t++))
     158:         if (c==0 || ++i ==6)
     159:             return(0);
     160:     return(1);
     161: }

#### Defined functions

comp defined in line 74; used 2 times

- in line 58
- in /usr/src/usr.bin/refer/what..c line 11

exch defined in line 63; used 2 times

- in line 58
- in /usr/src/usr.bin/refer/what..c line 11

lfind defined in line 143; used 1 times

- in line 52

main defined in line 15; never used
str6cmp defined in line 153; used 1 times

- in line 148

wrdoc defined in line 84; used 2 times

- in line 41, 59

#### Defined variables

files defined in line 8; used 17 times

- in line 67-68(2), 77-78(2), 94(2), 106
- in /usr/src/usr.bin/refer/what1.c line 67-68(2), 77-78(2), 94(2), 106
- in /usr/src/usr.bin/refer/what3.c line 61-62(2), 78

fnames defined in line 9; used 2 times

- in /usr/src/usr.bin/refer/what3.c line 60, 69

rb defined in line 11; used 8 times

- in line 42-44(3), 108-109(2), 135-140(3)

rbb defined in line 12; never used
rbp defined in line 12; used 2 times

- in line 108-110(2)

relfeed defined in line 10; used 8 times

- in line 26, 39, 48, 55, 84, 104, 113, 140

sccsid defined in line 2; never used

Last modified: 1995-01-22 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 716 |