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