home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / mxterm.zip / mxterm / screen.c < prev    next >
C/C++ Source or Header  |  1992-10-17  |  20KB  |  689 lines

  1. /*
  2.  *    $XConsortium: screen.c,v 1.30 91/08/22 16:27:13 gildea Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  7.  *
  8.  *                         All Rights Reserved
  9.  *
  10.  * Permission to use, copy, modify, and distribute this software and its
  11.  * documentation for any purpose and without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and that
  13.  * both that copyright notice and this permission notice appear in
  14.  * supporting documentation, and that the name of Digital Equipment
  15.  * Corporation not be used in advertising or publicity pertaining to
  16.  * distribution of the software without specific, written prior permission.
  17.  *
  18.  *
  19.  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  21.  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  23.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  24.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  25.  * SOFTWARE.
  26.  */
  27.  
  28. /* screen.c */
  29.  
  30. #include "ptyx.h"
  31. #include "error.h"
  32. #include "data.h"
  33.  
  34. #include <stdio.h>
  35. #include <signal.h>
  36. #ifdef SVR4
  37. #include <termios.h>
  38. #else
  39. #include <sys/ioctl.h>
  40. #endif
  41.  
  42. #ifdef att
  43. #include <sys/termio.h>
  44. #include <sys/stream.h>            /* get typedef used in ptem.h */
  45. #include <sys/ptem.h>
  46. #endif
  47.  
  48. extern Char *calloc(), *malloc(), *realloc();
  49. extern void free();
  50.  
  51. ScrnBuf Allocate (nrow, ncol, addr)
  52. /*
  53.    allocates memory for a 2-dimensional array of chars and returns a pointer
  54.    thereto
  55.    each line is formed from a pair of char arrays.  The first (even) one is
  56.    the actual character array and the second (odd) one is the attributes.
  57.  */
  58. register int nrow, ncol;
  59. Char **addr;
  60. {
  61.     register ScrnBuf base;
  62.     register Char *tmp;
  63.     register int i;
  64.  
  65.     if ((base = (ScrnBuf) calloc ((unsigned)(nrow *= 2), sizeof (char *))) == 0)
  66.         SysError (ERROR_SCALLOC);
  67.  
  68.     if ((tmp = calloc ((unsigned) (nrow * ncol), sizeof(char))) == 0)
  69.         SysError (ERROR_SCALLOC2);
  70.  
  71.     *addr = tmp;
  72.     for (i = 0; i < nrow; i++, tmp += ncol)
  73.         base[i] = tmp;
  74.  
  75.     return (base);
  76. }
  77.  
  78. /*
  79.  *  This is called when the screen is resized.
  80.  *  Returns the number of lines the text was moved down (neg for up).
  81.  *  (Return value only necessary with SouthWestGravity.)
  82.  */
  83. static
  84. Reallocate(sbuf, sbufaddr, nrow, ncol, oldrow, oldcol)
  85.     ScrnBuf *sbuf;
  86.     Char **sbufaddr;
  87.     int nrow, ncol, oldrow, oldcol;
  88. {
  89.     register ScrnBuf base;
  90.     register Char *tmp;
  91.     register int i, minrows, mincols;
  92.     Char *oldbuf;
  93.     int move_down = 0, move_up = 0;
  94.     
  95.     if (sbuf == NULL || *sbuf == NULL)
  96.         return 0;
  97.  
  98.     oldrow *= 2;
  99.     oldbuf = *sbufaddr;
  100.  
  101.     /*
  102.      * Special case if oldcol == ncol - straight forward realloc and
  103.      * update of the additional lines in sbuf
  104.      */
  105.  
  106.     /* this is a good idea, but doesn't seem to be implemented.  -gildea */
  107.  
  108.     /* 
  109.      * realloc sbuf, the pointers to all the lines.
  110.      * If the screen shrinks, remove lines off the top of the buffer
  111.      * if resizeGravity resource says to do so.
  112.      */
  113.     nrow *= 2;
  114.     if (nrow < oldrow  &&  term->misc.resizeGravity == SouthWestGravity) {
  115.         /* Remove lines off the top of the buffer if necessary. */
  116.         move_up = oldrow-nrow 
  117.                 - 2*(term->screen.max_row - term->screen.cur_row);
  118.         if (move_up < 0)
  119.         move_up = 0;
  120.         /* Overlapping bcopy here! */
  121.         bcopy(*sbuf+move_up, *sbuf,
  122.           (oldrow-move_up)*sizeof((*sbuf)[0]) );
  123.     }
  124.     *sbuf = (ScrnBuf) realloc((char *) (*sbuf),
  125.                   (unsigned) (nrow * sizeof(char *)));
  126.     if (*sbuf == 0)
  127.         SysError(ERROR_RESIZE);
  128.     base = *sbuf;
  129.  
  130.     /* 
  131.      *  create the new buffer space and copy old buffer contents there
  132.      *  line by line.
  133.      */
  134.     if ((tmp = calloc((unsigned) (nrow * ncol), sizeof(char))) == 0)
  135.         SysError(ERROR_SREALLOC);
  136.     *sbufaddr = tmp;
  137.     minrows = (oldrow < nrow) ? oldrow : nrow;
  138.     mincols = (oldcol < ncol) ? oldcol : ncol;
  139.     if (nrow > oldrow  &&  term->misc.resizeGravity == SouthWestGravity) {
  140.         /* move data down to bottom of expanded screen */
  141.         move_down = Min(nrow-oldrow, 2*term->screen.savedlines);
  142.         tmp += ncol*move_down;
  143.     }
  144.     for (i = 0; i < minrows; i++, tmp += ncol) {
  145.         bcopy(base[i], tmp, mincols);
  146.     }
  147.     /*
  148.      * update the pointers in sbuf
  149.      */
  150.     for (i = 0, tmp = *sbufaddr; i < nrow; i++, tmp += ncol)
  151.         base[i] = tmp;
  152.  
  153.         /* Now free the old buffer */
  154.     free(oldbuf);
  155.  
  156.     return move_down ? move_down/2 : -move_up/2; /* convert to rows */
  157. }
  158.  
  159. ScreenWrite (screen, str, flags, length)
  160. /*
  161.    Writes str into buf at row row and column col.  Characters are set to match
  162.    flags.
  163.  */
  164. TScreen *screen;
  165. char *str;
  166. register unsigned flags;
  167. register int length;        /* length of string */
  168. {
  169.     register Char *attrs;
  170.     register int avail  = screen->max_col - screen->cur_col + 1;
  171.     register Char *col;
  172.  
  173.     if (length > avail)
  174.         length = avail;
  175.     if (length <= 0)
  176.         return;
  177.  
  178.     col = screen->buf[avail = 2 * screen->cur_row] + screen->cur_col;
  179.     attrs = screen->buf[avail + 1] + screen->cur_col;
  180.     flags &= ATTRIBUTES;
  181.     flags |= CHARDRAWN;
  182.     bcopy(str, col, length);
  183.     while(length-- > 0)
  184.         *attrs++ = flags;
  185. }
  186.  
  187. ScrnInsertLine (sb, last, where, n, size)
  188. /*
  189.    Inserts n blank lines at sb + where, treating last as a bottom margin.
  190.    Size is the size of each entry in sb.
  191.    Requires: 0 <= where < where + n <= last
  192.             n <= MAX_ROWS
  193.  */
  194. register ScrnBuf sb;
  195. int last;
  196. register int where, n, size;
  197. {
  198.     register int i;
  199.     char *save [2 * MAX_ROWS];
  200.  
  201.  
  202.     /* save n lines at bottom */
  203.     bcopy ((char *) &sb [2 * (last -= n - 1)], (char *) save,
  204.         2 * sizeof (char *) * n);
  205.     
  206.     /* clear contents of old rows */
  207.     for (i = 2 * n - 1; i >= 0; i--)
  208.         bzero ((char *) save [i], size);
  209.  
  210.     /*
  211.      * WARNING, overlapping copy operation.  Move down lines (pointers).
  212.      *
  213.      *   +----|---------|--------+
  214.      *
  215.      * is copied in the array to:
  216.      *
  217.      *   +--------|---------|----+
  218.      */
  219.     bcopy ((char *) &sb [2 * where], (char *) &sb [2 * (where + n)],
  220.         2 * sizeof (char *) * (last - where));
  221.  
  222.     /* reuse storage for new lines at where */
  223.     bcopy ((char *)save, (char *) &sb[2 * where], 2 * sizeof(char *) * n);
  224. }
  225.  
  226.  
  227. ScrnDeleteLine (sb, last, where, n, size)
  228. /*
  229.    Deletes n lines at sb + where, treating last as a bottom margin.
  230.    Size is the size of each entry in sb.
  231.    Requires 0 <= where < where + n < = last
  232.            n <= MAX_ROWS
  233.  */
  234. register ScrnBuf sb;
  235. register int n, last, size;
  236. int where;
  237. {
  238.     register int i;
  239.     char *save [2 * MAX_ROWS];
  240.  
  241.     /* save n lines at where */
  242.     bcopy ((char *) &sb[2 * where], (char *)save, 2 * sizeof(char *) * n);
  243.  
  244.     /* clear contents of old rows */
  245.     for (i = 2 * n - 1 ; i >= 0 ; i--)
  246.         bzero ((char *) save [i], size);
  247.  
  248.     /* move up lines */
  249.     bcopy ((char *) &sb[2 * (where + n)], (char *) &sb[2 * where],
  250.         2 * sizeof (char *) * ((last -= n - 1) - where));
  251.  
  252.     /* reuse storage for new bottom lines */
  253.     bcopy ((char *)save, (char *) &sb[2 * last],
  254.         2 * sizeof(char *) * n);
  255. }
  256.  
  257.  
  258. ScrnInsertChar (sb, row, col, n, size)
  259.     /*
  260.       Inserts n blanks in sb at row, col.  Size is the size of each row.
  261.       */
  262.     ScrnBuf sb;
  263.     int row, size;
  264.     register int col, n;
  265. {
  266.     register int i, j;
  267.     register Char *ptr = sb [2 * row];
  268.     register Char *attrs = sb [2 * row + 1];
  269.     int wrappedbit = attrs[0]&LINEWRAPPED;
  270.  
  271.     attrs[0] &= ~LINEWRAPPED; /* make sure the bit isn't moved */
  272.     for (i = size - 1; i >= col + n; i--) {
  273.         ptr[i] = ptr[j = i - n];
  274.         attrs[i] = attrs[j];
  275.     }
  276.  
  277.     for (i=col; i<col+n; i++)
  278.         ptr[i] = ' ';
  279.     for (i=col; i<col+n; i++)
  280.         attrs[i] = CHARDRAWN;
  281.  
  282.     if (wrappedbit)
  283.         attrs[0] |= LINEWRAPPED;
  284. }
  285.  
  286.  
  287. ScrnDeleteChar (sb, row, col, n, size)
  288.     /*
  289.       Deletes n characters in sb at row, col. Size is the size of each row.
  290.       */
  291.     ScrnBuf sb;
  292.     register int row, size;
  293.     register int n, col;
  294. {
  295.     register Char *ptr = sb[2 * row];
  296.     register Char *attrs = sb[2 * row + 1];
  297.     register nbytes = (size - n - col);
  298.     int wrappedbit = attrs[0]&LINEWRAPPED;
  299.  
  300.     bcopy (ptr + col + n, ptr + col, nbytes);
  301.     bcopy (attrs + col + n, attrs + col, nbytes);
  302.     bzero (ptr + size - n, n);
  303.     bzero (attrs + size - n, n);
  304.     if (wrappedbit)
  305.         attrs[0] |= LINEWRAPPED;
  306. }
  307.  
  308.  
  309. ScrnRefresh (screen, toprow, leftcol, nrows, ncols, force)
  310. /*
  311.    Repaints the area enclosed by the parameters.
  312.    Requires: (toprow, leftcol), (toprow + nrows, leftcol + ncols) are
  313.             coordinates of characters in screen;
  314.          nrows and ncols positive.
  315.  */
  316. register TScreen *screen;
  317. int toprow, leftcol, nrows, ncols;
  318. Boolean force;            /* ... leading/trailing spaces */
  319. {
  320.     int y = toprow * FontHeight(screen) + screen->border +
  321.         screen->fnt_norm->ascent;
  322.     register int row;
  323.     register int topline = screen->topline;
  324.     int maxrow = toprow + nrows - 1;
  325.     int scrollamt = screen->scroll_amt;
  326.     int max = screen->max_row;
  327.  
  328.     if(screen->cursor_col >= leftcol && screen->cursor_col <=
  329.      (leftcol + ncols - 1) && screen->cursor_row >= toprow + topline &&
  330.      screen->cursor_row <= maxrow + topline)
  331.         screen->cursor_state = OFF;
  332.     for (row = toprow; row <= maxrow; y += FontHeight(screen), row++) {
  333.        register Char *chars;
  334.        register Char *attrs;
  335.        register int col = leftcol;
  336.        int maxcol = leftcol + ncols - 1;
  337.        int lastind;
  338.        int flags;
  339.        int x, n;
  340.        GC gc;
  341.        Boolean hilite;    
  342.  
  343.        if (row < screen->top_marg || row > screen->bot_marg)
  344.         lastind = row;
  345.        else
  346.         lastind = row - scrollamt;
  347.  
  348.        if (lastind < 0 || lastind > max)
  349.            continue;
  350.  
  351.        chars = screen->buf [2 * (lastind + topline)];
  352.        attrs = screen->buf [2 * (lastind + topline) + 1];
  353.  
  354.        if (row < screen->startHRow || row > screen->endHRow ||
  355.            (row == screen->startHRow && maxcol < screen->startHCol) ||
  356.            (row == screen->endHRow && col >= screen->endHCol))
  357.            {
  358.            /* row does not intersect selection; don't hilite */
  359.            if (!force) {
  360.            while (col <= maxcol && (attrs[col] & ~BOLD) == 0 &&
  361.               (chars[col] & ~040) == 0)
  362.                col++;
  363.  
  364.            while (col <= maxcol && (attrs[maxcol] & ~BOLD) == 0 &&
  365.               (chars[maxcol] & ~040) == 0)
  366.                maxcol--;
  367.            }
  368.            hilite = False;
  369.        }
  370.        else {
  371.            /* row intersects selection; split into pieces of single type */
  372.            if (row == screen->startHRow && col < screen->startHCol) {
  373.            ScrnRefresh(screen, row, col, 1, screen->startHCol - col,
  374.                    force);
  375.            col = screen->startHCol;
  376.            }
  377.            if (row == screen->endHRow && maxcol >= screen->endHCol) {
  378.            ScrnRefresh(screen, row, screen->endHCol, 1,
  379.                    maxcol - screen->endHCol + 1, force);
  380.            maxcol = screen->endHCol - 1;
  381.            }
  382.            /* remaining piece should be hilited */
  383.            hilite = True;
  384.        }
  385.  
  386.        if (col > maxcol) continue;
  387.  
  388.        flags = attrs[col];
  389.  
  390.        if ( (!hilite && (flags & INVERSE) != 0) ||
  391.             (hilite && (flags & INVERSE) == 0) )
  392.            if (flags & BOLD) gc = screen->reverseboldGC;
  393.            else gc = screen->reverseGC;
  394.        else 
  395.            if (flags & BOLD) gc = screen->normalboldGC;
  396.            else gc = screen->normalGC;
  397.  
  398.        x = CursorX(screen, col);
  399.        lastind = col;
  400.  
  401.        for (; col <= maxcol; col++) {
  402.         if (attrs[col] != flags) {
  403.            XDrawImageString(screen->display, TextWindow(screen), 
  404.                     gc, x, y, (char *) &chars[lastind], n = col - lastind);
  405.            if((flags & BOLD) && screen->enbolden)
  406.              XDrawString(screen->display, TextWindow(screen), 
  407.              gc, x + 1, y, (char *) &chars[lastind], n);
  408.            if(flags & UNDERLINE) 
  409.             XDrawLine(screen->display, TextWindow(screen), 
  410.              gc, x, y+1, x+n*FontWidth(screen), y+1);
  411.  
  412.            x += (col - lastind) * FontWidth(screen);
  413.  
  414.            lastind = col;
  415.  
  416.            flags = attrs[col];
  417.  
  418.               if ((!hilite && (flags & INVERSE) != 0) ||
  419.                (hilite && (flags & INVERSE) == 0) )
  420.                    if (flags & BOLD) gc = screen->reverseboldGC;
  421.                    else gc = screen->reverseGC;
  422.               else 
  423.                    if (flags & BOLD) gc = screen->normalboldGC;
  424.                    else gc = screen->normalGC;
  425.         }
  426.  
  427.         if(chars[col] == 0)
  428.             chars[col] = ' ';
  429.        }
  430.  
  431.  
  432.        if ( (!hilite && (flags & INVERSE) != 0) ||
  433.             (hilite && (flags & INVERSE) == 0) )
  434.            if (flags & BOLD) gc = screen->reverseboldGC;
  435.            else gc = screen->reverseGC;
  436.        else 
  437.            if (flags & BOLD) gc = screen->normalboldGC;
  438.            else gc = screen->normalGC;
  439.        XDrawImageString(screen->display, TextWindow(screen), gc, 
  440.              x, y, (char *) &chars[lastind], n = col - lastind);
  441.        if((flags & BOLD) && screen->enbolden)
  442.         XDrawString(screen->display, TextWindow(screen), gc,
  443.         x + 1, y, (char *) &chars[lastind], n);
  444.        if(flags & UNDERLINE) 
  445.         XDrawLine(screen->display, TextWindow(screen), gc, 
  446.          x, y+1, x + n * FontWidth(screen), y+1);
  447.     }
  448. }
  449.  
  450. ClearBufRows (screen, first, last)
  451. /*
  452.    Sets the rows first though last of the buffer of screen to spaces.
  453.    Requires first <= last; first, last are rows of screen->buf.
  454.  */
  455. register TScreen *screen;
  456. register int first, last;
  457. {
  458.     first *= 2;
  459.     last = 2 * last + 1;
  460.     while (first <= last)
  461.         bzero (screen->buf [first++], (screen->max_col + 1));
  462. }
  463.  
  464. /*
  465.   Resizes screen:
  466.   1. If new window would have fractional characters, sets window size so as to
  467.   discard fractional characters and returns -1.
  468.   Minimum screen size is 1 X 1.
  469.   Note that this causes another ExposeWindow event.
  470.   2. Enlarges screen->buf if necessary.  New space is appended to the bottom
  471.   and to the right
  472.   3. Reduces  screen->buf if necessary.  Old space is removed from the bottom
  473.   and from the right
  474.   4. Cursor is positioned as closely to its former position as possible
  475.   5. Sets screen->max_row and screen->max_col to reflect new size
  476.   6. Maintains the inner border (and clears the border on the screen).
  477.   7. Clears origin mode and sets scrolling region to be entire screen.
  478.   8. Returns 0
  479.   */
  480. ScreenResize (screen, width, height, flags)
  481.     register TScreen *screen;
  482.     int width, height;
  483.     unsigned *flags;
  484. {
  485.     int rows, cols;
  486.     int border = 2 * screen->border;
  487.     int move_down_by;
  488. #ifdef sun
  489. #ifdef TIOCSSIZE
  490.     struct ttysize ts;
  491. #endif    /* TIOCSSIZE */
  492. #else    /* sun */
  493. #ifdef TIOCSWINSZ
  494.     struct winsize ws;
  495. #endif    /* TIOCSWINSZ */
  496. #endif    /* sun */
  497.     Window tw = TextWindow (screen);
  498.  
  499.     /* clear the right and bottom internal border because of NorthWest
  500.        gravity might have left junk on the right and bottom edges */
  501.     XClearArea (screen->display, tw,
  502.             width - screen->border, 0,                /* right edge */
  503.             screen->border, height,           /* from top to bottom */
  504.             False);
  505.     XClearArea (screen->display, tw, 
  506.             0, height - screen->border,                      /* bottom */
  507.             width, screen->border,         /* all across the bottom */
  508.             False);
  509.  
  510.     /* round so that it is unlikely the screen will change size on  */
  511.     /* small mouse movements.                    */
  512.     rows = (height + FontHeight(screen) / 2 - border) /
  513.      FontHeight(screen);
  514.     cols = (width + FontWidth(screen) / 2 - border - screen->scrollbar) /
  515.      FontWidth(screen);
  516.     if (rows < 1) rows = 1;
  517.     if (cols < 1) cols = 1;
  518.  
  519.     /* update buffers if the screen has changed size */
  520.     if (screen->max_row != rows - 1 || screen->max_col != cols - 1) {
  521.         register int savelines = screen->scrollWidget ?
  522.          screen->savelines : 0;
  523.         int delta_rows = rows - (screen->max_row + 1);
  524.         
  525.         if(screen->cursor_state)
  526.             HideCursor();
  527.         if ( screen->alternate
  528.              && term->misc.resizeGravity == SouthWestGravity )
  529.             /* swap buffer pointers back to make all this hair work */
  530.             SwitchBufPtrs(screen);
  531.         if (screen->altbuf) 
  532.             (void) Reallocate(&screen->altbuf, (Char **)&screen->abuf_address,
  533.              rows, cols, screen->max_row + 1, screen->max_col + 1);
  534.         move_down_by = Reallocate(&screen->allbuf,
  535.                       (Char **)&screen->sbuf_address,
  536.                       rows + savelines, cols,
  537.                       screen->max_row + 1 + savelines,
  538.                       screen->max_col + 1);
  539.         screen->buf = &screen->allbuf[2 * savelines];
  540.  
  541.         screen->max_row += delta_rows;
  542.         screen->max_col = cols - 1;
  543.  
  544.         if (term->misc.resizeGravity == SouthWestGravity) {
  545.             screen->savedlines -= move_down_by;
  546.             if (screen->savedlines < 0)
  547.             screen->savedlines = 0;
  548.             if (screen->savedlines > screen->savelines)
  549.             screen->savedlines = screen->savelines;
  550.             if (screen->topline < -screen->savedlines)
  551.             screen->topline = -screen->savedlines;
  552.             screen->cur_row += move_down_by;
  553.             screen->cursor_row += move_down_by;
  554.             ScrollSelection(screen, move_down_by);
  555.  
  556.             if (screen->alternate)
  557.             SwitchBufPtrs(screen); /* put the pointers back */
  558.         }
  559.     
  560.         /* adjust scrolling region */
  561.         screen->top_marg = 0;
  562.         screen->bot_marg = screen->max_row;
  563.         *flags &= ~ORIGIN;
  564.  
  565.         if (screen->cur_row > screen->max_row)
  566.             screen->cur_row = screen->max_row;
  567.         if (screen->cur_col > screen->max_col)
  568.             screen->cur_col = screen->max_col;
  569.     
  570.         screen->fullVwin.height = height - border;
  571.         screen->fullVwin.width = width - border - screen->scrollbar;
  572.  
  573.     } else if(FullHeight(screen) == height && FullWidth(screen) == width)
  574.          return(0);    /* nothing has changed at all */
  575.  
  576.     if(screen->scrollWidget)
  577.         ResizeScrollBar(screen->scrollWidget, -1, -1, height);
  578.     
  579.     screen->fullVwin.fullheight = height;
  580.     screen->fullVwin.fullwidth = width;
  581.     ResizeSelection (screen, rows, cols);
  582. #ifdef sun
  583. #ifdef TIOCSSIZE
  584.     /* Set tty's idea of window size */
  585.     ts.ts_lines = rows;
  586.     ts.ts_cols = cols;
  587.     ioctl (screen->respond, TIOCSSIZE, &ts);
  588. #ifdef SIGWINCH
  589.     if(screen->pid > 1) {
  590.         int    pgrp;
  591.         
  592.         if (ioctl (screen->respond, TIOCGPGRP, &pgrp) != -1)
  593.             kill_process_group(pgrp, SIGWINCH);
  594.     }
  595. #endif    /* SIGWINCH */
  596. #endif    /* TIOCSSIZE */
  597. #else    /* sun */
  598. #ifdef TIOCSWINSZ
  599.     /* Set tty's idea of window size */
  600.     ws.ws_row = rows;
  601.     ws.ws_col = cols;
  602.     ws.ws_xpixel = width;
  603.     ws.ws_ypixel = height;
  604.     ioctl (screen->respond, TIOCSWINSZ, (char *)&ws);
  605. #ifdef notdef    /* change to SIGWINCH if this doesn't work for you */
  606.     if(screen->pid > 1) {
  607.         int    pgrp;
  608.         
  609.         if (ioctl (screen->respond, TIOCGPGRP, &pgrp) != -1)
  610.             kill_process_group(pgrp, SIGWINCH);
  611.     }
  612. #endif    /* SIGWINCH */
  613. #endif    /* TIOCSWINSZ */
  614. #endif    /* sun */
  615.     return (0);
  616. }
  617.  
  618. /*
  619.  * Sets the attributes from the row, col, to row, col + length according to
  620.  * mask and value. The bits in the attribute byte specified by the mask are
  621.  * set to the corresponding bits in the value byte. If length would carry us
  622.  * over the end of the line, it stops at the end of the line.
  623.  */
  624. void
  625. ScrnSetAttributes(screen, row, col, mask, value, length)
  626. TScreen *screen;
  627. int row, col;
  628. unsigned mask, value;
  629. register int length;        /* length of string */
  630. {
  631.     register Char *attrs;
  632.     register int avail  = screen->max_col - col + 1;
  633.  
  634.     if (length > avail)
  635.         length = avail;
  636.     if (length <= 0)
  637.         return;
  638.     attrs = screen->buf[2 * row + 1] + col;
  639.     value &= mask;    /* make sure we only change the bits allowed by mask*/
  640.     while(length-- > 0) {
  641.         *attrs &= ~mask;    /* clear the bits */
  642.         *attrs |= value;    /* copy in the new values */
  643.         attrs++;
  644.     }
  645. }
  646.  
  647. /*
  648.  * Gets the attributes from the row, col, to row, col + length into the
  649.  * supplied array, which is assumed to be big enough.  If length would carry us
  650.  * over the end of the line, it stops at the end of the line. Returns
  651.  * the number of bytes of attributes (<= length)
  652.  */
  653. int
  654. ScrnGetAttributes(screen, row, col, str, length)
  655. TScreen *screen;
  656. int row, col;
  657. Char *str;
  658. register int length;        /* length of string */
  659. {
  660.     register Char *attrs;
  661.     register int avail  = screen->max_col - col + 1;
  662.     int ret;
  663.  
  664.     if (length > avail)
  665.         length = avail;
  666.     if (length <= 0)
  667.         return 0;
  668.     ret = length;
  669.     attrs = screen->buf[2 * row + 1] + col;
  670.     while(length-- > 0) {
  671.         *str++ = *attrs++;
  672.     }
  673.     return ret;
  674. }
  675. Bool
  676. non_blank_line(sb, row, col, len)
  677. ScrnBuf sb;
  678. register int row, col, len;
  679. {
  680.     register int    i;
  681.     register Char *ptr = sb [2 * row];
  682.  
  683.     for (i = col; i < len; i++)    {
  684.         if (ptr[i])
  685.             return True;
  686.     }
  687.     return False;
  688. }
  689.