home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / PPP15B93.ZIP / SENDFILE.CPP < prev    next >
C/C++ Source or Header  |  1998-07-06  |  5KB  |  153 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 <malloc.h>
  16. #include <dir.h>
  17. #include <dos.h>
  18.  
  19. char *MYADDR = "n1160@filenet.ml.org";
  20. //char *MYADDR = "youraddress@somewhere";
  21.  
  22. typedef struct {
  23.   char addressee[81];
  24. } ADDRESS;
  25.  
  26. ADDRESS *address;
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30.   char s[81], s1[81], nameaddr[81], ref[181], fn[181], fn1[181];
  31.   char maindir[181], ext[10], *ss;
  32.   int i, ok, all, node;
  33.   static int lines;
  34.   struct ffblk ff;
  35.   FILE *fp;
  36.  
  37.  
  38.   strcpy(maindir, "X:\\");
  39.   maindir[0] = 'A' + getdisk();
  40.   getcurdir(0, maindir + 3);
  41.   sprintf(ref, "%s\\ADDRESS.NET", maindir);
  42.  
  43.   if (findfirst(ref, &ff, FA_HIDDEN) != 0) {
  44.     fprintf(stderr, "\nMust be run from FILEnet directory!\n");
  45.     exit(1);
  46.   }
  47.   if (argc < 2) {
  48.     fprintf(stderr, "\nEnter the path and filename to send\n:");
  49.     gets(fn);
  50.   } else
  51.     strcpy(fn, argv[1]);
  52.  
  53.   if (findfirst(fn, &ff, FA_HIDDEN) != 0) {
  54.     fprintf(stderr, "\nUnable to locate %s", fn);
  55.     exit(1);
  56.   }
  57.   if (argc < 3) {
  58.     fprintf(stderr,
  59.             "\nDestination node, '*' for all, <Enter> aborts.\n:");
  60.     gets(s);
  61.   } else
  62.     strcpy(s, argv[2]);
  63.   if (s[0] == 0) {
  64.     fprintf(stderr, "\nNo node specified, aborted!\n");
  65.     exit(1);
  66.   } else {
  67.     all = 0;
  68.     if (s[0] == '*') {
  69.       all = 1;
  70.       fp = fopen(ref, "r");
  71.       while (fgets(s, 80, fp))
  72.         lines++;
  73.       fprintf(stderr, "\nSending to %d addressees", lines);
  74.       address = (ADDRESS *) malloc((lines) * sizeof(char *));
  75.       if (!address) {
  76.         fprintf(stderr,
  77.                 "\nInsufficient memory to send all addressees!\n\n");
  78.         exit(1);
  79.       }
  80.       rewind(fp);
  81.       i = lines = 0;
  82.       while (fgets(s, 80, fp)) {
  83.         if (s[0] != '@')
  84.           continue;
  85.         ss = strtok(s, " ");
  86.         ss = strtok(NULL, "\n");
  87.         if (strncmp(ss, "news", 4) == 0)
  88.           continue;
  89.         if (stricmp(ss, MYADDR) == 0)
  90.           continue;
  91.         sprintf(address[i++].addressee, "%s", ss);
  92.         if (!address[i].addressee)
  93.           exit(1);
  94.         ++lines;
  95.       }
  96.       fclose(fp);
  97.     } else {
  98.       ok = 0;
  99.       fp = fopen(ref, "r");
  100.       while (fgets(s1, 80, fp)) {
  101.         if (s1[0] != '@')
  102.           continue;
  103.         ss = strtok(s1, " ");
  104.         node = atoi(&ss[1]);
  105.         if (node == (atoi(s))) {
  106.           ss = strtok(NULL, "\n");
  107.           strcpy(nameaddr, ss);
  108.           ok = 1;
  109.           break;
  110.         }
  111.       }
  112.       fclose(fp);
  113.       if (!ok) {
  114.         fprintf(stderr, "\nNo match for node %s\n", s);
  115.         exit(1);
  116.       } else
  117.         fprintf(stderr, "\nSending %s to %s\n", fn, nameaddr);
  118.     }
  119.     fnsplit(fn, NULL, NULL, s1, ext);
  120.     sprintf(fn1, "%s\\MQUEUE\\%s.UUE", maindir, s1);
  121.     if (findfirst(fn1, &ff, FA_HIDDEN) == 0) {
  122.       fprintf(stderr, "\nTarget file already exists!\n");
  123.       exit(1);
  124.     }
  125.     fp = fopen(fn1, "wt+");
  126.     if (!fp) {
  127.       fprintf(stderr, "\nUnable to open %s for output!\n", fn1);
  128.       exit(1);
  129.     }
  130.     fprintf(fp, "From: %s\n", MYADDR);
  131.     if (all) {
  132.       for (i = 0; i < lines && (address[i].addressee[0]); i++) {
  133.         fprintf(fp, "To: %s\n", address[i].addressee);
  134.         fprintf(stderr, "\nSending To: %s", address[i].addressee);
  135.       }
  136.     } else
  137.       fprintf(fp, "To: %s\n", nameaddr);
  138.     fprintf(fp, "MIME-Version: 1.0\n");
  139.     fprintf(fp, "Content-Type: text/plain; charset=us-ascii\n");
  140.     fprintf(fp, "Content-Transfer-Encoding: x-uue\n");
  141.     fprintf(fp, "Subject: %s%s\n\n", s1, ext);
  142.     fclose(fp);
  143.     if (address)
  144.       free(address);
  145.     address = NULL;
  146.     fprintf(stderr, "\nEncoding %s... ", fn);
  147.     sprintf(s1, "UU -encode %s %s", fn, fn1);
  148.     system(s1);
  149.   }
  150.   fprintf(stderr, "\n\n");
  151.   return 0;
  152. }
  153.