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

1.1       root        1: /*% cc -c -O %
                      2:  */
                      3: #include "vars.h"
                      4: move(copyflag)
                      5: {
                      6:        register int *adt, *ad1, *ad2;
                      7:        int fb, tb;
                      8:        int todot;
                      9:        int tonewdot;
                     10:        int totmved;
                     11:        int temp;
                     12:        int getcopy();
                     13: 
                     14:        setdot();
                     15:        nonzero();
                     16:        fb = curbuf - buffer;
                     17:        temp = getchar();
                     18:        tb = posn(temp, bname);
                     19:        if(tb >= 0)
                     20:                chngbuf(tb);
                     21:        else{
                     22:                ungetchar(temp);
                     23:                tb = fb;
                     24:        }
                     25:        if ((adt = address())==0){
                     26:                chngbuf(fb);
                     27:                error('x');
                     28:        }
                     29:        todot = adt - buffer[tb].zero;  /* syncbuf not needed! */
                     30:        chngbuf(fb);
                     31:        ad1 = addr1;
                     32:        ad2 = addr2;
                     33:        totmved = ad2 - ad1 + 1;
                     34:        lock++;
                     35:        if (copyflag) {
                     36:                tonewdot = addr2 - buffer[fb].zero;
                     37:                /*
                     38:                 * NOTE: in the copy command
                     39:                 *      copies of the lines are created using append
                     40:                 *      and then moved to the target position.
                     41:                 *      They are appended at the dollar of their
                     42:                 *      original buffer. (guarenteed to be higher address)
                     43:                 *      They are NOT appended at the target position
                     44:                 *      since, if the target position was lower than their
                     45:                 *      source position, getcopy would have to account
                     46:                 *      for the shift of the addresses due to the insert
                     47:                 *      of the copies.
                     48:                 */
                     49:                ad1 = dol;
                     50:                temp = cflag;
                     51:                append(getcopy, ad1++);
                     52:                cflag = temp;
                     53:                ad2 = dol;
                     54:        } else
                     55:                tonewdot = addr1 - buffer[fb].zero - 1;
                     56:        ad2++;
                     57:        adt = buffer[tb].zero + todot;
                     58:        chngbuf(tb);
                     59:        if (adt<ad1) {
                     60:                if ((++adt)!=ad1){
                     61:                        reverse(adt, ad1);
                     62:                        reverse(ad1, ad2);
                     63:                        reverse(adt, ad2);
                     64:                }
                     65:        } else {
                     66:                if (adt++ >= ad2) {
                     67:                        reverse(ad1, ad2);
                     68:                        reverse(ad2, adt);
                     69:                        reverse(ad1, adt);
                     70:                } else {
                     71:                        if(ad2 != zero + 1){
                     72:                                error('m');
                     73:                        }
                     74:                }
                     75:        }
                     76:        fixup(fb, tb, totmved);
                     77:        buffer[fb].dot = buffer[fb].zero + tonewdot;
                     78:        if(copyflag == 0 && fb == tb && todot >= tonewdot){
                     79:                todot -= totmved;
                     80:        }
                     81:        if(!copyflag)
                     82:                buffer[fb].cflag = TRUE;
                     83:        modified();
                     84:        dot = buffer[tb].dot = buffer[tb].zero + todot + totmved;
                     85:        zero = buffer[tb].zero;
                     86:        dol = buffer[tb].dol;
                     87:        unlock();
                     88: }
                     89: fixup(from,to,tot) int from, to, tot;
                     90: {
                     91:        register int b;
                     92:        register int n;
                     93:        register int lo;
                     94:        int hi;
                     95:        if(to == from){
                     96:                return;
                     97:        }
                     98:        if(to < from){
                     99:                n = tot;
                    100:                lo = to;
                    101:                hi = from;
                    102:        } else {
                    103:                n = -tot;
                    104:                lo = from;
                    105:                hi = to;
                    106:        }
                    107:        buffer[lo].dol += n;
                    108:        for(b = lo;++b < hi;){
                    109:                buffer[b].zero += n;
                    110:                buffer[b].dot += n;
                    111:                buffer[b].dol += n;
                    112:        }
                    113:        buffer[hi].zero += n;
                    114: }
                    115: reverse(a1, a2)
                    116:        register int *a1, *a2;
                    117: {
                    118:        register t;
                    119:        for (;;) {
                    120:                t = *--a2;
                    121:                if (a2 <= a1)
                    122:                        return;
                    123:                *a2 = *a1;
                    124:                *a1++ = t;
                    125:        }
                    126: }
                    127: getcopy()
                    128: {
                    129:        if (addr1 > addr2)
                    130:                return(EOF);
                    131:        getline(*addr1++, linebuf);
                    132:        return(0);
                    133: }

unix.superglobalmegacorp.com

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