home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / PPP15B12.ZIP / SENDFILE.CPP < prev    next >
C/C++ Source or Header  |  1996-08-11  |  5KB  |  160 lines

  1. /* * * * * * * * * * * * * * SENDFILE.C * * * * * * * * * * * * * * * * * * *
  2.  * Send any file to other FILEnet systems.                                  *
  3.  * Run from your FILEnet network directory.  UU must be in the path         *
  4.  *                                                                          *
  5.  * Syntax is: SENDFILE <full path and filename> <node number or '*'>        *
  6.  *                                                                          *
  7.  * If '*' is node number, file is sent to all addressees in ADDRESS.NET.    *
  8.  * If run without parameters, you are prompted for filename and system.     *
  9.  * Edit the originating addressee field to your own Internet address!       *
  10.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <alloc.h>
  16. #include <dir.h>
  17. #include <dos.h>
  18.  
  19. char *MYADDR = "edare@abs.net"; <--- CHANGE TO YOUR OWN INTERNET ADDRESS ---<
  20.  
  21. typedef struct {
  22.     char    addressee[81];
  23. } ADDRESSEE;
  24.  
  25. ADDRESSEE *address;
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.     char            s[81],
  30.                     s1[81],
  31.                     nameaddr[81],
  32.                     ref[181],
  33.                     fn[181],
  34.                     fn1[181];
  35.     char            maindir[181],
  36.                     ext[10],
  37.                          *ss;
  38.     int             i,
  39.                     ok,
  40.                     all,
  41.                     node;
  42.     static int      lines;
  43.     struct ffblk    ff;
  44.     FILE           *fp;
  45.  
  46.  
  47.     strcpy(maindir, "X:\\");
  48.     maindir[0] = 'A' + getdisk();
  49.     getcurdir(0, maindir + 3);
  50.     sprintf(ref, "%s\\ADDRESS.NET", maindir);
  51.  
  52.     if (findfirst(ref, &ff, FA_HIDDEN) != 0) {
  53.         fprintf(stderr, "\nMust be run from PPPnet directory!\n");
  54.         exit(1);
  55.     }
  56.     if (argc < 2) {
  57.         fprintf(stderr, "\nEnter the path and filename to send\n:");
  58.         gets(fn);
  59.     } else
  60.         strcpy(fn, argv[1]);
  61.  
  62.     if (findfirst(fn, &ff, FA_HIDDEN) != 0) {
  63.         fprintf(stderr, "\nUnable to locate %s", fn);
  64.         exit(1);
  65.     }
  66.     if (argc < 3) {
  67.         fprintf(stderr,
  68.             "\nDestination node, '*' for all, <Enter> aborts.\n:");
  69.         gets(s);
  70.     } else
  71.         strcpy(s, argv[2]);
  72.     if (s[0] == 0) {
  73.         fprintf(stderr, "\nNo node specified, aborted!\n");
  74.         exit(1);
  75.     } else {
  76.         all = 0;
  77.         if (s[0] == '*') {
  78.             all = 1;
  79.             fp = fopen(ref, "r");
  80.             while (fgets(s, 80, fp))
  81.                 if (s[0] == '@')
  82.                     lines++;
  83.             fprintf(stderr, "\nSending to %d addressees", lines);
  84.             address = (ADDRESSEE *) malloc((lines) * sizeof(char *));
  85.             if (!address) {
  86.                 fprintf(stderr,
  87.                     "\nInsufficient memory to send all addressees!\n\n");
  88.                 exit(1);
  89.             }
  90.             rewind(fp);
  91.             i = lines = 0;
  92.             while (fgets(s, 80, fp)) {
  93.                 if (s[0] != '@')
  94.                     continue;
  95.                 ss = strtok(s, " ");
  96.                 ss = strtok(NULL, "\n");
  97.                 if (strncmp(ss, "news", 4) == 0)
  98.                     continue;
  99.                 else {
  100.                     sprintf(address[i++].addressee, "%s", ss);
  101.                     if (!address[i].addressee)
  102.                         exit(1);
  103.                     ++lines;
  104.                 }
  105.             }
  106.             fclose(fp);
  107.         } else {
  108.             ok = 0;
  109.             fp = fopen(ref, "r");
  110.             while (fgets(s1, 80, fp)) {
  111.                 if (s1[0] != '@')
  112.                     continue;
  113.                 ss = strtok(s1, " ");
  114.                 node = atoi(&ss[1]);
  115.                 if (node == (atoi(s))) {
  116.                     ss = strtok(NULL, "\n");
  117.                     strcpy(nameaddr, ss);
  118.                     ok = 1;
  119.                     break;
  120.                 }
  121.             }
  122.             fclose(fp);
  123.             if (!ok) {
  124.                 fprintf(stderr, "\nNo match for node %s\n", s);
  125.                 exit(1);
  126.             } else
  127.                 fprintf(stderr, "\nSending %s to %s\n", fn, nameaddr);
  128.         }
  129.         fnsplit(fn, NULL, NULL, s1, ext);
  130.         sprintf(fn1, "%s\\MQUEUE\\%s.UUE", maindir, s1);
  131.         if (findfirst(fn1, &ff, FA_HIDDEN) == 0) {
  132.             fprintf(stderr, "\nTarget file already exists!\n");
  133.             exit(1);
  134.         }
  135.         fp = fopen(fn1, "wt+");
  136.         if (!fp) {
  137.             fprintf(stderr, "\nUnable to open %s for output!\n", fn1);
  138.             exit(1);
  139.         }
  140.         fprintf(fp, "From: %s\n", MYADDR);
  141.         if (all) {
  142.             for (i = 0; i < lines && (address[i].addressee[0]); i++) {
  143.                 fprintf(fp, "To: %s\n", address[i].addressee);
  144.                 fprintf(stderr, "\nSending To: %s", address[i].addressee);
  145.             }
  146.         } else
  147.             fprintf(fp, "To: %s\n", nameaddr);
  148.         fprintf(fp, "Subject: %s%s\n\n", s1, ext);
  149.         fclose(fp);
  150.         if (address)
  151.             free(address);
  152.         address = NULL;
  153.         fprintf(stderr, "\nEncoding %s... ", fn);
  154.         sprintf(s1, "UU -encode %s %s", fn, fn1);
  155.         system(s1);
  156.     }
  157.     fprintf(stderr, "\n\n");
  158.     return 0;
  159. }
  160.