added [v]iew option
This commit is contained in:
parent
03231a4337
commit
b1e78c40ba
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
* Written 1999 Jan 29 by Josh Cogliati
|
||||
* I grant this program to public domain.
|
||||
*
|
||||
* Modified by Bradley Bell, 2002
|
||||
* All modifications under GPL, version 2 or later
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -17,10 +20,19 @@ main(int argc, char *argv[])
|
|||
char filename[13];
|
||||
char *buf;
|
||||
struct stat statbuf;
|
||||
int v = 0;
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "v")) {
|
||||
v = 1;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: hogextract hogfile\n"
|
||||
"extracts all the files in hogfile into the current directory\n");
|
||||
printf("Usage: hogextract [v] hogfile\n"
|
||||
"extracts all the files in hogfile into the current directory\n"
|
||||
"Options:\n"
|
||||
" v View files, don't extract\n");
|
||||
exit(0);
|
||||
}
|
||||
hogfile = fopen(argv[1], "r");
|
||||
|
@ -34,15 +46,19 @@ main(int argc, char *argv[])
|
|||
fread(filename, 13, 1, hogfile);
|
||||
fread(&len, sizeof(int), 1, hogfile);
|
||||
printf("Filename: %s \tLength: %i\n", filename, len);
|
||||
buf = (char *)malloc(len);
|
||||
if (buf == NULL) {
|
||||
printf("Unable to allocate memory\n");
|
||||
} else {
|
||||
fread(buf, len, 1, hogfile);
|
||||
writefile = fopen(filename, "w");
|
||||
fwrite(buf, len, 1, writefile);
|
||||
fclose(writefile);
|
||||
free(buf);
|
||||
if (v)
|
||||
fseek(hogfile, len, SEEK_CUR);
|
||||
else {
|
||||
buf = (char *)malloc(len);
|
||||
if (buf == NULL) {
|
||||
printf("Unable to allocate memory\n");
|
||||
} else {
|
||||
fread(buf, len, 1, hogfile);
|
||||
writefile = fopen(filename, "w");
|
||||
fwrite(buf, len, 1, writefile);
|
||||
fclose(writefile);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(hogfile);
|
||||
|
|
Loading…
Reference in a new issue