if ((arc = fopen(argv[1], "r")) == (FILE *) NULL)
{
fprintf(stderr, "Can't open %s\n", argv[1]);
exit(1);
}
while ( (c = getc(arc)) != EOF )
{
switch( c )
{
case CNTRLL : UnPackOneFile(arc) ; break ;
case CNTRLZ : (void) fclose(arc) ; exit(0) ;
default : fprintf(stderr, "Ignoring %c\n", c) ;
/* default case is only reached if archive
* is not in valid format
*/
}
}
}
UnPackOneFile( arc )
FILE * arc ;
{
FILE * newFile ; char name[ MAXNAMELEN ] ; int c ;
/* first read the file name */
(void) fscanf( arc, "%s\n", name ) ;
name[ strlen(name) ] = 0 ; /* throw away newline */
printf("Extracting %s...", name) ;
/* open the new file */
if ( (newFile = fopen(name, "w")) == (FILE *) NULL )
{
fprintf(stderr, "Can't write file %s\n", name) ;
exit(1) ;
}
/* copy everything up to the next ^L or ^Z into the new file */
while ( (c = getc(arc)) != EOF )
{
if ( c == CNTRLL || c == CNTRLZ )
{
(void) ungetc( c, arc ) ;
break ;
}
else (void) putc( c, newFile ) ;
}
/* close the new file */
printf("Done.\n", name) ;
(void) fclose( newFile ) ;
}