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

  1. /*
  2. HEADER:                 CUG152.02;
  3. TITLE:                  Lump File Transfer Utility;
  4. DATE:                   09/04/85;
  5. DESCRIPTION:
  6.   "Transfers files in a group or "lump" such as
  7.    to or from a BBS."
  8. KEYWORDS:               lump, file, transfer;
  9. FILENAME:               LUMP.C;
  10. WARNINGS:
  11.   "The source code contains the comment that input files must
  12.       contain only printable ASCII characters.
  13.       (Note: The example in LUMP.DOC includes NON-ASCII files.
  14.    If the output file exists, the program aborts.
  15.    If no parameters are given the program tells about itself.
  16.    The authors claim copyrights and authorize non-commercial
  17.       use only.
  18.    The typist of this heading does not have equipment to run
  19.       this program and prepared this header from comments
  20.       within the source code or companion files."
  21. AUTHORS:                David N. Smith;
  22. COMPILERS:              CI/C86;
  23. REFERENCES:
  24.     AUTHERS:            " ";
  25.     TITLE:              " ";
  26.     CITATION:           " ";
  27. ENDREF
  28. */
  29. /* lump together a group of files. (Use UNLUMP to break apart */
  30.  
  31. #include "stdio.h"
  32.  
  33. FILE *infile, *outfile;
  34.  
  35. main(argc,argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.    int c, i;
  40.  
  41.    if(argc<3)  { usage(); exit(0); }
  42.  
  43.    argc--;
  44.    if( exists(argv[1]) )    { usage(); exit(1);  }
  45.    if( (outfile=fopen(argv[1], "w")) == NULL )    { usage();  exit(1); }
  46.    for( i=2; i<=argc; i++ ) {
  47.       if( (infile=fopen(argv[i],"r")) == NULL )  { inerr(argv[i]); exit(2); }
  48.       fprintf(outfile, "*FILE: %s\n", argv[i]);
  49.       printf("*FILE: %s\n", argv[i]);
  50.       while ( (c=getc(infile)) >= 0)
  51.          putc(c,outfile);
  52.       fclose(infile);
  53.    }
  54.  
  55. }
  56.  
  57.  
  58. usage()
  59. {
  60.    printf("Usage:  lump outfile infile1 ... \n");
  61.    printf("   Lump all input files into the output file,\n");
  62.    printf("   each being preceeded with a line identifying itself:\n");
  63.    printf("      *FILE: filename.ext\n\n");
  64. }
  65.  
  66.  
  67. inerr(s)
  68. char *s;
  69. {
  70.    printf("\nError opening file %s\n", s);
  71. }
  72.  
  73.  
  74. exists(s)
  75. char *s;
  76. {
  77.    FILE *f;
  78.    if( (f=fopen(s,"r")) == NULL )  return 0;
  79.    fclose(f);
  80.    return 1;
  81. }
  82.