home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_FLOFIL.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  8KB  |  187 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. /*                    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.250.    */
  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:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.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 this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #define rb_plus "r+b"
  49.  
  50. extern int WaZOO_callback (char *);
  51.  
  52. #define NUM_FLAGS 4
  53.  
  54.  
  55. /*--------------------------------------------------------------------------*/
  56. /* do_FLOfile (send files listed in .FLO files)                             */
  57. /*   returns TRUE (1) for good xfer, FALSE (0) for bad                      */
  58. /*--------------------------------------------------------------------------*/
  59. int do_FLOfile (char *ext_flags, int (*callback)(char *))
  60. {
  61.    FILE *fp;
  62.    char fname[80];
  63.    char s[80];
  64.    char *sptr;
  65.    char *HoldName;
  66.    int c;
  67.    int i,j;
  68.    struct stat buf;
  69.  
  70.    long current, last_start;
  71.  
  72.    HoldName = HoldAreaNameMunge(&called_addr);
  73.  
  74.    /*--------------------------------------------------------------------*/
  75.    /* Send files listed in ?LO files (attached files)                    */
  76.    /*--------------------------------------------------------------------*/
  77.    for (c = 0; c < (int) strlen (ext_flags); c++)
  78.       {
  79. #ifndef JACK_DECKER
  80.       if (caller && (ext_flags[c] == 'H'))
  81.          continue;
  82. #endif
  83.  
  84.       (void) sprintf (fname, "%s%s.%cLO",
  85.                HoldName, Hex_Addr_Str (&called_addr), ext_flags[c]);
  86.  
  87.       if (!stat (fname, &buf))
  88.          {
  89.          if ((fp = share_fopen (fname, rb_plus, DENY_NONE)) == NULL)
  90.             {
  91.             (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  92.             continue;
  93.             }
  94.  
  95.          current = 0L;
  96.          while (!feof (fp))
  97.             {
  98.             s[0] = 0;
  99.             last_start = current;
  100.             (void) fgets (s, 79, fp);
  101.  
  102.             sptr = s;
  103.  
  104.             for (i = 0; sptr[i]; i++)
  105.                if (sptr[i] <= ' ')
  106.                   sptr[i] = 0;
  107.  
  108.             current = ftell (fp);
  109.  
  110.             if (sptr[0] == TRUNC_AFTER)
  111.                {
  112.                sptr++;
  113.                i = TRUNC_AFTER;
  114.                }
  115.             else if (sptr[0] == SHOW_DELETE_AFTER)
  116.                {
  117.                sptr++;
  118.                i = SHOW_DELETE_AFTER;
  119.                }
  120.             else i = NOTHING_AFTER;
  121.  
  122.             if ((!sptr[0]) || (sptr[0] == ';'))
  123.                {
  124.                continue;
  125.                }
  126.  
  127.             if (sptr[0] != '~')
  128.                {
  129.                if (stat (sptr, &buf))            /* file exist? */
  130.                   {
  131.                   (void) got_error (MSG_TXT(M_FIND_MSG), sptr);
  132.                   continue;
  133.                   }
  134.                else if (!buf.st_size)
  135.                   {
  136.                   continue;                      /* 0 length? */
  137.                   }
  138.  
  139.                j = (*callback) (sptr);
  140.                if (!j)
  141.                   {
  142.                   (void) fclose (fp);
  143.                   net_problems = 1;
  144.                   return FALSE;
  145.                   }
  146.  
  147.                /*--------------------------------------------*/
  148.                /* File was sent.  Flag file name             */
  149.                /*--------------------------------------------*/
  150.                (void) fseek (fp, last_start, SEEK_SET);
  151.                (void) putc ('~', fp);                   /* flag it */
  152.                (void) fflush (fp);
  153.                rewind (fp);                      /* clear any eof flags */
  154.                (void) fseek (fp, current, SEEK_SET);
  155.  
  156.                if (j == SPEC_COND)               /* if "Funny" success,   */
  157.                   continue;                      /* don't delete/truncate */
  158.  
  159.                if (i == TRUNC_AFTER)
  160.                   {
  161.                   CLEAR_IOERR ();
  162.                   i = open (sptr, O_CREAT|O_TRUNC|O_BINARY|O_WRONLY, S_IREAD|S_IWRITE);
  163.                   status_line (MSG_TXT(M_TRUNC_MSG), sptr);
  164.                   (void) close (i);
  165.                   }
  166.                else if (i == SHOW_DELETE_AFTER)
  167.                   {
  168.                   CLEAR_IOERR ();
  169.                   (void) unlink (sptr);
  170.                   status_line (MSG_TXT(M_UNLINKING_MSG), sptr);
  171.                   }
  172.                else if (i == DELETE_AFTER)
  173.                   {
  174.                   CLEAR_IOERR ();
  175.                   (void) unlink (sptr);
  176.                   }
  177.                }
  178.             }                                    /* while */
  179.  
  180.          (void) fclose (fp);
  181.          (void) unlink (fname);
  182.          }                                       /* !stat */
  183.       }                                          /* for */
  184.  
  185.    return TRUE;
  186. }
  187.