home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 001-099 / ff093.lzh / MicroEmacs / source / src.arc / vmsvt.c < prev    next >
C/C++ Source or Header  |  1987-08-16  |  6KB  |  357 lines

  1. /*
  2.  *  VMS terminal handling routines
  3.  *
  4.  *  Known types are:
  5.  *    VT52, VT100, and UNKNOWN (which is defined to be an ADM3a)
  6.  *    written by Curtis Smith
  7.  */
  8.  
  9. #include        <stdio.h>
  10. #include        "estruct.h"
  11. #include    "edef.h"
  12.  
  13. #if     VMSVT
  14.  
  15. #define    termdef    1            /* don't define "term" external */
  16.  
  17. #include <ssdef.h>        /* Status code definitions        */
  18. #include <descrip.h>        /* Descriptor structures        */
  19. #include <iodef.h>        /* IO commands                */
  20. #include <ttdef.h>        /* tty commands                */
  21.  
  22. extern  int     ttopen();               /* Forward references.          */
  23. extern  int     ttgetc();
  24. extern  int     ttputc();
  25. extern  int     ttflush();
  26. extern  int     ttclose();
  27. extern  int    vmsopen();
  28. extern    int    vmskopen();
  29. extern    int    vmskclose();
  30. extern  int    vmseeol();
  31. extern  int    vmseeop();
  32. extern  int    vmsbeep();
  33. extern  int    vmsmove();
  34. extern    int    vmsrev();
  35. extern    int    vmscres();
  36. extern  int    eolexist;
  37. #if    COLOR
  38. extern    int    vmsfcol();
  39. extern    int    vmsbcol();
  40. #endif
  41.  
  42. #define    NROWS    24            /* # of screen rolls        */
  43. #define    NCOLS    80            /* # of screen columns        */
  44. #define    MARGIN    8            /* size of minimim margin and    */
  45. #define    SCRSIZ    64            /* scroll size for extended lines */
  46. #define    NPAUSE    100            /* # times thru update to pause */
  47.  
  48. /*
  49.  * Dispatch table. All the
  50.  * hard fields just point into the
  51.  * terminal I/O code.
  52.  */
  53. TERM    term    = {
  54.     NROWS - 1,
  55.     NROWS - 1,
  56.     NCOLS,
  57.     NCOLS,
  58.     MARGIN,
  59.     SCRSIZ,
  60.     NPAUSE,
  61.         &vmsopen,
  62.         &ttclose,
  63.     &vmskopen,
  64.     &vmskclose,
  65.         &ttgetc,
  66.         &ttputc,
  67.         &ttflush,
  68.         &vmsmove,
  69.         &vmseeol,
  70.         &vmseeop,
  71.         &vmsbeep,
  72.         &vmsrev,
  73.         &vmscres
  74. #if    COLOR
  75.     , &vmsfcol,
  76.     &vmsbcol
  77. #endif
  78. };
  79.  
  80. char * termeop;            /* Erase to end of page string        */
  81. int eoppad;            /* Number of pad characters after eop    */
  82. char * termeol;            /* Erase to end of line string        */
  83. int eolpad;            /* Number of pad characters after eol    */
  84. char termtype;            /* Terminal type identifier        */
  85.  
  86.  
  87. /*******
  88.  *  ttputs - Send a string to ttputc
  89.  *******/
  90.  
  91. ttputs(string)
  92. char * string;
  93. {
  94.     while (*string != '\0')
  95.         ttputc(*string++);
  96. }
  97.  
  98.  
  99. /*******
  100.  *  vmspad - Pad the output after an escape sequence
  101.  *******/
  102.  
  103. vmspad(count)
  104. int count;
  105. {
  106.     while (count-- > 0)
  107.         ttputc('\0');
  108. }
  109.  
  110.  
  111. /*******
  112.  *  vmsmove - Move the cursor
  113.  *******/
  114.  
  115. vmsmove(row, col)
  116. {
  117.     switch (termtype) {
  118.         case TT$_UNKNOWN:
  119.             ttputc('\033');
  120.             ttputc('=');
  121.             ttputc(row+' ');
  122.             ttputc(col+' ');
  123.             break;
  124.         case TT$_VT52:
  125.             ttputc('\033');
  126.             ttputc('Y');
  127.             ttputc(row+' ');
  128.             ttputc(col+' ');
  129.             break;
  130.                 case TT$_VT100:         /* I'm assuming that all these  */
  131.                 case TT$_VT101:         /* are a super set of the VT100 */
  132.                 case TT$_VT102:         /* If I'm wrong, just remove    */
  133.                 case TT$_VT105:         /* those entries that aren't.   */
  134.                 case TT$_VT125:
  135.                 case TT$_VT131:
  136.                 case TT$_VT132:
  137.                 case TT$_VT200_SERIES:
  138.             {
  139.                 char buffer[24];
  140.  
  141.                 sprintf(buffer, "\033[%d;%dH", row+1, col+1);
  142.                 ttputs(buffer);
  143.                 vmspad(50);
  144.             }
  145.     }
  146. }
  147.  
  148. /*******
  149.  *  vmsrev - set the reverse video status
  150.  *******/
  151.  
  152. vmsrev(status)
  153.  
  154. int status;    /* TRUE = reverse video, FALSE = normal video */
  155. {
  156.     switch (termtype) {
  157.         case TT$_UNKNOWN:
  158.             break;
  159.         case TT$_VT52:
  160.             break;
  161.         case TT$_VT100:
  162.             if (status) {
  163.                 ttputc('\033');
  164.                 ttputc('[');
  165.                 ttputc('7');
  166.                 ttputc('m');
  167.             } else {
  168.                 ttputc('\033');
  169.                 ttputc('[');
  170.                 ttputc('m');
  171.             }
  172.             break;
  173.     }
  174. }
  175.  
  176. /*******
  177.  *  vmscres - Change screen resolution (which it doesn't)
  178.  *******/
  179.  
  180. vmscres()
  181.  
  182. {
  183.     return(TRUE);
  184. }
  185.  
  186. spal()        /* change palette string */
  187.  
  188. {
  189.     /*    Does nothing here    */
  190. }
  191.  
  192. #if    COLOR
  193. /*******
  194.  *  vmsfcol - Set the forground color (not implimented)
  195.  *******/
  196.  
  197. vmsfcol()
  198. {
  199. }
  200.  
  201. /*******
  202.  *  vmsbcol - Set the background color (not implimented)
  203.  *******/
  204.  
  205. vmsbcol()
  206. {
  207. }
  208. #endif
  209.  
  210. /*******
  211.  *  vmseeol - Erase to end of line
  212.  *******/
  213.  
  214. vmseeol()
  215. {
  216.     ttputs(termeol);
  217.     vmspad(eolpad);
  218. }
  219.  
  220.  
  221. /*******
  222.  *  vmseeop - Erase to end of page (clear screen)
  223.  *******/
  224.  
  225. vmseeop()
  226. {
  227.     ttputs(termeop);
  228.     vmspad(eoppad);
  229. }
  230.  
  231.  
  232. /*******
  233.  *  vmsbeep - Ring the bell
  234.  *******/
  235.  
  236. vmsbeep()
  237. {
  238.     ttputc('\007');
  239. }
  240.  
  241.  
  242. /*******
  243.  *  vmsopen - Get terminal type and open terminal
  244.  *******/
  245.  
  246. vmsopen()
  247. {
  248.     termtype = vmsgtty();
  249.     switch (termtype) {
  250.         case TT$_UNKNOWN:    /* Assume ADM3a    */
  251.             eolexist = FALSE;
  252.             termeop = "\032";
  253.             eoppad = 0;
  254.             break;
  255.         case TT$_VT52:
  256.             termeol = "\033K";
  257.             eolpad = 0;
  258.             termeop = "\033H\033J";
  259.             eoppad = 0;
  260.             break;
  261.         case TT$_VT100:
  262.             revexist = TRUE;
  263.             termeol = "\033[K";
  264.             eolpad = 3;
  265.             termeop = "\033[;H\033[2J";
  266.             eoppad = 50;
  267.             break;
  268.         default:
  269.             puts("Terminal type not supported");
  270.             exit (SS$_NORMAL);
  271.     }
  272.     strcpy(sres, "NORMAL");
  273.         ttopen();
  274. }
  275.  
  276.  
  277. struct iosb {            /* I/O status block            */
  278.     short    i_cond;        /* Condition value            */
  279.     short    i_xfer;        /* Transfer count            */
  280.     long    i_info;        /* Device information            */
  281. };
  282.  
  283. struct termchar {        /* Terminal characteristics        */
  284.     char    t_class;    /* Terminal class            */
  285.     char    t_type;        /* Terminal type            */
  286.     short    t_width;    /* Terminal width in characters        */
  287.     long    t_mandl;    /* Terminal's mode and length        */
  288.     long    t_extend;    /* Extended terminal characteristics    */
  289. };
  290.  
  291. /*******
  292.  *  vmsgtty - Get terminal type from system control block
  293.  *******/
  294.  
  295. vmsgtty()
  296. {
  297.     short fd;
  298.     int status;
  299.     struct iosb iostatus;
  300.     struct termchar tc;
  301.     $DESCRIPTOR(devnam, "SYS$INPUT");
  302.  
  303.     status = sys$assign(&devnam, &fd, 0, 0);
  304.     if (status != SS$_NORMAL)
  305.         exit (status);
  306.  
  307.     status = sys$qiow(        /* Queue and wait        */
  308.         0,            /* Wait on event flag zero    */
  309.         fd,            /* Channel to input terminal    */
  310.         IO$_SENSEMODE,        /* Get current characteristic    */
  311.         &iostatus,        /* Status after operation    */
  312.         0, 0,            /* No AST service        */
  313.         &tc,            /* Terminal characteristics buf    */
  314.         sizeof(tc),        /* Size of the buffer        */
  315.         0, 0, 0, 0);        /* P3-P6 unused            */
  316.  
  317.                     /* De-assign the input device    */
  318.     if (sys$dassgn(fd) != SS$_NORMAL)
  319.         exit(status);
  320.  
  321.     if (status != SS$_NORMAL)    /* Jump out if bad status    */
  322.         exit(status);
  323.     if (iostatus.i_cond != SS$_NORMAL)
  324.         exit(iostatus.i_cond);
  325.  
  326.     return tc.t_type;        /* Return terminal type        */
  327. }
  328.  
  329. vmskopen()
  330.  
  331. {
  332. }
  333.  
  334. vmskclose()
  335.  
  336. {
  337. }
  338.  
  339. #if    FLABEL
  340. fnclabel(f, n)        /* label a function key */
  341.  
  342. int f,n;    /* default flag, numeric argument [unused] */
  343.  
  344. {
  345.     /* on machines with no function keys...don't bother */
  346.     return(TRUE);
  347. }
  348. #endif
  349. #else
  350.  
  351. hellovms()
  352.  
  353. {
  354. }
  355.  
  356. #endif    VMSVT
  357.