home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff119.lzh / MicroEMACS / src / src.zoo / vmsvt.c < prev    next >
C/C++ Source or Header  |  1987-12-09  |  9KB  |  431 lines

  1. /*
  2.  *  Advanced VMS terminal driver
  3.  *
  4.  *  Knows about any terminal defined in SMGTERMS.TXT and TERMTABLE.TXT
  5.  *  located in SYS$SYSTEM.
  6.  *
  7.  *  Author:  Curtis Smith
  8.  *  Last Updated: 07/14/87
  9.  */
  10.  
  11. #include    <stdio.h>        /* Standard I/O package        */
  12. #include    "estruct.h"        /* Emacs' structures        */
  13. #include    "edef.h"        /* Emacs' definitions        */
  14.  
  15. #if    VMSVT
  16.  
  17. #include     <descrip.h>        /* Descriptor definitions    */
  18.  
  19. /*  These would normally come from iodef.h and ttdef.h  */
  20. #define IO$_SENSEMODE    0x27        /* Sense mode of terminal    */
  21. #define TT$_UNKNOWN    0x00        /* Unknown terminal        */
  22.  
  23. /** Forward references **/
  24. int vmsopen(), ttclose(), vmskopen(), vmskclose(), ttgetc(), ttputc();
  25. int ttflush(), vmsmove(), vmseeol(), vmseeop(), vmsbeep(), vmsrev();
  26. int vmscres();
  27. extern int eolexist, revexist;
  28. extern char sres[];
  29.  
  30. #if COLOR
  31. int vmsfcol(), vmsbcol();
  32. #endif
  33.  
  34. /** SMG stuff **/
  35. static char * begin_reverse, * end_reverse, * erase_to_end_line;
  36. static char * erase_whole_display;
  37. static int termtype;
  38.  
  39. #define SMG$K_BEGIN_REVERSE        0x1bf
  40. #define SMG$K_END_REVERSE        0x1d6
  41. #define SMG$K_SET_CURSOR_ABS        0x23a
  42. #define SMG$K_ERASE_WHOLE_DISPLAY    0x1da
  43. #define SMG$K_ERASE_TO_END_LINE        0x1d9
  44.  
  45.  
  46. /* Dispatch table. All hard fields just point into the terminal I/O code. */
  47. TERM    term    = {
  48.     24 - 1,                /* Max number of rows allowable */
  49.     /* Filled in */ - 1,        /* Current number of rows used    */
  50.     132,                /* Max number of columns    */
  51.     /* Filled in */ 0,        /* Current number of columns    */
  52.     64,                /* Min margin for extended lines*/
  53.     8,                /* Size of scroll region    */
  54.     100,                /* # times thru update to pause */
  55.     vmsopen,            /* Open terminal at the start    */
  56.     ttclose,            /* Close terminal at end    */
  57.     vmskopen,            /* Open keyboard        */
  58.     vmskclose,            /* Close keyboard        */
  59.     ttgetc,                /* Get character from keyboard    */
  60.     ttputc,                /* Put character to display    */
  61.     ttflush,            /* Flush output buffers        */
  62.     vmsmove,            /* Move cursor, origin 0    */
  63.     vmseeol,            /* Erase to end of line        */
  64.     vmseeop,            /* Erase to end of page        */
  65.     vmsbeep,            /* Beep                */
  66.     vmsrev,                /* Set reverse video state    */
  67.     vmscres                /* Change screen resolution    */
  68. #if    COLOR
  69.     , vmsfcol,            /* Set forground color        */
  70.     vmsbcol                /* Set background color        */
  71. #endif
  72. };
  73.  
  74. /***
  75.  *  ttputs  -  Send a string to ttputc
  76.  *
  77.  *  Nothing returned
  78.  ***/
  79. ttputs(string)
  80. char * string;                /* String to write        */
  81. {
  82.     if (string)
  83.         while (*string != '\0')
  84.             ttputc(*string++);
  85. }
  86.  
  87.  
  88. /***
  89.  *  vmsmove  -  Move the cursor (0 origin)
  90.  *
  91.  *  Nothing returned
  92.  ***/
  93. vmsmove(row, col)
  94. int row;                /* Row position            */
  95. int col;                /* Column position        */
  96. {
  97.     char buffer[32];
  98.     int ret_length;
  99.     static int request_code = SMG$K_SET_CURSOR_ABS;
  100.     static int max_buffer_length = sizeof(buffer);
  101.     static int arg_list[3] = { 2 };
  102.     register char * cp;
  103.     
  104.     register int i;
  105.  
  106.     /* Set the arguments into the arg_list array
  107.      * SMG assumes the row/column positions are 1 based (boo!)
  108.      */
  109.     arg_list[1] = row + 1;
  110.     arg_list[2] = col + 1;
  111.  
  112.     if ((smg$get_term_data(        /* Get terminal data        */
  113.         &termtype,        /* Terminal table address    */
  114.         &request_code,        /* Request code            */
  115.         &max_buffer_length,    /* Maximum buffer length    */
  116.         &ret_length,        /* Return length        */
  117.         buffer,            /* Capability data buffer    */
  118.         arg_list)        /* Argument list array        */
  119.  
  120.     /* We'll know soon enough if this doesn't work        */
  121.             & 1) == 0) {
  122.                 ttputs("OOPS");
  123.                 return;
  124.             }
  125.  
  126.     /* Send out resulting sequence                */
  127.     i = ret_length;
  128.     cp = buffer;
  129.     while (i-- > 0)
  130.         ttputc(*cp++);
  131. }
  132.  
  133.  
  134. /***
  135.  *  vmsrev  -  Set the reverse video status
  136.  *
  137.  *  Nothing returned
  138.  ***/
  139. vmsrev(status)
  140. int status;                /* TRUE if setting reverse    */
  141. {
  142.     if (status)
  143.         ttputs(begin_reverse);
  144.     else 
  145.         ttputs(end_reverse);
  146. }
  147.  
  148. /***
  149.  *  vmscres  -  Change screen resolution (which it doesn't)
  150.  *
  151.  *  Nothing returned
  152.  ***/
  153. vmscres()
  154. {
  155.     /* But it could.  For vt100/vt200s, one could switch from
  156.     80 and 132 columns modes */
  157. }
  158.  
  159.  
  160. #if    COLOR
  161. /***
  162.  *  vmsfcol  -  Set the forground color (not implimented)
  163.  *
  164.  *  Nothing returned
  165.  ***/
  166. vmsfcol()
  167. {
  168. }
  169.  
  170. /***
  171.  *  vmsbcol  -  Set the background color (not implimented)
  172.  *
  173.  *  Nothing returned
  174.  ***/
  175. vmsbcol()
  176. {
  177. }
  178. #endif
  179.  
  180. /***
  181.  *  vmseeol  -  Erase to end of line
  182.  *
  183.  *  Nothing returned
  184.  ***/
  185. vmseeol()
  186. {
  187.     ttputs(erase_to_end_line);
  188. }
  189.  
  190.  
  191. /***
  192.  *  vmseeop  -  Erase to end of page (clear screen)
  193.  *
  194.  *  Nothing returned
  195.  ***/
  196. vmseeop()
  197. {
  198.     ttputs(erase_whole_display);
  199. }
  200.  
  201.  
  202. /***
  203.  *  vmsbeep  -  Ring the bell
  204.  *
  205.  *  Nothing returned
  206.  ***/
  207. vmsbeep()
  208. {
  209.     ttputc('\007');
  210. }
  211.  
  212.  
  213. /***
  214.  *  vmsgetstr  -  Get an SMG string capability by name
  215.  *
  216.  *  Returns:    Escape sequence
  217.  *        NULL    No escape sequence available
  218.  ***/ 
  219. char * vmsgetstr(request_code)
  220. int request_code;            /* Request code            */
  221. {
  222.     register char * result;
  223.     static char seq_storage[1024];
  224.     static char * buffer = seq_storage;
  225.     static int arg_list[2] = { 1, 1 };
  226.     int max_buffer_length, ret_length;
  227.  
  228.     /*  Precompute buffer length */
  229.     
  230.     max_buffer_length = (seq_storage + sizeof(seq_storage)) - buffer;
  231.  
  232.     /* Get terminal commands sequence from master table */
  233.  
  234.     if ((smg$get_term_data(    /* Get terminal data        */
  235.         &termtype,    /* Terminal table address    */
  236.         &request_code,    /* Request code            */
  237.         &max_buffer_length,/* Maximum buffer length    */
  238.         &ret_length,    /* Return length        */
  239.         buffer,        /* Capability data buffer    */
  240.         arg_list)    /* Argument list array        */
  241.  
  242.     /* If this doesn't work, try again with no arguments */
  243.     
  244.         & 1) == 0 && 
  245.  
  246.         (smg$get_term_data(    /* Get terminal data        */
  247.             &termtype,    /* Terminal table address    */
  248.             &request_code,    /* Request code            */
  249.             &max_buffer_length,/* Maximum buffer length    */
  250.             &ret_length,    /* Return length        */
  251.             buffer)        /* Capability data buffer    */
  252.  
  253.     /* Return NULL pointer if capability is not available */
  254.     
  255.             & 1) == 0)
  256.                 return NULL;
  257.  
  258.     /* Check for empty result */
  259.     if (ret_length == 0)
  260.         return NULL;
  261.     
  262.     /* Save current position so we can return it to caller */
  263.  
  264.     result = buffer;
  265.  
  266.     /* NIL terminate the sequence for return */
  267.     
  268.     buffer[ret_length] = 0;
  269.  
  270.     /* Advance buffer */
  271.  
  272.     buffer += ret_length + 1;
  273.  
  274.     /* Return capability to user */
  275.     return result;
  276. }
  277.  
  278.  
  279. /** I/O information block definitions **/
  280. struct iosb {            /* I/O status block            */
  281.     short    i_cond;        /* Condition value            */
  282.     short    i_xfer;        /* Transfer count            */
  283.     long    i_info;        /* Device information            */
  284. };
  285. struct termchar {        /* Terminal characteristics        */
  286.     char    t_class;    /* Terminal class            */
  287.     char    t_type;        /* Terminal type            */
  288.     short    t_width;    /* Terminal width in characters        */
  289.     long    t_mandl;    /* Terminal's mode and length        */
  290.     long    t_extend;    /* Extended terminal characteristics    */
  291. };
  292. static struct termchar tc;    /* Terminal characteristics        */
  293.  
  294. /***
  295.  *  vmsgtty - Get terminal type from system control block
  296.  *
  297.  *  Nothing returned
  298.  ***/
  299. vmsgtty()
  300. {
  301.     short fd;
  302.     int status;
  303.     struct iosb iostatus;
  304.     $DESCRIPTOR(devnam, "SYS$INPUT");
  305.  
  306.     /* Assign input to a channel */
  307.     status = sys$assign(&devnam, &fd, 0, 0);
  308.     if ((status & 1) == 0)
  309.         exit (status);
  310.  
  311.     /* Get terminal characteristics */
  312.     status = sys$qiow(        /* Queue and wait        */
  313.         0,            /* Wait on event flag zero    */
  314.         fd,            /* Channel to input terminal    */
  315.         IO$_SENSEMODE,        /* Get current characteristic    */
  316.         &iostatus,        /* Status after operation    */
  317.         0, 0,            /* No AST service        */
  318.         &tc,            /* Terminal characteristics buf */
  319.         sizeof(tc),        /* Size of the buffer        */
  320.         0, 0, 0, 0);        /* P3-P6 unused            */
  321.  
  322.     /* De-assign the input device */
  323.     if ((sys$dassgn(fd) & 1) == 0)
  324.         exit(status);
  325.  
  326.     /* Jump out if bad status */
  327.     if ((status & 1) == 0)
  328.         exit(status);
  329.     if ((iostatus.i_cond & 1) == 0)
  330.         exit(iostatus.i_cond);
  331. }
  332.  
  333.  
  334. /***
  335.  *  vmsopen  -  Get terminal type and open terminal
  336.  *
  337.  *  Nothing returned
  338.  ***/
  339. vmsopen()
  340. {
  341.     /* Get terminal type */
  342.     vmsgtty();
  343.     if (tc.t_type == TT$_UNKNOWN) {
  344.         printf("Terminal type is unknown!\n");
  345.         printf("Try set your terminal type with SET TERMINAL/INQUIRE\n");
  346.         printf("Or get help on SET TERMINAL/DEVICE_TYPE\n");
  347.         exit(3);
  348.     }
  349.  
  350.     /* Access the system terminal definition table for the        */
  351.     /* information of the terminal type returned by IO$_SENSEMODE    */
  352.     if ((smg$init_term_table_by_type(&tc.t_type, &termtype) & 1) == 0)
  353.         return -1;
  354.         
  355.     /* Set sizes */
  356.     term.t_nrow = ((unsigned int) tc.t_mandl >> 24) - 1;
  357.     term.t_ncol = tc.t_width;
  358.  
  359.     /* Get some capabilities */
  360.     begin_reverse = vmsgetstr(SMG$K_BEGIN_REVERSE);
  361.     end_reverse = vmsgetstr(SMG$K_END_REVERSE);
  362.     revexist = begin_reverse != NULL && end_reverse != NULL;
  363.     erase_to_end_line = vmsgetstr(SMG$K_ERASE_TO_END_LINE);
  364.     eolexist = erase_to_end_line != NULL;
  365.     erase_whole_display = vmsgetstr(SMG$K_ERASE_WHOLE_DISPLAY);
  366.  
  367.     /* Set resolution */
  368.     strcpy(sres, "NORMAL");
  369.  
  370.     /* Open terminal I/O drivers */
  371.     ttopen();
  372. }
  373.  
  374.  
  375. /***
  376.  *  vmskopen  -  Open keyboard (not used)
  377.  *
  378.  *  Nothing returned
  379.  ***/
  380. vmskopen()
  381. {
  382. }
  383.  
  384.  
  385. /***
  386.  *  vmskclose  -  Close keyboard (not used)
  387.  *
  388.  *  Nothing returned
  389.  ***/
  390. vmskclose()
  391. {
  392. }
  393.  
  394.  
  395. /***
  396.  *  fnclabel  -  Label function keys (not used)
  397.  *
  398.  *  Nothing returned
  399.  ***/
  400. #if    FLABEL
  401. fnclabel(f, n)        /* label a function key */
  402. int f,n;    /* default flag, numeric argument [unused] */
  403. {
  404.     /* on machines with no function keys...don't bother */
  405.     return(TRUE);
  406. }
  407. #endif
  408.  
  409.  
  410. /***
  411.  *  spal  -  Set palette type  (Are you kidding?)
  412.  *
  413.  *  Nothing returned
  414.  ***/
  415. spal()
  416. {
  417. }
  418.  
  419. #else
  420.  
  421. /***
  422.  *  hellovms  -  Avoid error because of empty module
  423.  *
  424.  *  Nothing returned
  425.  ***/
  426. hellovms()
  427. {
  428. }
  429.  
  430. #endif
  431.