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