Annotation of researchv10no/cmd/refer/inv6.c, revision 1.1

1.1     ! root        1: # include "stdio.h"
        !             2: # include "assert.h"
        !             3: whash(ft, fa, fb, nhash, iflong, ptotct, phused)
        !             4:        FILE *fa, *fb, *ft;
        !             5:        int nhash, *phused;
        !             6:        long *ptotct;
        !             7: {
        !             8: char line[100];
        !             9: int hash = 0, hused = 0;
        !            10: long totct = 0L;
        !            11: int ct = 0;
        !            12: long point;
        !            13: long opoint = -1;
        !            14: int m;
        !            15: int k; long lp;
        !            16: long *hpt;
        !            17: int *hfreq = NULL;
        !            18: 
        !            19: hpt = (long *) calloc (nhash+1, sizeof(*hpt));
        !            20: assert (hpt != NULL);
        !            21: hfreq = (int *) calloc (nhash, sizeof(*hfreq));
        !            22: assert (hfreq !=NULL);
        !            23: hpt[0] = 0;
        !            24: lp= 0;
        !            25: while (fgets(line, 100, ft))
        !            26:        {
        !            27:        totct++;
        !            28:        sscanf(line, "%d %ld", &k, &point);
        !            29:        if (hash < k)
        !            30:                {
        !            31:                hused++;
        !            32:                if (iflong) putl(-1L, fb); else putw(-1, fb);
        !            33:                hfreq[hash]=ct;
        !            34:                while (hash<k)
        !            35:                        {
        !            36:                        hpt[++hash] = lp;
        !            37:                        hfreq[hash] = 0;
        !            38:                        }
        !            39:                hpt[hash] = lp += iflong? sizeof(long) : sizeof(int);
        !            40:                opoint= -1;
        !            41:                ct=0;
        !            42:                }
        !            43:        if (point!=opoint)
        !            44:                {
        !            45:                if (iflong)
        !            46:                        putl(opoint=point, fb);
        !            47:                else
        !            48:                        putw( (int)(opoint=point), fb);
        !            49:                lp += iflong? sizeof(long) : sizeof(int);
        !            50:                ct++;
        !            51:                }
        !            52:        }
        !            53: if (iflong) putl(-1L, fb); else putw(-1,fb);
        !            54: while (hash<nhash)
        !            55:        hpt[++hash]=lp;
        !            56: fwrite(&nhash, sizeof(nhash), 1, fa);
        !            57: fwrite(&iflong, sizeof(iflong), 1, fa);
        !            58: fwrite(hpt, sizeof(*hpt), nhash, fa);
        !            59: fwrite (hfreq, sizeof(*hfreq), nhash, fa);
        !            60: *ptotct = totct;
        !            61: *phused = hused;
        !            62: }
        !            63: putl(ll, f)
        !            64:        long ll;
        !            65:        FILE *f;
        !            66: {
        !            67: int *x;
        !            68: if (sizeof(long) == sizeof(int))
        !            69:        {
        !            70:        putw(ll, f);
        !            71:        return;
        !            72:        }
        !            73: x = &ll;
        !            74: putw(x[0], f);
        !            75: putw(x[1], f);
        !            76: }
        !            77: long getl(f)
        !            78:        FILE *f;
        !            79: {
        !            80: int x[2];
        !            81: int *ll;
        !            82: x[0] = getw(f);
        !            83: x[1] = getw(f);
        !            84: ll = x;
        !            85: return (*ll);
        !            86: }

unix.superglobalmegacorp.com

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