home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
-
- #include "eclproto.h"
- #include "xc.h"
- #include "im.h"
- #include "xc_term.h"
-
- /* Communications port */
- #define PORT COM1
-
- /* row used to display status */
- #define ECL_STATUS_ROW 24
-
- #define NUM_ACTION_KEYS 4
-
- /* Here we define the function to toggle the terminal's Insert mode */
- int toggle_insert_mode(TERM_PTR term_ptr)
- {
- int orow,ocol;
-
- xcv_gcur(&orow,&ocol);
- xcv_scur(24,53);
-
- if (term_ptr->insert_mode) {
- term_ptr->insert_mode = 0;
- printf("OFF");
- }
- else {
- term_ptr->insert_mode = 1;
- printf("ON ");
- }
-
- xcv_scur(orow,ocol);
-
- return(1);
- }
-
-
- /* Here we define the function to toggle output to the printer (stdprn) */
- int toggle_printer_mode(TERM_PTR term_ptr)
- {
- int orow,ocol;
-
- xcv_gcur(&orow,&ocol);
- xcv_scur(24,29);
-
- if (term_ptr->printer_status) {
- term_ptr->printer_status = 0;
- printf("OFF");
- }
- else {
- term_ptr->printer_status = 1;
- printf("ON ");
- }
-
- xcv_scur(orow,ocol);
-
- return(1);
- }
-
-
-
- /* Here we define the function to toggle the length of the terminal's tab width */
- int toggle_tab_width(TERM_PTR term_ptr)
- {
- int orow,ocol;
-
- xcv_gcur(&orow,&ocol);
- xcv_scur(24,74);
-
- if (term_ptr->tab_width == 8) {
- term_ptr->tab_width = 4;
- printf("4");
- }
- else {
- term_ptr->tab_width = 8;
- printf("8");
- }
-
- xcv_scur(orow,ocol);
-
- return(1);
- }
-
-
-
- /* Here we define the function to exit the terminal emulator */
- int alt_x_exit(TERM_PTR term_ptr)
- {
- return(0);
- }
-
-
- /* Here we define the Idle Time Processing Function
- to report on the status of the six modem signals */
- int signal_check(TERM_PTR term_ptr)
- {
- static int dtr = 1;
- static int rts = 1;
- static int cts = 1;
- static int dsr = 1;
- static int ri = 1;
- static int dcd = 1;
- static char re_scan = 1;
- int rc;
- int orow,ocol;
-
- rc = xc_dtr(PORT,2);
- if (rc != dtr) {
- dtr = rc;
- re_scan = 1;
- }
- rc = xc_rts(PORT,2);
- if (rc != rts) {
- rts = rc;
- re_scan = 1;
- }
- rc = xc_cts(PORT);
- if (rc != cts) {
- cts = rc;
- re_scan = 1;
- }
- rc = xc_dsr(PORT);
- if (rc != dsr) {
- dsr = rc;
- re_scan = 1;
- }
- rc = xc_ri(PORT);
- if (rc != ri) {
- ri = rc;
- re_scan = 1;
- }
- rc = xc_dcd(PORT);
- if (rc != dcd) {
- dcd = rc;
- re_scan = 1;
- }
- if (re_scan) {
- xcv_gcur(&orow,&ocol);
- xcv_scur(23,0);
- printf(" | DTR :%2d | RTS:%2d | CTS:%2d | DSR:%2d | RI:%2d | DCD:%2d |",dtr,rts,cts,dsr,ri,dcd);
- xcv_scur(orow,ocol);
- re_scan = 0;
- }
- return(1);
- }
-
-
- /* Here we associate each "Action Key" with it's associated function */
- XCharNode user_key_info_array[NUM_ACTION_KEYS] =
- {
- {0X1700,toggle_insert_mode}, /* Alt-I Key */
- {0X1900,toggle_printer_mode}, /* Alt-P Key */
- {0X1400,toggle_tab_width}, /* Alt-T Key */
- {0X2D00,alt_x_exit}, /* Alt-X Key */
- };
-
- /* Here we initialize the user_key_info_ptr argument */
- XCharInfo user_key_info_ptr[1] =
- {
- NUM_ACTION_KEYS, /* number of user defined action keys */
- user_key_info_array /* array of action key - function information */
- };
-
-
- void main(int argc, char *argv[])
- {
- int rc;
- int term_type;
-
- if (argc!=2) {
- printf("\n\nFORMAT: ecl_term [terminal type]");
- printf("\nWHERE: terminal type: 0 = ANSI; 1 = VT100; 2 = VT52;");
- return;
- }
-
- rc = xc_entr(8);
- if (rc) {
- printf("\nUnable to allocate asked for receive buffer space");
- return;
- }
-
- rc = xc_tport(PORT);
- if (rc) {
- printf("\nPort does not exist");
- xc_exit();
- return;
- }
-
- rc = xc_link(PORT,0);
- if (rc) {
- printf("\nInterrupts already enabled");
- xc_exit();
- return;
- }
-
-
- xc_init(PORT, BAUD2400, NOPAR, DATA8, STOP1);
- xc_dtr(PORT,1);
- xc_rts(PORT,1);
-
-
- term_type = atoi(argv[1]);
-
- /* clear the screen */
- xcv_scrl(0,0,24,79,0X07,0);
-
- /* position cursor at status row, column 0 */
- xcv_scur(ECL_STATUS_ROW,0);
- printf(" [Alt-X EXIT] [Alt-P Printer OFF] [Alt-I Insert Mode OFF] [Alt-T Tab Size 8]");
-
- /* position the cursor at (0,0) : First position of terminal */
- xcv_scur(0,0);
-
- switch (term_type) {
- case 0:
- /* run ANSI Terminal */
- rc = xcterm_ansi(PORT,0,22,0X011B,1,user_key_info_ptr,signal_check);
- break;
-
- case 1:
- /* run VT100 Terminal */
- rc = xcterm_vt100(PORT,0,22,0X011B,1,user_key_info_ptr,signal_check);
- break;
-
- case 2:
- /* run VT52 Terminal */
- rc = xcterm_vt52(PORT,0,22,0X011B,1,user_key_info_ptr,signal_check);
- break;
-
- default :
- break;
- }
- /* clear the screen */
- xcv_scrl(0,0,24,79,0X07,0);
-
- /* position the cursor at (0,0) */
- xcv_scur(0,0);
-
- xc_dtr(PORT,0);
- xc_rts(PORT,0);
- xc_unlk(PORT);
- xc_exit();
-
- }