home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_TERMOV.C < prev    next >
C/C++ Source or Header  |  1991-08-15  |  13KB  |  311 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*          This module was originally written by Vince Perriello           */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                        BinkleyTerm ANSI mapping                          */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n132.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45. #include <stdio.h>
  46. #include <signal.h>
  47. #include <ctype.h>
  48. #include <conio.h>
  49. #include <string.h>
  50. #include <process.h>
  51. #include <stdlib.h>
  52. #include <dos.h>
  53.  
  54. #ifdef OS_2
  55. #define INCL_DOSPROCESS
  56. #endif
  57.  
  58. #ifdef __TURBOC__
  59. #include <alloc.h>
  60. #else
  61. #include <malloc.h>
  62. #endif
  63.  
  64. #include "com.h"
  65. #include "xfer.h"
  66. #include "zmodem.h"
  67. #include "keybd.h"
  68. #include "sbuf.h"
  69. #include "sched.h"
  70. #include "externs.h"
  71. #include "prototyp.h"
  72.  
  73.  
  74. /*--------------------------------------------------------------------------*/
  75. /*                                                                          */
  76. /* ansi_map() -- map function key into an ANSI escape sequence if we have   */
  77. /* one to correspond to the key. The "emulation" is VT100-type, we map the  */
  78. /* arrow keys to the ANSI escape sequences for up, down, right and left,    */
  79. /* and we map the function keys into the VT100 keypad, assuming application */
  80. /* mode, like Procomm. That is, we take the VT100 keypad, split it in two   */
  81. /* vertically, and use the F-keys to represent the left side, and the       */
  82. /* "shifted" F-keys to represent the right side.                            */
  83. /*                                                                          */
  84. /*              The result, if any, is transmitted to the host.             */
  85. /*                                                                          */
  86. /*--------------------------------------------------------------------------*/
  87. /* ESC Seq        IBM key       Scan code VT100 key    */
  88.  
  89. static char *ansi_seq[] = { 
  90.    "\033OP",   /* F1            3b00      PF1          */
  91.    "\033OQ",   /* F2            3c00      PF2          */
  92.    "\033Ow",   /* F3            3d00      keypad '7'   */
  93.    "\033Ox",   /* F4            3e00      keypad '8'   */
  94.    "\033Ot",   /* F5            3f00      keypad '4'   */
  95.    "\033Ou",   /* F6            4000      keypad '5'   */
  96.    "\033Oq",   /* F7            4100      keypad '1'   */
  97.    "\033Or",   /* F8            4200      keypad '2'   */
  98.    "\033Op",   /* F9            4300      keypad '0'   */
  99.    "\033Op",   /* F10           4400      keypad '0'   */
  100.    "",         /*               4500                   */
  101.    "",         /*               4600                   */
  102.    "",         /*               4700                   */
  103.    "\033[A",   /* Up Arrow      4800      Up Arrow     */
  104.    "",         /*               4900                   */
  105.    "",         /*               4a00                   */
  106.    "\033[D",   /* Left Arrow    4b00      Left Arrow   */
  107.    "",         /*               4c00                   */
  108.    "\033[C",   /* Right Arrow   4d00      Right Arrow  */
  109.    "",         /*               4e00                   */
  110.    "",         /*               4f00                   */
  111.    "\033[B",   /* Down Arrow    5000      Down Arrow   */
  112.    "",         /*               5100                   */
  113.    "",         /*               5200                   */
  114.    "",         /*               5300                   */
  115.    "\033OR",   /* Shift-F1      5400      PF3          */
  116.    "\033OS",   /* Shift-F2      5500      PF4          */
  117.    "\033Oy",   /* Shift-F3      5600      keypad '9'   */
  118.    "\033Om",   /* Shift-F4      5700      keypad '-'   */
  119.    "\033Ov",   /* Shift-F5      5800      keypad '6'   */
  120.    "\033Ol",   /* Shift-F6      5900      keypad ','   */
  121.    "\033Os",   /* Shift-F7      5a00      keypad '3'   */
  122.    "\033OM",   /* Shift-F8      5b00      keypad 'Enter' */
  123.    "\033On",   /* Shift-F9      5c00      keypad '.'   */
  124.    "\033OM",   /* Shift-F10     5d00      keypad 'Enter' */
  125.    ""
  126. };
  127.  
  128. void ansi_map (ScanVal)
  129. unsigned ScanVal;
  130. {
  131.    register KeyCode;
  132.    register char *s;
  133.  
  134.    KeyCode = ScanVal >> 8;                       /* Isolate to key scan code */
  135.    if ((KeyCode < 0x3b) || (KeyCode > 0x5d))
  136.       return;                                    /* Not in range, give up    */
  137.    s = ansi_seq[KeyCode - 0x3b];                 /* Index to our sequence    */
  138.    SENDCHARS (s, strlen (s), 0);                 /* Send the mapped string   */
  139. }
  140.  
  141. int term_overlay (k)
  142. int k;
  143. {
  144.    int c;
  145.    long t1;
  146.  
  147.          switch (k)
  148.             {
  149.             case ALTB:
  150.                ++baud;
  151.                if (!btypes[baud].rate_value)
  152.                   baud = 0;
  153.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  154.                cur_baud = btypes[baud].rate_value;
  155.                scr_printf (msgtxt[M_BINK_NOW_AT]);
  156.                (void) sprintf (junk, "%u baud.\r\n", btypes[baud].rate_value);
  157.                scr_printf (junk);
  158.                break;
  159.  
  160.             case ALTC:
  161.                scr_printf ("\r\n7 or 8 data bits? ");
  162.                (void) fgets (junk, 100, stdin);
  163.                comm_bits = (atoi (junk) == 7) ? BITS_7 : BITS_8;
  164.                if (comm_bits == BITS_8)
  165.                   {
  166.                   parity = NO_PARITY;
  167.                   }
  168.                else
  169.                   {
  170.                   scr_printf ("(E)ven, (O)dd, or (N)o parity? ");
  171.                   (void) fgets (junk, 100, stdin);
  172.                   (void) strupr (junk);
  173.                   parity = (junk[0] == 'E') ? EVEN_PARITY :
  174.                      ((junk[0] == 'O') ? ODD_PARITY : NO_PARITY);
  175.                   }
  176.                scr_printf ("1 or 2 stop bits? ");
  177.                (void) fgets (junk, 100, stdin);
  178.                stop_bits = (atoi (junk) == 1) ? STOP_1 : STOP_2;
  179.  
  180.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  181.                break;
  182.  
  183.             case ALTD:
  184.                scr_printf (msgtxt[M_PHONE_OR_NODE]);
  185.                if (!get_number (junk))
  186.                   break;
  187.                if (strchr (junk, '/') != NULL)
  188.                   {
  189.                   if (nodeproc (junk))
  190.                      {
  191.                      (void) strcpy (junk, (char *) (newnodedes.PhoneNumber));
  192.                      do_dial_strings ();
  193.                      }
  194.                   else break;
  195.                   }
  196.                caller = 0;
  197.                try_2_connect (junk);             /* try to connect         */
  198.                gong ();
  199.                break;
  200.  
  201.                 case ALTE:
  202.                 screen_clear ();
  203.                     break;
  204.  
  205.             case ALTH:
  206.                t1 = timerset (300);
  207.                while (CARRIER)
  208.                   if (timeup (t1))
  209.                      {
  210.                      scr_printf (msgtxt[M_NO_DROP_DTR]);
  211.                      break;
  212.                      }
  213.                   else
  214.                      {
  215.                      DTR_OFF ();
  216.                      }
  217.                status_line (msgtxt[M_END_OF_CONNECT]);
  218.                DTR_ON ();
  219.                break;
  220.  
  221.                 case ALTI:
  222.                     mdm_init (term_init);
  223.                     break;
  224.  
  225.             case ALTJ:
  226.                scr_printf ("\r\n");
  227.                scr_printf (&(msgtxt[M_SHELLING][1]));
  228.                scr_printf (msgtxt[M_TYPE_EXIT]);
  229. //               MDM_DISABLE ();
  230.                change_prompt ();
  231.                b_spawn (NULL);
  232.                /* Re-enable ourselves */
  233.                if (Cominit (port_ptr) != 0x1954)
  234.                   {
  235.                   (void) printf ("\r\n%s\r\n", msgtxt[M_FOSSIL_GONE]);
  236.                   exit (1);
  237.                   }
  238.                 come_back();            /* CML */
  239.                scr_printf (msgtxt[M_WELCOME_BACK]);
  240.                DTR_ON ();
  241.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  242.                break;
  243.  
  244.             case ALTP:
  245.                c = port_ptr;
  246.                if (++port_ptr == MAXport)
  247.                   port_ptr = 0;
  248.                MDM_DISABLE ();
  249.                if (Cominit (port_ptr) != 0x1954)
  250.                   {
  251.                   port_ptr = c;
  252.                   (void) Cominit(port_ptr);
  253.                   }
  254. //                if (!com_reinit())            /* CML */
  255. //                    {
  256. //                    printf ("\n%s\n", msgtxt[M_FOSSIL_GONE]);
  257. //                    exit (1);
  258. //                    }
  259.  
  260.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  261.                DTR_ON ();
  262.                scr_printf (msgtxt[M_BINK_NOW_USING]);
  263.                WRITE_ANSI (port_ptr + '1');
  264.                scr_printf (":\r\n");
  265.                XON_ENABLE ();
  266.                break;
  267.  
  268.             case ALTS:
  269.                if (old_fossil)
  270.                   {
  271.                   scr_printf (msgtxt[M_NO_BREAK]);
  272.                   }
  273.                else
  274.                   {
  275.                   scr_printf (msgtxt[M_SENDING_BREAK]);
  276.                   send_break (100);
  277.                   scr_printf (msgtxt[M_DONE]);
  278.                   }
  279.                break;
  280.  
  281.             case ALTV:
  282.                scr_printf (msgtxt[M_YOU_ARE_USING]);
  283.                scr_printf (ANNOUNCE);
  284.                scr_printf ("\r\n");
  285.                scr_printf (ver_stuff);
  286.                break;
  287.  
  288.             case ALTF1:
  289.             case ALTF2:
  290.             case ALTF3:
  291.             case ALTF4:
  292.             case ALTF5:
  293.             case ALTF6:
  294.             case ALTF7:
  295.             case ALTF8:
  296.             case ALTF9:
  297.                c = ((unsigned) k >> 8) - 0x68;
  298.                if (keys[c] != NULL)
  299.                   {
  300.                   SENDCHARS (keys[c], strlen (keys[c]), 0);
  301.                   }
  302.                break;
  303.  
  304.             default:
  305.                return (1);
  306.             }
  307.  
  308.    return (0);
  309. }
  310.  
  311.