home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / ex / ex_put.c.new < prev    next >
Text File  |  1980-02-17  |  4KB  |  225 lines

  1. fgoto()
  2. {
  3.     register int l, c;
  4.  
  5.     if (destcol > COLUMNS - 1) {
  6.         destline += destcol / COLUMNS;
  7.         destcol %= COLUMNS;
  8.     }
  9.     if (outcol > COLUMNS - 1) {
  10.         l = (outcol + 1) / COLUMNS;
  11.         outline += l;
  12.         outcol %= COLUMNS;
  13.         if (AM == 0) {
  14.             while (l > 0) {
  15.                 if (pfast)
  16.                     putch('\r');
  17.                 putch('\n');
  18.                 l--;
  19.             }
  20.             outcol = 0;
  21.         }
  22.         if (outline > LINES - 1) {
  23.             destline -= outline - (LINES - 1);
  24.             outline = LINES - 1;
  25.         }
  26.     }
  27.     if (destline > LINES - 1) {
  28.         l = destline;
  29.         destline = LINES - 1;
  30.         if (outline < LINES - 1) {
  31.             c = destcol;
  32.             if (pfast == 0 && (!CA || holdcm))
  33.                 destcol = 0;
  34.             fgoto();
  35.             destcol = c;
  36.         }
  37.         while (l > LINES - 1) {
  38.             putch('\n');
  39.             l--;
  40.             if (pfast == 0)
  41.                 outcol = 0;
  42.         }
  43.     }
  44.     if (destline < outline && !(CA && !holdcm || UP != NOSTR))
  45.         destline = outline;
  46.     if (CA && !holdcm) {
  47.         char *cgp;
  48.  
  49.         cgp = tgoto(CM, destcol, destline);
  50.         if (plod(strlen(cgp)) > 0)
  51.             plod(0);
  52.         else
  53.             tputs(cgp, 0, putch);
  54.     } else
  55.         plod(0);
  56.     outline = destline;
  57.     outcol = destcol;
  58. }
  59.  
  60. /*
  61.  * Tab to column col by flushing and then setting destcol.
  62.  * Used by "set all".
  63.  */
  64. tab(col)
  65.     int col;
  66. {
  67.  
  68.     flush1();
  69.     destcol = col;
  70. }
  71.  
  72. /*
  73.  * Move (slowly) to destination.
  74.  * Hard thing here is using home cursor on really deficient terminals.
  75.  * Otherwise just use cursor motions, hacking use of tabs and overtabbing
  76.  * and backspace.
  77.  */
  78.  
  79. static int plodcnt, plodflg;
  80.  
  81. plodput(c)
  82. {
  83.     if (plodflg)
  84.         plodcnt--;
  85.     else
  86.         putch(c);
  87. }
  88.  
  89. plod(cnt)
  90. {
  91.     register int i, j, k;
  92.     int soutcol, soutline, sdestcol, sdestline;
  93.  
  94.     plodcnt = plodflg = cnt;
  95.     soutcol = outcol;
  96.     soutline = outline;
  97.     sdestcol = destcol;
  98.     sdestline = destline;
  99.     if (HO) {
  100.         if (GT)
  101.             i = (destcol >> 3) + (destcol & 07);
  102.         else
  103.             i = destcol;
  104.         if (destcol >= outcol)
  105.             if (GT && (j = ((destcol - (outcol &~ 07)) >> 3)))
  106.                 j += destcol & 07;
  107.             else
  108.                 j = destcol - outcol;
  109.         else
  110.             if (outcol - destcol <= i && (BS || BC))
  111.                 i = j = outcol - destcol;
  112.             else
  113.                 j = i + 1;
  114.         k = outline - destline;
  115.         if (k < 0)
  116.             k = -k;
  117.         j += k;
  118.         if (i + destline < j) {
  119.             tputs(HO, 0, plodput);
  120.             outcol = outline = 0;
  121.         } else if (LL) {
  122.             k = (LINES - 1) - destline;
  123.             if (i + k + 2 < j) {
  124.                 tputs(LL, 0, plodput);
  125.                 outcol = 0;
  126.                 outline = LINES - 1;
  127.             }
  128.         }
  129.     }
  130.     if (GT)
  131.         i = (destcol >> 3) + (destcol & 07);
  132.     else
  133.         i = destcol;
  134.     if (BT && outcol > destcol) {
  135.         j = (((outcol+7) & ~7) - destcol - 1) >> 3;
  136.         j *= (k = strlen(BT));
  137.         if ((k = (destcol&7)+k) > 4)
  138.             j += 8 - (destcol&7);
  139.         else
  140.             j += k;
  141.     }
  142.     else
  143.         j = outcol - destcol;
  144.     if ((!NONL || outline >= destline) && (!NC || outline < destline) &&
  145.         (j > i + 1 || outcol > destcol && !BS && !BC)) {
  146.         plodput('\r');
  147.         if (NC) {
  148.             plodput('\n');
  149.             outline++;
  150.         }
  151.         outcol = 0;
  152.     }
  153.     while (outline < destline) {
  154.         outline++;
  155.         plodput('\n');
  156.         if (plodflg && plodcnt < 0)
  157.             goto out;
  158.         if (NONL || pfast == 0)
  159.             outcol = 0;
  160.     }
  161.     if (BT)
  162.         k = strlen(BT);
  163.     while (outcol > destcol) {
  164.         if (plodflg && plodcnt < 0)
  165.             goto out;
  166.         if (BT && outcol - destcol > 4+k) {
  167.             tputs(BT, 0, plodput);
  168.             outcol--;
  169.             outcol &= ~7;
  170.             continue;
  171.         }
  172.         outcol--;
  173.         if (BC)
  174.             tputs(BC, 0, plodput);
  175.         else
  176.             plodput('\b');
  177.     }
  178.     while (outline > destline) {
  179.         outline--;
  180.         tputs(UP, 0, plodput);
  181.         if (plodflg && plodcnt < 0)
  182.             goto out;
  183.     }
  184.     if (GT && destcol - outcol > 1) {
  185.         while ((i = ((outcol + 8) &~ 7)) <= destcol) {
  186.             if (TA)
  187.                 tputs(TA, 0, plodput);
  188.             else
  189.                 plodput('\t');
  190.             outcol = i;
  191.         }
  192.         if (destcol - outcol > 4 && (BC || BS)) {
  193.             if (TA)
  194.                 tputs(TA, 0, plodput);
  195.             else
  196.                 plodput('\t');
  197.             outcol = i;
  198.             while (outcol > destcol) {
  199.                 outcol--;
  200.                 if (BC)
  201.                     tputs(BC, 0, plodput);
  202.                 else
  203.                     plodput('\b');
  204.             }
  205.         }
  206.     }
  207.     while (outcol < destcol) {
  208.         if (inopen && ND)
  209.             tputs(ND, 0, plodput);
  210.         else
  211.             plodput(' ');
  212.         outcol++;
  213.         if (plodflg && plodcnt < 0)
  214.             goto out;
  215.     }
  216. out:
  217.     if (plodflg) {
  218.         outcol = soutcol;
  219.         outline = soutline;
  220.         destcol = sdestcol;
  221.         destline = sdestline;
  222.     }
  223.     return(plodcnt);
  224. }
  225.