Annotation of researchv8dc/cmd/qed/string.c, revision 1.1.1.1

1.1       root        1: /*% cc -c -O %
                      2:  */
                      3: #include "vars.h"
                      4: #define        strfree string[NSTRING].str
                      5: char *strstart;
                      6: 
                      7: length(s)
                      8:        register char *s;
                      9: {
                     10:        register char *t;
                     11:        if((t=s)==0)
                     12:                return(0);
                     13:        do;while(*t++);
                     14:        return(t-s-1);
                     15: }
                     16: startstring(){
                     17:        strstart=strfree;
                     18: }
                     19: addstring(c){
                     20:        if(strfree==strchars+NSTRCHARS)
                     21:                strcompact();
                     22:        *strfree++ = c;
                     23: }
                     24: dropstring(){
                     25:        --strfree;
                     26: }
                     27: cpstr(a, b)
                     28:        register char *a, *b;
                     29: {
                     30:        do;while (*b++ = *a++);
                     31: }
                     32: shiftstring(up){       /* A highly machine-dependent routine */
                     33:        register struct string *sp;
                     34:        for(sp=string; sp<=string+NSTRING; sp++)
                     35:                if(up)
                     36:                        sp->str += (int)strarea;
                     37:                else
                     38:                        sp->str -= (int)strarea;
                     39: }
                     40: clearstring(z){
                     41:        string[z].len = 0;
                     42:        string[z].str = nullstr;
                     43: }
                     44: copystring(s)
                     45:        register char *s;
                     46: {
                     47:        while(*s)
                     48:                addstring(*s++);
                     49: }
                     50: eqstr(a, b)
                     51:        register char *a, *b;
                     52: {
                     53:        while(*a)
                     54:                if(*a++ != *b++)
                     55:                        return(FALSE);
                     56:        return(*b=='\0');
                     57: }
                     58: /*
                     59:  * dupstring duplicates a string.
                     60:  * Because we may strcompact(), we do it first if necessary.
                     61:  */
                     62: dupstring(z)
                     63: {
                     64:        if(strfree+string[z].len > strchars+NSTRCHARS)
                     65:                strcompact();   /* if insufficient, will get error when we copystring() */
                     66:        copystring(string[z].str);
                     67: }
                     68: setstring(n){
                     69:        addstring('\0');
                     70:        if((string[n].len = length(strstart)) == 0)
                     71:                string[n].str = nullstr;
                     72:        else
                     73:                string[n].str = strstart;
                     74:        if(strfree >= strchars + NSTRCHARS)
                     75:                strcompact();
                     76: }
                     77: strcompact(){
                     78:        register struct string *cursor;
                     79:        struct string *thisstr;
                     80:        register char *s, *t;
                     81:        lock++;
                     82:        s=strchars;
                     83:        for(;;){
                     84:                t=strchars+NSTRCHARS;
                     85:                for(cursor=string;cursor!=string+NSTRING;cursor++)
                     86:                        if(s<=cursor->str && cursor->str<t){
                     87:                                t = cursor->str;
                     88:                                thisstr = cursor;
                     89:                        }
                     90:                if(t==strchars+NSTRCHARS)
                     91:                        break;
                     92:                thisstr->str=s;
                     93:                do;while(*s++ = *t++);
                     94:        }
                     95:        t=strstart;
                     96:        strstart=s;
                     97:        while(t!=strfree)
                     98:                *s++ = *t++;
                     99:        strfree=s;
                    100:        if(s==strchars+NSTRCHARS){
                    101:                strfree=strstart;
                    102:                error('Z');
                    103:        }
                    104:        unlock();
                    105: }

unix.superglobalmegacorp.com

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