home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts314b4 / bsend.c < prev    next >
C/C++ Source or Header  |  1994-01-08  |  7KB  |  217 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 written by Bob Hartman                  */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                  BinkleyTerm Batch Sender State Machine                  */
  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.  
  47. /* System include files */
  48. #ifdef __TOS__
  49. /* #pragma warn -sus */
  50. #else
  51. #include <fcntl.h>
  52. #endif
  53. #include <stdio.h>
  54.  
  55.  
  56. #include "bink.h"
  57. #include "msgs.h"
  58. #include "com.h"
  59. #include "sbuf.h"
  60. #include "defines.h"
  61. #include "ascii.h"
  62. #include "vfossil.h"
  63.  
  64.  
  65. #define NO_SEALINK_IS_TELINK 1
  66.  
  67. int cdecl BSInit (XMARGSP args, int start_state);
  68. int cdecl BSEnd (XMARGSP args, int cur_state);
  69. int cdecl BSMoreFiles (XMARGSP args);
  70. int cdecl BSWaitType (XMARGSP args);
  71. int cdecl BSCheckFNm (XMARGSP args);
  72. int cdecl BSCheckFile (XMARGSP args);
  73. int cdecl BSEndSend (XMARGSP args);
  74.  
  75. STATES Batch_Sender[] = {
  76.    { "BSInit", ( void *) BSInit },
  77.    { "BSEnd", ( void *) BSEnd },
  78.    { "BS0", ( void *) BSMoreFiles },
  79.    { "BS1", ( void *) BSWaitType },
  80.    { "BS2", ( void *) BSCheckFNm },
  81.    { "BS3", ( void *) BSCheckFile },
  82.    { "BS4", ( void *) BSEndSend  },
  83. };
  84.  
  85. int cdecl BSInit (XMARGSP args, int start_state)
  86. {
  87.    args->result = start_state;
  88.    XON_DISABLE ();
  89.    return (start_state);
  90. }
  91.  
  92. int cdecl BSEnd (XMARGSP args, int cur_state)
  93. {
  94.    args->result = cur_state;
  95.    return (cur_state);
  96. }
  97.  
  98. int cdecl BSMoreFiles (XMARGSP args )
  99. {
  100.    if (args->filename != NULL)
  101.       {
  102.       /* BS0.1 */
  103.       return (BS1);
  104.       }
  105.    else
  106.       {
  107.       /* BS0.2 */
  108.       return (BS4);
  109.       }
  110. }
  111.  
  112. int cdecl BSWaitType (XMARGSP args)
  113. {
  114.    long BS1Timer;
  115.    int in_char;
  116.  
  117.    BS1Timer = timerset (2000);
  118.    while (!timeup (BS1Timer))
  119.       {
  120.       if ((in_char = PEEKBYTE ()) >= 0)
  121.          {
  122.          switch (in_char)
  123.             {
  124.             case NAK:
  125.                /* State BS1.1 */
  126.                args->result = Modem7_Send_File (args->filename);
  127.                return (BS2);
  128.  
  129.             case WANTCRC:
  130.                /* State BS1.2 */
  131.                if (!no_sealink)
  132.                   {
  133.                   args->result = SEAlink_Send_File (args->filename, NULL);
  134.                   return (BS3);
  135.                   }
  136. #ifdef NO_SEALINK_IS_TELINK
  137.                else
  138.                   {
  139.                   args->result = Telink_Send_File (args->filename, NULL);
  140.                   return (BS3);
  141.                   }
  142. #endif
  143.                /* Fallthrough if we aren't doing SEAlink */
  144.  
  145.             default:
  146.                /* State BS1.3 */
  147.                (void) TIMED_READ (0);
  148.                time_release ();
  149.             }
  150.          }
  151.       else
  152.          {
  153.          if (!CARRIER)
  154.             return (CARRIER_ERR);
  155.          else
  156.             time_release ();
  157.          }
  158.       }
  159.  
  160.    /* State BS1.4 */
  161.    return (TIME_ERR);
  162. }
  163.  
  164. int cdecl BSCheckFNm (XMARGSP args)
  165. {
  166.    if (args->result == SUCCESS)
  167.       {
  168.       /* State BS2.1 */
  169.       args->result = Telink_Send_File (args->filename, NULL);
  170.       return (BS3);
  171.       }
  172.    else
  173.       {
  174.       /* State BS2.2 */
  175.       return (FNAME_ERR);
  176.       }
  177. }
  178.  
  179. int cdecl BSCheckFile (XMARGSP args)
  180. {
  181.    return (args->result);
  182. }
  183.  
  184. int cdecl BSEndSend ( XMARGSP args )
  185. {
  186.    long BS4Timer;
  187.  
  188.    BS4Timer = timerset (1000);
  189.    while (!timeup (BS4Timer))
  190.       {
  191.       switch (TIMED_READ (1))
  192.          {
  193.          case NAK:
  194.          case WANTCRC:
  195.             SENDBYTE (EOT);
  196.             args->result = SUCCESS;
  197.             return (SUCCESS);
  198.          }
  199.       }
  200.  
  201.    /* State BS4.2 */
  202.    SENDBYTE (EOT);
  203.    args->result = SUCCESS;
  204.    return (SUCCESS);
  205. }
  206.  
  207. int Batch_Send (char *filename)
  208. {
  209.    XMARGS batch;
  210.    int res;
  211.  
  212.    batch.result = 0;
  213.    batch.filename = filename;
  214.    res = state_machine (Batch_Sender, &batch, 2);
  215.    return (res);
  216. }
  217.