Annotation of researchv9/jtools/src/pads/host/sf.c, revision 1.1

1.1     ! root        1: #define SF_HASH 823
        !             2: struct SF_CELL {
        !             3:        SF_CELL *link;
        !             4:        char     buf[1];
        !             5: };
        !             6: void sprintf(char*, char* ...);
        !             7: 
        !             8: char *sf(char *f ... )
        !             9: {
        !            10:        int *a = (int*)&f;
        !            11:        static SF_CELL *Table[SF_HASH];
        !            12:        static Calls, Strings, Worst, Bytes;
        !            13:        char x[1024], *p;
        !            14:        unsigned long len, h, i;
        !            15:        struct SF_CELL *s;
        !            16: 
        !            17:        if( !f ){
        !            18:                static char report[128];
        !            19:                sprintf( report, "strings=%d calls=%d worst=%d bytes=%d",
        !            20:                                 Strings,   Calls,   Worst,    Bytes );
        !            21:                return report;
        !            22:        }
        !            23:        ++Calls;                
        !            24:        sprintf( x, f, a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9] );
        !            25:        h = 0;
        !            26:        for( len = 0, p = x; *p; )
        !            27:                h += (*p++) << (++len%4);
        !            28:        h %= SF_HASH;
        !            29:        for( s=Table[h],i=1; s; s=s->link,++i )
        !            30:                if(!strcmp(x,s->buf)) return s->buf;
        !            31:        ++Strings;
        !            32:        if( i>Worst ) Worst = i;
        !            33:        len = (len+4+sizeof(SF_CELL*)) / 4 * 4;         /* vax */
        !            34:        s = (SF_CELL*) new char [len];
        !            35:        if( !s ) return "sf(): out of memory";
        !            36:        Bytes += len;
        !            37:        s->link = Table[h];
        !            38:        Table[h] = s;
        !            39:        strcpy( s->buf, x );
        !            40:        return s->buf;
        !            41: }

unix.superglobalmegacorp.com

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