1: #ifndef lint
   2: static char sccsid[] = "@(#)wwupdate.c	3.16 4/24/85";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1983 Regents of the University of California,
   7:  * All rights reserved.  Redistribution permitted subject to
   8:  * the terms of the Berkeley Software License Agreement.
   9:  */
  10: 
  11: #include "ww.h"
  12: #include "tt.h"
  13: 
  14: wwupdate1(top, bot)
  15: {
  16:     int i;
  17:     register j;
  18:     register union ww_char *ns, *os;
  19:     char *touched;
  20:     char didit;
  21: 
  22:     wwnupdate++;
  23:     for (i = top, touched = &wwtouched[i]; i < bot && !wwinterrupt();
  24:          i++, touched++) {
  25:         if (!*touched)
  26:             continue;
  27:         if (*touched & WWU_MAJOR && tt.tt_clreol != 0) {
  28:             register gain = 0;
  29:             register best_gain = 0;
  30:             register best;
  31: 
  32:             wwnmajline++;
  33:             j = wwncol;
  34:             ns = &wwns[i][j];
  35:             os = &wwos[i][j];
  36:             while (--j >= 0) {
  37:                 /*
  38: 				 * The cost of clearing is:
  39: 				 *	ncol - nblank + X
  40: 				 * The cost of straight update is:
  41: 				 *	ncol - nsame
  42: 				 * We clear if:  nblank - nsame > X
  43: 				 * X is the clreol overhead.
  44: 				 * So we make gain = nblank - nsame.
  45: 				 */
  46:                 if ((--ns)->c_w == (--os)->c_w)
  47:                     gain--;
  48:                 else
  49:                     best_gain--;
  50:                 if (ns->c_w == ' ')
  51:                     gain++;
  52:                 if (gain >= best_gain) {
  53:                     best = j;
  54:                     best_gain = gain;
  55:                 }
  56:             }
  57:             if (best_gain > 4) {
  58:                 (*tt.tt_move)(i, best);
  59:                 (*tt.tt_clreol)();
  60:                 for (j = wwncol - best, os = &wwos[i][best];
  61:                      --j >= 0;)
  62:                     os++->c_w = ' ';
  63:             } else
  64:                 wwnmajmiss++;
  65:         }
  66:         *touched = 0;
  67:         wwnupdline++;
  68:         didit = 0;
  69:         ns = wwns[i];
  70:         os = wwos[i];
  71:         for (j = 0; j < wwncol;) {
  72:             register char *p, *q;
  73:             char m;
  74:             int c;
  75:             register n;
  76:             char buf[512];          /* > wwncol */
  77:             union ww_char lastc;
  78: 
  79:             for (; j++ < wwncol && ns++->c_w == os++->c_w;)
  80:                 ;
  81:             if (j > wwncol)
  82:                 break;
  83:             p = buf;
  84:             m = ns[-1].c_m & tt.tt_availmodes;
  85:             c = j - 1;
  86:             os[-1] = ns[-1];
  87:             *p++ = ns[-1].c_c;
  88:             n = 5;
  89:             q = p;
  90:             while (j < wwncol && (ns->c_m&tt.tt_availmodes) == m) {
  91:                 *p++ = ns->c_c;
  92:                 if (ns->c_w == os->c_w) {
  93:                     if (--n <= 0)
  94:                         break;
  95:                     os++;
  96:                     ns++;
  97:                 } else {
  98:                     n = 5;
  99:                     q = p;
 100:                     lastc = *os;
 101:                     *os++ = *ns++;
 102:                 }
 103:                 j++;
 104:             }
 105:             tt.tt_nmodes = m;
 106:             if (wwwrap
 107:                 && i == wwnrow - 1 && q - buf + c == wwncol) {
 108:                 if (tt.tt_hasinsert) {
 109:                     if (q - buf != 1) {
 110:                         (*tt.tt_move)(i, c);
 111:                         (*tt.tt_write)(buf + 1,
 112:                             q - buf - 1);
 113:                         (*tt.tt_move)(i, c);
 114:                         tt.tt_ninsert = 1;
 115:                         (*tt.tt_write)(buf, 1);
 116:                         tt.tt_ninsert = 0;
 117:                     } else {
 118:                         (*tt.tt_move)(i, c - 1);
 119:                         (*tt.tt_write)(buf, 1);
 120:                         tt.tt_nmodes = ns[-2].c_m;
 121:                         (*tt.tt_move)(i, c - 1);
 122:                         tt.tt_ninsert = 1;
 123:                         (*tt.tt_write)(&ns[-2].c_c, 1);
 124:                         tt.tt_ninsert = 0;
 125:                     }
 126:                 } else {
 127:                     if (q - buf > 1) {
 128:                         (*tt.tt_move)(i, c);
 129:                         (*tt.tt_write)(buf, q-buf-1);
 130:                     }
 131:                     os[-1] = lastc;
 132:                     *touched = WWU_TOUCHED;
 133:                 }
 134:             } else {
 135:                 (*tt.tt_move)(i, c);
 136:                 (*tt.tt_write)(buf, q - buf);
 137:             }
 138:             didit++;
 139:         }
 140:         if (!didit)
 141:             wwnupdmiss++;
 142:     }
 143: }

Defined functions

wwupdate1 defined in line 14; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2024
Valid CSS Valid XHTML 1.0 Strict