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