#include #include /* * Extract the files for Efficient C Programming * Invoke as a.out ArchiveFile * where ArchiveFile is the name of the downloaded file */ #define PrefixString "ECP: FILEname=" #define MaxLineLen 256 int main( int argc, char *argv[ ] ) { FILE *ArchiveFp; char ThisLine[ MaxLineLen + 2 ]; char CurrentFile[ 256 ]; FILE *CurrentFp = NULL; if( argc != 2 ) { fprintf( stderr, "Usage: %s file\n", argv[ 0 ] ); return 1; } ArchiveFp = fopen( argv[ 1 ], "r" ); if( ArchiveFp == NULL ) { perror( argv[ 1 ] ); return 1; } while( fgets( ThisLine, MaxLineLen, ArchiveFp ) != NULL ) { if( strstr( ThisLine, PrefixString ) != NULL ) if( sscanf( ThisLine, "/* " PrefixString "%s" " */", CurrentFile ) ) { if( CurrentFp != NULL ) fclose( CurrentFp ); CurrentFp = fopen( CurrentFile, "w" ); if( CurrentFp == NULL ) { perror( CurrentFile ); return 1; } printf( "Extracting %s\n", CurrentFile ); } fputs( ThisLine, CurrentFp ); } fclose( CurrentFp ); fclose( ArchiveFp ); return 0; }