home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / BSEND.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  7KB  |  202 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 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.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. #define NO_SEALINK_IS_TELINK 1
  51.  
  52. int BSInit (XMARGSP, int);
  53. int BSEnd (XMARGSP, int);
  54. int BSMoreFiles (XMARGSP);
  55. int BSWaitType (XMARGSP);
  56. int BSCheckFNm (XMARGSP);
  57. int BSCheckFile (XMARGSP);
  58. int BSEndSend (XMARGSP);
  59.  
  60. STATES Batch_Sender[] = {
  61.    { "BSInit",  BSInit },
  62.    { "BSEnd",  BSEnd },
  63.    { "BS0",  BSMoreFiles },
  64.    { "BS1",  BSWaitType },
  65.    { "BS2",  BSCheckFNm },
  66.    { "BS3",  BSCheckFile },
  67.    { "BS4",  BSEndSend  },
  68. };
  69.  
  70. int BSInit (XMARGSP args, int start_state)
  71. {
  72.    args->result = start_state;
  73.    XON_DISABLE ();
  74.    return (start_state);
  75. }
  76.  
  77. int BSEnd (XMARGSP args,int cur_state)
  78. {
  79.    args->result = cur_state;
  80.    return (cur_state);
  81. }
  82.  
  83. int BSMoreFiles (XMARGSP args)
  84. {
  85.    if (args->filename != NULL)
  86.       {
  87.       /* BS0.1 */
  88.       return (BS1);
  89.       }
  90.    else
  91.       {
  92.       /* BS0.2 */
  93.       return (BS4);
  94.       }
  95. }
  96.  
  97. int BSWaitType (XMARGSP args)
  98. {
  99.    long BS1Timer;
  100.    int in_char;
  101.  
  102.    BS1Timer = timerset (2000);
  103.    while (!timeup (BS1Timer))
  104.       {
  105.       if ((in_char = PEEKBYTE ()) >= 0)
  106.          {
  107.          switch (in_char)
  108.             {
  109.             case NAK:
  110.                /* State BS1.1 */
  111.                args->result = Modem7_Send_File (args->filename);
  112.                return (BS2);
  113.  
  114.             case WANTCRC:
  115.                /* State BS1.2 */
  116.                if (!no_sealink)
  117.                   {
  118.                   args->result = SEAlink_Send_File (args->filename, NULL);
  119.                   return (BS3);
  120.                   }
  121. #ifdef NO_SEALINK_IS_TELINK
  122.                else
  123.                   {
  124.                   args->result = Telink_Send_File (args->filename, NULL);
  125.                   return (BS3);
  126.                   }
  127. #endif
  128.                /* Fallthrough if we aren't doing SEAlink */
  129.  
  130.             default:
  131.                /* State BS1.3 */
  132.                (void) TIMED_READ (0);
  133.                time_release ();
  134.             }
  135.          }
  136.       else
  137.          {
  138.          if (!CARRIER)
  139.             return (CARRIER_ERR);
  140.          else
  141.             time_release ();
  142.          }
  143.       }
  144.  
  145.    /* State BS1.4 */
  146.    return (TIME_ERR);
  147. }
  148.  
  149. int BSCheckFNm (XMARGSP args)
  150. {
  151.    if (args->result == SUCCESS)
  152.       {
  153.       /* State BS2.1 */
  154.       args->result = Telink_Send_File (args->filename, NULL);
  155.       return (BS3);
  156.       }
  157.    else
  158.       {
  159.       /* State BS2.2 */
  160.       return (FNAME_ERR);
  161.       }
  162. }
  163.  
  164. int BSCheckFile (XMARGSP args)
  165. {
  166.    return (args->result);
  167. }
  168.  
  169. int BSEndSend (XMARGSP args)
  170. {
  171.    long BS4Timer;
  172.  
  173.    BS4Timer = timerset (1000);
  174.    while (!timeup (BS4Timer))
  175.       {
  176.       switch (TIMED_READ (1))
  177.          {
  178.          case NAK:
  179.          case WANTCRC:
  180.             SENDBYTE (EOT);
  181.             args->result = SUCCESS;
  182.             return (SUCCESS);
  183.          }
  184.       }
  185.  
  186.    /* State BS4.2 */
  187.    SENDBYTE (EOT);
  188.    args->result = SUCCESS;
  189.    return (SUCCESS);
  190. }
  191.  
  192. int Batch_Send (char *filename)
  193. {
  194.    XMARGS batch;
  195.    int res;
  196.  
  197.    batch.result = 0;
  198.    batch.filename = filename;
  199.    res = state_machine (Batch_Sender, &batch, 2);
  200.    return (res);
  201. }
  202.