Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | /* |
| 2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
| 3 | * It is copyright by its individual contributors, as recorded in the |
||
| 4 | * project's Git history. See COPYING.txt at the top level for license |
||
| 5 | * terms and a link to the Git history. |
||
| 6 | */ |
||
| 7 | /* |
||
| 8 | * Written 1999 Jan 29 by Josh Cogliati |
||
| 9 | * Modified by Bradley Bell, 2002, 2003 |
||
| 10 | * This program is licensed under the terms of the GPL, version 2 or later |
||
| 11 | */ |
||
| 12 | |||
| 13 | #ifdef HAVE_CONFIG_H |
||
| 14 | #include <conf.h> |
||
| 15 | #endif |
||
| 16 | |||
| 17 | #include <stdio.h> |
||
| 18 | #include <stdlib.h> |
||
| 19 | #include <string.h> |
||
| 20 | #include <sys/types.h> |
||
| 21 | #include <sys/stat.h> |
||
| 22 | #include <fcntl.h> |
||
| 23 | |||
| 24 | #define SWAPINT(x) (((x)<<24) | (((unsigned)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) |
||
| 25 | |||
| 26 | int |
||
| 27 | main(int argc, char *argv[]) |
||
| 28 | { |
||
| 29 | FILE *hogfile, *writefile; |
||
| 30 | int len; |
||
| 31 | char filename[13]; |
||
| 32 | char *buf; |
||
| 33 | struct stat statbuf; |
||
| 34 | int v = 0; |
||
| 35 | |||
| 36 | if (argc > 1 && !strcmp(argv[1], "v")) { |
||
| 37 | v = 1; |
||
| 38 | argc--; |
||
| 39 | argv++; |
||
| 40 | } |
||
| 41 | |||
| 42 | if (argc < 2) { |
||
| 43 | printf("Usage: hogextract [v] hogfile [filename]\n" |
||
| 44 | "extracts all the files in hogfile into the current directory\n" |
||
| 45 | "Options:\n" |
||
| 46 | " v View files, don't extract\n"); |
||
| 47 | exit(0); |
||
| 48 | } |
||
| 49 | hogfile = fopen(argv[1], "rb"); |
||
| 50 | stat(argv[1], &statbuf); |
||
| 51 | printf("%i\n", (int)statbuf.st_size); |
||
| 52 | buf = (char *)malloc(3); |
||
| 53 | fread(buf, 3, 1, hogfile); |
||
| 54 | printf("Extracting from: %s\n", argv[1]); |
||
| 55 | free(buf); |
||
| 56 | while(ftell(hogfile)<statbuf.st_size) { |
||
| 57 | fread(filename, 13, 1, hogfile); |
||
| 58 | fread(&len, 1, 4, hogfile); |
||
| 59 | #ifdef WORDS_BIGENDIAN |
||
| 60 | len = SWAPINT(len); |
||
| 61 | #endif |
||
| 62 | if (argc > 2 && strcmp(argv[2], filename)) |
||
| 63 | fseek(hogfile, len, SEEK_CUR); |
||
| 64 | else { |
||
| 65 | printf("Filename: %s \tLength: %i\n", filename, len); |
||
| 66 | if (v) |
||
| 67 | fseek(hogfile, len, SEEK_CUR); |
||
| 68 | else { |
||
| 69 | buf = (char *)malloc(len); |
||
| 70 | if (buf == NULL) { |
||
| 71 | printf("Unable to allocate memory\n"); |
||
| 72 | } else { |
||
| 73 | fread(buf, len, 1, hogfile); |
||
| 74 | writefile = fopen(filename, "wb"); |
||
| 75 | fwrite(buf, len, 1, writefile); |
||
| 76 | fclose(writefile); |
||
| 77 | free(buf); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | fclose(hogfile); |
||
| 83 | |||
| 84 | return 0; |
||
| 85 | } |