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

1.1       root        1: /*% cc -c -O %
                      2:  */
                      3: #include "vars.h"
                      4: bufinit(n)
                      5:        int *n;
                      6: {
                      7:        struct buffer *bufp;
                      8:        register *fend;
                      9:        fend=n;
                     10:        for(bufp=buffer;bufp!=buffer+NBUFS;bufp++){
                     11:                bufp->zero=fend;
                     12:                bufp->dot=fend;
                     13:                bufp->dol=fend;
                     14:                bufp->cflag = FALSE;
                     15:        }
                     16: }
                     17: chngbuf(bb)
                     18:        int bb;
                     19: {
                     20:        syncbuf();
                     21:        newbuf(bb);
                     22:        savedfile = FILE(curbuf-buffer);
                     23: }
                     24: newbuf(bb){
                     25:        curbuf = buffer+bb;
                     26:        zero=curbuf->zero;
                     27:        dot=curbuf->dot;
                     28:        dol=curbuf->dol;
                     29:        cflag = curbuf->cflag;
                     30: }
                     31: fixbufs(n)
                     32:        register n;
                     33: {
                     34:        register struct buffer *bufp;
                     35:        lock++;
                     36:        for(bufp=curbuf+1;bufp!=buffer+NBUFS;bufp++){
                     37:                bufp->zero+=n;
                     38:                bufp->dot+=n;
                     39:                bufp->dol+=n;
                     40:        }
                     41:        unlock();
                     42: }
                     43: syncbuf()
                     44: {
                     45:        /* curbuf->zero = zero; /* we never assign to it, so needn't save */
                     46:        curbuf->dot=dot;
                     47:        curbuf->dol=dol;
                     48:        curbuf->cflag = cflag!=FALSE;   /* Normalize to fit in a char */
                     49: }
                     50: error(code)
                     51: {
                     52:        extern savint;  /* error during a ! > < | ?? */
                     53:        unlock();
                     54:        if(code){
                     55:                for(;stackp != stack ;--stackp)
                     56:                        if(stackp->type == BUF || stackp->type == STRING){
                     57:                                putchar('?');
                     58:                                if(stackp->type == BUF){
                     59:                                        putchar('b');
                     60:                                        putchar(bname[stackp->bufptr - buffer]);
                     61:                                        putlong((long)stackp->lineno);
                     62:                                        putchar('.');
                     63:                                }else{
                     64:                                        putchar('z');
                     65:                                        putchar(bname[stackp->lineno]);
                     66:                                }
                     67:                                putlong((long)stackp->charno);
                     68:                                putchar(' ');
                     69:                        }
                     70:                putchar('?');
                     71:                putchar(lasterr=(code&~FILERR));
                     72:                if(code&FILERR){
                     73:                        putchar(' ');
                     74:                        putl(string[FILEBUF].str);
                     75:                } else
                     76:                        putchar('\n');
                     77:        }
                     78:        if(eflag && code)
                     79:                exit(code);
                     80:        nestlevel = 0;
                     81:        listf = FALSE;
                     82:        gflag = FALSE;
                     83:        biggflag = FALSE;
                     84:        stackp = stack;
                     85:        peekc = 0;
                     86:        if(code && code!='?'){          /* if '?', system cleared tty input buf */
                     87:                while(lastttyc!='\n' && lastttyc!=EOF){
                     88:                        getchar();
                     89:                }
                     90:        }
                     91:        lseek(0, 0L, 2);
                     92:        if (io > 0) {
                     93:                close(io);
                     94:                io = -1;
                     95:                cflag = TRUE;   /* well, maybe not, but better be safe */
                     96:        }
                     97:        appflag=0;
                     98:        if(savint>=0){
                     99:                signal(SIGINT, savint);
                    100:                savint= -1;
                    101:        }
                    102:        reset();
                    103: }
                    104: init()
                    105: {
                    106:        register char *p;
                    107:        register pid;
                    108:        lock++;
                    109:        close(tfile);
                    110:        tfname = "/tmp/qxxxxx";
                    111:        pid = getpid();
                    112:        for (p = &tfname[11]; p > &tfname[6];) {
                    113:                *--p = (pid%10) + '0';
                    114:                pid /= 10;
                    115:        }
                    116:        close(creat(tfname, 0600));
                    117:        tfile = open(tfname, 2);
                    118:        tfile2 = open(tfname, 2);
                    119:        ioctl(tfile, FIOCLEX, 0);
                    120:        ioctl(tfile2, FIOCLEX, 0);
                    121:        brk(fendcore);
                    122:        bufinit(fendcore);
                    123:        newbuf(0);
                    124:        lastdol=dol;
                    125:        endcore = fendcore - 2;
                    126:        stackp=stack;
                    127:        stackp->type=TTY;
                    128:        unlock();
                    129: }
                    130: comment()
                    131: {
                    132:        register c, mesg;
                    133: 
                    134:        c = getchar();
                    135:        mesg = 0;
                    136:        if(c == '\"') {
                    137:                mesg++;
                    138:                c = getchar();
                    139:        }
                    140:        while(c != '\n' && c != '\"') {
                    141:                if(mesg)
                    142:                        putchar(c);
                    143:                c = getchar();
                    144:        }
                    145:        if(mesg) {
                    146:                if(c == '\n')
                    147:                        putchar(c);
                    148:                flush();
                    149:        }
                    150: }
                    151: abs(n)
                    152: register n;
                    153: {
                    154:        return(n<0?-n:n);
                    155: }
                    156: /*
                    157:  * Slow, but avoids garbage collection
                    158:  */
                    159: settruth(t)
                    160:        register t;
                    161: {
                    162:        if(atoi(string[TRUTH].str) != t)
                    163:                numset(TRUTH, t);
                    164: }
                    165: setcount(c)
                    166:        register c;
                    167: {
                    168:        if(atoi(string[COUNT].str) != c)
                    169:                numset(COUNT, c);
                    170: }
                    171: truth(){
                    172:        return(atoi(string[TRUTH].str) != FALSE);
                    173: }
                    174: modified(){
                    175:        cflag=TRUE;
                    176:        eok=FALSE;
                    177:        qok=FALSE;
                    178: }

unix.superglobalmegacorp.com

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