home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_FLOFIL.C < prev    next >
C/C++ Source or Header  |  1990-07-04  |  8KB  |  206 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. /*                    BinkleyTerm .FLO file Processor                       */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n132.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. #include <stdio.h>
  45. #include <signal.h>
  46. #include <io.h>
  47. #include <conio.h>
  48. #include <string.h>
  49. #include <stdlib.h>
  50. #include <errno.h>
  51. #include <sys\types.h>
  52. #include <sys\stat.h>
  53. #include <fcntl.h>
  54.  
  55. #define WAZOO_SECTION
  56. #include "com.h"
  57. #include "xfer.h"
  58. #include "zmodem.h"
  59. #include "keybd.h"
  60. #include "sbuf.h"
  61. #include "sched.h"
  62. #include "externs.h"
  63. #include "prototyp.h"
  64.  
  65. #define rb_plus "r+b"
  66.  
  67. extern int WaZOO_callback (char *);
  68.  
  69. #define NUM_FLAGS 4
  70.  
  71.  
  72. /*--------------------------------------------------------------------------*/
  73. /* do_FLOfile (send files listed in .FLO files)                             */
  74. /*   returns TRUE (1) for good xfer, FALSE (0) for bad                      */
  75. /*--------------------------------------------------------------------------*/
  76. int do_FLOfile (ext_flags,callback)
  77. char *ext_flags;
  78. int (*callback)(char *);
  79. {
  80.    FILE *fp;
  81.    char fname[80];
  82.    char s[80];
  83.    char *sptr;
  84.    char *HoldName;
  85.    int c;
  86.    int i,j;
  87.    struct stat buf;
  88.  
  89.    long current, last_start;
  90.  
  91.    HoldName = HoldAreaNameMunge(&called_addr);
  92.  
  93.    /*--------------------------------------------------------------------*/
  94.    /* Send files listed in ?LO files (attached files)                    */
  95.    /*--------------------------------------------------------------------*/
  96.    for (c = 0; c < (int) strlen (ext_flags); c++)
  97.       {
  98. #ifndef JACK_DECKER
  99.       if (caller && (ext_flags[c] == 'H'))
  100.          continue;
  101. #endif
  102.  
  103.       (void) sprintf (fname, "%s%s.%cLO",
  104.                HoldName, Hex_Addr_Str (&called_addr), ext_flags[c]);
  105.  
  106.       if (!stat (fname, &buf))
  107.          {
  108.          if ((fp = fopen (fname, rb_plus)) == NULL)
  109.             {
  110.             (void) got_error (msgtxt[M_OPEN_MSG], fname);
  111.             continue;
  112.             }
  113.  
  114.          current = 0L;
  115.          while (!feof (fp))
  116.             {
  117.             s[0] = 0;
  118.             last_start = current;
  119.             (void) fgets (s, 79, fp);
  120.  
  121.             sptr = s;
  122.  
  123.             for (i = 0; sptr[i]; i++)
  124.                if (sptr[i] <= ' ')
  125.                   sptr[i] = 0;
  126.  
  127.             current = ftell (fp);
  128.  
  129.             if (sptr[0] == TRUNC_AFTER)
  130.                {
  131.                sptr++;
  132.                i = TRUNC_AFTER;
  133.                }
  134.             else if (sptr[0] == SHOW_DELETE_AFTER)
  135.                {
  136.                sptr++;
  137.                i = SHOW_DELETE_AFTER;
  138.                }
  139.             else i = NOTHING_AFTER;
  140.  
  141.             if ((!sptr[0]) || (sptr[0] == ';'))
  142.                {
  143.                continue;
  144.                }
  145.  
  146.             if (sptr[0] != '~')
  147.                {
  148.                if (stat (sptr, &buf))            /* file exist? */
  149.                   {
  150.                   (void) got_error (msgtxt[M_FIND_MSG], sptr);
  151.                   continue;
  152.                   }
  153.                else if (!buf.st_size)
  154.                   {
  155.                   continue;                      /* 0 length? */
  156.                   }
  157.  
  158.                j = (*callback) (sptr);
  159.                if (!j)
  160.                   {
  161.                   (void) fclose (fp);
  162.                   net_problems = 1;
  163.                   return FALSE;
  164.                   }
  165.  
  166.                /*--------------------------------------------*/
  167.                /* File was sent.  Flag file name             */
  168.                /*--------------------------------------------*/
  169.                (void) fseek (fp, last_start, SEEK_SET);
  170.                (void) putc ('~', fp);                   /* flag it */
  171.                (void) fflush (fp);
  172.                rewind (fp);                      /* clear any eof flags */
  173.                (void) fseek (fp, current, SEEK_SET);
  174.  
  175.                if (j == SPEC_COND)               /* if "Funny" success,   */
  176.                   continue;                      /* don't delete/truncate */
  177.  
  178.                if (i == TRUNC_AFTER)
  179.                   {
  180.                   CLEAR_IOERR ();
  181.                   i = open (sptr, O_CREAT|O_TRUNC|O_BINARY|O_WRONLY, S_IREAD|S_IWRITE);
  182.                   status_line (msgtxt[M_TRUNC_MSG], sptr);
  183.                   (void) close (i);
  184.                   }
  185.                else if (i == SHOW_DELETE_AFTER)
  186.                   {
  187.                   CLEAR_IOERR ();
  188.                   (void) unlink (sptr);
  189.                   status_line (msgtxt[M_UNLINKING_MSG], sptr);
  190.                   }
  191.                else if (i == DELETE_AFTER)
  192.                   {
  193.                   CLEAR_IOERR ();
  194.                   (void) unlink (sptr);
  195.                   }
  196.                }
  197.             }                                    /* while */
  198.  
  199.          (void) fclose (fp);
  200.          (void) unlink (fname);
  201.          }                                       /* !stat */
  202.       }                                          /* for */
  203.  
  204.    return TRUE;
  205. }
  206.