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