Annotation of researchv10no/cmd/twig/code.c, revision 1.1.1.1

1.1       root        1: #include "common.h"
                      2: #include "code.h"
                      3: #define BLOCKSIZE      10
                      4: 
                      5: Code *cdfreep = NULL;
                      6: 
                      7: Code *
                      8: CodeGetBlock()
                      9: {
                     10:        static int count = 0;
                     11:        static Code *blockp = NULL;
                     12:        Code *cp;
                     13: 
                     14:        if(cdfreep!=NULL) {
                     15:                cp = cdfreep;
                     16:                cdfreep = cdfreep->prev;
                     17:        } else {
                     18:                if(count==0) {
                     19:                        blockp = (Code *) malloc (BLOCKSIZE*sizeof(Code));
                     20:                        count = BLOCKSIZE;
                     21:                }
                     22:                cp = blockp++;
                     23:                count--;
                     24:        }
                     25:        cp->prev = NULL;
                     26:        cp->firstFree = cp->segment;
                     27:        return(cp);
                     28: }
                     29: 
                     30: void
                     31: CodeFreeBlock(cd)
                     32:        Code *cd;
                     33: {
                     34:        if (cd!=NULL) {
                     35:                cd->prev = cdfreep;
                     36:                cdfreep = cd;
                     37:        }
                     38: }
                     39: 
                     40: Code *
                     41: CodeStoreChar(cd, c)
                     42:        Code *cd;
                     43:        char c;
                     44: {
                     45:        if(cd->firstFree - cd->segment >= CSEGSIZE) {
                     46:                Code *ncd = CodeGetBlock();
                     47:                ncd->prev = cd;
                     48:                cd = ncd;
                     49:        }
                     50:        *cd->firstFree = c;
                     51:        cd->firstFree++;
                     52:        return(cd);
                     53: }
                     54: 
                     55: Code *
                     56: CodeStoreString(cd, s)
                     57:        Code *cd;
                     58:        char *s;
                     59: {
                     60:        while(*s!='\0') cd = CodeStoreChar(cd, *s++);
                     61:        return(cd);
                     62: }
                     63: 
                     64: Code *
                     65: CodeAppend(cd1, cd2)
                     66:        Code *cd1, *cd2;
                     67: {
                     68:        if(cd2==NULL) return(cd1);
                     69:        cd2->prev = CodeAppend(cd1, cd2->prev);
                     70:        return(cd2);
                     71: }
                     72: 
                     73: void
                     74: CodeWrite(f, cd)
                     75:        FILE *f;
                     76:        Code *cd;
                     77: {
                     78:        register char *cp;
                     79: 
                     80:        if (cd != NULL)
                     81:                {CodeWrite(outfile, cd->prev);
                     82:                 for(cp=cd->segment; cp < cd->firstFree; cp++)
                     83:                        putc(*cp, f);
                     84:                }
                     85: }
                     86: 
                     87: Code *
                     88: CodeMarkLine(cd,lineno)
                     89:        Code *cd;
                     90:        int lineno;
                     91: {
                     92:        char buf[100];
                     93:        sprintf(buf,"\n# line %d \"%s\"\n", lineno, inFileName);
                     94:        return(CodeStoreString(cd,buf));
                     95: }

unix.superglobalmegacorp.com

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