home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_TERM.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  15KB  |  423 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-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*          This module was originally written by Vince Perriello           */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                       BinkleyTerm Terminal Module                        */
  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.250.    */
  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:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.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.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. void term_Poll (ADDRP);
  51.  
  52. int b_term ()
  53. {
  54.    int j, k;
  55.    int c;
  56.    unsigned int mask = 0xff;
  57.    int gateway_mode = 0;
  58.    int done;
  59.    struct _key_fnc_hdr *OldKeyFncHdr;
  60.    char *autodl = "**\030B00";                   /* Zmodem autodl str.  */
  61.    char *search_autodl = autodl;
  62.    FILE *logfile = NULL;                         /* log file stream
  63.                                                   * descriptor */
  64.    char prot;
  65.    char *p;
  66.  
  67.    int retval = 1;                               /* What to tell the mainline */
  68.    ADDR baddr;
  69.  
  70.    OldKeyFncHdr = KbMapSet (&TrmnlKeyFncHdr);
  71.  
  72.    set_prior(4);                                    /* Always High */
  73.    vfossil_cursor (1);
  74.    done = 0;
  75.    first_block = 0;
  76.    if ((term_init != NULL) && (!CARRIER))
  77.       {
  78.       (void) set_baud (max_baud.rate_value, 0);
  79.       mdm_cmd_string (term_init, 0);                /* then the modem init */
  80.       }
  81.  
  82.    while (!done)
  83.       {
  84.       c = -1;
  85.       if (CHAR_AVAIL ())
  86.          {
  87.          c = MODEM_IN ();
  88.  
  89.          if (comm_bits == BITS_7)
  90.             c &= 0x7f;
  91.  
  92.          /* Check for Zmodem AutoDownload sequence */
  93.          if ((c & 0x7f) == (int) *search_autodl)
  94.             {
  95.             if (!*++search_autodl)
  96.                {
  97.                scr_printf (MSG_TXT(M_ZMODEM_STARTED));
  98.                CLEAR_INBOUND();
  99.  
  100.                (void) Download (NULL, (int)'Z', NULL);
  101.  
  102.                scr_printf (MSG_TXT(M_ZMODEM_FINISHED));
  103.                search_autodl = autodl;
  104.                }
  105.             }
  106.          else search_autodl = autodl;
  107.  
  108. /*
  109.  * I really don't like looking for this piece of crap, but people
  110.  * seem to really want it, so I guess I lose.  Now if only
  111.  * QuickBBS would do things that were ANSI compatible - ugh!
  112.  */
  113.          if (c == ' ')
  114.             {
  115.             screen_clear ();
  116.             }
  117.          else if ((c == ENQ) && (answerback != NULL))
  118.             {
  119.             mdm_cmd_string (answerback, 1);
  120.             }
  121.          else
  122.             {
  123.             WRITE_ANSI ((char)c);
  124.             }
  125.  
  126.          if (logfile != NULL)
  127.             {
  128.             (void) fwrite (&c, 1, 1, logfile);
  129.             }
  130.          }
  131.  
  132.       if (KEYPRESS () || ctrlc_ctr)
  133.          {
  134.          c = 0;
  135.          if (ctrlc_ctr)
  136.             {
  137.             /* We got a ^C, so output it properly */
  138.             while (KEYPRESS ())                  /* Flush keyboard buffer */
  139.                (void) FOSSIL_CHAR ();
  140.             ctrlc_ctr = 0;
  141.             SENDBYTE (3);
  142.             continue;
  143.             }
  144. /* Get the keystroke. Map it, saving the original keystroke. */
  145.  
  146.          k = (int) KbRemap (j = FOSSIL_CHAR ());
  147.  
  148. /* See if it mapped into 'toggle gateway'. If so, do it.     */
  149.  
  150.          if ((unsigned)k == F_TERM_GATEWAYMODE)
  151.             {
  152.             gateway_mode = ~gateway_mode;
  153.             continue;
  154.             }
  155. /*
  156.  * It wasn't 'toggle gateway'. See if it's a command at all.
  157.  * Or if we are currently in gateway mode.
  158.  * 
  159.  * If we are in gateway mode, we will send the raw keystroke
  160.  * out the comm port (zero plus scan code in the case of a
  161.  * function key).
  162.  *
  163.  * Otherwise, we'll send normal keystrokes out verbatim, and
  164.  * apply "ANSI mapping" to function keys.
  165.  */
  166.          if (gateway_mode || ((unsigned)k & F_TERM_BASE) != F_TERM_BASE)
  167.             {
  168.             if (comm_bits == BITS_7)
  169.                mask = 0x7f;
  170.             else mask = 0xff;
  171.  
  172.             if (gateway_mode)
  173.                {
  174.                SENDBYTE ((unsigned char )(c = (j & mask)));
  175.                if (c == 0)
  176.                   SENDBYTE ((unsigned char)(((unsigned int)j >> 8) & mask));
  177.                }
  178.             else
  179.                {
  180.                c = k & mask;
  181.                if (c != 0)
  182.                   SENDBYTE ((unsigned char) c);
  183.                else
  184.                   ansi_map ((unsigned) k);
  185.                }
  186.             continue;
  187.             }
  188. /*
  189.  * It's a command key, which has been remapped to one of our internal
  190.  * codes. Dispatch on it.
  191.  */
  192.          if (!term_overlay (k))
  193.             continue;
  194.       /* else */
  195.          switch ((unsigned)k)
  196.             {
  197.             case F_TERM_CAPTUREFILE:
  198.                if (logfile != NULL)
  199.                   {
  200.                   (void) fclose (logfile);
  201.                   logfile = NULL;
  202.                   (void) sprintf (junk, MSG_TXT(M_LOG_CLOSED), capturename);
  203.                   scr_printf(junk);
  204.                   break;
  205.                   }
  206.  
  207.                if ((logptr == NULL) || (*logptr == '\0'))
  208.                   {
  209.                   scr_printf (MSG_TXT(M_INPUT_LOGFILE));
  210.                   (void) fgets (capturename, 100, stdin);
  211.                   if ((k = (int) strlen (capturename)) != 0)
  212.                      capturename[--k] = '\0'; /* no '\n' */
  213.                   }
  214.                else
  215.                   {
  216.                   (void) strcpy (capturename, logptr);
  217.                   k = 1;
  218.                   }
  219.                if (k)
  220.                   {
  221.                   logfile = share_fopen (capturename, "ab", DENY_WRITE);
  222.                   if (logfile == NULL)
  223.                      (void) sprintf (junk, MSG_TXT(M_LOG_NOT_OPEN), capturename);
  224.                   else
  225.                      (void) sprintf (junk, MSG_TXT(M_LOG_OPEN), capturename);
  226.                   scr_printf(junk);
  227.                   }
  228.                break;
  229.  
  230.              case F_TERM_POLLBOSS:
  231.                term_Poll (&boss_addr);
  232.                break;
  233.  
  234.              case F_TERM_POLLNODE:
  235.                scr_printf ("\n");
  236.                scr_printf (MSG_TXT(M_ENTER_NET_NODE));
  237.                if (!get_number (junk))
  238.                   break;
  239.                if ((find_address (junk, &baddr) == 0)
  240.                || ((int)(baddr.Net) < 0)
  241.                || ((int)(baddr.Node) < 0)
  242.                || (nodefind (&baddr,1) == 0)) 
  243.                   {
  244.                   (void) printf ("\n%s '%s'\n", &(MSG_TXT(M_NO_ADDRESS)[1]), junk);
  245.                   break;
  246.                   }
  247.  
  248.                if (!baddr.Zone)
  249.                   baddr.Zone = found_zone;
  250.  
  251.                term_Poll (&baddr);
  252.                break;
  253.  
  254.             case F_TERM_DIALGROUP:
  255.                if (!list_search ())
  256.                   screen_clear ();
  257.                break;
  258.  
  259.             case F_TERM_MAILERMODE:
  260.                if (port_ptr != original_port)
  261.                   {
  262.                   status_line (" %s COM%d:", MSG_TXT(M_SWITCHING_BACK), original_port + 1);
  263.                   MDM_DISABLE ();
  264.                   port_ptr = original_port;
  265.                   if (Cominit (port_ptr, buftmo) != 0x1954)
  266.                      {
  267.                      port_ptr = c;
  268.                      (void) Cominit(port_ptr, buftmo);
  269.                      }
  270.                   program_baud ();
  271.                   RAISE_DTR ();
  272.                   }
  273.                retval = 0;
  274.  
  275.             /* Fall into exit code */
  276.  
  277.             case F_TERM_EXITBINK:
  278.                if (logfile != NULL)
  279.                   (void) fclose (logfile);
  280.                done = 1;
  281.                break;
  282.  
  283.             case F_TERM_UPLOAD:
  284.                scr_printf (MSG_TXT(M_READY_TO_SEND));
  285.                scr_printf (MSG_TXT(M_WHICH_PROTOCOL));
  286.                scr_printf ("Z)modem     S)EAlink     T)elink     X)modem\r\n");
  287.                if (extern_protocols != NULL)
  288.                   {
  289.                   scr_printf (extern_protocols);
  290.                   scr_printf ("\r\n");
  291.                   }
  292.  
  293.                scr_printf (MSG_TXT(M_CHOOSE));
  294.                junk[0] = '\0';
  295.                (void) fgets (junk, 100, stdin);
  296.                if ((junk[0] == '\0') || (junk[0] == '\n'))
  297.                   break;
  298.                if (!(prot = (char) toupper (junk[0])))
  299.                   break;
  300.                p = NULL;
  301.                if ((strchr (native_protocols, prot) == NULL)
  302.                && ((extern_protocols == NULL) ? (1) : (p = strchr (extern_protocols, prot)) == NULL))
  303.                   {
  304.                   scr_printf (MSG_TXT(M_DONT_KNOW_PROTO));
  305.                   break;
  306.                   }
  307.                scr_printf (MSG_TXT(M_FILE_TO_SEND));
  308.                junk[0] = '\0';
  309.                (void) fgets (junk, 100, stdin);
  310.                if ((k = strlen (junk)) != 0)
  311.                   junk[--k] = '\0';
  312.                if ((junk[0] == '\0') || (junk[0] == '\n'))
  313.                   break;
  314.  
  315.                if ((!k) || (!dexists (junk)))
  316.                   break;
  317.  
  318.                (void) Upload (junk, (int) prot, p);
  319.                break;
  320.  
  321.             case F_TERM_DOWNLOAD:
  322.                scr_printf (MSG_TXT(M_READY_TO_RECEIVE));
  323.                scr_printf (MSG_TXT(M_WHICH_PROTOCOL));
  324.                scr_printf ("Z)modem     S)EAlink     T)elink     X)modem\r\n");
  325.                if (extern_protocols != NULL)
  326.                   {
  327.                   scr_printf (extern_protocols);
  328.                   scr_printf ("\r\n");
  329.                   }
  330.                scr_printf (MSG_TXT(M_CHOOSE));
  331.                junk[0] = '\0';
  332.                (void) fgets (junk, 100, stdin);
  333.                if ((junk[0] == '\0') || (junk[0] == '\n'))
  334.                   break;
  335.                if (!(prot = (char) toupper (junk[0])))
  336.                   break;
  337.                p = NULL;
  338.                if ((strchr (native_protocols, prot) == NULL)
  339.                && ((extern_protocols == NULL) ? (1) : (p = strchr (extern_protocols, prot)) == NULL))
  340.                   {
  341.                   scr_printf (MSG_TXT(M_DONT_KNOW_PROTO));
  342.                   break;
  343.                   }
  344.  
  345.                (void) Download (NULL, (int)prot, p);
  346.                break;
  347.  
  348.             case F_TERM_HELPSCREEN:
  349.                main_help ();
  350.                break;
  351.  
  352.             default:
  353.                break;
  354.             }
  355.          }
  356.       if (c == -1)
  357.          time_release ();
  358.       }
  359.  
  360.    (void) KbMapSet(OldKeyFncHdr);
  361.  
  362.    set_prior(2);                                          /* Regular */
  363.    return (retval);
  364. }
  365.  
  366. /*
  367.  * Handle polls from terminal mode.
  368.  */
  369.  
  370. void term_Poll (ADDRP address)
  371. {
  372.    unsigned save1, save2, save3;
  373.  
  374.    save1 = comm_bits;
  375.    save2 = parity;
  376.    save3 = stop_bits;
  377.  
  378.    un_attended = 1;
  379.    if (fullscreen)
  380.       {
  381.       sb_dirty ();
  382.       opening_banner ();
  383.       mailer_banner ();
  384.  
  385.       (void) sprintf (junk, "%s", Full_Addr_Str (address));
  386.       junk[28] = '\0';
  387.  
  388.       sb_fill (hold_hWnd, ' ', colors.hold);
  389.       SendMessage( hold_hWnd, WM_COMMAND, GD_MODE, 0L );
  390.       SendMessage( hold_hWnd, WM_COMMAND, GD_CLR, 0L );
  391.       sb_move (hold_hWnd, 2, 12);
  392.       sb_puts( hold_Poll, MSG_TXT(M_POLLING_COLON));
  393.       sb_move (hold_hWnd, 4, 16 - strlen (junk) / 2);
  394.       sb_puts( hold_Addr, junk);
  395.       sb_show ();
  396.       }
  397.    else
  398.       {
  399.       scr_printf (MSG_TXT(M_MAILER_MODE));
  400.       }
  401.    if (!CARRIER)
  402.       mdm_hangup ();
  403.    (void) do_mail (address, 1);
  404.    un_attended = 0;
  405.    if (fullscreen)
  406.       {
  407.       screen_clear ();
  408.       }
  409.    else
  410.       {
  411.       scr_printf ("\r\n");
  412.       }
  413.    scr_printf (MSG_TXT(M_MANUAL_MODE));
  414.  
  415.    comm_bits = save1;
  416.    parity = save2;
  417.    stop_bits = save3;
  418.    program_baud ();
  419.  
  420.    gong ();
  421.    vfossil_cursor (1);
  422. }
  423.