Annotation of 43BSDReno/usr.bin/refer/NOTUSED/thash.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)thash.c     4.2 (Berkeley) 5/11/89";
                      3: #endif
                      4: 
                      5: #include <stdio.h>
                      6: #include "pathnames.h"
                      7: 
                      8: #define MAXLINE 750
                      9: 
                     10: int nh 500;
                     11: int saw[6000];
                     12: char *comname = _PATH_EIGN;
                     13: 
                     14: main (argc,argv)
                     15: char *argv[];
                     16: {
                     17: 
                     18:        int i, z;
                     19:        char *name;
                     20: 
                     21:        FILE *f;
                     22: 
                     23:        while (argc>1 && argv[1][0] == '-')
                     24:        {
                     25:                switch(argv[1][1])
                     26:                {
                     27:                case 'h':
                     28:                        nh = atoi(argv[1]+2); 
                     29:                        break;
                     30:                }
                     31:                argc--; 
                     32:                argv++;
                     33:        }
                     34:        if (argc<=1)
                     35:                dofile(stdin, "");
                     36:        else
                     37:                for(i=1; i<argc; i++)
                     38:                {
                     39:                        f = fopen(name=argv[i], "r");
                     40:                        if (f==NULL)
                     41:                                err("No file %s",name);
                     42:                        else
                     43:                                dofile(f, name);
                     44:                }
                     45:        for(z=i=0; i<nh; i++)
                     46:        {
                     47:                if (saw[i]) z++;
                     48:        }
                     49:        printf("hashes %d used %d\n",nh,z);
                     50: }
                     51: 
                     52: dofile(f, name)
                     53: FILE *f;
                     54: char *name;
                     55: {
                     56:        /* read file f & spit out keys & ptrs */
                     57:        char line[MAXLINE], *s;
                     58:        char key[20], *p;
                     59:        int k 0;
                     60:        int c, lim;
                     61:        int alph 0;
                     62:        int used 0;
                     63:        long lp 0;
                     64: 
                     65:        while (fgets(line, MAXLINE, f))
                     66:        {
                     67:                k++;
                     68:                used=alph=0;
                     69:                lim = strlen(line);
                     70:                p = key;
                     71:                for(s=line; c= *s; s++)
                     72:                {
                     73:                        if (isalpha(c) || isdigit(c))
                     74:                        {
                     75:                                if (alph++ < 6)
                     76:                                        *p++ = c;
                     77:                        }
                     78:                        else
                     79:                        {
                     80:                                *p = 0;
                     81:                                if (outkey(p=key))
                     82:                                {
                     83:                                        tkey(key,k);
                     84:                                        used=1;
                     85:                                }
                     86:                                alph=0;
                     87:                        }
                     88:                }
                     89:                lp += lim;
                     90:        }
                     91: }
                     92: 
                     93: outkey( ky)
                     94: char *ky;
                     95: {
                     96:        int n;
                     97:        n = strlen(ky);
                     98:        if (n<3) return(0);
                     99:        if (isdigit(ky[0]))
                    100:                if (ky[0] != '1' || ky[1] != '9' || n!= 4) return(0);
                    101:        return(1);
                    102: }
                    103: 
                    104: hash (s)
                    105: char *s;
                    106: {
                    107:        int c, n, q;
                    108:        for(q=n=0; c= *s; s++)
                    109:                n += (c*n + c << (n%4));
                    110:        return(n);
                    111: }
                    112: 
                    113: err (s, a)
                    114: char *s;
                    115: {
                    116:        fprintf(stderr, "Error: ");
                    117:        fprintf(stderr, s, a);
                    118:        putc('\n', stderr);
                    119: }
                    120: 
                    121: prefix(t, s)
                    122: char *t, *s;
                    123: {
                    124:        int c, d;
                    125:        while ( (c= *t++) == *s++)
                    126:                if (c==0) return(1);
                    127:        return(c==0 ? 1: 0);
                    128: }
                    129: 
                    130: mindex(s, c)
                    131: char *s;
                    132: {
                    133:        register char *p;
                    134:        for( p=s; *p; p++)
                    135:                if (*p ==c)
                    136:                        return(p);
                    137:        return(0);
                    138: }
                    139: 
                    140: tkey(s,nw)
                    141: char *s;
                    142: {
                    143:        int x;
                    144:        x = abs(hash(s)) % nh;
                    145:        /* if (saw[x]) printf("%d %d\n", x, nw); */
                    146:        saw[x]= nw;
                    147: }
                    148: 
                    149: abs(n)
                    150: {
                    151:        return(n>0 ? n : -n);
                    152: }

unix.superglobalmegacorp.com

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