home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n002 / 4.ddi / DEMOS.ZIP / ECL_TERM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  4.7 KB  |  248 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. #include "eclproto.h"
  6. #include "xc.h"
  7. #include "im.h"
  8. #include "xc_term.h"
  9.  
  10. /* Communications port */
  11. #define PORT   COM1
  12.  
  13. /* row used to display status */
  14. #define ECL_STATUS_ROW    24
  15.  
  16. #define NUM_ACTION_KEYS    4
  17.  
  18. /* Here we define the function to toggle the terminal's Insert mode */
  19. int toggle_insert_mode(TERM_PTR term_ptr)
  20. {
  21.     int orow,ocol;
  22.  
  23.     xcv_gcur(&orow,&ocol);
  24.     xcv_scur(24,53);
  25.  
  26.     if (term_ptr->insert_mode)  {
  27.         term_ptr->insert_mode = 0;
  28.         printf("OFF");        
  29.     }
  30.     else  {
  31.         term_ptr->insert_mode = 1;
  32.         printf("ON ");        
  33.     }
  34.  
  35.     xcv_scur(orow,ocol);
  36.     
  37.     return(1);
  38. }
  39.  
  40.  
  41. /* Here we define the function to toggle output to the printer (stdprn) */
  42. int toggle_printer_mode(TERM_PTR term_ptr)
  43. {
  44.     int orow,ocol;
  45.  
  46.     xcv_gcur(&orow,&ocol);
  47.     xcv_scur(24,29);
  48.  
  49.     if (term_ptr->printer_status)  {
  50.         term_ptr->printer_status = 0;
  51.         printf("OFF");        
  52.     }
  53.     else  {
  54.         term_ptr->printer_status = 1;
  55.         printf("ON ");        
  56.     }
  57.  
  58.     xcv_scur(orow,ocol);
  59.  
  60.     return(1);
  61. }
  62.  
  63.  
  64.  
  65. /* Here we define the function to toggle the length of the terminal's tab width */
  66. int toggle_tab_width(TERM_PTR term_ptr)
  67. {
  68.     int orow,ocol;
  69.  
  70.     xcv_gcur(&orow,&ocol);
  71.     xcv_scur(24,74);
  72.  
  73.     if (term_ptr->tab_width == 8)  {
  74.         term_ptr->tab_width = 4;
  75.         printf("4");        
  76.     }
  77.     else  {
  78.         term_ptr->tab_width = 8;
  79.         printf("8");        
  80.     }
  81.  
  82.     xcv_scur(orow,ocol);
  83.  
  84.     return(1);
  85. }
  86.  
  87.  
  88.  
  89. /* Here we define the function to exit the terminal emulator */
  90. int alt_x_exit(TERM_PTR term_ptr)
  91. {
  92.     return(0);
  93. }
  94.  
  95.  
  96. /* Here we define the Idle Time Processing Function 
  97.    to report on the status of the six modem signals */
  98. int signal_check(TERM_PTR term_ptr)
  99. {
  100.     static int dtr = 1;
  101.     static int rts = 1;
  102.     static int cts = 1;
  103.     static int dsr = 1;
  104.     static int ri = 1;
  105.     static int dcd = 1;
  106.     static char re_scan = 1;
  107.     int rc;
  108.     int orow,ocol;
  109.     
  110.     rc = xc_dtr(PORT,2);
  111.     if (rc != dtr)  {
  112.         dtr = rc;
  113.         re_scan = 1;
  114.     }
  115.     rc = xc_rts(PORT,2);
  116.     if (rc != rts)  {
  117.         rts = rc;
  118.         re_scan = 1;
  119.     }
  120.     rc = xc_cts(PORT);
  121.     if (rc != cts)  {
  122.         cts = rc;
  123.         re_scan = 1;
  124.     }
  125.     rc = xc_dsr(PORT);
  126.     if (rc != dsr)  {
  127.         dsr = rc;
  128.         re_scan = 1;
  129.     }
  130.     rc = xc_ri(PORT);
  131.     if (rc != ri)  {
  132.         ri = rc;
  133.         re_scan = 1;
  134.     }
  135.     rc = xc_dcd(PORT);
  136.     if (rc != dcd)  {
  137.         dcd = rc;
  138.         re_scan = 1;
  139.     }
  140.     if (re_scan)  {
  141.         xcv_gcur(&orow,&ocol);
  142.         xcv_scur(23,0);
  143.         printf("   |  DTR :%2d  |  RTS:%2d  |  CTS:%2d  |  DSR:%2d  |  RI:%2d   |   DCD:%2d   |",dtr,rts,cts,dsr,ri,dcd);
  144.         xcv_scur(orow,ocol);
  145.         re_scan = 0;
  146.     }
  147.     return(1);
  148. }
  149.  
  150.  
  151. /* Here we associate each "Action Key" with it's associated function */
  152. XCharNode  user_key_info_array[NUM_ACTION_KEYS] =
  153. {
  154.     {0X1700,toggle_insert_mode},      /* Alt-I Key */
  155.     {0X1900,toggle_printer_mode},     /* Alt-P Key */
  156.     {0X1400,toggle_tab_width},        /* Alt-T Key */
  157.     {0X2D00,alt_x_exit},              /* Alt-X Key */
  158. };
  159.  
  160. /* Here we initialize the user_key_info_ptr argument */
  161. XCharInfo  user_key_info_ptr[1] =
  162. {
  163.   NUM_ACTION_KEYS,       /* number of user defined action keys */
  164.   user_key_info_array    /* array of action key - function information */
  165. };
  166.  
  167.  
  168. void main(int argc, char *argv[])
  169. {
  170.     int rc;
  171.     int term_type;
  172.  
  173.     if (argc!=2)  {
  174.         printf("\n\nFORMAT: ecl_term [terminal type]");
  175.         printf("\nWHERE: terminal type: 0 = ANSI;  1 = VT100;  2 = VT52;");
  176.         return;
  177.     }
  178.  
  179.     rc = xc_entr(8);
  180.     if (rc)  {
  181.         printf("\nUnable to allocate asked for receive buffer space");
  182.         return;
  183.     }
  184.  
  185.     rc = xc_tport(PORT);
  186.     if (rc)  {
  187.         printf("\nPort does not exist");
  188.         xc_exit();
  189.         return;
  190.     }
  191.  
  192.     rc = xc_link(PORT,0);    
  193.     if (rc)  {
  194.         printf("\nInterrupts already enabled");
  195.         xc_exit();
  196.         return;
  197.     }
  198.  
  199.  
  200.     xc_init(PORT, BAUD2400, NOPAR, DATA8, STOP1);
  201.     xc_dtr(PORT,1);
  202.     xc_rts(PORT,1);
  203.  
  204.  
  205.     term_type = atoi(argv[1]);
  206.  
  207.     /* clear the screen */
  208.     xcv_scrl(0,0,24,79,0X07,0);
  209.  
  210.     /* position cursor at status row, column 0 */
  211.     xcv_scur(ECL_STATUS_ROW,0);
  212.     printf(" [Alt-X EXIT] [Alt-P Printer OFF] [Alt-I Insert Mode OFF] [Alt-T Tab Size 8]");
  213.  
  214.     /* position the cursor at (0,0) : First position of terminal */
  215.     xcv_scur(0,0);
  216.  
  217.     switch (term_type)  {
  218.         case 0:
  219.             /* run ANSI Terminal */
  220.             rc = xcterm_ansi(PORT,0,22,0X011B,1,user_key_info_ptr,signal_check);
  221.         break;
  222.  
  223.         case 1:
  224.             /* run VT100 Terminal */
  225.             rc = xcterm_vt100(PORT,0,22,0X011B,1,user_key_info_ptr,signal_check);
  226.         break;
  227.  
  228.         case 2:
  229.             /* run VT52 Terminal */
  230.             rc = xcterm_vt52(PORT,0,22,0X011B,1,user_key_info_ptr,signal_check);
  231.         break;
  232.         
  233.         default :
  234.         break;
  235.     }
  236.     /* clear the screen */
  237.     xcv_scrl(0,0,24,79,0X07,0);
  238.  
  239.     /* position the cursor at (0,0) */
  240.     xcv_scur(0,0);
  241.  
  242.     xc_dtr(PORT,0);
  243.     xc_rts(PORT,0);
  244.     xc_unlk(PORT);
  245.     xc_exit();
  246.  
  247. }
  248.