home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / M7SEND.C < prev    next >
C/C++ Source or Header  |  1990-05-14  |  6KB  |  200 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 Modem7 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. #include <string.h>
  51. #include <ctype.h>
  52.  
  53. /* Local include files */
  54. #include "defines.h"
  55. #include "com.h"
  56. #include "xfer.h"
  57. #include "zmodem.h"
  58. #include "keybd.h"
  59. #include "sbuf.h"
  60. #include "sched.h"
  61. #include "externs.h"
  62. #include "prototyp.h"
  63.  
  64. int MSInit (XMARGSP, int);
  65. int MSEnd (XMARGSP, int);
  66. int MSWaitNak (XMARGSP);
  67. int MSWaitChAck (XMARGSP);
  68. int MSWaitCksm (XMARGSP);
  69.  
  70. STATES Modem7_Sender[] = {
  71.    { "MSInit",  MSInit },
  72.    { "MSEnd",  MSEnd },
  73.    { "MS0",  MSWaitNak },
  74.    { "MS1",  MSWaitChAck },
  75.    { "MS2",  MSWaitCksm }
  76. };
  77.  
  78. int MSInit (args, start_state)
  79. XMARGSP args;
  80. int start_state;
  81. {
  82.    char *p;
  83.    int i;
  84.    struct FILEINFO dta;
  85.  
  86.    XON_DISABLE ();
  87.    args->tries = 0;
  88.    (void) dfind (&dta, args->filename, 0);
  89.    (void) strcpy (args->m7name, "           ");
  90.    for (i = 0, p = dta.name; i < 8; p++, i++)
  91.       if ((*p != '.') && (*p != '\0'))
  92.          args->m7name[i] = toupper(*p);
  93.       else
  94.          break;
  95.  
  96.    if (*p == '.')
  97.       ++p;
  98.    for (i = 8; i < 11; p++, i++)
  99.       if ((*p != '.') && (*p != '\0'))
  100.          args->m7name[i] = toupper(*p);
  101.       else
  102.          break;
  103.  
  104.    /* Now do the checksum */
  105.    args->check = SUB;
  106.    for (i = 0; i < 11; i++)
  107.       args->check += (unsigned char) args->m7name[i];
  108.  
  109.    return (start_state);
  110. }
  111.  
  112. int MSEnd (args, cur_state)
  113. XMARGSP args;
  114. int cur_state;
  115. {
  116.    args->result = cur_state;
  117.    return (cur_state);
  118. }
  119.  
  120. int MSWaitNak (args)
  121. XMARGSP args;
  122. {
  123.    if (args->tries >= 10)
  124.       return (FNAME_ERR);
  125.  
  126.    if (!CARRIER)
  127.       return (CARRIER_ERR);
  128.  
  129.    if (TIMED_READ (10) != NAK)
  130.       {
  131.       ++args->tries;
  132.       return (MS0);
  133.       }
  134.  
  135.    SENDBYTE (ACK);
  136.    SENDBYTE ((unsigned char) *(args->m7name));
  137.    args->fptr = args->m7name + 1;
  138.    return (MS1);
  139. }
  140.  
  141. int MSWaitChAck (args)
  142. XMARGSP args;
  143. {
  144.    if (!CARRIER)
  145.       return (CARRIER_ERR);
  146.  
  147.    if (TIMED_READ (10) != ACK)
  148.       {
  149.       ++args->tries;
  150.       SENDBYTE ('u');
  151.       return (MS0);
  152.       }
  153.  
  154.    /* If filename done */
  155.    if (*(args->fptr) == '\0')
  156.       {
  157.       SENDBYTE (SUB);
  158.       return (MS2);
  159.       }
  160.    else
  161.       {
  162.       /* Send next char of name */
  163.       SENDBYTE ((unsigned char) *args->fptr++);
  164.       return (MS1);
  165.       }
  166. }
  167.  
  168. int MSWaitCksm (args)
  169. XMARGSP args;
  170. {
  171.    int in_char;
  172.  
  173.    if (!CARRIER)
  174.       return (CARRIER_ERR);
  175.  
  176.    if (((in_char = TIMED_READ (10)) < 0) || (in_char != args->check))
  177.       {
  178.       SENDBYTE ('u');
  179.       ++args->tries;
  180.       return (MS0);
  181.       }
  182.    else
  183.       {
  184.       SENDBYTE (ACK);
  185.       return (SUCCESS);
  186.       }
  187. }
  188.  
  189. int Modem7_Send_File (filename)
  190. char *filename;
  191. {
  192.    XMARGS batch;
  193.    int res;
  194.  
  195.    batch.result = 0;
  196.    batch.filename = filename;
  197.    res = state_machine (Modem7_Sender, &batch, 2);
  198.    return (res);
  199. }
  200.