home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / termsize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-21  |  3.4 KB  |  139 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: termsize.c,v 1.5 1995/10/21 18:40:38 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    termsize.c
  7.  * Author:    T.E.Dickey
  8.  * Created:    02 Oct 1985
  9.  * Last update:
  10.  *        18 Feb 1995, port to AXP (renamed 'alarm')
  11.  *        17 Aug 1988, use SYS$COMMAND rather than SYS$INPUT.
  12.  *        03 Oct 1985
  13.  *
  14.  * Function:    This module interrogates/alters the terminal screen size.  If
  15.  *        the terminal is a DEC-crt with advanced-video, the caller may
  16.  *        use 'termsize' to switch between 80/132 column width at the
  17.  *        same time.  (If non-AVO, no change is made to the screen size).
  18.  *
  19.  * Arguments:    reset    True if caller wishes a change to be made to the screen
  20.  *            size, based on the other arguments.
  21.  *        width_    Address of 32-bit integer containing caller's screen
  22.  *            width.  If a zero is passed here, it denotes that the
  23.  *            caller does not wish to modify the current value.
  24.  *            If a value greater than 80 is passed, the terminal must
  25.  *            have AVO to perform the change.  Also, if the current
  26.  *            value is greater than 80, AVO must be set to perform
  27.  *            a change.
  28.  *        length_    Address of 32-bit integer containing caller's screen
  29.  *            length.  If a zero is passed here, it denotes that the
  30.  *            caller does not wish to modify the current value.
  31.  *
  32.  * Returns:    TRUE iff the procedure executed normally.  If a screen-width
  33.  *        change was requested which could not be performed, then the
  34.  *        routine returns FALSE.  I/O errors are all fatal (we should get
  35.  *        none).
  36.  *
  37.  *        The resulting screen size is always returned in the width/length
  38.  *        arguments.
  39.  */
  40.  
  41. #include    <starlet.h>
  42. #include    <lib$routines.h>
  43. #include    <dcdef.h>
  44. #include    <ttdef.h>
  45. #include    <tt2def.h>
  46.  
  47. #include    <descrip.h>
  48. #include    <iodef.h>
  49. #include    <stsdef.h>
  50.  
  51. #include    "crt.h"
  52.  
  53. /*
  54.  * Local definitions:
  55.  */
  56. #define    OK(f)    $VMS_STATUS_SUCCESS(status=f)
  57. #define    SYS(f)    if (!OK(f)) lib$stop(status)
  58. #define    QIO(mask)    sys$qiow (\
  59.             0,        /* Event flag number        */\
  60.             tty_chan,\
  61.             mask,\
  62.             &iosb,0,0,\
  63.             &cbfr,        /* buffer address        */\
  64.             sizeof(cbfr),    /* buffer size            */\
  65.             0,        /* P3 -- speed specifier    */\
  66.             0,        /* P4 -- fill specifier        */\
  67.             0,        /* P5 -- parity flags        */\
  68.             0)        /* prompt-string buffer size    */
  69.  
  70. #define    FAIL    {    sound_alarm();\
  71.             *width_ = width;    *length_= length;\
  72.             return (0);    }
  73.  
  74. /*
  75.  * Local (static) data:
  76.  */
  77. static    $DESCRIPTOR(tty_name,"SYS$COMMAND");
  78. static    unsigned short    tty_chan = 0;
  79.  
  80. int
  81. termsize (int reset, int *width_, int *length_)
  82. {
  83.     int    status,
  84.         DEC_avo,
  85.         width,
  86.         length;
  87.     struct    {
  88.         short    sts,
  89.             count;
  90.         unsigned device;
  91.         }    iosb;
  92.     struct    {
  93.         unsigned
  94.         char    class,
  95.             type;
  96.         short    width;
  97.         unsigned ttdef,        /* basic characteristics    */
  98.             tt2def;        /* extended characteristics    */
  99.         }    cbfr;
  100.  
  101.     if (! tty_chan)
  102.     {
  103.         SYS(sys$assign(&tty_name, &tty_chan, 0,0));
  104.     }
  105.  
  106.     SYS(QIO(IO$_SENSEMODE));
  107.     DEC_avo    = (cbfr.tt2def & TT2$M_AVO) && (cbfr.tt2def & TT2$M_DECCRT);
  108.     width    = cbfr.width;
  109.     length    = cbfr.ttdef >> TT$V_PAGE;
  110.  
  111.     if (reset && (*width_ || *length_))
  112.     {
  113.         if (*width_  <= 0)    *width_ = width;
  114.         if (*length_ <= 0)    *length_= length;
  115.  
  116.         if (*width_ > 80 && width <= 80)
  117.         {
  118.             if (DEC_avo)    putraw ("\033[?3h");    /* 132-col */
  119.             else        FAIL;
  120.         }
  121.         else if (width > 80 && *width_ <= 80)
  122.         {
  123.             if (DEC_avo)    putraw ("\033[?3l");    /* 80-col */
  124.             else        FAIL;
  125.         }
  126.  
  127.         cbfr.width = *width_;
  128.         cbfr.ttdef &= ~TT$M_PAGE;
  129.         cbfr.ttdef |= (*length_ << TT$V_PAGE);
  130.         SYS(QIO(IO$_SETMODE));
  131.     }
  132.     else
  133.     {
  134.         *width_ = width;
  135.         *length_= length;
  136.     }
  137.     return (1);
  138. }
  139.