Annotation of researchv10no/cmd/sort/tables.c, revision 1.1

1.1     ! root        1: /* Copyright 1990, AT&T Bell Labs */
        !             2: #include <stdlib.h>
        !             3: #include <string.h>
        !             4: #include <ctype.h>
        !             5: #include "fsort.h"
        !             6: 
        !             7: /* STACK=1000 makes lots of room under normal conditions.
        !             8:    But it can be broken.  40 cycles like this will do it:
        !             9:        a,b,...z,za,zb,...zz,zza,zzb,...,zzz,zzza,...
        !            10:    Minor changes to rsort() would allow the stack to be
        !            11:    extended discontiguously.  Pity we don't have alloca any more.
        !            12: */
        !            13: 
        !            14: #define BUFFER 6000000
        !            15: #define MINBUF 10000   /* not worth trying */
        !            16: #define STACK 1000
        !            17: 
        !            18: uchar *bufmax;
        !            19: struct rec *buffer;
        !            20: unsigned long bufsiz = BUFFER;
        !            21: struct rec endfile;
        !            22: struct list *stack;
        !            23: struct list *stackmax;
        !            24: 
        !            25: uchar ident[256];      /* identity transform */
        !            26: uchar fold[256];       /* fold upper case to lower */
        !            27: 
        !            28: uchar all[256];                /* all chars significant */
        !            29: uchar dict[256];       /* sig chars for dictionary order */
        !            30: uchar ascii[256];      /* ascii graphics significant */
        !            31: 
        !            32: void
        !            33: tabinit(void)
        !            34: {
        !            35:        int i;
        !            36:        memset((char*)all,1,256);
        !            37: 
        !            38:        memset((char*)(dict+'0'),1,10);
        !            39:        memset((char*)(dict+'A'),1,26);
        !            40:        memset((char*)(dict+'a'),1,26);
        !            41:        dict[' '] = dict['\t'] = 1;
        !            42: 
        !            43:        memset((char*)(ascii+040),1,0137); /* 040-0176 */
        !            44: 
        !            45:        for(i=0; i<256; i++)
        !            46:                fold[i] = ident[i] = i;
        !            47:        for(i='a'; i<='z'; i++)
        !            48:                fold[i] += 'A' - 'a';
        !            49: 
        !            50:        stack = (struct list*)malloc(STACK*sizeof(*stack));
        !            51:        do {
        !            52:                if((buffer=(struct rec*)malloc(bufsiz)) != 0)
        !            53:                        break;
        !            54:        } while((bufsiz/=2) > MINBUF);
        !            55:        if(buffer==0 || stack==0)
        !            56:                fatal("can't get working space", "", 0);
        !            57:        bufmax = (uchar*)buffer + bufsiz - 2*sizeof(*buffer);
        !            58:        stack->head = stack->tail = 0;
        !            59:        stackmax = stack + STACK;
        !            60: }
        !            61: 
        !            62: void
        !            63: tabfree(void)
        !            64: {
        !            65:        free(stack);
        !            66:        free(buffer);
        !            67: }
        !            68: 
        !            69: void
        !            70: optiony(char *s)
        !            71: {
        !            72:        long size = atol(s);
        !            73:        if(!isdigit(s[0]))
        !            74:                fatal("no size for -y","",0);
        !            75:        if(size >= MINBUF/10)   /* tiny helps debugging */
        !            76:                bufsiz = size;
        !            77:        else if(size == 0)
        !            78:                bufsiz = 10L*BUFFER;
        !            79:        else fatal("-y too small", "", 0);
        !            80: }

unix.superglobalmegacorp.com

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