Annotation of 43BSDTahoe/ucb/window/wwupdate.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  */
        !            17: 
        !            18: #ifndef lint
        !            19: static char sccsid[] = "@(#)wwupdate.c 3.19 (Berkeley) 6/29/88";
        !            20: #endif /* not lint */
        !            21: 
        !            22: #include "ww.h"
        !            23: #include "tt.h"
        !            24: 
        !            25: wwupdate1(top, bot)
        !            26: {
        !            27:        int i;
        !            28:        register j;
        !            29:        register union ww_char *ns, *os;
        !            30:        char *touched;
        !            31:        char didit;
        !            32: 
        !            33:        wwnupdate++;
        !            34:        for (i = top, touched = &wwtouched[i]; i < bot && !wwinterrupt();
        !            35:             i++, touched++) {
        !            36:                if (!*touched)
        !            37:                        continue;
        !            38:                if (*touched & WWU_MAJOR && tt.tt_clreol != 0) {
        !            39:                        register gain = 0;
        !            40:                        register best_gain = 0;
        !            41:                        register best;
        !            42: 
        !            43:                        wwnmajline++;
        !            44:                        j = wwncol;
        !            45:                        ns = &wwns[i][j];
        !            46:                        os = &wwos[i][j];
        !            47:                        while (--j >= 0) {
        !            48:                                /*
        !            49:                                 * The cost of clearing is:
        !            50:                                 *      ncol - nblank + X
        !            51:                                 * The cost of straight update is:
        !            52:                                 *      ncol - nsame
        !            53:                                 * We clear if:  nblank - nsame > X
        !            54:                                 * X is the clreol overhead.
        !            55:                                 * So we make gain = nblank - nsame.
        !            56:                                 */
        !            57:                                if ((--ns)->c_w == (--os)->c_w)
        !            58:                                        gain--;
        !            59:                                else
        !            60:                                        best_gain--;
        !            61:                                if (ns->c_w == ' ')
        !            62:                                        gain++;
        !            63:                                if (gain >= best_gain) {
        !            64:                                        best = j;
        !            65:                                        best_gain = gain;
        !            66:                                }
        !            67:                        }
        !            68:                        if (best_gain > 4) {
        !            69:                                (*tt.tt_move)(i, best);
        !            70:                                (*tt.tt_clreol)();
        !            71:                                for (j = wwncol - best, os = &wwos[i][best];
        !            72:                                     --j >= 0;)
        !            73:                                        os++->c_w = ' ';
        !            74:                        } else
        !            75:                                wwnmajmiss++;
        !            76:                }
        !            77:                *touched = 0;
        !            78:                wwnupdline++;
        !            79:                didit = 0;
        !            80:                ns = wwns[i];
        !            81:                os = wwos[i];
        !            82:                for (j = 0; j < wwncol;) {
        !            83:                        register char *p, *q;
        !            84:                        char m;
        !            85:                        int c;
        !            86:                        register n;
        !            87:                        char buf[512];                  /* > wwncol */
        !            88:                        union ww_char lastc;
        !            89: 
        !            90:                        for (; j++ < wwncol && ns++->c_w == os++->c_w;)
        !            91:                                ;
        !            92:                        if (j > wwncol)
        !            93:                                break;
        !            94:                        p = buf;
        !            95:                        m = ns[-1].c_m;
        !            96:                        c = j - 1;
        !            97:                        os[-1] = ns[-1];
        !            98:                        *p++ = ns[-1].c_c;
        !            99:                        n = 5;
        !           100:                        q = p;
        !           101:                        while (j < wwncol && ns->c_m == m) {
        !           102:                                *p++ = ns->c_c;
        !           103:                                if (ns->c_w == os->c_w) {
        !           104:                                        if (--n <= 0)
        !           105:                                                break;
        !           106:                                        os++;
        !           107:                                        ns++;
        !           108:                                } else {
        !           109:                                        n = 5;
        !           110:                                        q = p;
        !           111:                                        lastc = *os;
        !           112:                                        *os++ = *ns++;
        !           113:                                }
        !           114:                                j++;
        !           115:                        }
        !           116:                        tt.tt_nmodes = m;
        !           117:                        if (wwwrap
        !           118:                            && i == wwnrow - 1 && q - buf + c == wwncol) {
        !           119:                                if (tt.tt_hasinsert) {
        !           120:                                        if (q - buf != 1) {
        !           121:                                                (*tt.tt_move)(i, c);
        !           122:                                                (*tt.tt_write)(buf + 1,
        !           123:                                                        q - buf - 1);
        !           124:                                                (*tt.tt_move)(i, c);
        !           125:                                                tt.tt_ninsert = 1;
        !           126:                                                (*tt.tt_write)(buf, 1);
        !           127:                                                tt.tt_ninsert = 0;
        !           128:                                        } else {
        !           129:                                                (*tt.tt_move)(i, c - 1);
        !           130:                                                (*tt.tt_write)(buf, 1);
        !           131:                                                tt.tt_nmodes = ns[-2].c_m;
        !           132:                                                (*tt.tt_move)(i, c - 1);
        !           133:                                                tt.tt_ninsert = 1;
        !           134:                                                (*tt.tt_write)(&ns[-2].c_c, 1);
        !           135:                                                tt.tt_ninsert = 0;
        !           136:                                        }
        !           137:                                } else {
        !           138:                                        if (q - buf > 1) {
        !           139:                                                (*tt.tt_move)(i, c);
        !           140:                                                (*tt.tt_write)(buf, q-buf-1);
        !           141:                                        }
        !           142:                                        os[-1] = lastc;
        !           143:                                        *touched = WWU_TOUCHED;
        !           144:                                }
        !           145:                        } else {
        !           146:                                (*tt.tt_move)(i, c);
        !           147:                                (*tt.tt_write)(buf, q - buf);
        !           148:                        }
        !           149:                        didit++;
        !           150:                }
        !           151:                if (!didit)
        !           152:                        wwnupdmiss++;
        !           153:        }
        !           154: }

unix.superglobalmegacorp.com

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