]> icculus.org git repositories - btb/d2x.git/blob - utility/hogextract.c
added utilities
[btb/d2x.git] / utility / hogextract.c
1 /* Written 1999 Jan 29 by Josh Cogliati
2    I grant this program to public domain.
3 */
4 #include<stdio.h>
5 #include<sys/types.h>
6 #include<sys/stat.h>
7 #include<fcntl.h>
8
9
10 void main(int argc, char *argv[]){
11   FILE * hogfile, * writefile;
12   int fp, len, fseekret=0;
13   char filename[13];
14   char * buf;
15   struct stat statbuf;
16   if(argc != 2){
17     printf("Usage: hogextract hogfile\n"
18            "extracts all the files in hogfile into the current directory\n"
19            );
20     exit(0);
21   }
22   hogfile = fopen(argv[1],"r"); 
23   stat(argv[1],&statbuf);
24   printf("%i\n",statbuf.st_size);
25   buf = (char *)malloc(3);
26   fread(buf,3,1,hogfile);
27   printf("Extracting from: %s\n",argv[1]);
28   free(buf);
29   while(ftell(hogfile)<statbuf.st_size){
30     fread(filename,13,1,hogfile);
31     fread(&len,sizeof(int),1,hogfile);
32     printf("Filename: %s \tLength: %i\n",filename,len);
33     buf = (char *)malloc(len);
34     if(buf == NULL) {
35       printf("Unable to allocate memory\n");
36     } else {
37       fread(buf,len,1,hogfile);
38       writefile = fopen(filename,"w");
39       fwrite(buf, len, 1 , writefile);
40       fclose(writefile);
41       free(buf);
42     };
43   }
44   fclose(hogfile);
45 }