| 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 |
#include <dirent.h> |
| 24 |
|
| 25 |
#define SWAPINT(x) (((x)<<24) | (((unsigned)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) |
| 26 |
|
| 27 |
int |
| 28 |
main(int argc, char *argv[]) |
| 29 |
{ |
| 30 |
FILE *hogfile, *readfile; |
| 31 |
DIR *dp; |
| 32 |
struct dirent *ep; |
| 33 |
char filename[13]; |
| 34 |
char *buf; |
| 35 |
struct stat statbuf; |
| 36 |
int tmp; |
| 37 |
|
| 38 |
if (argc != 2) { |
| 39 |
printf("Usage: hogcreate hogfile\n" |
| 40 |
"creates hogfile using all the files in the current directory\n"); |
| 41 |
exit(0); |
| 42 |
} |
| 43 |
hogfile = fopen(argv[1], "wb"); |
| 44 |
buf = (char *)malloc(3); |
| 45 |
strncpy(buf, "DHF", 3); |
| 46 |
fwrite(buf, 3, 1, hogfile); |
| 47 |
printf("Creating: %s\n", argv[1]); |
| 48 |
free(buf); |
| 49 |
dp = opendir("./"); |
| 50 |
if (dp != NULL) { |
| 51 |
while ((ep = readdir(dp))) { |
| 52 |
if (strlen(ep->d_name) > 12) { |
| 53 |
fprintf(stderr, "error: filename %s too long! (12 chars max!)\n", ep->d_name); |
| 54 |
return 1; |
| 55 |
} |
| 56 |
memset(filename, 0, 13); |
| 57 |
strcpy(filename, ep->d_name); |
| 58 |
stat(filename, &statbuf); |
| 59 |
if(! S_ISDIR(statbuf.st_mode)) { |
| 60 |
printf("Filename: %s \tLength: %i\n", filename, (int)statbuf.st_size); |
| 61 |
readfile = fopen(filename, "rb"); |
| 62 |
buf = (char *)malloc(statbuf.st_size); |
| 63 |
if (buf == NULL) { |
| 64 |
printf("Unable to allocate memery\n"); |
| 65 |
} else { |
| 66 |
fwrite(filename, 13, 1, hogfile); |
| 67 |
tmp = (int)statbuf.st_size; |
| 68 |
#ifdef WORDS_BIGENDIAN |
| 69 |
tmp = SWAPINT(tmp); |
| 70 |
#endif |
| 71 |
fwrite(&tmp, 4, 1, hogfile); |
| 72 |
fread(buf, statbuf.st_size, 1, readfile); |
| 73 |
fwrite(buf, statbuf.st_size, 1, hogfile); |
| 74 |
} |
| 75 |
fclose(readfile); |
| 76 |
|
| 77 |
} |
| 78 |
} |
| 79 |
closedir(dp); |
| 80 |
} |
| 81 |
fclose(hogfile); |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |