2 * Written 1999 Jan 29 by Josh Cogliati
3 * Modified by Bradley Bell, 2002, 2003
4 * This program is licensed under the terms of the GPL, version 2 or later
14 #include <sys/types.h>
18 #define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8))
21 main(int argc, char *argv[])
23 FILE *hogfile, *writefile;
30 if (argc > 1 && !strcmp(argv[1], "v")) {
37 printf("Usage: hogextract [v] hogfile [filename]\n"
38 "extracts all the files in hogfile into the current directory\n"
40 " v View files, don't extract\n");
43 hogfile = fopen(argv[1], "rb");
44 stat(argv[1], &statbuf);
45 printf("%i\n", (int)statbuf.st_size);
46 buf = (char *)malloc(3);
47 if ( fread(buf, 3, 1, hogfile) != 1 ) {
48 printf("Error reading %s\n", argv[1]);
52 printf("Extracting from: %s\n", argv[1]);
54 while(ftell(hogfile)<statbuf.st_size) {
55 if ( fread(filename, 13, 1, hogfile) != 1 ||
56 fread(&len, 1, 4, hogfile) != 4 ) {
57 printf("Error reading %s\n", argv[1]);
61 #ifdef WORDS_BIGENDIAN
64 if (argc > 2 && strcmp(argv[2], filename))
65 fseek(hogfile, len, SEEK_CUR);
67 printf("Filename: %s \tLength: %i\n", filename, len);
69 fseek(hogfile, len, SEEK_CUR);
71 buf = (char *)malloc(len);
73 printf("Unable to allocate memory\n");
75 if ( fread(buf, len, 1, hogfile) != 1 ) {
76 printf("Error reading %s\n", argv[1]);
80 writefile = fopen(filename, "wb");
81 fwrite(buf, len, 1, writefile);