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 >
Wrap
Text File
|
1985-03-10
|
2KB
|
94 lines
/*
HEADER: CUG152.03;
TITLE: Unlump File Transfer Utility;
DATE: 09/04/85;
DESCRIPTION:
"Separates files which have been transferred in a group or "lump"
with the utility LUMP.EXE."
KEYWORDS: lump, unlump, file, transfer;
FILENAME: UNLUMP.C;
WARNINGS:
"If no parameters are given the program tells about itself.
The authors claim copyrights and authorize non-commercial
use only.
The typist of this heading does not have equipment to run
this program and prepared this header from comments
within the source code or companion files."
AUTHORS: David N. Smith;
COMPILERS: CI/C86;
REFERENCES:
AUTHERS: " ";
TITLE: " ";
CITATION: " ";
ENDREF
*/
/* UNLUMP: Break apart files lumped together by LUMP */
#include "stdio.h"
#define BUFL 512
FILE *infile, *outfile;
main(argc,argv)
int argc;
char *argv[];
{
int c, i;
char filename[61];
char buf[BUFL];
int opened = 0;
if(argc<2) { usage(); exit(0); }
argc--;
if( (infile=fopen(argv[1], "r")) == NULL ) inerr();
while( fgets(buf, BUFL, infile) != NULL ) {
filename[0] = '\0';
sscanf( buf, "*FILE: %60s", filename );
if( filename[0] != '\0' ) {
if(opened) fclose(outfile);
printf( "*FILE: %s\n", filename );
if( (outfile=fopen(filename,"w")) == NULL ) outerr();
opened = 1;
continue;
}
if( !opened ) fmterr();
if( fputs(buf, outfile) == EOF ) outerr();
}
if( ferror(infile) ) inerr();
fclose(infile);
}
usage()
{
printf("Usage: unlump infile \n");
printf(" UnLump the input file into output files named in it.\n");
printf(" Files are separated by a line with the format:\n");
printf(" *FILE: filename.ext\n\n");
}
inerr()
{
printf("\nError opening or reading input file \n");
fclose(infile);
exit(1);
}
outerr()
{
printf("\nError opening or writing output file \n");
fclose(outfile);
exit(1);
}
fmterr()
{
printf("\nFile does not have proper LUMP format\n");
exit(1);
}