home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 152_01 / unlump.c < prev    next >
Text File  |  1985-03-10  |  2KB  |  94 lines

  1. /*
  2. HEADER:                 CUG152.03;
  3. TITLE:                  Unlump File Transfer Utility;
  4. DATE:                   09/04/85;
  5. DESCRIPTION:
  6.   "Separates files which have been transferred in a group or "lump"
  7.       with the utility LUMP.EXE."
  8. KEYWORDS:               lump, unlump, file, transfer;
  9. FILENAME:               UNLUMP.C;
  10. WARNINGS:
  11.   "If no parameters are given the program tells about itself.
  12.    The authors claim copyrights and authorize non-commercial
  13.       use only.
  14.    The typist of this heading does not have equipment to run
  15.       this program and prepared this header from comments
  16.       within the source code or companion files."
  17. AUTHORS:                David N. Smith;
  18. COMPILERS:              CI/C86;
  19. REFERENCES:
  20.     AUTHERS:            " ";
  21.     TITLE:              " ";
  22.     CITATION:           " ";
  23. ENDREF
  24. */
  25. /* UNLUMP:  Break apart files lumped together by LUMP */
  26.  
  27. #include "stdio.h"
  28.  
  29. #define  BUFL  512
  30.  
  31. FILE *infile, *outfile;
  32.  
  33. main(argc,argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.    int c, i;
  38.    char filename[61];
  39.    char buf[BUFL];
  40.    int opened = 0;
  41.  
  42.    if(argc<2)  { usage(); exit(0); }
  43.  
  44.    argc--;
  45.    if( (infile=fopen(argv[1], "r")) == NULL )     inerr();
  46.    while( fgets(buf, BUFL, infile) != NULL )  {
  47.       filename[0] = '\0';
  48.       sscanf( buf, "*FILE: %60s", filename );
  49.       if( filename[0] != '\0' )  {
  50.          if(opened)  fclose(outfile);
  51.          printf( "*FILE: %s\n", filename );
  52.          if( (outfile=fopen(filename,"w")) == NULL )    outerr();
  53.          opened = 1;
  54.          continue;
  55.          }
  56.       if( !opened )  fmterr();
  57.       if( fputs(buf, outfile) == EOF )  outerr();
  58.       }
  59.    if( ferror(infile) )  inerr();
  60.    fclose(infile);
  61. }
  62.  
  63.  
  64. usage()
  65. {
  66.    printf("Usage:  unlump infile \n");
  67.    printf("   UnLump the input file into output files named in it.\n");
  68.    printf("   Files are separated by  a line with the format:\n");
  69.    printf("      *FILE: filename.ext\n\n");
  70. }
  71.  
  72.  
  73. inerr()
  74. {
  75.    printf("\nError opening or reading input file \n");
  76.    fclose(infile);
  77.    exit(1);
  78. }
  79.  
  80.  
  81. outerr()
  82. {
  83.    printf("\nError opening or writing output file \n");
  84.    fclose(outfile);
  85.    exit(1);
  86. }
  87.  
  88.  
  89. fmterr()
  90. {
  91.    printf("\nFile does not have proper LUMP format\n");
  92.    exit(1);
  93. }
  94.