home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / BREC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  7KB  |  228 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 Receiver 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. int BRInit (XMARGSP, int);
  51. int BREnd (XMARGSP, int);
  52. int BRTestSL (XMARGSP);
  53. int BRCheckSL (XMARGSP);
  54. int BRCheckFNm (XMARGSP);
  55. int BRCheckFile (XMARGSP);
  56. int BRFindType (XMARGSP);
  57.  
  58. STATES Batch_Receiver[] = {
  59.    { "BRInit",  BRInit },
  60.    { "BREnd",  BREnd },
  61.    { "BR0",  BRTestSL },
  62.    { "BR1",  BRCheckSL },
  63.    { "BR2",  BRCheckFNm },
  64.    { "BR3",  BRCheckFile },
  65.    { "BR4",  BRFindType },
  66. };
  67.  
  68. int BRInit (XMARGSP args, int start_state)
  69. {
  70.    XON_DISABLE ();
  71.    args->filename = calloc( 1, 13 );
  72.    return (start_state);
  73. }
  74.  
  75. int BREnd (XMARGSP args, int cur_state)
  76. {
  77.    free (args->filename);
  78.    return (cur_state);
  79. }
  80.  
  81. int BRTestSL (XMARGSP args)
  82. {
  83.    if (!no_sealink)
  84.       SENDBYTE (WANTCRC);
  85.  
  86.    args->T1 = timerset (1000);
  87.    args->T2 = timerset (12000);
  88.  
  89.    return (BR1);
  90. }
  91.  
  92. int BRCheckSL (XMARGSP args)
  93. {
  94.    long BR1Timer;
  95.  
  96.    BR1Timer = timerset (200);
  97.    while (!timeup (BR1Timer))
  98.       {
  99.       if (timeup (args->T2) || no_sealink)
  100.          {
  101.          args->result = Modem7_Receive_File (args->filename);
  102.          return (BR2);
  103.          }
  104.       if ((args->CHR = PEEKBYTE ()) >= 0)
  105.          {
  106.          return (BR4);
  107.          }
  108.       if (timeup (args->T1))
  109.          {
  110.          args->result = Modem7_Receive_File (args->filename);
  111.          return (BR2);
  112.          }
  113.       else
  114.          {
  115.          if (!CARRIER)
  116.             return (CARRIER_ERR);
  117.          else
  118.             time_release ();
  119.          }
  120.       }
  121.  
  122.    SENDBYTE (WANTCRC);
  123.    return (BR1);
  124. }
  125.  
  126. int BRCheckFNm (XMARGSP args)
  127. {
  128.    char buff1[20];
  129.    char *p;
  130.    int i;
  131.  
  132.    (void) memset (buff1, 0, 19);
  133.  
  134.    /* Was it the last file */
  135.    if (args->result == EOT_RECEIVED)
  136.       {
  137.       return (SUCCESS);
  138.       }
  139.    /* Did we get a valid filename */
  140.    else if (args->result == SUCCESS)
  141.       {
  142.       /* First set up the filename buffer */
  143.       p = buff1;
  144.       for (i = 0; i < 8; ++p, i++)
  145.          {
  146.          if (args->filename[i] != ' ')
  147.             {
  148.             *p = args->filename[i];
  149.             }
  150.          else
  151.             break;
  152.          }
  153.  
  154.       *p = '.';
  155.       ++p;
  156.       *p = '\0';
  157.       for (i = 8; i < 11; ++p, i++)
  158.          {
  159.          if (args->filename[i] != ' ')
  160.             {
  161.             *p = args->filename[i];
  162.             }
  163.          else
  164.             break;
  165.          }
  166.       *p = '\0';
  167.       (void) strcpy (args->filename, buff1);
  168.       args->result = Xmodem_Receive_File (args->path, args->filename);
  169.       return (BR3);
  170.       }
  171.    /* Otherwise, we have to exit */
  172.    else
  173.       return (args->result);
  174. }
  175.  
  176. int BRCheckFile (XMARGSP args)
  177. {
  178.    /* Was the file transfer good */
  179.    if ((args->result == SUCCESS) || (args->result == SUCCESS_EOT))
  180.       {
  181.       return (BR0);
  182.       }
  183.    else
  184.       {
  185.       return (args->result);
  186.       }
  187. }
  188.  
  189. int BRFindType (XMARGSP args)
  190. {
  191.    switch (args->CHR)
  192.       {
  193.       case SOH:
  194.       case SYN:
  195.          args->result = Batch_Xmodem_Receive_File (args->path, args->filename);
  196.          return (BR3);
  197.  
  198.       case EOT:
  199.          (void) TIMED_READ (0);
  200.          SENDBYTE (ACK);
  201.          return (SUCCESS);
  202.  
  203.   /*  NUL is a special case of "noise." We want to reset our timer if we
  204.    *  see one.
  205.    */
  206.  
  207.       case NUL:
  208.          args->T1 = timerset (2000);
  209.  
  210.       default:
  211.          break;
  212.       }
  213.  
  214.    (void) TIMED_READ (0);
  215.    return (BR1);
  216. }
  217.  
  218. int Batch_Receive (char *where)
  219. {
  220.    XMARGS batch;
  221.    int res;
  222.  
  223.    batch.result = 0;
  224.    batch.path = where;
  225.    res = state_machine (Batch_Receiver, &batch, 2);
  226.    return (res);
  227. }
  228.