home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 278.lha / UuSharUtil / uujoin.c < prev    next >
C/C++ Source or Header  |  1989-08-05  |  3KB  |  106 lines

  1.  
  2. /**********
  3.  *
  4.  * uujoin - join all related uuencoded files for decoding. All related files
  5.  *          must start with the same filename ending with .1, .2, .3, .n.
  6.  *
  7.  *          Usage : uujoin filename (no extension)
  8.  *
  9.  *          It will search for consecutively numbered files and join them to
  10.  *          filename argv[1].uuj.
  11.  *
  12.  *
  13.  * Related Files                    Relationship
  14.  * -------------------------------------------------------------------------
  15.  *
  16.  * -------------------------------------------------------------------------
  17.  *
  18.  * File History:
  19.  *
  20.  * Date        Author               Version     Comments
  21.  * -------------------------------------------------------------------------
  22.  * 10-Jun-89   Keith Elbertson         1.0P     Original Version
  23.  * -------------------------------------------------------------------------
  24.  *
  25.  * Known Bug List:
  26.  * -------------------------------------------------------------------------
  27.  *
  28.  * -------------------------------------------------------------------------
  29.  *
  30.  * Copyright (c) 1989 Keith Elbertson, All Rights Reserved.
  31.  *
  32.  **********/
  33.  
  34.  
  35. #include <stdio.h>
  36.  
  37. #define MAXPATH 128
  38. #define STRING_BUFFER_SIZE 512
  39.  
  40. void
  41. main(argc, argv)
  42. int argc;
  43. char **argv;
  44. {
  45.    FILE *infile, *outfile;
  46.    char outfilename[MAXPATH] = "";          /* room for filename and path */
  47.    char infilename[MAXPATH]  = "";
  48.    char stringbuffer[STRING_BUFFER_SIZE] = "";
  49.    int  extnum = 1;                    /* extension number */
  50.  
  51.  
  52.    puts("Copyright 1989, Keith Elbertson, All Rights Reserved.");
  53.  
  54.    if ( argc != 2) {
  55.  
  56.       puts("Usage: UUJOIN <filename> /* no extension */");
  57.       exit();
  58.    }
  59.  
  60.    strcat (outfilename, argv[1]);      /* copy path and name to buffer */
  61.    strcat (outfilename, ".UUJ");       /* append .UUJ to it. */
  62.  
  63.    printf("Sending output to %s\n", outfilename);
  64.    fflush(stdout);
  65.  
  66.    if (outfile = fopen(outfilename, "w")){
  67.  
  68.       while( found_input( infilename, argv[1], extnum++)){
  69.  
  70.          register int found_BEGIN = 0;
  71.  
  72.          printf("Working on %s\n" ,infilename);
  73.          fflush(stdout);
  74.  
  75.          if ( infile = fopen( infilename, "r")){
  76.  
  77.             while ( fgets ( stringbuffer, STRING_BUFFER_SIZE, infile )){
  78.  
  79.                if (found_BEGIN) {
  80.  
  81.                   if(!(strncmp(stringbuffer, "END", 3))) break;
  82.                   else fputs( stringbuffer, outfile);
  83.                }
  84.                if(!(strncmp(stringbuffer, "BEGIN" , 5))) found_BEGIN++;
  85.             }
  86.             if( ! found_BEGIN ){
  87.  
  88.                printf("Didn't find BEGIN in %s\n" , infilename);
  89.             }
  90.             fclose(infile);
  91.          }
  92.       }
  93.       fclose(outfile);
  94.    }
  95. }
  96.  
  97. int
  98. found_input(inname,outname,ext)
  99. char *inname, *outname;
  100. int ext;
  101. {
  102.    sprintf(inname, "%s.%d", outname, ext);
  103.  
  104.    return ( ! (access(inname, 4))); /* access returns 0 if accessable */
  105. }
  106.