home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts314b4 / b_flofil.c < prev    next >
C/C++ Source or Header  |  1994-01-08  |  8KB  |  215 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. #ifndef LATTICE
  47. #include <io.h>
  48. #endif
  49. #include <conio.h>
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <errno.h>
  53. #ifdef __TOS__
  54. #include <ext.h>
  55. #else
  56. #include <sys\types.h>
  57. #include <sys\stat.h>
  58. #include <fcntl.h>
  59. #endif
  60.  
  61. #include "bink.h"
  62. #include "msgs.h"
  63. #include "com.h"
  64. #include "zmodem.h"
  65. #include "session.h"
  66.  
  67.  
  68. BOOLEAN send_flo(char *fname, int (*callback)(char *))
  69. {
  70.        FILE *fp;
  71.        char s[80];
  72.        char *sptr;
  73.        int i,j;
  74.        struct stat buf;
  75.  
  76.        long current, last_start;
  77.  
  78.        if (!stat (fname, &buf))
  79.     {
  80.         if ((fp = fopen (fname, read_binary_plus)) == NULL)
  81.         {
  82.             got_error (msgtxt[M_OPEN_MSG], fname);
  83.             return TRUE;
  84.         }
  85.  
  86.         current = 0L;
  87.         while (!feof (fp))
  88.         {
  89.             s[0] = 0;
  90.             last_start = current;
  91.             fgets (s, 79, fp);
  92.  
  93.             sptr = s;
  94.  
  95.             for (i = 0; sptr[i]; i++)
  96.                    if (sptr[i] <= ' ')
  97.                       sptr[i] = 0;
  98.  
  99.             current = ftell (fp);
  100.  
  101.             if (sptr[0] == TRUNC_AFTER)
  102.             {
  103.                    sptr++;
  104.                    i = TRUNC_AFTER;
  105.             }
  106.             else if (sptr[0] == SHOW_DELETE_AFTER)
  107.             {
  108.                    sptr++;
  109.                    i = SHOW_DELETE_AFTER;
  110.             }
  111.             else
  112.                 i = NOTHING_AFTER;
  113.  
  114.             if ((!sptr[0]) || (sptr[0] == ';'))
  115.             {
  116.                 continue;
  117.             }
  118.  
  119.             if (sptr[0] != '~')
  120.             {
  121.                 if (stat (sptr, &buf))            /* file exist? */
  122.                 {
  123.                     got_error (msgtxt[M_FIND_MSG], sptr);
  124.                       continue;
  125.                 }
  126.                    else if (!buf.st_size)
  127.                 {
  128.                     continue;                      /* 0 length? */
  129.                 }
  130.  
  131.                    j = (*callback) (sptr);
  132.                    if (!j)
  133.                 {
  134.                     fclose (fp);
  135.                       net_problems = TRUE;
  136.                       return FALSE;
  137.                 }
  138.  
  139.                    /*--------------------------------------------*/
  140.                    /* File was sent.  Flag file name             */
  141.                    /*--------------------------------------------*/
  142.                    fseek (fp, last_start, SEEK_SET);
  143.                    putc ('~', fp);                   /* flag it */
  144.                    fflush (fp);
  145.                    rewind (fp);                      /* clear any eof flags */
  146.                    fseek (fp, current, SEEK_SET);
  147.  
  148.                    if (j == SPEC_COND)               /* if "Funny" success,   */
  149.                     continue;                  /* don't delete/truncate */
  150.  
  151.                    if (i == TRUNC_AFTER)
  152.                 {
  153.                     CLEAR_IOERR ();
  154.                       i = open (sptr, O_CREAT|O_TRUNC|O_BINARY|O_WRONLY, DEFAULT_MODE);
  155.                       status_line (msgtxt[M_TRUNC_MSG], sptr);
  156.                       close (i);
  157.                    }
  158.                    else if (i == SHOW_DELETE_AFTER)
  159.                 {
  160.                     CLEAR_IOERR ();
  161.                       unlink (sptr);
  162.                       status_line (msgtxt[M_UNLINKING_MSG], sptr);
  163.                 }
  164.                    else if (i == DELETE_AFTER)
  165.                 {
  166.                     CLEAR_IOERR ();
  167.                       unlink (sptr);
  168.                 }
  169.             }
  170.         }                                    /* while */
  171.  
  172.         fclose (fp);
  173.         unlink (fname);
  174.     }                                       /* !stat */
  175.     return TRUE;
  176. }
  177.  
  178. /*--------------------------------------------------------------------------*/
  179. /* do_FLOfile (send files listed in .FLO files)                             */
  180. /*   returns TRUE (1) for good xfer, FALSE (0) for bad                      */
  181. /*--------------------------------------------------------------------------*/
  182.  
  183. int do_FLOfile( char *ext_flags, int (*callback)(char *) , ADDR *ad )
  184. {
  185.        char fname[80];
  186.        char *HoldName;
  187.  
  188.        HoldName = HoldAreaNameMunge(ad);
  189.  
  190.        /*--------------------------------------------------------------------*/
  191.        /* Send files listed in ?LO files (attached files)                    */
  192.        /*--------------------------------------------------------------------*/
  193.  
  194.  
  195.     while(*ext_flags)
  196.     {
  197.         char c = *ext_flags++;
  198.  
  199.         if(caller && (c == 'H') && !check_holdonus(ad, (char**)NULL))
  200.             continue;
  201.  
  202.           sprintf (fname, "%s%s.%cLO", HoldName, Hex_Addr_Str(ad), c);
  203.         if(!send_flo(fname, callback))
  204.             return FALSE;
  205.  
  206. #ifdef IOS
  207.         sprintf(fname, "%s%s.%cFT", HoldName, Addr36(ad), c);
  208.         if(!send_flo(fname, callback))
  209.             return FALSE;
  210. #endif
  211.     }
  212.  
  213.        return TRUE;
  214. }
  215.