home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 198_01 / display.c < prev    next >
C/C++ Source or Header  |  1990-01-23  |  38KB  |  1,561 lines

  1. /*
  2.  * The functions in this file handle redisplay. There are two halves, the
  3.  * ones that update the virtual display screen, and the ones that make the
  4.  * physical display screen the same as the virtual display screen. These
  5.  * functions use hints that are left in the windows by the commands.
  6.  *
  7.  */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. typedef struct  VIDEOTAG {
  14.         int    v_flag;                 /* Flags */
  15. #if    COLOR
  16.     int    v_fcolor;        /* current forground color */
  17.     int    v_bcolor;        /* current background color */
  18.     int    v_rfcolor;        /* requested forground color */
  19.     int    v_rbcolor;        /* requested background color */
  20. #endif
  21.         char    v_text[1];              /* Screen data. */
  22. }       VIDEO;
  23.  
  24. #define VFCHG   0x0001                  /* Changed flag            */
  25. #define    VFEXT    0x0002            /* extended (beyond column 80)    */
  26. #define    VFREV    0x0004            /* reverse video status        */
  27. #define    VFREQ    0x0008            /* reverse video request    */
  28. #define    VFCOL    0x0010            /* color change requested    */
  29. #define    VFSCROL    0x0020            /* cleared by scrolling        */
  30.  
  31. #define    WFSCROL    0x0040            /* window scrolled        */
  32.  
  33. VIDEO   **vscreen;                      /* Virtual screen. */
  34. VIDEO   **vsave;                        /* Used for scrolling. */
  35. #if    MEMMAP == 0
  36. VIDEO   **pscreen;                      /* Physical screen. */
  37. VIDEO   **psave;                        /* Used for scrolling. */
  38. #endif
  39.  
  40. int didlins, didldel;
  41.  
  42. #define fastputc(c)    TTputc(c)
  43.  
  44. /* these declarations must match termio.c */
  45.  
  46. #if     VMS
  47. extern char obuf[NOBUF];                /* Output buffer               */
  48. extern int nobuf;                       /* # of bytes in above    */
  49.  
  50. #undef fastputc
  51. #define fastputc(c)    {if (nobuf >= NOBUF) ttflush(); obuf[nobuf++] = (c);}
  52. #endif
  53.  
  54. #if     V7 | USG | BSD
  55. #undef fastputc
  56. #define fastputc(c)        putc((c), stdout)
  57. #endif
  58.  
  59. #if    (TERMCAP | VMSVT) & COLOR
  60. extern int usedcolor;
  61. #endif
  62.  
  63. /*
  64.  * Initialize the data structures used by the display code. The edge vectors
  65.  * used to access the screens are set up. The operating system's terminal I/O
  66.  * channel is set up. All the other things get initialized at compile time.
  67.  * The original window has "WFCHG" set, so that it will get completely
  68.  * redrawn on the first call to "update".
  69.  */
  70. vtinit()
  71. {
  72.     register int i;
  73.     register VIDEO *vp;
  74.     char *malloc();
  75.  
  76.     TTopen();        /* open the screen */
  77.     TTkopen();        /* open the keyboard */
  78.     TTrev(FALSE);
  79.     if (firstflag) {
  80.     vscreen = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
  81.     vsave = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
  82.     }
  83.  
  84.     if (vscreen == NULL || vsave == NULL)
  85.         exit(1);
  86.  
  87. #if    MEMMAP == 0
  88.     if (firstflag) {
  89.     pscreen = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
  90.     psave = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
  91.     }
  92.  
  93.     if (pscreen == NULL || psave == NULL)
  94.         exit(1);
  95. #endif
  96.  
  97.     for (i = 0; i < term.t_mrow; ++i)
  98.         {
  99.     if (firstflag) vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_mcol);
  100.     else vp = vscreen[i];
  101.  
  102.         if (vp == NULL)
  103.             exit(1);
  104.  
  105.     vp->v_flag = 0;
  106. #if    COLOR
  107.     vp->v_rfcolor = 7;
  108.     vp->v_rbcolor = 0;
  109. #endif
  110.         vscreen[i] = vp;
  111. #if    MEMMAP == 0
  112.     if (firstflag) vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_mcol);
  113.     else vp = pscreen[i];
  114.  
  115.         if (vp == NULL)
  116.             exit(1);
  117.  
  118.     vp->v_flag = 0;
  119.         pscreen[i] = vp;
  120. #endif
  121.         }
  122. }
  123.  
  124. /*
  125.  * Clean up the virtual terminal system, in anticipation for a return to the
  126.  * operating system. Move down to the last line and clear it out (the next
  127.  * system prompt will be written in the line). Shut down the channel to the
  128.  * terminal.
  129.  */
  130. vttidy()
  131. {
  132. #if    VMSVT | TERMCAP
  133.     ttscroll(0, term.t_nrow, 0);
  134. #endif
  135.     mlerase();
  136.     movecursor(term.t_nrow, 0);
  137.     TTflush();
  138.     TTclose();
  139.     TTkclose();
  140. }
  141.  
  142. /*
  143.  * Set the virtual cursor to the specified row and column on the virtual
  144.  * screen. There is no checking for nonsense values; this might be a good
  145.  * idea during the early stages.
  146.  */
  147. vtmove(row, col)
  148. {
  149.     vtrow = row;
  150.     vtcol = col;
  151. }
  152.  
  153. /* Write a character to the virtual screen. The virtual row and
  154.    column are updated. If we are not yet on left edge, don't print
  155.    it yet. If the line is too long put a "$" in the last column.
  156.    This routine only puts printing characters into the virtual
  157.    terminal buffers. Only column overflow is checked.
  158. */
  159.  
  160. vtputc(c)
  161.  
  162. int c;
  163.  
  164. {
  165.     register VIDEO *vp;    /* ptr to line being updated */
  166.  
  167.     vp = vscreen[vtrow];
  168.  
  169.     if (c == '\t') {
  170.         do {
  171.             vtputc(' ');
  172.         } while (((vtcol + taboff) % tabsize) != 0);
  173.     } else if (vtcol >= term.t_ncol) {
  174.         ++vtcol;
  175.         vp->v_text[term.t_ncol - 1] = '$';
  176.     } else if ((c&0x7F) < 0x20 || (c&0x7F) == 0x7F) {
  177.         vtputc('^');
  178.         vtputc((c&0x7F) ^ 0x40);
  179.     } else {
  180.         if (vtcol >= 0)
  181.             vp->v_text[vtcol] = c;
  182.         ++vtcol;
  183.     }
  184. }
  185.  
  186. /* Write a line to the virtual screen.  Does equivalent of
  187.     for (j=0; j<llength(lp); ++j) vtputc(lgetc(lp, j));
  188.  */
  189.  
  190. vtputl(lp)
  191. register LINE *lp;    /* line to update */
  192. {
  193.     register VIDEO *vp;    /* ptr to line being updated */
  194.     register int i, c;
  195.  
  196.     vp = vscreen[vtrow];
  197.  
  198.     for (i = 0; i < llength(lp); ++i) {
  199.         c = lgetc(lp, i);
  200.         if (c == '\t') {
  201.             do {
  202.                 if (vtcol >= term.t_ncol) {
  203.                     vp->v_text[term.t_ncol - 1] = '$';
  204.                     return;
  205.                 } else {
  206.                     if (vtcol >= 0)
  207.                         vp->v_text[vtcol] = ' ';
  208.                     ++vtcol;
  209.                 }
  210.             } while (((vtcol + taboff) % tabsize) != 0);
  211.         } else if (vtcol >= term.t_ncol) {
  212.             vp->v_text[term.t_ncol - 1] = '$';
  213.             return;
  214.         } else if (c < 0x20 || c >= 0x7F) {
  215.             if ((c&0x7F) < 0x20 || (c&0x7F) == 0x7F) {
  216.                 if (vtcol >= 0) vp->v_text[vtcol] = '^';
  217.                 ++vtcol;
  218.                 if (vtcol >= term.t_ncol) {
  219.                     vp->v_text[term.t_ncol - 1] = '$';
  220.                     return;
  221.                 } else if (vtcol >= 0)
  222.                     vp->v_text[vtcol] = ((c&0x7F) ^ 0x40);
  223.             } else if (vtcol >= 0)
  224.                 vp->v_text[vtcol] = c;
  225.             ++vtcol;
  226.         } else {
  227.             if (vtcol >= 0)
  228.                 vp->v_text[vtcol] = c;
  229.             ++vtcol;
  230.         }
  231.     }
  232. }
  233.  
  234. /* Write a string to the virtual screen and return its length */
  235.  
  236. int vtputs(s)
  237. register char *s;
  238. {
  239.     register VIDEO *vp;    /* ptr to line being updated */
  240.     register int i;
  241.  
  242.     vp = vscreen[vtrow];
  243.  
  244.     for (i = 0; *s != '\0' && vtcol < term.t_ncol; ++i) {
  245.         if (vtcol >= 0) vp->v_text[vtcol] = *(s++);
  246.         ++vtcol;
  247.     }
  248.     return(i);
  249. }
  250.  
  251. /*
  252.  * Erase from the end of the software cursor to the end of the line on which
  253.  * the software cursor is located.
  254.  */
  255. vteeol()
  256. {
  257.     register VIDEO      *vp;
  258.  
  259.     vp = vscreen[vtrow];
  260.     if (vtcol < 0) vtcol = 0;
  261.     while (vtcol < term.t_ncol)
  262.         vp->v_text[vtcol++] = ' ';
  263. }
  264.  
  265. /* upscreen:    user routine to force a screen update
  266.         always finishes complete update        */
  267.  
  268. upscreen(f, n)
  269.  
  270. {
  271.     update(TRUE);
  272.     return(TRUE);
  273. }
  274.  
  275. /*
  276.  * Make sure that the display is right. This is a three part process. First,
  277.  * scan through all of the windows looking for dirty ones. Check the framing,
  278.  * and refresh the screen. Second, make sure that "currow" and "curcol" are
  279.  * correct for the current window. Third, make the virtual and physical
  280.  * screens the same.
  281.  * force == HOOK like FALSE, but also does not update cursor
  282.  *   (for edt page scrolling)
  283.  */
  284. update(force)
  285.  
  286. int force;    /* force update past type ahead? */
  287.  
  288. {
  289.     register WINDOW *wp;
  290.  
  291. #if    TYPEAH
  292.     if (force != TRUE && typahead())
  293.         return(TRUE);
  294. #endif
  295. #if    VISMAC == 0
  296.     if (force != TRUE && kbdmode == PLAY)
  297.         return(TRUE);
  298. #endif
  299.  
  300.     /* update any windows that need refreshing */
  301.     wp = wheadp;
  302.     while (wp != NULL) {
  303.         if (wp->w_flag) {
  304.             /* if the window has changed, service it */
  305.             reframe(wp);    /* check the framing */
  306.             if ((wp->w_flag & ~WFMODE) == WFEDIT)
  307.                 updone(wp);    /* update EDITed line */
  308.             else if ((wp->w_flag & ~(WFMODE | WFMOVE)) == WFSCROL)
  309.                 updscroll(wp);
  310.             else if (wp->w_flag & ~WFMOVE)
  311.                 updall(wp);    /* update all lines */
  312.             if (wp->w_flag & WFMODE)
  313.                 modeline(wp);    /* update modeline */
  314.             wp->w_flag = 0;
  315.             wp->w_force = 0;
  316.         }
  317.         /* on to the next window */
  318.         wp = wp->w_wndp;
  319.     }
  320.  
  321.     /* recalc the current hardware cursor location */
  322.     updpos();
  323.  
  324. #if    MEMMAP
  325.     /* update the cursor and flush the buffers */
  326.     movecursor(currow, curcol - lbound);
  327. #endif
  328.  
  329.     /* check for lines to de-extend */
  330.     upddex();
  331.  
  332.     /* if screen is garbage, re-plot it */
  333.     if (sgarbf != FALSE)
  334.         updgar();
  335.  
  336.     /* update the virtual screen to the physical screen */
  337.     if (updupd(force) != ABORT) {
  338.  
  339.         /* update the cursor and flush the buffers */
  340. #if    MEMMAP | RAINBOW
  341. #else
  342.         /* Fast way to move the cursor a little bit */
  343.         if (ttrow == currow &&
  344.                 ttcol < curcol - lbound &&
  345.                 ttcol + 5 > curcol - lbound)
  346.               do {fastputc(pscreen[currow]->v_text[ttcol]);++ttcol;}
  347.               while (ttcol < curcol - lbound);
  348. #endif
  349.         if (force != HOOK)
  350.             movecursor(currow, curcol - lbound);
  351.     }
  352.  
  353.     if (force != HOOK) TTflush();
  354.     return(TRUE);
  355. }
  356.  
  357. /*    reframe:    check to see if the cursor is on in the window
  358.             and re-frame it if needed or wanted        */
  359.  
  360. reframe(wp)
  361.  
  362. WINDOW *wp;
  363.  
  364. {
  365.     register LINE *lp, *slp, *blp;
  366.     register int i;
  367.     int top, bot, j, k, scrolled;
  368.     VIDEO *vp;
  369.  
  370.     scrolled = 0;
  371.  
  372.     blp = wp->w_bufp->b_linep;    /* last line of buffer */
  373.  
  374.     /* if not a requested reframe, check for a needed one */
  375.     if ((wp->w_flag & WFFORCE) == 0) {
  376.         lp = wp->w_linep;
  377.         for (i = 0; i < wp->w_ntrows; i++) {
  378.  
  379.             /* if the line is in the window, no reframe */
  380.             if (lp == wp->w_dotp)
  381.                 return(TRUE);
  382.  
  383.             /* if we are at the end of the file, reframe */
  384.             if (lp == blp)
  385.                 break;
  386.  
  387.             /* on to the next line */
  388.             lp = lforw(lp);
  389.         }
  390.     }
  391.  
  392.     /* reaching here, we need a window refresh */
  393.     i = wp->w_force;
  394.  
  395.     /* how far back to reframe? */
  396.     if (i > 0) {        /* only one screen worth of lines max */
  397.         if (--i >= wp->w_ntrows)
  398.             i = wp->w_ntrows - 1;
  399.     } else if (i < 0) {    /* negative update???? */
  400.         i += wp->w_ntrows;
  401.         if (i < 0)
  402.             i = 0;
  403.     } else
  404.         i = wp->w_ntrows / 2;
  405.  
  406.     /* backup to new line at top of window */
  407.     lp = wp->w_dotp;
  408.     while (i != 0 && lback(lp) != blp) {
  409.         --i;
  410.         lp = lback(lp);
  411.     }
  412.  
  413. #if    VMSVT | TERMCAP
  414.  
  415.     if (isvt100) {
  416.         /* backup to get end of buffer on last line */
  417.         i = wp->w_ntrows - 2;
  418.         if (lp != blp) {
  419.             slp = lp;
  420.             if (wp->w_dotp != blp)
  421.                 slp = lforw(slp);
  422.             if (slp != blp)
  423.                 while(i > 0 && lforw(slp) != blp) {
  424.                     --i;
  425.                     slp = lforw(slp);
  426.                 }
  427.             while(i > 0 && lback(lp) != blp) {
  428.                 --i;
  429.                 lp = lback(lp);
  430.             }
  431.         }
  432.     }
  433.     
  434.     /* check if scrolling possible */
  435.     if (sgarbf == FALSE && isvt100 == TRUE && wp->w_ntrows > 2) {
  436.         slp = wp->w_linep;
  437.         i = 0;
  438.         while (i < wp->w_ntrows && slp != lp && slp != blp)
  439.             {++i; slp = lforw(slp);}
  440.         if (slp != lp)    {
  441.             slp = wp->w_linep;
  442.             i = 0;
  443.             while (-i < wp->w_ntrows && slp != lp && slp != blp)
  444.                 {--i; slp = lback(slp);}
  445.         }
  446.  
  447.         scrolled = (slp == lp);
  448.  
  449.         if (slp == lp && i != 0) {
  450.             top = wp->w_toprow + menuflag;
  451.             bot = top + wp->w_ntrows - 1;
  452.             ttscroll(top, bot, i);
  453.             if (i > 0) {        /* scroll page up */
  454.                 for (j = top; j < top + i; j++) {
  455.                     vp = pscreen[j];
  456.                     psave[bot + top - j] = vp;
  457.                     vsave[bot + top - j] = vscreen[j];
  458.                     vsave[bot + top - j]->v_flag |= VFSCROL;
  459.                     for(k = 0; k < term.t_ncol; k++)
  460.                         vp->v_text[k] = ' ';
  461. #if    (TERMCAP | VMSVT) & COLOR
  462.                     if (usedcolor) {
  463.                         vp = vscreen[j];
  464.                         vp->v_fcolor = 7;
  465.                         vp->v_bcolor = 0;
  466.                         vp->v_flag |= VFCHG | VFCOL;
  467.                     }
  468. #endif
  469.                 }
  470.                 for (j = top + i; j <= bot; j++) {
  471.                     psave[j - i] = pscreen[j];
  472.                     vsave[j - i] = vscreen[j];
  473.                 }
  474.             }
  475.             else {            /* scroll page down */
  476.                 i = -i;
  477.                 for (j = bot + 1 - i; j <= bot; j++) {
  478.                     vp = pscreen[j];
  479.                     psave[bot + top - j] = vp;
  480.                     vsave[bot + top - j] = vscreen[j];
  481.                     vsave[bot + top - j]->v_flag |= VFSCROL;
  482.                     for(k = 0; k < term.t_ncol; k++)
  483.                         vp->v_text[k] = ' ';
  484. #if    (TERMCAP | VMSVT) & COLOR
  485.                     if (usedcolor) {
  486.                         vp = vscreen[j];
  487.                         vp->v_fcolor = 7;
  488.                         vp->v_bcolor = 0;
  489.                         vp->v_flag |= VFCHG | VFCOL;
  490.                     }
  491. #endif
  492.                 }
  493.                 for (j = top; j < bot + 1 - i; j++) {
  494.                     psave[j + i] = pscreen[j];
  495.                     vsave[j + i] = vscreen[j];
  496.                 }
  497.             }
  498.             for (j = top; j <= bot; j++) {
  499.                 pscreen[j] = psave[j];
  500.                 vscreen[j] = vsave[j];
  501.             }
  502.         }
  503.     }
  504. #endif
  505.  
  506.     /* and reset the current line at top of window */
  507.     wp->w_linep = lp;
  508.     if (scrolled) {
  509.         wp->w_flag |= WFSCROL;
  510.         if (wheadp->w_wndp == NULL) didlins = didldel = 0;
  511.     }
  512.     else wp->w_flag |= WFHARD;
  513.     wp->w_flag &= ~WFFORCE;
  514.     return(TRUE);
  515. }
  516.  
  517. /*    updone:    update the current line    to the virtual screen        */
  518.  
  519. updone(wp)
  520.  
  521. WINDOW *wp;    /* window to update current line in */
  522.  
  523. {
  524.     register LINE *lp;    /* line to update */
  525.     register int sline;    /* physical screen line to update */
  526.  
  527.     /* search down the line we want */
  528.     lp = wp->w_linep;
  529.     sline = wp->w_toprow + menuflag;
  530.     while (lp != wp->w_dotp) {
  531.         ++sline;
  532.         lp = lforw(lp);
  533.     }
  534.  
  535.     /* and update the virtual line */
  536.     vscreen[sline]->v_flag |= VFCHG;
  537.     vscreen[sline]->v_flag &= ~VFREQ;
  538.     taboff = wp->w_fcol;
  539.     vtmove(sline, -taboff);
  540.     vtputl(lp);
  541. #if    COLOR
  542.     vscreen[sline]->v_rfcolor = wp->w_fcolor;
  543.     vscreen[sline]->v_rbcolor = wp->w_bcolor;
  544. #endif
  545.     vteeol();
  546.     taboff = 0;
  547. }
  548.  
  549. /*    updscroll: update scrolled lines in a window on the virtual screen */
  550.  
  551. updscroll(wp)
  552. WINDOW *wp;    /* window to update lines in */
  553.  
  554. {
  555.     register LINE *lp;    /* line to update */
  556.     register int sline;    /* physical screen line to update */
  557.  
  558.     /* search down the lines, updating them */
  559.     lp = wp->w_linep;
  560.     sline = wp->w_toprow + menuflag;
  561.     while (sline < wp->w_toprow + wp->w_ntrows + menuflag) {
  562.         if (vscreen[sline]->v_flag & VFSCROL) {
  563.             vscreen[sline]->v_flag |= VFCHG;
  564.             vscreen[sline]->v_flag &= ~VFREQ;
  565.             taboff = wp->w_fcol;
  566.             vtmove(sline, -taboff);
  567.             if (lp != wp->w_bufp->b_linep) vtputl(lp);
  568. #if    COLOR
  569.             vscreen[sline]->v_rfcolor = wp->w_fcolor;
  570.             vscreen[sline]->v_rbcolor = wp->w_bcolor;
  571. #endif
  572.             vteeol();
  573.         }
  574.         if (lp != wp->w_bufp->b_linep) lp = lforw(lp);
  575.         ++sline;
  576.     }
  577.  
  578. }
  579.  
  580. /*    updall:    update all the lines in a window on the virtual screen */
  581.  
  582. updall(wp)
  583.  
  584. WINDOW *wp;    /* window to update lines in */
  585.  
  586. {
  587.     register LINE *lp;    /* line to update */
  588.     register int sline;    /* physical screen line to update */
  589.  
  590. #if MENUS
  591.     /* menu line */
  592.     if (menuflag)    {
  593.         vscreen[0]->v_flag |= (VFCHG | VFREQ);
  594.         taboff = 0;
  595.         vtmove(0, 0);
  596.         vtputl(menuline);
  597. #if    COLOR
  598.         vscreen[0]->v_rfcolor = gbcolor;
  599.         vscreen[0]->v_rbcolor = gfcolor;
  600. #endif
  601.         vteeol();
  602.     }    
  603. #endif
  604.  
  605.     /* search down the lines, updating them */
  606.     lp = wp->w_linep;
  607.     sline = wp->w_toprow + menuflag;
  608.     while (sline < wp->w_toprow + wp->w_ntrows + menuflag) {
  609.  
  610.         /* and update the virtual line */
  611.         vscreen[sline]->v_flag |= VFCHG;
  612.         vscreen[sline]->v_flag &= ~VFREQ;
  613.         taboff = wp->w_fcol;
  614.         vtmove(sline, -taboff);
  615.         if (lp != wp->w_bufp->b_linep) {
  616.             /* if we are not at the end */
  617.             vtputl(lp);
  618.             lp = lforw(lp);
  619.         }
  620.  
  621.         /* on to the next one */
  622. #if    COLOR
  623.         vscreen[sline]->v_rfcolor = wp->w_fcolor;
  624.         vscreen[sline]->v_rbcolor = wp->w_bcolor;
  625. #endif
  626.         vteeol();
  627.         ++sline;
  628.     }
  629.  
  630. }
  631.  
  632. /*    updpos:    update the position of the hardware cursor and handle extended
  633.         lines. This is the only update for simple moves.    */
  634.  
  635. updpos()
  636.  
  637. {
  638.     register LINE *lp;
  639.     register int c;
  640.     register int i;
  641.     int j, savcol, savrow;
  642.  
  643.     /* find the current row */
  644.     lp = curwp->w_linep;
  645.     currow = curwp->w_toprow + menuflag;
  646.     while (lp != curwp->w_dotp) {
  647.         ++currow;
  648.         lp = lforw(lp);
  649.     }
  650.  
  651.     /* find the current column */
  652.     curcol = 0;
  653.     i = 0;
  654.     while (i < curwp->w_doto) {
  655.         c = lgetc(lp, i++);
  656.         if (c == '\t')
  657.             curcol += tabsize - (curcol % tabsize) - 1;
  658.         else
  659.             if ((c&0x7F) < 0x20 || (c&0x7F) == 0x7f)
  660.                 ++curcol;
  661.  
  662.         ++curcol;
  663.     }
  664.  
  665.     /* if extended, flag so and update the virtual line image */
  666.     if (curcol < curwp->w_fcol || curcol - curwp->w_fcol >= term.t_ncol-1) {
  667.         if (hscroll) {
  668.             curcol -= curwp->w_fcol;
  669.             j = hjump;
  670.             if (j <= 0) j = 1;
  671.             if (j > term.t_ncol-1) j = term.t_ncol-1;
  672.             if (curcol > 0) j = -j;
  673.             while(curcol < 0 || curcol >= term.t_ncol-1) {
  674.                 curcol += j;
  675.                 curwp->w_fcol -= j;
  676.             }
  677.             if (curwp->w_fcol < 0) {
  678.                 curcol += curwp->w_fcol;
  679.                 curwp->w_fcol = 0;
  680.             }
  681.             curwp->w_flag |= WFHARD | WFMODE;
  682.             savcol = curcol; savrow = currow;
  683.             updall(curwp);
  684.             modeline(curwp);
  685.             curwp->w_flag &= ~(WFHARD | WFMODE);
  686.             taboff = lbound = curwp->w_fcol;
  687.             curcol = savcol+taboff; currow = savrow;
  688.         }
  689.         else {
  690.             vscreen[currow]->v_flag |= (VFEXT | VFCHG);
  691.             updext();
  692.         }
  693.     } else    {
  694.         taboff = lbound = curwp->w_fcol;
  695.     }
  696. }
  697.  
  698. /*    upddex:    de-extend any line that derserves it        */
  699.  
  700. upddex()
  701.  
  702. {
  703.     register WINDOW *wp;
  704.     register LINE *lp;
  705.     register int i;
  706.  
  707.     wp = wheadp;
  708.  
  709.     while (wp != NULL) {
  710.         lp = wp->w_linep;
  711.         i = wp->w_toprow + menuflag;
  712.  
  713.         while (i < wp->w_toprow + wp->w_ntrows + menuflag) {
  714.             if (vscreen[i]->v_flag & VFEXT) {
  715.                 if (wp != curwp || lp != wp->w_dotp ||
  716.                    (curcol - wp->w_fcol < term.t_ncol - 1 &&
  717.                     curcol >= wp->w_fcol)) {
  718.                     taboff = wp->w_fcol;
  719.                     vtmove(i, -taboff);
  720.                     if (lp != wp->w_bufp->b_linep)
  721.                         vtputl(lp);
  722.                     vteeol();
  723.  
  724.                     /* this line no longer is extended */
  725.                     vscreen[i]->v_flag &= ~VFEXT;
  726.                     vscreen[i]->v_flag |= VFCHG;
  727.                 }
  728.             }
  729.             if (lp != wp->w_bufp->b_linep) lp = lforw(lp);
  730.             ++i;
  731.         }
  732.         /* and onward to the next window */
  733.         wp = wp->w_wndp;
  734.     }
  735. }
  736.  
  737. /*    updgar:    if the screen is garbage, clear the physical screen and
  738.         the virtual screen and force a full update        */
  739.  
  740. updgar()
  741.  
  742. {
  743.     register char *txt;
  744.     register int i,j;
  745.  
  746.     for (i = 0; i < term.t_nrow; ++i) {
  747.         vscreen[i]->v_flag |= VFCHG;
  748. #if    REVSTA
  749.         vscreen[i]->v_flag &= ~VFREV;
  750. #endif
  751. #if    COLOR
  752.         vscreen[i]->v_fcolor = gfcolor;
  753.         vscreen[i]->v_bcolor = gbcolor;
  754. #endif
  755. #if    MEMMAP == 0
  756.         txt = pscreen[i]->v_text;
  757.         for (j = 0; j < term.t_ncol; ++j)
  758.             txt[j] = ' ';
  759. #endif
  760.     }
  761.  
  762. #if    VMSVT | TERMCAP
  763.     ttsetwid(term.t_ncol);
  764.     ttscroll(0, term.t_nrow, 0);
  765. #if    DECEDT
  766.     /* hack to force vt100's into keypad mode */
  767.     if (isvt100) { fastputc('\033'); fastputc('='); }
  768. #endif
  769. #endif
  770.     movecursor(0, 0);         /* Erase the screen. */
  771.     (*term.t_eeop)();
  772.     sgarbf = FALSE;             /* Erase-page clears */
  773.     i = mpresf;
  774.     mpresf = FALSE;             /* the message area. */
  775. #if    COLOR
  776.     mlerase();            /* needs to be cleared if colored */
  777. #endif
  778.     if (i)    mlwrite("%s", mlline);
  779.     didlins = didldel = 0;
  780. }
  781.  
  782. /*    updupd:    update the physical screen from the virtual screen    */
  783.  
  784. updupd(force)
  785.  
  786. int force;    /* forced update flag */
  787.  
  788. {
  789.     register VIDEO *vp1;
  790.     register int i;
  791. #if    VMSVT || TERMCAP
  792.     int n, r, j, k, cmp;
  793.  
  794.     if (didlins < 0 || didlins >= term.t_nrow) didlins = 0;
  795.     if (didldel < 0 || didldel >= term.t_nrow) didldel = 0;
  796. #endif
  797.  
  798.     for (i = 0; i < term.t_nrow; ++i) {
  799.         vp1 = vscreen[i];
  800.  
  801.         /* for each line that needs to be updated*/
  802.         if ((vp1->v_flag & VFCHG) != 0) {
  803. #if    TYPEAH
  804.             if (force != TRUE && typahead())
  805.                 return(ABORT);
  806. #endif
  807. #if    MEMMAP
  808.             lupdate(i, vp1);
  809. #else
  810. #if    VMSVT || TERMCAP
  811.             cmp = 1;
  812.             if (isvt100 && (didldel || didlins) &&
  813.                 (vp1->v_flag & (VFREV|VFREQ)) == 0 &&
  814.                 i+2 < term.t_nrow &&
  815.                 (vscreen[i+1]->v_flag & VFCHG) != 0 &&
  816.                 (vscreen[i+2]->v_flag & VFCHG) != 0 &&
  817.                 (cmp=strncmp(vp1->v_text, pscreen[i]->v_text,
  818.                     term.t_ncol)) != 0) {
  819.                 /* check for inserted lines */
  820.                 n = i+1; j = 1;
  821.                 /* look for a match further down */
  822.                 if (didlins)
  823.                   while (n < term.t_nrow &&
  824.                     ((vscreen[n]->v_flag&(VFREQ|VFREV))==0)&&
  825.                     strncmp(vscreen[n]->v_text,
  826.                         pscreen[n]->v_text, term.t_ncol)!=0 &&
  827.                     (j=strncmp(vscreen[n]->v_text,
  828.                         pscreen[i]->v_text, term.t_ncol))!=0 &&
  829.                     n-i < didlins)
  830.                         n++;
  831.                 r = i+1;
  832.                 n = n - i;
  833.                 /* see how many lines match */
  834.                 if (j == 0)
  835.                   while (r+n < term.t_nrow &&
  836.                     ((vscreen[r+n]->v_flag&(VFREQ|VFREV))==0)&&
  837.                     !strncmp(vscreen[r+n]->v_text,
  838.                         pscreen[r]->v_text, term.t_ncol))
  839.                         r++;
  840.                 /* scroll the lines */
  841.                 if (j == 0 && r > i+1) {
  842.                     r = r + n - 1;
  843.                     ttscroll(i, r, -n);
  844.                     for (j = 0; j < n; j++) {
  845.                         psave[j] = pscreen[r-j];
  846.                         for (k=0; k<term.t_ncol; k++)
  847.                             psave[j]->v_text[k] = ' ';
  848. #if    (TERMCAP | VMSVT) & COLOR
  849.                         if (usedcolor) {
  850.                           vscreen[i+j]->v_flag |=
  851.                                 VFCHG | VFCOL;
  852.                           vscreen[i+j]->v_fcolor = 7;
  853.                           vscreen[i+j]->v_bcolor = 0;
  854.                           lupdate(i+j,
  855.                             vscreen[i+j],
  856.                             pscreen[r-j]);
  857.                         }
  858. #endif
  859.                     }
  860.                     for (j = r; j >= i+n; j--) {
  861.                         pscreen[j] = pscreen[j-n];
  862.                         vscreen[j]->v_flag &=
  863.                           ~(VFCHG | VFCOL | VFSCROL);
  864.                     }
  865.                     for (j = 0; j < n; j++)
  866.                         pscreen[i+j] = psave[j];
  867.                 }
  868.                 else if (didldel) {
  869.                 /* check for deleted lines */
  870.                 n = i+1; j = 1;
  871.                 while (n < term.t_nrow &&
  872.                     ((vscreen[n]->v_flag&(VFREQ|VFREV))==0)&&
  873.                     strncmp(vscreen[n]->v_text,
  874.                         pscreen[n]->v_text, term.t_ncol)!=0 &&
  875.                     (j=strncmp(vscreen[i]->v_text,
  876.                         pscreen[n]->v_text, term.t_ncol))!=0 &&
  877.                     n-i < didldel)
  878.                         n++;
  879.                 r = i+1;
  880.                 n = n - i;
  881.                 if (j == 0)
  882.                   while (r+n < term.t_nrow &&
  883.                     ((vscreen[r+n]->v_flag&(VFREQ|VFREV))==0)&&
  884.                     !strncmp(vscreen[r]->v_text,
  885.                         pscreen[r+n]->v_text, term.t_ncol))
  886.                         r++;
  887.                 if (j == 0 && r > i+1) {
  888.                     r = r + n - 1;
  889.                     ttscroll(i, r, n);
  890.                     for (j = 0; j < n; j++) {
  891.                         psave[j] = pscreen[i+j];
  892.                         for (k=0; k<term.t_ncol; k++)
  893.                             psave[j]->v_text[k] = ' ';
  894. #if    (TERMCAP | VMSVT) & COLOR
  895.                         if (usedcolor) {
  896.                           vscreen[r-j]->v_flag |=
  897.                                 VFCHG | VFCOL;
  898.                           vscreen[r-j]->v_fcolor = 7;
  899.                           vscreen[r-j]->v_bcolor = 0;
  900.                           lupdate(r-j,
  901.                             vscreen[r-j],
  902.                             pscreen[i+j]);
  903.                         }
  904. #endif
  905.                     }
  906.                     for (j = i; j <= r-n; j++) {
  907.                         pscreen[j] = pscreen[j+n];
  908.                         vscreen[j]->v_flag &=
  909.                           ~(VFCHG | VFCOL | VFSCROL);
  910.                     }
  911.                     for (j = 0; j < n; j++)
  912.                         pscreen[r-j] = psave[j];
  913.                 }
  914.                 }
  915.             }
  916.             if (cmp) lupdate(i, vp1, pscreen[i]);
  917.             else vp1->v_flag &= ~(VFCHG | VFCOL | VFSCROL);
  918. #else
  919.             lupdate(i, vp1, pscreen[i]);
  920. #endif
  921. #endif
  922.         }
  923.     }
  924.     didlins = didldel = 0;
  925.     return(TRUE);
  926. }
  927.  
  928. /*    updext: update the extended line which the cursor is currently
  929.         on at a column greater than the terminal width. The line
  930.         will be scrolled right or left to let the user see where
  931.         the cursor is
  932.                                 */
  933.  
  934. updext()
  935.  
  936. {
  937.     register int rcursor;    /* real cursor location */
  938.     register LINE *lp;    /* pointer to current line */
  939.     int islong;
  940.  
  941.     /* calculate what column the real cursor will end up in */
  942.     islong = (curcol >= curwp->w_fcol);
  943.     if (islong)
  944.         rcursor = (curcol - curwp->w_fcol - term.t_ncol) % term.t_scrsiz
  945.                 + term.t_margin + 1;
  946.     else    {
  947.         rcursor = term.t_scrsiz -
  948.                 ((curwp->w_fcol - curcol) % term.t_scrsiz);
  949.         if (rcursor > curcol) rcursor = curcol;
  950.     }
  951.     taboff = lbound = curcol - rcursor;
  952.  
  953.     /* scan through the line outputing characters to the virtual screen */
  954.     /* once we reach the left edge                    */
  955.     vtmove(currow, -taboff);    /* start scanning offscreen */
  956.     lp = curwp->w_dotp;        /* line to output */
  957.     vtputl(lp);
  958.  
  959.     /* truncate the virtual line, restore tab offset */
  960.     vteeol();
  961.     taboff = 0;
  962.  
  963.     /* and put a '$' in column 1 */
  964.     if (islong)
  965.         vscreen[currow]->v_text[0] = '$';
  966. }
  967.  
  968. /*
  969.  * Update a single line. This does not know how to use insert or delete
  970.  * character sequences; we are using VT52 functionality. Update the physical
  971.  * row and column variables. It does try an exploit erase to end of line. The
  972.  * RAINBOW version of this routine uses fast video.
  973.  */
  974. #if    MEMMAP
  975. /*    lupdate specific code for the IBM-PC and other compatables */
  976.  
  977. lupdate(row, vp1)
  978.  
  979. int row;        /* row of screen to update */
  980. VIDEO *vp1;        /* virtual screen image */
  981.  
  982. {
  983. #if    COLOR
  984.     scwrite(row, vp1->v_text, vp1->v_rfcolor, vp1->v_rbcolor);
  985.     vp1->v_fcolor = vp1->v_rfcolor;
  986.     vp1->v_bcolor = vp1->v_rbcolor;
  987. #else
  988.     if (vp1->v_flag & VFREQ)
  989.         scwrite(row, vp1->v_text, 0, 7);
  990.     else
  991.         scwrite(row, vp1->v_text, 7, 0);
  992. #endif
  993.     /* flag this line as changed */
  994.     vp1->v_flag &= ~(VFCHG | VFCOL | VFSCROL);
  995.  
  996. }
  997.  
  998. #else
  999.  
  1000. lupdate(row, vp1, vp2)
  1001.  
  1002. int row;        /* row of screen to update */
  1003. VIDEO *vp1;        /* virtual screen image */
  1004. VIDEO *vp2;        /* physical screen image */
  1005.  
  1006. {
  1007. #if RAINBOW
  1008. /*    lupdate specific code for the DEC rainbow 100 micro    */
  1009.  
  1010.     register char *cp1;
  1011.     register char *cp2;
  1012.     register int nch;
  1013.  
  1014.     /* since we don't know how to make the rainbow do this, turn it off */
  1015.     flags &= (~VFREV & ~VFREQ);
  1016.  
  1017.     cp1 = &vp1->v_text[0];                    /* Use fast video. */
  1018.     cp2 = &vp2->v_text[0];
  1019.     putline(row+1, 1, cp1);
  1020.     nch = term.t_ncol;
  1021.  
  1022.     do
  1023.         {
  1024.         *cp2 = *cp1;
  1025.         ++cp2;
  1026.         ++cp1;
  1027.         }
  1028.     while (--nch);
  1029.     *flags &= ~(VFCHG | VFSCROL);
  1030. #else
  1031. /*    lupdate code for all other versions        */
  1032.  
  1033.     register char *cp1;
  1034.     register char *cp2;
  1035.     register char *cp3;
  1036.     register char *cp4;
  1037.     register char *cp5;
  1038.     register int nbflag;    /* non-blanks to the right flag? */
  1039.     int rev;        /* reverse video flag */
  1040.     int req;        /* reverse video request flag */
  1041.  
  1042.  
  1043.     /* set up pointers to virtual and physical lines */
  1044.     cp1 = &vp1->v_text[0];
  1045.     cp2 = &vp2->v_text[0];
  1046.  
  1047. #if    COLOR
  1048.     TTforg(vp1->v_rfcolor);
  1049.     TTbacg(vp1->v_rbcolor);
  1050. #endif
  1051.  
  1052. #if    REVSTA | COLOR
  1053.     /* if we need to change the reverse video status of the
  1054.        current line, we need to re-write the entire line     */
  1055.     rev = (vp1->v_flag & VFREV) == VFREV;
  1056.     req = (vp1->v_flag & VFREQ) == VFREQ;
  1057.     if ((rev != req)
  1058. #if    COLOR
  1059.         || (vp1->v_fcolor != vp1->v_rfcolor) || (vp1->v_bcolor != vp1->v_rbcolor)
  1060. #endif
  1061. #if    HP150
  1062.     /* the HP150 has some reverse video problems */
  1063.         || req || rev
  1064. #endif
  1065.             ) {
  1066.         movecursor(row, 0);    /* Go to start of line. */
  1067.         /* set rev video if needed */
  1068.         if (rev != req)
  1069.             (*term.t_rev)(req);
  1070.  
  1071.         /* scan through the line and dump it to the screen and
  1072.            the virtual screen array                */
  1073.         cp3 = &vp1->v_text[term.t_ncol];
  1074.         while (cp1 < cp3) {
  1075.             fastputc(*cp1);
  1076.             ++ttcol;
  1077.             *cp2++ = *cp1++;
  1078.         }
  1079.         /* turn rev video off */
  1080.         if (rev != req)
  1081.             (*term.t_rev)(FALSE);
  1082.  
  1083.         /* update the needed flags */
  1084.         vp1->v_flag &= ~(VFCHG | VFSCROL);
  1085.         if (req)
  1086.             vp1->v_flag |= VFREV;
  1087.         else
  1088.             vp1->v_flag &= ~VFREV;
  1089. #if    COLOR
  1090.         vp1->v_fcolor = vp1->v_rfcolor;
  1091.         vp1->v_bcolor = vp1->v_rbcolor;
  1092. #endif
  1093.         return(TRUE);
  1094.     }
  1095. #endif
  1096.  
  1097.     /* advance past any common chars at the left */
  1098.     while (cp1 != &vp1->v_text[term.t_ncol] && cp1[0] == cp2[0]) {
  1099.         ++cp1;
  1100.         ++cp2;
  1101.     }
  1102.  
  1103. /* This can still happen, even though we only call this routine on changed
  1104.  * lines. A hard update is always done when a line splits, a massive
  1105.  * change is done, or a buffer is displayed twice. This optimizes out most
  1106.  * of the excess updating. A lot of computes are used, but these tend to
  1107.  * be hard operations that do a lot of update, so I don't really care.
  1108.  */
  1109.     /* if both lines are the same, no update needs to be done */
  1110.     if (cp1 == &vp1->v_text[term.t_ncol]) {
  1111.          vp1->v_flag &= ~(VFCHG | VFSCROL);
  1112.         return(FALSE);        /* signal that nothing was done */
  1113.     }
  1114.  
  1115.     /* find out if there is a match on the right */
  1116.     nbflag = FALSE;
  1117.     cp3 = &vp1->v_text[term.t_ncol];
  1118.     cp4 = &vp2->v_text[term.t_ncol];
  1119.  
  1120.     while (cp3[-1] == cp4[-1]) {
  1121.         --cp3;
  1122.         --cp4;
  1123.         if (cp3[0] != ' ')        /* Note if any nonblank */
  1124.             nbflag = TRUE;        /* in right match. */
  1125.     }
  1126.  
  1127.     cp5 = cp3;
  1128.  
  1129.     /* Erase to EOL ? */
  1130.     if (nbflag == FALSE && eolexist == TRUE
  1131. #if    REVSTA | COLOR
  1132.         && (req != TRUE)
  1133. #endif
  1134.         ) {
  1135.         while (cp5!=cp1 && cp5[-1]==' ')
  1136.             --cp5;
  1137.  
  1138.         if (cp3-cp5 <= 3)        /* Use only if erase is */
  1139.             cp5 = cp3;        /* fewer characters. */
  1140.     }
  1141.  
  1142.     movecursor(row, cp1 - &vp1->v_text[0]);
  1143.  
  1144. #if    REVSTA
  1145.     TTrev(rev);
  1146. #endif
  1147.  
  1148.     while (cp1 != cp5) {        /* Ordinary. */
  1149.         fastputc(*cp1);
  1150.         ++ttcol;
  1151.         *cp2++ = *cp1++;
  1152.     }
  1153.  
  1154.     if (cp5 != cp3) {        /* Erase. */
  1155.         TTeeol();
  1156.         while (cp1 != cp3)
  1157.             *cp2++ = *cp1++;
  1158.     }
  1159. #if    REVSTA
  1160.     TTrev(FALSE);
  1161. #endif
  1162.     vp1->v_flag &= ~(VFCHG | VFSCROL);    /* flag this line as updated */
  1163.     return(TRUE);
  1164. #endif
  1165. }
  1166. #endif
  1167.  
  1168. /*
  1169.  * Redisplay the mode line for the window pointed to by the "wp". This is the
  1170.  * only routine that has any idea of how the modeline is formatted. You can
  1171.  * change the modeline format by hacking at this routine. Called by "update"
  1172.  * any time there is a dirty window.
  1173.  */
  1174. modeline(wp)
  1175.     WINDOW *wp;
  1176. {
  1177.     register char *cp;
  1178.     register int c;
  1179.     register int n;        /* cursor position count */
  1180.     register BUFFER *bp;
  1181.     register i;            /* loop index */
  1182.     register lchar;        /* character to draw line in buffer with */
  1183.     register firstm;        /* is this the first mode? */
  1184.  
  1185.     n = wp->w_toprow + wp->w_ntrows + menuflag;    /* Location. */
  1186.  
  1187.     vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL;/* Redraw next time. */
  1188. #if    COLOR
  1189.     vscreen[n]->v_rfcolor = 0;            /* black on */
  1190.     vscreen[n]->v_rbcolor = 7;            /* white.....*/
  1191. #endif
  1192.     taboff = 0;
  1193.     vtmove(n, 0);                           /* Seek to right line. */
  1194.     if (wp == curwp)                /* mark the current buffer */
  1195.     lchar = '=';
  1196.     else
  1197. #if    REVSTA
  1198.     if (revexist)
  1199.         lchar = ' ';
  1200.     else
  1201. #endif
  1202.         lchar = '-';
  1203.  
  1204.     vtputc(lchar);
  1205.     bp = wp->w_bufp;
  1206.  
  1207.     if ((bp->b_flag&BFCHG) != 0)                /* "*" if changed. */
  1208.         vtputc('*');
  1209.     else
  1210.         vtputc(lchar);
  1211.  
  1212.     if ((bp->b_flag&BFTRUNC) != 0)                /* "#" if truncated. */
  1213.         vtputc('#');
  1214.     else
  1215.         vtputc(lchar);
  1216.  
  1217.     if ((bp->b_flag&BFNAROW) != 0)                /* "<>" if narrowed. */
  1218.         { vtputc('<'); vtputc('>'); }
  1219.     else
  1220.         { vtputc(lchar); vtputc(lchar); }
  1221.  
  1222.     n  = 11;    /* =,#,*,<,>, , , ,(,),  */
  1223.     vtputc(' ');                /* Buffer name. */
  1224.     n += vtputs(PROGNAME);
  1225.     vtputc(' ');
  1226.     n += vtputs(VERSION);
  1227.     vtputc(' ');
  1228.  
  1229.     /* are we horizontally scrolled? */
  1230.     if (wp->w_fcol > 0) {
  1231.         vtputc('[');
  1232.         vtputc('<');
  1233.         n += 4 + vtputs(itoa(wp->w_fcol));
  1234.         vtputc(']');
  1235.         vtputc(' ');
  1236.     }
  1237.     vtputc('(');
  1238.  
  1239.     /* display the modes */
  1240.  
  1241.     firstm = TRUE;
  1242.     for (i = 0; i < NUMMODES; i++)    /* add in the mode flags */
  1243.         if (wp->w_bufp->b_mode & (1 << i)) {
  1244.             if (firstm != TRUE)
  1245.                 {++n; vtputc(' ');}
  1246.             firstm = FALSE;
  1247.             n += vtputs(modename[i]);
  1248.         }
  1249.     vtputc(')');
  1250.     vtputc(' ');
  1251.  
  1252. #if 0
  1253.     vtputc(lchar);
  1254.     vtputc((wp->w_flag&WFCOLR) != 0  ? 'C' : lchar);
  1255.     vtputc((wp->w_flag&WFMODE) != 0  ? 'M' : lchar);
  1256.     vtputc((wp->w_flag&WFHARD) != 0  ? 'H' : lchar);
  1257.     vtputc((wp->w_flag&WFEDIT) != 0  ? 'E' : lchar);
  1258.     vtputc((wp->w_flag&WFMOVE) != 0  ? 'V' : lchar);
  1259.     vtputc((wp->w_flag&WFFORCE) != 0 ? 'F' : lchar);
  1260.     vtputc(lchar);
  1261.     n += 8;
  1262. #endif
  1263.  
  1264.     vtputc(lchar);
  1265.     vtputc(lchar);
  1266.     vtputc(' ');
  1267.     n += 3;
  1268.     cp = &bp->b_bname[0];
  1269.  
  1270.     while ((c = *cp++) != 0)
  1271.         {
  1272.         vtputc(c);
  1273.         ++n;
  1274.         }
  1275.  
  1276.     vtputc(' ');
  1277.     vtputc(lchar);
  1278.     vtputc(lchar);
  1279.     n += 3;
  1280.  
  1281.     if (bp->b_fname[0] != 0)            /* File name. */
  1282.         {
  1283.     vtputc(' ');
  1284.     n += 2 + vtputs("File: ");
  1285.  
  1286.         cp = &bp->b_fname[0];
  1287.  
  1288.         while ((c = *cp++) != 0)
  1289.             {
  1290.             vtputc(c);
  1291.             ++n;
  1292.             }
  1293.  
  1294.     vtputc(' ');
  1295.         }
  1296.  
  1297.     while (n < term.t_ncol)             /* Pad to full width. */
  1298.         {
  1299.         vtputc(lchar);
  1300.         ++n;
  1301.         }
  1302. }
  1303.  
  1304. upmode()    /* update all the mode lines */
  1305.  
  1306. {
  1307.     register WINDOW *wp;
  1308.  
  1309.     wp = wheadp;
  1310.     while (wp != NULL) {
  1311.         wp->w_flag |= WFMODE;
  1312.         wp = wp->w_wndp;
  1313.     }
  1314. }
  1315.  
  1316. upwind()    /* force hard updates on all windows */
  1317. {
  1318.     register WINDOW *wp;
  1319.  
  1320.     wp = wheadp;
  1321.     while (wp != NULL) {
  1322.         wp->w_flag |= WFHARD | WFMODE;
  1323.         wp = wp->w_wndp;
  1324.     }
  1325. }
  1326.  
  1327. /*
  1328.  * Send a command to the terminal to move the hardware cursor to row "row"
  1329.  * and column "col". The row and column arguments are origin 0. Optimize out
  1330.  * random calls. Update "ttrow" and "ttcol".
  1331.  */
  1332. movecursor(row, col)
  1333.     {
  1334.     if (row!=ttrow || col!=ttcol)
  1335.         {
  1336.         ttrow = row;
  1337.         ttcol = col;
  1338.         TTmove(row, col);
  1339.         }
  1340.     }
  1341.  
  1342. /*
  1343.  * Erase the message line. This is a special routine because the message line
  1344.  * is not considered to be part of the virtual screen. It always works
  1345.  * immediately; the terminal buffer is flushed via a call to the flusher.
  1346.  */
  1347. mlerase()
  1348.     {
  1349.     int i;
  1350.     
  1351.     movecursor(term.t_nrow, 0);
  1352.  
  1353.     if (discmd == FALSE)
  1354.     return;
  1355.  
  1356. #if    COLOR
  1357.      TTforg(7);
  1358.      TTbacg(0);
  1359. #endif
  1360.     if (eolexist == TRUE)
  1361.         TTeeol();
  1362.     else {
  1363.         for (i = 0; i < term.t_ncol - 1; i++)
  1364.             fastputc(' ');
  1365.         movecursor(term.t_nrow, 1);    /* force the move! */
  1366.         movecursor(term.t_nrow, 0);
  1367.     }
  1368.     TTflush();
  1369.     mpresf = FALSE;
  1370.     }
  1371.  
  1372. /*
  1373.  * Write a message into the message line. Keep track of the physical cursor
  1374.  * position. A small class of printf like format items is handled. Assumes the
  1375.  * stack grows down; this assumption is made by the "++" in the argument scan
  1376.  * loop. Set the "message line" flag TRUE.
  1377.  */
  1378.  
  1379. /*VARARGS*/
  1380.  
  1381. mlwrite(fmt, arg)
  1382.     char *fmt;        /* format string for output */
  1383.     char *arg;        /* pointer to first argument to print */
  1384.     {
  1385.     register int c;    /* current char in format string */
  1386.     register char *ap;    /* ptr to current data field */
  1387.     char *s;
  1388.     int i, f;
  1389.  
  1390.     /* if we are not currently echoing the command line, abort this */
  1391.  
  1392.     if (discmd == FALSE) {
  1393.     movecursor(term.t_nrow, 0);
  1394.     return;
  1395.     }
  1396.  
  1397. #if    COLOR
  1398.     TTforg(7);
  1399.     TTbacg(0);
  1400. #endif
  1401.  
  1402.     /* if we can not erase to end-of-line, do it manually */
  1403.  
  1404.     if (eolexist == FALSE && mpresf == TRUE) {
  1405.         mlerase();
  1406.         TTflush();
  1407.     }
  1408.  
  1409.     mllen = 0;
  1410.     movecursor(term.t_nrow, 0);
  1411.     ap = (char *) &arg;
  1412.     while ((c = *fmt++) != 0 && mllen < term.t_ncol) {
  1413.         if (c != '%') {
  1414.             mlline[mllen++] = c;
  1415.             }
  1416.         else
  1417.             {
  1418.             c = *fmt++;
  1419.             switch (c) {
  1420.                 case 'd':
  1421.                     mlputi(*(int *)ap, 10);
  1422.                     ap += sizeof(int);
  1423.                     break;
  1424.  
  1425.                 case 'o':
  1426.                     mlputi(*(int *)ap,  8);
  1427.                     ap += sizeof(int);
  1428.                     break;
  1429.  
  1430.                 case 'x':
  1431.                     mlputi(*(int *)ap, 16);
  1432.                     ap += sizeof(int);
  1433.                     break;
  1434.  
  1435.                 case 'D':
  1436.                     mlputli(*(long *)ap, 10);
  1437.                     ap += sizeof(long);
  1438.                     break;
  1439.  
  1440.                 case 's':
  1441.                     s = *(char **)ap;
  1442.                     ap += sizeof(char *);
  1443.             while (*s != '\0') mlline[mllen++] = *s++;
  1444.                     break;
  1445.  
  1446.         case 'f':
  1447.             /* break it up */
  1448.             i = *(int *) ap;
  1449.             f = i % 100;
  1450.  
  1451.             /* send out the integer portion */
  1452.             mlputi(i / 100, 10);
  1453.             mlline[mllen++] = '.';
  1454.             mlline[mllen++] = (f / 10) + '0';
  1455.             mlline[mllen++] = (f % 10) + '0';
  1456.  
  1457.             ap += sizeof(int);
  1458.             break;
  1459.  
  1460.                 default:
  1461.             mlline[mllen++] = c;
  1462.                 }
  1463.             }
  1464.         }
  1465.  
  1466.     if (mllen >= term.t_ncol) mllen = term.t_ncol - 1;
  1467.     mlline[mllen] = '\0';
  1468.     ttcol += mllen;
  1469.     for(ap = mlline; *ap; ap++)
  1470.     fastputc(*ap);
  1471.  
  1472.     /* if we can, erase to the end of screen */
  1473.  
  1474.     if (eolexist == TRUE && mpresf == TRUE)
  1475.         TTeeol();
  1476.     TTflush();
  1477.     mpresf = ((mllen > 0)? TRUE: FALSE);
  1478.     }
  1479.  
  1480. /*
  1481.  * Force a string out to the message line regardless of the
  1482.  * current $discmd setting. This is needed when $debug is TRUE
  1483.  * and for the write-message and clear-message-line commands
  1484.  */
  1485. mlforce(s)
  1486.     char *s;    /* string to force out */
  1487. {
  1488.     register oldcmd;    /* original command display flag */
  1489.  
  1490.     oldcmd = discmd;    /* save the discmd value */
  1491.     discmd = TRUE;        /* and turn display on */
  1492.     mlwrite(s);        /* write the string out */
  1493.     discmd = oldcmd;    /* and restore the original setting */
  1494. }
  1495.  
  1496. /*
  1497.  * Write out a string. Update the physical cursor position. This assumes that
  1498.  * the characters in the string all have width "1"; if this is not the case
  1499.  * things will get screwed up a little.
  1500.  */
  1501. mlputs(s)
  1502.     char *s;
  1503.     {
  1504.     register int c;
  1505.  
  1506.     while ((c = *s++) != 0)
  1507.         {
  1508.         fastputc(c);
  1509.         ++ttcol;
  1510.         }
  1511.     }
  1512.  
  1513. /*
  1514.  * do the same except as a long integer.
  1515.  */
  1516.  
  1517. mlputli(l, r)
  1518.     long l;
  1519.     {
  1520.     register long q;
  1521.     int digit;
  1522.  
  1523.     if (l < 0)
  1524.         {
  1525.         l = -l;
  1526.         mlline[mllen++] = '-';
  1527.         }
  1528.  
  1529.     q = l/r;
  1530.  
  1531.     if (q != 0)
  1532.         mlputli(q, r);
  1533.  
  1534.     digit = (int)(l%r);
  1535.     mlline[mllen++] = ((digit < 10)? '0'+digit: 'A'+digit-10);
  1536.     }
  1537.  
  1538. /*
  1539.  * Write out an integer, in the specified radix using mlputli.
  1540.  */
  1541. mlputi(i, r)
  1542.     {
  1543.     mlputli( (long) i, r);
  1544.     }
  1545.  
  1546. #if RAINBOW
  1547.  
  1548. putline(row, col, buf)
  1549.     int row, col;
  1550.     char buf[];
  1551.     {
  1552.     int n;
  1553.  
  1554.     n = strlen(buf);
  1555.     if (col + n - 1 > term.t_ncol)
  1556.         n = term.t_ncol - col + 1;
  1557.     Put_Data(row, col, n, buf);
  1558.     }
  1559. #endif
  1560.  
  1561.