home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts314b4 / b_termov.c < prev    next >
C/C++ Source or Header  |  1994-01-08  |  14KB  |  337 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. #ifndef LATTICE
  51. #include <process.h>
  52. #endif
  53. #include <stdlib.h>
  54. #ifndef __TOS__
  55. #include <dos.h>
  56. #endif
  57.  
  58. #ifdef OS_2
  59. #define INCL_DOSPROCESS
  60. #endif
  61.  
  62. #ifdef __TURBOC__
  63. #ifndef __TOS__
  64. #include <alloc.h>
  65. #endif
  66. #else
  67. #ifndef LATTICE
  68. #include <malloc.h>
  69. #endif
  70. #endif
  71.  
  72. #include "bink.h"
  73. #include "msgs.h"
  74. #include "com.h"
  75. #include "keybd.h"
  76. #include "sbuf.h"
  77. #include "ascii.h"
  78. #include "nodeproc.h"
  79. #include "vfossil.h"
  80.  
  81. /*--------------------------------------------------------------------------*/
  82. /*                                                                          */
  83. /* ansi_map() -- map function key into an ANSI escape sequence if we have   */
  84. /* one to correspond to the key. The "emulation" is VT100-type, we map the  */
  85. /* arrow keys to the ANSI escape sequences for up, down, right and left,    */
  86. /* and we map the function keys into the VT100 keypad, assuming application */
  87. /* mode, like Procomm. That is, we take the VT100 keypad, split it in two   */
  88. /* vertically, and use the F-keys to represent the left side, and the       */
  89. /* "shifted" F-keys to represent the right side.                            */
  90. /*                                                                          */
  91. /*              The result, if any, is transmitted to the host.             */
  92. /*                                                                          */
  93. /*--------------------------------------------------------------------------*/
  94. /* ESC Seq        IBM key       Scan code VT100 key    */
  95.  
  96. static char *ansi_seq[] = { 
  97.    "\033OP",   /* F1            3b00      PF1          */
  98.    "\033OQ",   /* F2            3c00      PF2          */
  99.    "\033Ow",   /* F3            3d00      keypad '7'   */
  100.    "\033Ox",   /* F4            3e00      keypad '8'   */
  101.    "\033Ot",   /* F5            3f00      keypad '4'   */
  102.    "\033Ou",   /* F6            4000      keypad '5'   */
  103.    "\033Oq",   /* F7            4100      keypad '1'   */
  104.    "\033Or",   /* F8            4200      keypad '2'   */
  105.    "\033Op",   /* F9            4300      keypad '0'   */
  106.    "\033Op",   /* F10           4400      keypad '0'   */
  107.    "",         /*               4500                   */
  108.    "",         /*               4600                   */
  109.    "",         /*               4700                   */
  110.    "\033[A",   /* Up Arrow      4800      Up Arrow     */
  111.    "",         /*               4900                   */
  112.    "",         /*               4a00                   */
  113.    "\033[D",   /* Left Arrow    4b00      Left Arrow   */
  114.    "",         /*               4c00                   */
  115.    "\033[C",   /* Right Arrow   4d00      Right Arrow  */
  116.    "",         /*               4e00                   */
  117.    "",         /*               4f00                   */
  118.    "\033[B",   /* Down Arrow    5000      Down Arrow   */
  119.    "",         /*               5100                   */
  120.    "",         /*               5200                   */
  121.    "",         /*               5300                   */
  122.    "\033OR",   /* Shift-F1      5400      PF3          */
  123.    "\033OS",   /* Shift-F2      5500      PF4          */
  124.    "\033Oy",   /* Shift-F3      5600      keypad '9'   */
  125.    "\033Om",   /* Shift-F4      5700      keypad '-'   */
  126.    "\033Ov",   /* Shift-F5      5800      keypad '6'   */
  127.    "\033Ol",   /* Shift-F6      5900      keypad ','   */
  128.    "\033Os",   /* Shift-F7      5a00      keypad '3'   */
  129.    "\033OM",   /* Shift-F8      5b00      keypad 'Enter' */
  130.    "\033On",   /* Shift-F9      5c00      keypad '.'   */
  131.    "\033OM",   /* Shift-F10     5d00      keypad 'Enter' */
  132.    ""
  133. };
  134.  
  135. void ansi_map( unsigned int ScanVal )
  136. {
  137.    register KeyCode;
  138.    register char *s;
  139.  
  140.    KeyCode = ScanVal >> 8;                       /* Isolate to key scan code */
  141.    if ((KeyCode < 0x3b) || (KeyCode > 0x5d))
  142.       return;                                    /* Not in range, give up    */
  143.    s = ansi_seq[KeyCode - 0x3b];                 /* Index to our sequence    */
  144.    SENDCHARS (s, strlen (s), 0);                 /* Send the mapped string   */
  145. }
  146.  
  147. int term_overlay( int k )
  148. {
  149.    int c;
  150.    long t1;
  151.  
  152.          switch (k)
  153.             {
  154.             case ALTB:
  155.                ++baud;
  156.                if (!btypes[baud].rate_value)
  157.                   baud = 0;
  158.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  159.                cur_baud = btypes[baud].rate_value;
  160.                scr_printf (msgtxt[M_BINK_NOW_AT]);
  161.                (void) sprintf (junk, "%u baud.\r\n", btypes[baud].rate_value);
  162.                scr_printf (junk);
  163.                break;
  164.  
  165.             case ALTC:
  166.                scr_printf ("\r\n7 or 8 data bits? ");
  167.                (void) fgets (junk, 100, stdin);
  168.                comm_bits = (atoi (junk) == 7) ? BITS_7 : BITS_8;
  169.                if (comm_bits == BITS_8)
  170.                   {
  171.                   parity = NO_PARITY;
  172.                   }
  173.                else
  174.                   {
  175.                   scr_printf ("(E)ven, (O)dd, or (N)o parity? ");
  176.                   (void) fgets (junk, 100, stdin);
  177.                   (void) strupr (junk);
  178.                   parity = (junk[0] == 'E') ? EVEN_PARITY :
  179.                      ((junk[0] == 'O') ? ODD_PARITY : NO_PARITY);
  180.                   }
  181.                scr_printf ("1 or 2 stop bits? ");
  182.                (void) fgets (junk, 100, stdin);
  183.                stop_bits = (atoi (junk) == 1) ? STOP_1 : STOP_2;
  184.  
  185.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  186.                break;
  187.  
  188.             case ALTD:
  189.                scr_printf (msgtxt[M_PHONE_OR_NODE]);
  190.                if (!get_number (junk))
  191.                   break;
  192.                if (strchr (junk, '/') != NULL)
  193.                   {
  194.                   if (nodeproc (junk))
  195.                      {
  196.                      (void) strcpy (junk, (char *) (newnodedes.PhoneNumber));
  197.                      do_dial_strings ();
  198.                      }
  199.                   else break;
  200.                   }
  201.                caller = 0;
  202.                try_2_connect (junk);             /* try to connect         */
  203.                gong ();
  204.                break;
  205.  
  206.                 case ALTE:
  207.                 screen_clear ();
  208.                     break;
  209.  
  210.             case ALTH:
  211.                t1 = timerset (300);
  212.                while (CARRIER)
  213.                   if (timeup (t1))
  214.                      {
  215.                      scr_printf (msgtxt[M_NO_DROP_DTR]);
  216.                      break;
  217.                      }
  218.                   else
  219.                      {
  220. #ifdef NEW /* FASTMODEM  10.09.1989 */
  221.                      hang_up ();
  222. #else
  223.                      DTR_OFF ();
  224. #endif
  225.                      }
  226.                status_line (msgtxt[M_END_OF_CONNECT]);
  227.                DTR_ON ();
  228.                break;
  229.  
  230.                 case ALTI:
  231.                     mdm_init (term_init);
  232.                     break;
  233.  
  234. #if 0    /* oho! We want escape to get processed! */
  235.             case ESC:
  236.                 sb_popup(10,1,2,78, do_shell, 1);
  237.                 break;
  238. #endif
  239.             case ALTJ:
  240.                scr_printf ("\r\n");
  241.                scr_printf (&(msgtxt[M_SHELLING][1]));
  242.                scr_printf (msgtxt[M_TYPE_EXIT]);
  243.                MDM_DISABLE ();
  244.                change_prompt ();
  245.                b_spawn (NULL);
  246.                /* Re-enable ourselves */
  247.                if (Cominit (port_ptr) != 0x1954)
  248.                   {
  249.                   (void) printf ("\r\n%s\r\n", msgtxt[M_FOSSIL_GONE]);
  250.                   if (reset_port) exit_port();
  251.                   exit (1);
  252.                   }
  253.                scr_printf (msgtxt[M_WELCOME_BACK]);
  254.                DTR_ON ();
  255.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  256.                break;
  257.  
  258.             case ALTP:
  259.                c = port_ptr;
  260.                if (++port_ptr == MAXport)
  261.                   port_ptr = 0;
  262.                MDM_DISABLE ();
  263.                if (Cominit (port_ptr) != 0x1954)
  264.                   {
  265.                   port_ptr = c;
  266.                   (void) Cominit(port_ptr);
  267.                   }
  268.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  269.                DTR_ON ();
  270.                scr_printf (msgtxt[M_BINK_NOW_USING]);
  271.                WRITE_ANSI (port_ptr + '1');
  272.                scr_printf (":\r\n");
  273.                XON_ENABLE ();
  274.                break;
  275.  
  276.             case ALTS:
  277. #ifndef ATARIST
  278.                if (old_fossil)
  279.                   {
  280.                   scr_printf (msgtxt[M_NO_BREAK]);
  281.                   }
  282.                else
  283. #endif
  284.                   {
  285.                   scr_printf (msgtxt[M_SENDING_BREAK]);
  286.                   send_break (100);
  287.                   scr_printf (msgtxt[M_DONE]);
  288.                   }
  289.                break;
  290.  
  291.             case ALTV:
  292.                screen_clear();
  293.                scr_printf (msgtxt[M_YOU_ARE_USING]);
  294.                scr_printf (ANNOUNCE);
  295.                scr_printf ("\r\n");
  296.                scr_printf (ver_stuff);
  297. #ifdef NEW
  298.                scr_printf("Thanks to everyone for their bug reports and suggestions, including:\r\n");
  299.                scr_printf("  Bernd Renzing, Rinaldo Visscher, Johan Ansems, Theo Runia, Jon Webb,\r\n");
  300.                scr_printf("  Albi Rebmann, Udo Erdelhoff, David Thomas, Joop Koopman, Joerg Spilker,\r\n");
  301.                scr_printf("  Daron Brewood, Phil Gadsby, Alexander Bochmann, John Graham,\r\n");
  302.                scr_printf("  Stephan Slabihoud, etc...\r\n");
  303.                scr_printf("And of course thanks to the Binkley Trio (Vince Perriello, Bob Hartman\r\n");
  304.                scr_printf("and Alan Applegate) for creating BinkleyTerm in the first place!\r\n\r\n");
  305.                scr_printf("- STeVeN.   My Little Phoney BBS, +44-793-849044\r\n");
  306.                scr_printf("            FidoNet 2:255/355, NeST 90:1004/1004\r\n");
  307.                scr_printf("            sgreen@cix.compulink.co.uk\r\n\r\n");
  308. #endif
  309.                break;
  310.  
  311.             case ALTF1:
  312.             case ALTF2:
  313.             case ALTF3:
  314.             case ALTF4:
  315.             case ALTF5:
  316.             case ALTF6:
  317.             case ALTF7:
  318.             case ALTF8:
  319.             case ALTF9:
  320. #if N_SHELLS >= 10
  321.             case ALTF10:
  322. #endif
  323.                c = ((unsigned) k >> 8) - 0x68;
  324.                if (keys[c] != NULL)
  325.                   {
  326.                   SENDCHARS (keys[c], strlen (keys[c]), 0);
  327.                   }
  328.                break;
  329.  
  330.             default:
  331.                return (1);
  332.             }
  333.  
  334.    return (0);
  335. }
  336.  
  337.