home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / b_term.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  13.0 KB  |  482 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-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*          This module was originally written by Vince Perriello           */
  13. /*                                                                          */
  14. /*                       BinkleyTerm Terminal Module                        */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47. void term_Poll (ADDRP);
  48.  
  49. int 
  50. b_term ()
  51. {
  52. #ifdef BUFFERED_CONSOLE_WRITE
  53.     static char tbuf[200];        /*PLF Sun  12-01-1991  06:28:59 */
  54.     int tcnt = 0;                /*PLF Sun  12-01-1991  06:29:06 */
  55. #endif
  56.     short j, k;
  57.     short c;
  58.     unsigned int mask = 0xff;
  59.     int gateway_mode = 0;
  60.     int done;
  61.     struct _key_fnc_hdr *OldKeyFncHdr;
  62.     char *autodl = "**\030B00";    /* Zmodem autodl str.  */
  63.     char *search_autodl = autodl;
  64.  
  65. #ifdef HAVE_HYDRA
  66.     char *hauto   = "\030cA\\f5\\a3\030a";
  67.     char *search_hauto  = hauto;
  68. #endif /* HAVE_HYDRA */
  69.  
  70.     FILE *logfile = NULL;        /* log file stream */
  71.     char prot;
  72.     char *p;
  73.  
  74.     int retval = 1;                /* What to tell the mainline */
  75.     ADDR baddr;
  76.  
  77.     OldKeyFncHdr = KbMapSet (&TrmnlKeyFncHdr);
  78.  
  79.     set_prior (4);                /* Always High */
  80.     vfossil_cursor (1);
  81.     done = 0;
  82.     first_block = 0;
  83.     if ((term_init != NULL) && (!CARRIER))
  84.     {
  85.         (void) set_baud (max_baud.rate_value, 0);
  86.         mdm_cmd_string (term_init, 0);    /* then the modem init */
  87.     }
  88.  
  89.     while (!done)
  90.     {
  91.         c = -1;
  92.         if (CHAR_AVAIL ())
  93.         {
  94.             c = MODEM_IN ();
  95.  
  96.             if (comm_bits == BITS_7)
  97.                 c &= 0x7f;
  98.  
  99.             /* Check for Zmodem AutoDownload sequence */
  100.             if ((c & 0x7f) == (int) *search_autodl)
  101.             {
  102.                 if (!*++search_autodl)
  103.                 {
  104.                     scr_printf (MSG_TXT (M_ZMODEM_STARTED));
  105.                     CLEAR_INBOUND ();
  106.  
  107.                     (void) Download (NULL, (int) 'Z', NULL);
  108.  
  109.                     scr_printf (MSG_TXT (M_ZMODEM_FINISHED));
  110.                     search_autodl = autodl;
  111.                 }
  112.             }
  113.             else
  114.                 search_autodl = autodl;
  115.  
  116. #ifdef HAVE_HYDRA
  117.             /* Check for HYDRA AutoStart sequence */
  118.             if ((c & 0x7f) == (int) *search_hauto)
  119.             {
  120.                 if (!*++search_hauto)
  121.                 {
  122.                     scr_printf (MSG_TXT (M_HYDRA_AUTO_STARTED));
  123.  
  124.                     (void) Download (NULL, (int) 'H', NULL);
  125.  
  126.                     scr_printf (MSG_TXT (M_HYDRA_AUTO_FINISHED));
  127.                     search_hauto = hauto;
  128.                 }
  129.             }
  130.             else
  131.                 search_hauto = hauto;
  132. #endif /* HAVE_HYDRA */
  133.  
  134. /*
  135.  * I really don't like looking for this piece of crap, but people
  136.  * seem to really want it, so I guess I lose.  Now if only
  137.  * QuickBBS would do things that were ANSI compatible - ugh!
  138.  */
  139.             if (c == ' ')
  140.             {
  141.                 screen_clear ();
  142. #ifdef BUFFERED_CONSOLE_WRITE
  143.                 tcnt = 0;
  144. #endif
  145.             }
  146.             else if ((c == ENQ) && (answerback != NULL))
  147.             {
  148.                 mdm_cmd_string (answerback, 1);
  149.             }
  150.             else
  151.             {
  152. #ifndef BUFFERED_CONSOLE_WRITE
  153.                 WRITE_ANSI ((char)c);
  154. #else
  155.                 tbuf[tcnt++] = (char) c;    /*PLF Sun  12-01-1991  06:31:52 */
  156.                 if (tcnt == sizeof (tbuf) - 1)
  157.                 {
  158.                     tbuf[tcnt] = 0;
  159.                     puts (tbuf);
  160.                     tcnt = 0;
  161.                 }
  162. #endif
  163.             }
  164.  
  165.             if (logfile != NULL)
  166.             {
  167.                 (void) fwrite (&c, 1, 1, logfile);
  168.             }
  169.         }
  170. #ifdef BUFFERED_CONSOLE_WRITE
  171.         else    /* No characters received */
  172.         if (tcnt)
  173.         {
  174.             tbuf[tcnt] = 0;
  175.             puts (tbuf);
  176.             tcnt = 0;
  177.             c = 0;
  178.         }
  179. #endif
  180.  
  181.         if (KEYPRESS () || ctrlc_ctr)
  182.         {
  183.             if (ctrlc_ctr)
  184.             {
  185.                 /* We got a ^C, so output it properly */
  186.                 while (KEYPRESS ())    /* Flush keyboard buffer */
  187.                     (void) FOSSIL_CHAR ();
  188.                 ctrlc_ctr = 0;
  189.                 SENDBYTE (3);
  190.                 continue;
  191.             }
  192.             /* Get the keystroke. Map it, saving the original keystroke. */
  193.  
  194.             k = (short) KbRemap (j = FOSSIL_CHAR ());
  195.  
  196.             /* See if it mapped into 'toggle gateway'. If so, do it.     */
  197.  
  198.             if ((unsigned short) k == F_TERM_GATEWAYMODE)
  199.             {
  200.                 gateway_mode = ~gateway_mode;
  201.                 continue;
  202.             }
  203. /*
  204.  * It wasn't 'toggle gateway'. See if it's a command at all.
  205.  * Or if we are currently in gateway mode.
  206.  *
  207.  * If we are in gateway mode, we will send the raw keystroke
  208.  * out the comm port (zero plus scan code in the case of a
  209.  * function key).
  210.  *
  211.  * Otherwise, we'll send normal keystrokes out verbatim, and
  212.  * apply "ANSI mapping" to function keys.
  213.  */
  214.             if (gateway_mode || ((unsigned short) k & F_TRM_BS) != F_TRM_BS)
  215.             {
  216.                 if (comm_bits == BITS_7)
  217.                     mask = 0x7f;
  218.                 else
  219.                     mask = 0xff;
  220.  
  221.                 if (gateway_mode)
  222.                 {
  223.                     SENDBYTE ((unsigned char) (c = (j & mask)));
  224.                     if (c == 0)
  225.                         SENDBYTE ((unsigned char) (((unsigned short) j >> 8) & mask));
  226.                 }
  227.                 else
  228.                 {
  229.                     c = k & mask;
  230.                     if (c != 0)
  231.                         SENDBYTE ((unsigned char) c);
  232.                     else
  233.                         ansi_map ((unsigned short) k);
  234.                 }
  235.                 continue;
  236.             }
  237. /*
  238.  * It's a command key, which has been remapped to one of our internal
  239.  * codes. Dispatch on it.
  240.  */
  241.             if (!term_overlay (k))
  242.                 continue;
  243.             /* else */
  244.             switch ((unsigned short) k)
  245.             {
  246.             case F_TERM_CAPTUREFILE:
  247.                 if (logfile != NULL)
  248.                 {
  249.                     (void) fclose (logfile);
  250.                     logfile = NULL;
  251.                     (void) sprintf (junk, MSG_TXT (M_LOG_CLOSED), capturename);
  252.                     scr_printf (junk);
  253.                     break;
  254.                 }
  255.  
  256.                 if ((logptr == NULL) || (*logptr == '\0'))
  257.                 {
  258.                     scr_printf (MSG_TXT (M_INPUT_LOGFILE));
  259.                     (void) fgets (capturename, 100, stdin);
  260.                     if ((k = (short) strlen (capturename)) != 0)
  261.                         capturename[--k] = '\0';    /* no '\n' */
  262.                 }
  263.                 else
  264.                 {
  265.                     (void) strcpy (capturename, logptr);
  266.                     k = 1;
  267.                 }
  268.                 if (k)
  269.                 {
  270.                     logfile = share_fopen (capturename, append_binary, DENY_WRITE);
  271.                     if (logfile == NULL)
  272.                         (void) sprintf (junk, MSG_TXT (M_LOG_NOT_OPEN), capturename);
  273.                     else
  274.                         (void) sprintf (junk, MSG_TXT (M_LOG_OPEN), capturename);
  275.                     scr_printf (junk);
  276.                 }
  277.                 break;
  278.  
  279.             case F_TERM_POLLBOSS:
  280.                 term_Poll (&boss_addr);
  281.                 break;
  282.  
  283.             case F_TERM_POLLNODE:
  284.                 scr_printf ("\n");
  285.                 scr_printf (MSG_TXT (M_ENTER_NET_NODE));
  286.                 if (!get_number (junk))
  287.                     break;
  288.                 if ((find_address (junk, &baddr) == 0)
  289.                     || ((int) (baddr.Net) < 0)
  290.                     || ((int) (baddr.Node) < 0)
  291.                     || (nodefind (&baddr, 1) == 0))
  292.                 {
  293.                     (void) printf ("\n%s '%s'\n", &(MSG_TXT (M_NO_ADDRESS)[1]), junk);
  294.                     break;
  295.                 }
  296.  
  297.                 if (!baddr.Zone)
  298.                     baddr.Zone = found_zone;
  299.  
  300.                 term_Poll (&baddr);
  301.                 break;
  302.  
  303.             case F_TERM_DIALGROUP:
  304.                 if (!list_search ())
  305.                     screen_clear ();
  306.                 break;
  307.  
  308.             case F_TERM_MAILERMODE:
  309.                 if (port_ptr != original_port)
  310.                 {
  311.                     status_line (" %s COM%d:", MSG_TXT (M_SWITCHING_BACK), original_port + 1);
  312.                     MDM_DISABLE ();
  313.                     port_ptr = original_port;
  314.                     if (Cominit (port_ptr, buftmo) != 0x1954)
  315.                     {
  316.                         port_ptr = c;
  317.                         (void) Cominit (port_ptr, buftmo);
  318.                     }
  319.                     program_baud ();
  320.                     RAISE_DTR ();
  321.                 }
  322.                 retval = 0;
  323.  
  324.                 /* Fall into exit code */
  325.  
  326.             case F_TERM_EXITBINK:
  327.                 if (logfile != NULL)
  328.                     (void) fclose (logfile);
  329.                 done = 1;
  330.                 break;
  331.  
  332.             case F_TERM_UPLOAD:
  333.                 scr_printf (MSG_TXT (M_READY_TO_SEND));
  334.                 scr_printf (MSG_TXT (M_WHICH_PROTOCOL));
  335. #ifdef HAVE_HYDRA
  336.                 scr_printf ("H)ydra    Z)modem     S)EAlink     T)elink     X)modem\r\n");
  337. #else
  338.                 scr_printf ("Z)modem   S)EAlink    T)elink      X)modem\r\n");
  339. #endif /* HAVE_HYDRA */
  340.                 if (extern_protocols != NULL)
  341.                 {
  342.                     scr_printf (extern_protocols);
  343.                     scr_printf ("\r\n");
  344.                 }
  345.  
  346.                 scr_printf (MSG_TXT (M_CHOOSE));
  347.                 junk[0] = '\0';
  348.                 (void) fgets (junk, 100, stdin);
  349.                 if ((junk[0] == '\0') || (junk[0] == '\n'))
  350.                     break;
  351.                 if (!(prot = (char) toupper (junk[0])))
  352.                     break;
  353.                 p = NULL;
  354.                 if ((strchr (native_protocols, prot) == NULL)
  355.                     && ((extern_protocols == NULL) ? (1) : (p = strchr (extern_protocols, prot)) == NULL))
  356.                 {
  357.                     scr_printf (MSG_TXT (M_DONT_KNOW_PROTO));
  358.                     break;
  359.                 }
  360.                 scr_printf (MSG_TXT (M_FILE_TO_SEND));
  361.                 junk[0] = '\0';
  362.                 (void) fgets (junk, 100, stdin);
  363.                 if ((k = strlen (junk)) != 0)
  364.                     junk[--k] = '\0';
  365.                 if ((junk[0] == '\0') || (junk[0] == '\n'))
  366.                     break;
  367.  
  368.                 if ((!k) || (!dexists (junk)))
  369.                     break;
  370.  
  371.                 (void) Upload (junk, (int) prot, p);
  372.                 break;
  373.  
  374.             case F_TERM_DOWNLOAD:
  375.                 scr_printf (MSG_TXT (M_READY_TO_RECEIVE));
  376.                 scr_printf (MSG_TXT (M_WHICH_PROTOCOL));
  377.  
  378. #ifdef HAVE_HYDRA
  379.                 scr_printf ("H)ydra    Z)modem     S)EAlink     T)elink     X)modem\r\n");
  380. #else
  381.                 scr_printf ("Z)modem   S)EAlink    T)elink      X)modem\r\n");
  382. #endif /* HAVE_HYDRA */
  383.  
  384.                 if (extern_protocols != NULL)
  385.                 {
  386.                     scr_printf (extern_protocols);
  387.                     scr_printf ("\r\n");
  388.                 }
  389.                 scr_printf (MSG_TXT (M_CHOOSE));
  390.                 junk[0] = '\0';
  391.                 (void) fgets (junk, 100, stdin);
  392.                 if ((junk[0] == '\0') || (junk[0] == '\n'))
  393.                     break;
  394.                 if (!(prot = (char) toupper (junk[0])))
  395.                     break;
  396.                 p = NULL;
  397.                 if ((strchr (native_protocols, prot) == NULL)
  398.                     && ((extern_protocols == NULL) ? (1) : (p = strchr (extern_protocols, prot)) == NULL))
  399.                 {
  400.                     scr_printf (MSG_TXT (M_DONT_KNOW_PROTO));
  401.                     break;
  402.                 }
  403.  
  404.                 (void) Download (NULL, (int) prot, p);
  405.                 break;
  406.  
  407.             case F_TERM_HELPSCREEN:
  408.                 main_help ();
  409.                 break;
  410.  
  411.             default:
  412.                 break;
  413.             }
  414.         }
  415.  
  416.         if (c == -1)
  417.             time_release ();
  418.     }
  419.  
  420.     (void) KbMapSet (OldKeyFncHdr);
  421.  
  422.     set_prior (2);                /* Regular */
  423.     return (retval);
  424. }
  425.  
  426. /*
  427.  * Handle polls from terminal mode.
  428.  */
  429.  
  430. void 
  431. term_Poll (ADDRP address)
  432. {
  433.     unsigned save1, save2, save3;
  434.  
  435.     save1 = comm_bits;
  436.     save2 = parity;
  437.     save3 = stop_bits;
  438.  
  439.     un_attended = 1;
  440.     if (fullscreen)
  441.     {
  442.         sb_dirty ();
  443.         opening_banner ();
  444.         mailer_banner ();
  445.  
  446.         (void) sprintf (junk, "%s", Full_Addr_Str (address));
  447.         junk[28] = '\0';
  448.  
  449.         sb_fill (holdwin, ' ', colors.hold);
  450.         sb_move (holdwin, 2, 12);
  451.         sb_puts (holdwin, MSG_TXT (M_POLLING_COLON));
  452.         sb_move (holdwin, 4, (short) (16 - strlen (junk) / 2));
  453.         sb_puts (holdwin, junk);
  454.         sb_show ();
  455.     }
  456.     else
  457.     {
  458.         scr_printf (MSG_TXT (M_MAILER_MODE));
  459.     }
  460.     if (!CARRIER)
  461.         mdm_hangup ();
  462.     (void) do_mail (address, 1);
  463.     un_attended = 0;
  464.     if (fullscreen)
  465.     {
  466.         screen_clear ();
  467.     }
  468.     else
  469.     {
  470.         scr_printf ("\r\n");
  471.     }
  472.     scr_printf (MSG_TXT (M_MANUAL_MODE));
  473.  
  474.     comm_bits = save1;
  475.     parity = save2;
  476.     stop_bits = save3;
  477.     program_baud ();
  478.  
  479.     gong ();
  480.     vfossil_cursor (1);
  481. }
  482.