home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_TERM.C < prev    next >
C/C++ Source or Header  |  1991-08-23  |  21KB  |  561 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.  
  46. #include <stdio.h>
  47. #include <signal.h>
  48. #include <ctype.h>
  49. #include <conio.h>
  50. #include <string.h>
  51. #include <process.h>
  52. #include <stdlib.h>
  53. #include <dos.h>
  54.  
  55. #ifdef OS_2
  56. #define INCL_DOSPROCESS
  57. #endif
  58.  
  59. #ifdef __TURBOC__
  60. #include <alloc.h>
  61. #include <dir.h>
  62. #else
  63. #include <malloc.h>
  64. #endif
  65.  
  66. #include "com.h"
  67. #include "xfer.h"
  68. #include "zmodem.h"
  69. #include "keybd.h"
  70. #include "sbuf.h"
  71. #include "sched.h"
  72. #include "externs.h"
  73. #include "prototyp.h"
  74.  
  75.  
  76. extern int fossil_init;                /* CML */
  77.  
  78.  
  79. int b_term ()
  80. {
  81.    int k;
  82.    int c;
  83.    int done;
  84.    unsigned save1, save2, save3;
  85.    char *autodl = "**\030B00";                   /* Zmodem autodl str.  */
  86.    char *search_autodl = autodl;
  87.    FILE *logfile = NULL;                         /* log file stream
  88.                                                   * descriptor */
  89.    char prot;
  90.    char *p;                                      /* Used for external
  91.                                                   * protocol */
  92.    int retval = 1;                               /* What to tell the mainline */
  93.    int err;
  94.    ADDR baddr;
  95.  
  96. #ifdef OS_2
  97.    struct FILEINFO fileinfo;
  98. #else
  99. #ifndef __TURBOC__
  100.    struct find_t fileinfo;
  101. #else
  102.    struct ffblk fileinfo;
  103. #endif
  104. #endif
  105.  
  106.    set_prior(4);                                    /* Always High */
  107.    vfossil_cursor (1);
  108.    done = 0;
  109.     first_block = 0;
  110.     if ((term_init != NULL) && (!CARRIER))
  111.         {
  112.       (void) set_baud (max_baud.rate_value, 0);
  113.        mdm_cmd_string (term_init, 0);                /* then the modem init
  114.                                                       * string */
  115.         }
  116.  
  117.    while (!done)
  118.       {
  119.       c = -1;
  120.       if (CHAR_AVAIL ())
  121.          {
  122.          c = MODEM_IN ();
  123.  
  124.          if (comm_bits == BITS_7)
  125.             c &= 0x7f;
  126.  
  127.          /* Check for Zmodem AutoDownload sequence */
  128.          if ((c & 0x7f) == *search_autodl)
  129.             {
  130.             if (!*++search_autodl)
  131.                {
  132.                scr_printf (msgtxt[M_ZMODEM_STARTED]);
  133.                CLEAR_INBOUND();
  134.  
  135.                save1 = comm_bits;
  136.                save2 = parity;
  137.                save3 = stop_bits;
  138.                comm_bits = BITS_8;
  139.                parity = NO_PARITY;
  140.                stop_bits = STOP_1;
  141.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  142.                XON_DISABLE ();
  143.  
  144.                (void) get_Zmodem (download_path, NULL);
  145.                comm_bits = save1;
  146.                parity = save2;
  147.                stop_bits = save3;
  148.                MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  149.                XON_ENABLE ();
  150.  
  151.                scr_printf (msgtxt[M_ZMODEM_FINISHED]);
  152.                search_autodl = autodl;
  153.                }
  154.             }
  155.          else search_autodl = autodl;
  156.  
  157. /*
  158.  * I really don't like looking for this piece of crap, but people
  159.  * seem to really want it, so I guess I lose.  Now if only
  160.  * QuickBBS would do things that were ANSI compatible - ugh!
  161.  */
  162.          if (c == ' ')
  163.             {
  164.             screen_clear ();
  165.             }
  166.          else if ((c == ENQ) && (answerback != NULL))
  167.             {
  168.             mdm_cmd_string (answerback, 1);
  169.             }
  170.          else
  171.             {
  172.             WRITE_ANSI (c);
  173.             }
  174.  
  175.          if (logfile != NULL)
  176.             {
  177.             (void) fwrite (&c, 1, 1, logfile);
  178.             }
  179.          }
  180.       if (KEYPRESS () || ctrlc_ctr)
  181.          {
  182.          c = 0;
  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. #if 0
  190.             while (Com_Tx_NW (3) == 0)
  191.                ;
  192. #endif
  193.             com_putc(3);        /* CML */
  194.             continue;
  195.             }
  196.          k = (int) FOSSIL_CHAR ();
  197.          if (term_overlay (k))
  198.             {
  199.             switch (k)
  200.                {
  201.                case ALTL:
  202.                   if (logfile != NULL)
  203.                      {
  204.                      (void) fclose (logfile);
  205.                      logfile = NULL;
  206.                      sprintf (junk, msgtxt[M_LOG_CLOSED], capturename);
  207.                      scr_printf(junk);
  208.                      break;
  209.                      }
  210.  
  211.                   if ((logptr == NULL) || (*logptr == '\0'))
  212.                      {
  213.                      scr_printf (msgtxt[M_INPUT_LOGFILE]);
  214.                      (void) fgets (capturename, 100, stdin);
  215.                      if (k = (int) strlen (capturename))
  216.                         capturename[--k] = '\0'; /* no '\n' */
  217.                      }
  218.                   else
  219.                      {
  220.                      (void) strcpy (capturename, logptr);
  221.                      k = 1;
  222.                      }
  223.                   if (k)
  224.                      {
  225.                      logfile = fopen (capturename, "ab");
  226.                      if (logfile == NULL)
  227.                         sprintf (junk, msgtxt[M_LOG_NOT_OPEN], capturename);
  228.                      else
  229.                         sprintf (junk, msgtxt[M_LOG_OPEN], capturename);
  230.                      scr_printf(junk);
  231.                      }
  232.                   break;
  233.  
  234.                 case ALTY:
  235.                   baddr = boss_addr;
  236.                   goto polling;
  237.  
  238.                 case ALTM:
  239.                   scr_printf ("\n");
  240.                   scr_printf (msgtxt[M_ENTER_NET_NODE]);
  241.                   if (!get_number (junk))
  242.                      break;
  243.                   if ((!find_address (junk, &baddr))
  244.                        || (baddr.Net < 0)
  245.                   || (baddr.Node < 0)
  246.                   || (!nodefind (&baddr,1)))
  247.                      {
  248.                      (void) printf ("\n%s '%s'\n", &(msgtxt[M_NO_ADDRESS][1]), junk);
  249.                      break;
  250.                      }
  251.                   if (!baddr.Zone)
  252.                      baddr.Zone = found_zone;
  253. polling:
  254.                   un_attended = 1;
  255.                   if (fullscreen)
  256.                      {
  257.                      sb_dirty ();
  258.                      opening_banner ();
  259.                      mailer_banner ();
  260.                      sb_fill (holdwin, ' ', colors.hold);
  261.                      sb_move (holdwin, 2, 12);
  262.                      sb_puts (holdwin, msgtxt[M_POLLING_COLON]);
  263.                      (void) sprintf (junk, "%s", Full_Addr_Str (&baddr));
  264.                      junk[28] = '\0';
  265.                      sb_move (holdwin, 4, 16 - strlen (junk) / 2);
  266.                      sb_puts (holdwin, (unsigned char *) junk);
  267.                      sb_show ();
  268.                      }
  269.                   else
  270.                      {
  271.                      scr_printf (msgtxt[M_MAILER_MODE]);
  272.                      }
  273.                   if (!CARRIER)
  274.                      mdm_hangup ();
  275.                   (void) do_mail (&baddr, 1);
  276.                   un_attended = 0;
  277.                   if (fullscreen)
  278.                      {
  279.                      screen_clear ();
  280.                      }
  281.                   else
  282.                      {
  283.                      scr_printf ("\r\n");
  284.                      }
  285.                   scr_printf (msgtxt[M_MANUAL_MODE]);
  286.                   gong ();
  287.                   vfossil_cursor (1);
  288.                   break;
  289.  
  290.                case ALTR:
  291.                   if (!list_search ())
  292.                      screen_clear ();
  293.                   break;
  294.  
  295.                case ALTU:
  296.                        if (port_ptr != original_port)
  297.                            {
  298.                            status_line (" %s COM%d:", msgtxt[M_SWITCHING_BACK], original_port + 1);
  299.                       MDM_DISABLE ();
  300.                        port_ptr = original_port;
  301.                         fossil_init = 0;        /* CML: make fossil sign-on show */
  302.                       if (Cominit (port_ptr) != 0x1954)
  303.                          {
  304.                          port_ptr = c;
  305.                           Cominit(port_ptr);
  306.                          }
  307.                       MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  308.                       DTR_ON ();
  309.                            }
  310.                   retval = 0;
  311.                /* Fall into exit code */
  312.  
  313.                case ALTX:
  314.                   if (logfile != NULL)
  315.                      (void) fclose (logfile);
  316.                   done = 1;
  317.                   break;
  318.  
  319.                case PGUP:
  320.                   scr_printf (msgtxt[M_READY_TO_SEND]);
  321.                   scr_printf (msgtxt[M_WHICH_PROTOCOL]);
  322.                   scr_printf ("Z)modem     S)EAlink     T)elink     X)modem\r\n");
  323.                   if (extern_protocols != NULL)
  324.                      {
  325.                      scr_printf (extern_protocols);
  326.                      scr_printf ("\r\n");
  327.                      }
  328.                   scr_printf (msgtxt[M_CHOOSE]);
  329.                   junk[0] = '\0';
  330.                   (void) fgets (junk, 100, stdin);
  331.                   if ((junk[0] == '\0') || (junk[0] == '\n'))
  332.                      break;
  333.                   if (!(prot = toupper (junk[0])))
  334.                      break;
  335.                   p = NULL;
  336.                   if ((strchr (native_protocols, prot) == NULL)
  337.                       && ((p = strchr (extern_protocols, prot)) == NULL))
  338.                      {
  339.                      scr_printf (msgtxt[M_DONT_KNOW_PROTO]);
  340.                      break;
  341.                      }
  342.                   scr_printf (msgtxt[M_FILE_TO_SEND]);
  343.                   junk[0] = '\0';
  344.                   (void) fgets (junk, 100, stdin);
  345.                   if (k = strlen (junk))
  346.                      junk[--k] = '\0';
  347.                   if ((junk[0] == '\0') || (junk[0] == '\n'))
  348.                      break;
  349.  
  350. #ifndef OS_2
  351. #ifndef __TURBOC__
  352.                   if ((!k) || (_dos_findfirst (junk, 0, &fileinfo)))
  353. #else
  354.                   if ((!k) || (findfirst (junk, &fileinfo, 0)))
  355. #endif
  356. #else
  357.                   if ((!k) || (dir_findfirst (junk, 0, &fileinfo)))
  358. #endif
  359.                      break;
  360.  
  361.                   err = 1;                          /* Xmodem, Ymodem, Telink
  362.                                                      * flag */
  363.                   save1 = comm_bits;
  364.                   save2 = parity;
  365.                   save3 = stop_bits;
  366.                   comm_bits = BITS_8;
  367.                   parity = NO_PARITY;
  368.                   stop_bits = STOP_1;
  369.                   MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  370.                   XON_DISABLE ();
  371.  
  372.                   /* My apologies for the 'goto's below. But this sucker
  373.                      is much more readable this way. */
  374.  
  375.                   /* If external protocol requested, call it */
  376.  
  377.                   if (p)
  378.                      {
  379.                      do_extern ("Send", (int) prot, junk);
  380.                      goto upload_done;
  381.                      }
  382.  
  383.                   /* Check for Xmodem or Ymodem, as neither
  384.                      has a batch mode ...                 */
  385.  
  386.                   if ((prot == 'X') || (prot == 'Y'))
  387.                      {
  388.                      (void) Xmodem_Send_File (junk, NULL);
  389.                      goto upload_done;
  390.                      }
  391.  
  392.                   /* If we get here, the protocol is Telink, SEAlink
  393.                    * or Zmodem. All batch protocols. So we have to do
  394.                    * a batch to support wildcard uploads. */
  395.  
  396.                   /* Find the end of the path part of the name */
  397.  
  398.                   p = strrchr (junk, '\\');
  399.                   if (p == NULL)
  400.                      p = strrchr (junk, '/');
  401.                   if (p == NULL)
  402.                      p = strchr (junk, ':');
  403.                   if (p == NULL)
  404.                      p = junk;
  405.                   else
  406.                      p++;
  407.  
  408.                   /*  At this point *p points to the location in the input
  409.                    *  string where the prepended path information ends. All
  410.                    *  we need to do, then, is to keep plugging in the stuff
  411.                    *  we get from _dos_find(first|next) and transfer files.
  412.                    *  We already have the first matching filename from the
  413.                    *  _dos_findfirst we did above, so we use a "do" loop.
  414.                    */
  415.  
  416.                   do
  417.                      {
  418.                      /* Append the current filename */
  419. #ifndef __TURBOC__
  420.                      (void) strcpy (p, fileinfo.name);
  421. #else
  422.                      (void) strcpy (p, fileinfo.ff_name);
  423. #endif
  424.  
  425.                      /* Send the file with the proper protocol */
  426.  
  427.                      if (prot == 'Z')
  428.                         err = Send_Zmodem (junk, NULL, 0, 0);
  429.                      else
  430.                         {
  431.                         err = !Batch_Send (junk);
  432.                         }
  433. #ifndef OS_2
  434. #ifndef __TURBOC__
  435.                      } while ((err) && (!_dos_findnext (&fileinfo)));
  436. #else
  437.                      } while ((err) && (!findnext (&fileinfo)));
  438. #endif
  439. #else
  440.                      } while ((err) && (!dir_findnext (&fileinfo)));
  441. #endif
  442.  
  443.  
  444.                   /* Finish the proper protocol if need be */
  445.  
  446.                   if (err)
  447.                      {
  448.                      if (prot == 'Z')
  449.                         (void) Send_Zmodem (NULL, NULL, END_BATCH, 0);
  450.                      else
  451.                         (void) Batch_Send (NULL);
  452.                      }
  453. upload_done:
  454.                   comm_bits = save1;
  455.                   parity = save2;
  456.                   stop_bits = save3;
  457.                   MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  458.                   XON_ENABLE ();
  459.                   gong ();
  460.                   break;
  461.  
  462.                case PGDN:
  463.                   scr_printf (msgtxt[M_READY_TO_RECEIVE]);
  464.                   scr_printf (msgtxt[M_WHICH_PROTOCOL]);
  465.                   scr_printf ("Z)modem     S)EAlink     T)elink     X)modem\r\n");
  466.                   if (extern_protocols != NULL)
  467.                      {
  468.                      scr_printf (extern_protocols);
  469.                      scr_printf ("\r\n");
  470.                      }
  471.                   scr_printf (msgtxt[M_CHOOSE]);
  472.                   junk[0] = '\0';
  473.                   (void) fgets (junk, 100, stdin);
  474.                   if ((junk[0] == '\0') || (junk[0] == '\n'))
  475.                      break;
  476.                   if (!(prot = toupper (junk[0])))
  477.                      break;
  478.                   p = NULL;
  479.                   if ((strchr (native_protocols, prot) == NULL)
  480.                       && ((p = strchr (extern_protocols, prot)) == NULL))
  481.                      {
  482.                      scr_printf (msgtxt[M_DONT_KNOW_PROTO]);
  483.                      break;
  484.                      }
  485.                   save1 = comm_bits;
  486.                   save2 = parity;
  487.                   save3 = stop_bits;
  488.                   comm_bits = BITS_8;
  489.                   parity = NO_PARITY;
  490.                   stop_bits = STOP_1;
  491.                   MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  492.                   XON_DISABLE ();
  493.                   if ((prot == 'X') || (prot == 'Y') || p != NULL)
  494.                      {
  495.                      scr_printf (msgtxt[M_FILE_TO_RECEIVE]);
  496.                      junk[0] = '\0';
  497.                      (void) fgets (junk, 100, stdin);
  498.                      if ((junk[0] == '\0') || (junk[0] == '\n'))
  499.                         break;
  500.                      if (!(k = strlen (junk)))
  501.                         break;
  502.                      junk[--k] = '\0';
  503.  
  504.                      if (p)
  505.                         {
  506.                         do_extern ("Get", (int) prot, junk);
  507.                         }
  508.                      else
  509.                         {
  510.                         if (junk[0] != '\0')
  511.                            {
  512.                            (void) Xmodem_Receive_File (download_path, junk);
  513.                            }
  514.                         }
  515.                      }
  516.                   else if (prot == 'Z')
  517.                      {
  518.                      (void) get_Zmodem (download_path, NULL);
  519.                      }
  520.                   else
  521.                      {
  522.                      (void) Batch_Receive (download_path);
  523.                      }
  524.  
  525.                   comm_bits = save1;
  526.                   parity = save2;
  527.                   stop_bits = save3;
  528.                   MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  529.                   XON_ENABLE ();
  530.                   gong ();
  531.                   break;
  532.  
  533.                case ALTF10:
  534.                   main_help ();
  535.                   break;
  536.  
  537.                default:
  538.                   if (comm_bits == BITS_7)
  539.                      c = k & 0x7f;
  540.                   else c = k & 0xff;
  541.  
  542.                   if (c != 0)
  543.                     {
  544. #if 0
  545.                      while (Com_Tx_NW ((unsigned char) c) == 0)
  546.                         ;
  547. #endif
  548.                     com_putc((unsigned char)c);        /* CML */
  549.                     }
  550.                   else
  551.                      ansi_map ((unsigned) k);
  552.                }
  553.             }
  554.          }
  555.       if (c == -1)
  556.          time_release ();
  557.       }
  558. set_prior(2);                                          /* Regular */
  559. return (retval);
  560. }
  561.