summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.h14
-rw-r--r--src/externs.h2
-rw-r--r--src/init1.c24
-rw-r--r--src/init2.c3667
4 files changed, 69 insertions, 3638 deletions
diff --git a/src/config.h b/src/config.h
index 343f675c..143740ef 100644
--- a/src/config.h
+++ b/src/config.h
@@ -162,14 +162,6 @@
/*
- * OPTION: Allow parsing of the ascii template files in "init.c".
- * This must be defined if you do not have valid binary image files.
- * It should be usually be defined anyway to allow easy "updating".
- */
-#define ALLOW_TEMPLATES
-
-
-/*
* OPTION: Handle signals
*/
#define HANDLE_SIGNALS
@@ -414,12 +406,6 @@
#define ALLOW_EASY_DISARM
/*
- * Check the modification time of *_info.raw files
- * (by Keldon Jones)
- */
-#define CHECK_MODIFICATION_TIME
-
-/*
* Using the fast autoroller can be considered as cheating
*/
#define USE_FAST_AUTOROLLER
diff --git a/src/externs.h b/src/externs.h
index 9e1aa372..fbc11627 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -998,12 +998,10 @@ extern errr init_v_info(void);
extern void init_file_paths(char *path);
extern void init_angband(void);
extern errr init_buildings(void);
-#ifdef ALLOW_TEMPLATES
extern s16b error_idx;
extern s16b error_line;
extern u32b fake_name_size;
extern u32b fake_text_size;
-#endif /* ALLOW_TEMPLATES */
/* loadsave.c */
extern void register_savefile(int num);
diff --git a/src/init1.c b/src/init1.c
index 5eb5815e..ded9a281 100644
--- a/src/init1.c
+++ b/src/init1.c
@@ -20,24 +20,9 @@
* name and text information in a single pass. Thus, the game will not
* be able to load any template file with more than 20K of names or 60K
* of text, even though technically, up to 64K should be legal.
- *
- * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
- * in this file is compiled out, and the game will not run unless valid
- * "binary template files" already exist in "lib/data". Thus, one can
- * compile Angband with ALLOW_TEMPLATES defined, run once to create the
- * "*.raw" files in "lib/data", and then quit, and recompile without
- * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
- * from changing the ascii template files in potentially dangerous ways.
- *
- * The code could actually be removed and placed into a "stand-alone"
- * program, but that feels a little silly, especially considering some
- * of the platforms that we currently support.
*/
-#ifdef ALLOW_TEMPLATES
-
-
/*** Helper arrays for parsing ascii template files ***/
/*
@@ -10611,15 +10596,6 @@ errr init_wf_info_txt(FILE *fp, char *buf)
}
-#else /* ALLOW_TEMPLATES */
-
-#ifdef MACINTOSH
-static int i = 0;
-#endif
-
-#endif /* ALLOW_TEMPLATES */
-
-
/* Random dungeon grid effects */
#define RANDOM_NONE 0x00
#define RANDOM_FEATURE 0x01
diff --git a/src/init2.c b/src/init2.c
index 8b2e6d89..6db66d28 100644
--- a/src/init2.c
+++ b/src/init2.c
@@ -5,12 +5,6 @@
#include "angband.h"
-#if !defined(MACINTOSH) && defined(CHECK_MODIFICATION_TIME)
-#include <sys/types.h>
-#include <sys/stat.h>
-#endif /* !MACINTOSH && CHECK_MODIFICATION_TIME */
-
-
/*
* This file is used to initialise various variables and arrays for the
* Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
@@ -27,11 +21,7 @@
* be able to load any template file with more than 20K of names or 60K
* of text, even though technically, up to 64K should be legal.
*
- * The "init1.c" file is used only to parse the ascii template files,
- * to create the binary image files. If you include the binary image
- * files instead of the ascii template files, then you can undefine
- * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c". Note
- * that the binary image files are extremely system dependant.
+ * The "init1.c" file is used only to parse the ascii template files.
*/
@@ -276,9 +266,20 @@ void init_file_paths(char *path)
}
-
-#ifdef ALLOW_TEMPLATES
-
+/**
+ * Realloc the given character array.
+ */
+static void z_realloc(char **p, size_t n) {
+ /* realloc doesn't really support size 0, but we want to shrink the allocated area regardless. */
+ if (n == 0) {
+ n = 1;
+ }
+ /* do the reallocation */
+ *p = realloc(*p, n);
+ if (*p == NULL) {
+ quit("Error during realloc.");
+ }
+}
/*
* Hack -- help give useful error messages
@@ -312,46 +313,6 @@ static cptr err_str[9] =
};
-#endif /* ALLOW_TEMPLATES */
-
-
-#if defined(CHECK_MODIFICATION_TIME)
-
-static errr check_modification_date(int fd, cptr template_file)
-{
- char buf[1024];
-
- struct stat txt_stat, raw_stat;
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_EDIT, template_file);
-
- /* Access stats on text file */
- if (stat(buf, &txt_stat))
- {
- /* Error */
- return ( -1);
- }
-
- /* Access stats on raw file */
- if (fstat(fd, &raw_stat))
- {
- /* Error */
- return ( -1);
- }
-
- /* Ensure text file is not newer than raw file */
- if (txt_stat.st_mtime > raw_stat.st_mtime)
- {
- /* Reprocess text file */
- return ( -1);
- }
-
- return (0);
-}
-
-#endif /* CHECK_MODIFICATION_TIME */
-
/*
* Hack -- take notes on line 23
*/
@@ -364,63 +325,6 @@ static void note(cptr str)
-/*** Initialise from binary image files ***/
-
-
-/*
- * Initialise the "f_info" array, by parsing a binary "image" file
- */
-static errr init_f_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != f_head->v_major) ||
- (test.v_minor != f_head->v_minor) ||
- (test.v_patch != f_head->v_patch) ||
- (test.v_extra != f_head->v_extra) ||
- (test.info_num != f_head->info_num) ||
- (test.info_len != f_head->info_len) ||
- (test.head_size != f_head->head_size) ||
- (test.info_size != f_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*f_head) = test;
-
-
- /* Allocate the "f_info" array */
- C_MAKE(f_info, f_head->info_num, feature_type);
-
- /* Read the "f_info" array */
- fd_read(fd, (char*)(f_info), f_head->info_size);
-
-
- /* Allocate the "f_name" array */
- C_MAKE(f_name, f_head->name_size, char);
-
- /* Read the "f_name" array */
- fd_read(fd, (char*)(f_name), f_head->name_size);
-
-
- /* Allocate the "f_text" array */
- C_MAKE(f_text, f_head->text_size, char);
-
- /* Read the "f_text" array */
- fd_read(fd, (char*)(f_text), f_head->text_size);
-
-
- /* Success */
- return (0);
-}
-
-
-
/*
* Initialise the "f_info" array
*
@@ -429,10 +333,6 @@ static errr init_f_info_raw(int fd)
*/
static errr init_f_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -461,47 +361,6 @@ static errr init_f_info(void)
f_head->info_size = f_head->info_num * f_head->info_len;
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "f_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_f_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'f_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "f_name" and "f_text" */
@@ -557,142 +416,9 @@ static errr init_f_info(void)
quit("Error in 'f_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(f_head), f_head->head_size);
-
- /* Dump the "f_info" array */
- fd_write(fd, (char*)(f_info), f_head->info_size);
-
- /* Dump the "f_name" array */
- fd_write(fd, (char*)(f_name), f_head->name_size);
-
- /* Dump the "f_text" array */
- fd_write(fd, (char*)(f_text), f_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "f_info" array */
- C_KILL(f_info, f_head->info_num, feature_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(f_name, fake_name_size, char);
- C_KILL(f_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'f_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_f_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'f_info.raw' file.");
-
- /* Success */
- return (0);
-}
-
-
-
-/*
- * Initialise the "k_info" array, by parsing a binary "image" file
- */
-static errr init_k_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != k_head->v_major) ||
- (test.v_minor != k_head->v_minor) ||
- (test.v_patch != k_head->v_patch) ||
- (test.v_extra != k_head->v_extra) ||
- (test.info_num != k_head->info_num) ||
- (test.info_len != k_head->info_len) ||
- (test.head_size != k_head->head_size) ||
- (test.info_size != k_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*k_head) = test;
-
-
- /* Allocate the "k_info" array */
- C_MAKE(k_info, k_head->info_num, object_kind);
-
- /* Read the "k_info" array */
- fd_read(fd, (char*)(k_info), k_head->info_size);
-
-
- /* Allocate the "k_name" array */
- C_MAKE(k_name, k_head->name_size, char);
-
- /* Read the "k_name" array */
- fd_read(fd, (char*)(k_name), k_head->name_size);
-
-
- /* Allocate the "k_text" array */
- C_MAKE(k_text, k_head->text_size, char);
-
- /* Read the "k_text" array */
- fd_read(fd, (char*)(k_text), k_head->text_size);
-
+ /* Reduce sizes of the arrays */
+ z_realloc(&f_name, f_head->name_size);
+ z_realloc(&f_text, f_head->text_size);
/* Success */
return (0);
@@ -708,10 +434,6 @@ static errr init_k_info_raw(int fd)
*/
static errr init_k_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -740,47 +462,6 @@ static errr init_k_info(void)
k_head->info_size = k_head->info_num * k_head->info_len;
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "k_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_k_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'k_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "k_name" and "k_text" */
@@ -836,303 +517,14 @@ static errr init_k_info(void)
quit("Error in 'k_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(k_head), k_head->head_size);
-
- /* Dump the "k_info" array */
- fd_write(fd, (char*)(k_info), k_head->info_size);
-
- /* Dump the "k_name" array */
- fd_write(fd, (char*)(k_name), k_head->name_size);
-
- /* Dump the "k_text" array */
- fd_write(fd, (char*)(k_text), k_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "k_info" array */
- C_KILL(k_info, k_head->info_num, object_kind);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(k_name, fake_name_size, char);
- C_KILL(k_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'k_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_k_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'k_info.raw' file.");
-
- /* Success */
- return (0);
-}
-
-
-
-/*
- * Initialise the "a_info" array, by parsing a binary "image" file
- */
-static errr init_a_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != a_head->v_major) ||
- (test.v_minor != a_head->v_minor) ||
- (test.v_patch != a_head->v_patch) ||
- (test.v_extra != a_head->v_extra) ||
- (test.info_num != a_head->info_num) ||
- (test.info_len != a_head->info_len) ||
- (test.head_size != a_head->head_size) ||
- (test.info_size != a_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*a_head) = test;
-
-
- /* Allocate the "a_info" array */
- C_MAKE(a_info, a_head->info_num, artifact_type);
-
- /* Read the "a_info" array */
- fd_read(fd, (char*)(a_info), a_head->info_size);
-
-
- /* Allocate the "a_name" array */
- C_MAKE(a_name, a_head->name_size, char);
-
- /* Read the "a_name" array */
- fd_read(fd, (char*)(a_name), a_head->name_size);
-
-
- /* Allocate the "a_text" array */
- C_MAKE(a_text, a_head->text_size, char);
-
- /* Read the "a_text" array */
- fd_read(fd, (char*)(a_text), a_head->text_size);
-
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "s_info" array, by parsing a binary "image" file
- */
-static errr init_s_info_raw(int fd)
-{
- header test;
- /*int i;*/
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != s_head->v_major) ||
- (test.v_minor != s_head->v_minor) ||
- (test.v_patch != s_head->v_patch) ||
- (test.v_extra != s_head->v_extra) ||
- (test.info_num != s_head->info_num) ||
- (test.info_len != s_head->info_len) ||
- (test.head_size != s_head->head_size) ||
- (test.info_size != s_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*s_head) = test;
-
-
- /* Allocate the "s_info" array */
- C_MAKE(s_info, s_head->info_num, skill_type);
-
- /* Read the "s_info" array */
- fd_read(fd, (char*)(s_info), s_head->info_size);
-
-
- /* Allocate the "s_name" array */
- C_MAKE(s_name, s_head->name_size, char);
-
- /* Read the "s_name" array */
- fd_read(fd, (char*)(s_name), s_head->name_size);
-
-
- /* Allocate the "s_text" array */
- C_MAKE(s_text, s_head->text_size, char);
-
- /* Read the "s_text" array */
- fd_read(fd, (char*)(s_text), s_head->text_size);
-
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "ab_info" array, by parsing a binary "image" file
- */
-static errr init_ab_info_raw(int fd)
-{
- header test;
- /*int i;*/
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != ab_head->v_major) ||
- (test.v_minor != ab_head->v_minor) ||
- (test.v_patch != ab_head->v_patch) ||
- (test.v_extra != ab_head->v_extra) ||
- (test.info_num != ab_head->info_num) ||
- (test.info_len != ab_head->info_len) ||
- (test.head_size != ab_head->head_size) ||
- (test.info_size != ab_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*ab_head) = test;
-
-
- /* Allocate the "ab_info" array */
- C_MAKE(ab_info, ab_head->info_num, ability_type);
-
- /* Read the "ab_info" array */
- fd_read(fd, (char*)(ab_info), ab_head->info_size);
-
-
- /* Allocate the "ab_name" array */
- C_MAKE(ab_name, ab_head->name_size, char);
-
- /* Read the "ab_name" array */
- fd_read(fd, (char*)(ab_name), ab_head->name_size);
-
-
- /* Allocate the "ab_text" array */
- C_MAKE(ab_text, ab_head->text_size, char);
-
- /* Read the "ab_text" array */
- fd_read(fd, (char*)(ab_text), ab_head->text_size);
-
+ /* Reduce sizes of the arrays */
+ z_realloc(&k_name, k_head->name_size);
+ z_realloc(&k_text, k_head->text_size);
/* Success */
return (0);
}
-/*
- * Initialise the "set_info" array, by parsing a binary "image" file
- */
-static errr init_set_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != set_head->v_major) ||
- (test.v_minor != set_head->v_minor) ||
- (test.v_patch != set_head->v_patch) ||
- (test.v_extra != set_head->v_extra) ||
- (test.info_num != set_head->info_num) ||
- (test.info_len != set_head->info_len) ||
- (test.head_size != set_head->head_size) ||
- (test.info_size != set_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*set_head) = test;
-
-
- /* Allocate the "a_info" array */
- C_MAKE(set_info, set_head->info_num, set_type);
-
- /* Read the "a_info" array */
- fd_read(fd, (char*)(set_info), set_head->info_size);
-
-
- /* Allocate the "a_name" array */
- C_MAKE(set_name, set_head->name_size, char);
-
- /* Read the "a_name" array */
- fd_read(fd, (char*)(set_name), set_head->name_size);
-
-
- /* Allocate the "a_text" array */
- C_MAKE(set_text, set_head->text_size, char);
-
- /* Read the "a_text" array */
- fd_read(fd, (char*)(set_text), set_head->text_size);
-
- /* Success */
- return (0);
-}
/*
@@ -1143,10 +535,6 @@ static errr init_set_info_raw(int fd)
*/
static errr init_set_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -1175,47 +563,6 @@ static errr init_set_info(void)
set_head->info_size = set_head->info_num * set_head->info_len;
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "set_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "set_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_set_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'set_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "set_name" and "set_text" */
@@ -1271,88 +618,9 @@ static errr init_set_info(void)
quit("Error in 'set_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "set_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(set_head), set_head->head_size);
-
- /* Dump the "set_info" array */
- fd_write(fd, (char*)(set_info), set_head->info_size);
-
- /* Dump the "set_name" array */
- fd_write(fd, (char*)(set_name), set_head->name_size);
-
- /* Dump the "set_text" array */
- fd_write(fd, (char*)(set_text), set_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "set_info" array */
- C_KILL(set_info, set_head->info_num, set_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(set_name, fake_name_size, char);
- C_KILL(set_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "set_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot open 'set_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_set_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'set_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&set_name, set_head->name_size);
+ z_realloc(&set_text, set_head->text_size);
/* Success */
return (0);
@@ -1367,10 +635,6 @@ static errr init_set_info(void)
*/
static errr init_a_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -1399,47 +663,6 @@ static errr init_a_info(void)
a_head->info_size = a_head->info_num * a_head->info_len;
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "a_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_a_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'a_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "a_name" and "a_text" */
@@ -1495,88 +718,9 @@ static errr init_a_info(void)
quit("Error in 'a_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(a_head), a_head->head_size);
-
- /* Dump the "a_info" array */
- fd_write(fd, (char*)(a_info), a_head->info_size);
-
- /* Dump the "a_name" array */
- fd_write(fd, (char*)(a_name), a_head->name_size);
-
- /* Dump the "a_text" array */
- fd_write(fd, (char*)(a_text), a_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "a_info" array */
- C_KILL(a_info, a_head->info_num, artifact_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(a_name, fake_name_size, char);
- C_KILL(a_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot open 'a_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_a_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'a_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&a_name, a_head->name_size);
+ z_realloc(&a_text, a_head->text_size);
/* Success */
return (0);
@@ -1591,12 +735,6 @@ static errr init_a_info(void)
*/
static errr init_s_info(void)
{
- int fd;
-
- /* int i; */
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -1624,47 +762,6 @@ static errr init_s_info(void)
s_head->head_size = sizeof(header);
s_head->info_size = s_head->info_num * s_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "s_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "s_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_s_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 's_info.raw' file.");
- msg_print(NULL);
- }
-
/*** Make the fake arrays ***/
/* Fake the size of "a_name" and "a_text" */
@@ -1719,87 +816,9 @@ static errr init_s_info(void)
quit("Error in 's_info.txt' file.");
}
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "s_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(s_head), s_head->head_size);
-
- /* Dump the "s_info" array */
- fd_write(fd, (char*)(s_info), s_head->info_size);
-
- /* Dump the "s_name" array */
- fd_write(fd, (char*)(s_name), s_head->name_size);
-
- /* Dump the "s_text" array */
- fd_write(fd, (char*)(s_text), s_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "s_info" array */
- C_KILL(s_info, s_head->info_num, skill_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(s_name, fake_name_size, char);
- C_KILL(s_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "s_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot open 's_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_s_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 's_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&s_name, s_head->name_size);
+ z_realloc(&s_text, s_head->text_size);
/* Success */
return (0);
@@ -1813,12 +832,6 @@ static errr init_s_info(void)
*/
static errr init_ab_info(void)
{
- int fd;
-
- /* int i; */
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -1827,6 +840,7 @@ static errr init_ab_info(void)
char buf[1024];
+
/*** Make the "header" ***/
/* Allocate the "header" */
@@ -1846,47 +860,6 @@ static errr init_ab_info(void)
ab_head->head_size = sizeof(header);
ab_head->info_size = ab_head->info_num * ab_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ab_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "ab_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_ab_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'ab_info.raw' file.");
- msg_print(NULL);
- }
-
/*** Make the fake arrays ***/
/* Fake the size of "a_name" and "a_text" */
@@ -1941,141 +914,9 @@ static errr init_ab_info(void)
quit("Error in 'ab_info.txt' file.");
}
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ab_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(ab_head), ab_head->head_size);
-
- /* Dump the "ab_info" array */
- fd_write(fd, (char*)(ab_info), ab_head->info_size);
-
- /* Dump the "ab_name" array */
- fd_write(fd, (char*)(ab_name), ab_head->name_size);
-
- /* Dump the "ab_text" array */
- fd_write(fd, (char*)(ab_text), ab_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "ab_info" array */
- C_KILL(ab_info, ab_head->info_num, ability_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(ab_name, fake_name_size, char);
- C_KILL(ab_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ab_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot open 'ab_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_ab_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'ab_info.raw' file.");
-
- /* Success */
- return (0);
-}
-
-
-
-/*
- * Initialise the "e_info" array, by parsing a binary "image" file
- */
-static errr init_e_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != e_head->v_major) ||
- (test.v_minor != e_head->v_minor) ||
- (test.v_patch != e_head->v_patch) ||
- (test.v_extra != e_head->v_extra) ||
- (test.info_num != e_head->info_num) ||
- (test.info_len != e_head->info_len) ||
- (test.head_size != e_head->head_size) ||
- (test.info_size != e_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*e_head) = test;
-
-
- /* Allocate the "e_info" array */
- C_MAKE(e_info, e_head->info_num, ego_item_type);
-
- /* Read the "e_info" array */
- fd_read(fd, (char*)(e_info), e_head->info_size);
-
-
- /* Allocate the "e_name" array */
- C_MAKE(e_name, e_head->name_size, char);
-
- /* Read the "e_name" array */
- fd_read(fd, (char*)(e_name), e_head->name_size);
-
-
- /* Allocate the "e_text" array */
- C_MAKE(e_text, e_head->text_size, char);
-
- /* Read the "e_text" array */
- fd_read(fd, (char*)(e_text), e_head->text_size);
-
+ /* Reduce sizes of the arrays */
+ z_realloc(&ab_name, ab_head->name_size);
+ z_realloc(&ab_text, ab_head->text_size);
/* Success */
return (0);
@@ -2091,10 +932,6 @@ static errr init_e_info_raw(int fd)
*/
static errr init_e_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -2122,50 +959,6 @@ static errr init_e_info(void)
e_head->head_size = sizeof(header);
e_head->info_size = e_head->info_num * e_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "e_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_e_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'e_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "e_name" and "e_text" */
@@ -2221,127 +1014,9 @@ static errr init_e_info(void)
quit("Error in 'e_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(e_head), e_head->head_size);
-
- /* Dump the "e_info" array */
- fd_write(fd, (char*)(e_info), e_head->info_size);
-
- /* Dump the "e_name" array */
- fd_write(fd, (char*)(e_name), e_head->name_size);
-
- /* Dump the "e_text" array */
- fd_write(fd, (char*)(e_text), e_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "e_info" array */
- C_KILL(e_info, e_head->info_num, ego_item_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(e_name, fake_name_size, char);
- C_KILL(e_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'e_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_e_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'e_info.raw' file.");
-
- /* Success */
- return (0);
-}
-
-
-/*
- * Initialise the "ra_info" array, by parsing a binary "image" file
- */
-static errr init_ra_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != ra_head->v_major) ||
- (test.v_minor != ra_head->v_minor) ||
- (test.v_patch != ra_head->v_patch) ||
- (test.v_extra != ra_head->v_extra) ||
- (test.info_num != ra_head->info_num) ||
- (test.info_len != ra_head->info_len) ||
- (test.head_size != ra_head->head_size) ||
- (test.info_size != ra_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*ra_head) = test;
-
-
- /* Allocate the "ra_info" array */
- C_MAKE(ra_info, ra_head->info_num, randart_part_type);
-
- /* Read the "ra_info" array */
- fd_read(fd, (char*)(ra_info), ra_head->info_size);
- fd_read(fd, (char*)(ra_gen), 30 * sizeof (randart_gen_type));
+ /* Reduce sizes of the arrays */
+ z_realloc(&e_name, e_head->name_size);
+ z_realloc(&e_text, e_head->text_size);
/* Success */
return (0);
@@ -2357,10 +1032,6 @@ static errr init_ra_info_raw(int fd)
*/
static errr init_ra_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -2368,7 +1039,6 @@ static errr init_ra_info(void)
/* General buffer */
char buf[1024];
-
/*** Make the "header" ***/
/* Allocate the "header" */
@@ -2389,49 +1059,6 @@ static errr init_ra_info(void)
ra_head->info_size = ra_head->info_num * ra_head->info_len;
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ra_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "ra_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_ra_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'ra_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "ra_name" and "ra_text" */
@@ -2482,573 +1109,11 @@ static errr init_ra_info(void)
quit("Error in 'ra_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ra_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(ra_head), ra_head->head_size);
-
- /* Dump the "ra_info" array */
- fd_write(fd, (char*)(ra_info), ra_head->info_size);
- fd_write(fd, (char*)(ra_gen), 30 * sizeof (randart_gen_type));
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "ra_info" array */
- C_KILL(ra_info, ra_head->info_num, randart_part_type);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ra_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'ra_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_ra_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'ra_info.raw' file.");
-
- /* Success */
- return (0);
-}
-
-
-
-/*
- * Initialise the "r_info" array, by parsing a binary "image" file
- */
-static errr init_r_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != r_head->v_major) ||
- (test.v_minor != r_head->v_minor) ||
- (test.v_patch != r_head->v_patch) ||
- (test.v_extra != r_head->v_extra) ||
- (test.info_num != r_head->info_num) ||
- (test.info_len != r_head->info_len) ||
- (test.head_size != r_head->head_size) ||
- (test.info_size != r_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*r_head) = test;
-
-
- /* Allocate the "r_info" array */
- C_MAKE(r_info, r_head->info_num, monster_race);
-
- /* Read the "r_info" array */
- fd_read(fd, (char*)(r_info), r_head->info_size);
-
-
- /* Allocate the "r_name" array */
- C_MAKE(r_name, r_head->name_size, char);
-
- /* Read the "r_name" array */
- fd_read(fd, (char*)(r_name), r_head->name_size);
-
-
- /* Allocate the "r_text" array */
- C_MAKE(r_text, r_head->text_size, char);
-
- /* Read the "r_text" array */
- fd_read(fd, (char*)(r_text), r_head->text_size);
-
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "re_info" array, by parsing a binary "image" file
- */
-static errr init_re_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != re_head->v_major) ||
- (test.v_minor != re_head->v_minor) ||
- (test.v_patch != re_head->v_patch) ||
- (test.v_extra != re_head->v_extra) ||
- (test.info_num != re_head->info_num) ||
- (test.info_len != re_head->info_len) ||
- (test.head_size != re_head->head_size) ||
- (test.info_size != re_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*re_head) = test;
-
-
- /* Allocate the "re_info" array */
- C_MAKE(re_info, re_head->info_num, monster_ego);
-
- /* Read the "re_info" array */
- fd_read(fd, (char*)(re_info), re_head->info_size);
-
-
- /* Allocate the "re_name" array */
- C_MAKE(re_name, re_head->name_size, char);
-
- /* Read the "re_name" array */
- fd_read(fd, (char*)(re_name), re_head->name_size);
-
- /* Success */
- return (0);
-}
-
-
-/*
- * Initialise the "d_info" array, by parsing a binary "image" file
- */
-static errr init_d_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != d_head->v_major) ||
- (test.v_minor != d_head->v_minor) ||
- (test.v_patch != d_head->v_patch) ||
- (test.v_extra != d_head->v_extra) ||
- (test.info_num != d_head->info_num) ||
- (test.info_len != d_head->info_len) ||
- (test.head_size != d_head->head_size) ||
- (test.info_size != d_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*d_head) = test;
-
-
- /* Allocate the "d_info" array */
- C_MAKE(d_info, d_head->info_num, dungeon_info_type);
-
- /* Read the "d_info" array */
- fd_read(fd, (char*)(d_info), d_head->info_size);
-
-
- /* Allocate the "r_name" array */
- C_MAKE(d_name, d_head->name_size, char);
-
- /* Read the "d_name" array */
- fd_read(fd, (char*)(d_name), d_head->name_size);
-
- /* Allocate the "d_text" array */
- C_MAKE(d_text, d_head->text_size, char);
-
- /* Read the "d_text" array */
- fd_read(fd, (char*)(d_text), d_head->text_size);
-
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "st_info" array, by parsing a binary "image" file
- */
-static errr init_st_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != st_head->v_major) ||
- (test.v_minor != st_head->v_minor) ||
- (test.v_patch != st_head->v_patch) ||
- (test.v_extra != st_head->v_extra) ||
- (test.info_num != st_head->info_num) ||
- (test.info_len != st_head->info_len) ||
- (test.head_size != st_head->head_size) ||
- (test.info_size != st_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*st_head) = test;
-
-
- /* Allocate the "st_info" array */
- C_MAKE(st_info, st_head->info_num, store_info_type);
-
- /* Read the "st_info" array */
- fd_read(fd, (char*)(st_info), st_head->info_size);
-
-
- /* Allocate the "st_name" array */
- C_MAKE(st_name, st_head->name_size, char);
-
- /* Read the "st_name" array */
- fd_read(fd, (char*)(st_name), st_head->name_size);
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "ba_info" array, by parsing a binary "image" file
- */
-static errr init_ba_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != ba_head->v_major) ||
- (test.v_minor != ba_head->v_minor) ||
- (test.v_patch != ba_head->v_patch) ||
- (test.v_extra != ba_head->v_extra) ||
- (test.info_num != ba_head->info_num) ||
- (test.info_len != ba_head->info_len) ||
- (test.head_size != ba_head->head_size) ||
- (test.info_size != ba_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*ba_head) = test;
-
-
- /* Allocate the "ba_info" array */
- C_MAKE(ba_info, ba_head->info_num, store_action_type);
-
- /* Read the "ba_info" array */
- fd_read(fd, (char*)(ba_info), ba_head->info_size);
-
-
- /* Allocate the "ba_name" array */
- C_MAKE(ba_name, ba_head->name_size, char);
-
- /* Read the "ba_name" array */
- fd_read(fd, (char*)(ba_name), ba_head->name_size);
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "ow_info" array, by parsing a binary "image" file
- */
-static errr init_ow_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != ow_head->v_major) ||
- (test.v_minor != ow_head->v_minor) ||
- (test.v_patch != ow_head->v_patch) ||
- (test.v_extra != ow_head->v_extra) ||
- (test.info_num != ow_head->info_num) ||
- (test.info_len != ow_head->info_len) ||
- (test.head_size != ow_head->head_size) ||
- (test.info_size != ow_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*ow_head) = test;
-
-
- /* Allocate the "ow_info" array */
- C_MAKE(ow_info, ow_head->info_num, owner_type);
-
- /* Read the "ow_info" array */
- fd_read(fd, (char*)(ow_info), ow_head->info_size);
-
-
- /* Allocate the "ow_name" array */
- C_MAKE(ow_name, ow_head->name_size, char);
-
- /* Read the "ow_name" array */
- fd_read(fd, (char*)(ow_name), ow_head->name_size);
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "wf_info" array, by parsing a binary "image" file
- */
-static errr init_wf_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != wf_head->v_major) ||
- (test.v_minor != wf_head->v_minor) ||
- (test.v_patch != wf_head->v_patch) ||
- (test.v_extra != wf_head->v_extra) ||
- (test.info_num != wf_head->info_num) ||
- (test.info_len != wf_head->info_len) ||
- (test.head_size != wf_head->head_size) ||
- (test.info_size != wf_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*wf_head) = test;
-
-
- /* Allocate the "wf_info" array */
- C_MAKE(wf_info, wf_head->info_num, wilderness_type_info);
-
- /* Read the "wf_info" array */
- fd_read(fd, (char*)(wf_info), wf_head->info_size);
-
-
- /* Allocate the "wf_name" array */
- C_MAKE(wf_name, wf_head->name_size, char);
-
- /* Read the "wf_name" array */
- fd_read(fd, (char*)(wf_name), wf_head->name_size);
-
- /* Allocate the "wf_text" array */
- C_MAKE(wf_text, wf_head->text_size, char);
-
- /* Read the "wf_text" array */
- fd_read(fd, (char*)(wf_text), wf_head->text_size);
-
- /* Read the "wildc2i" array */
- fd_read(fd, (char*)wildc2i, 256 * sizeof(int));
-
/* Success */
return (0);
}
-/*
- * Initialise the "player" arrays, by parsing a binary "image" file
- */
-static errr init_player_info_raw(int fd)
-{
- header test;
- int i;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != rp_head->v_major) ||
- (test.v_minor != rp_head->v_minor) ||
- (test.v_patch != rp_head->v_patch) ||
- (test.v_extra != rp_head->v_extra) ||
- (test.info_num != rp_head->info_num) ||
- (test.info_len != rp_head->info_len) ||
- (test.head_size != rp_head->head_size) ||
- (test.info_size != rp_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*rp_head) = test;
-
-
- /* Allocate the "rp_info" array */
- C_MAKE(race_info, rp_head->info_num, player_race);
-
- /* Read the "rp_info" array */
- fd_read(fd, (char*)(race_info), rp_head->info_size);
-
-
- /* Allocate the "rp_name" array */
- C_MAKE(rp_name, rp_head->name_size, char);
-
- /* Read the "rp_name" array */
- fd_read(fd, (char*)(rp_name), rp_head->name_size);
-
- /* Allocate the "rp_text" array */
- C_MAKE(rp_text, rp_head->text_size, char);
-
- /* Read the "rp_text" array */
- fd_read(fd, (char*)(rp_text), rp_head->text_size);
-
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != rmp_head->v_major) ||
- (test.v_minor != rmp_head->v_minor) ||
- (test.v_patch != rmp_head->v_patch) ||
- (test.v_extra != rmp_head->v_extra) ||
- (test.info_num != rmp_head->info_num) ||
- (test.info_len != rmp_head->info_len) ||
- (test.head_size != rmp_head->head_size) ||
- (test.info_size != rmp_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*rmp_head) = test;
-
-
- /* Allocate the "rmp_info" array */
- C_MAKE(race_mod_info, rmp_head->info_num, player_race_mod);
-
- /* Read the "rmp_info" array */
- fd_read(fd, (char*)(race_mod_info), rmp_head->info_size);
-
-
- /* Allocate the "rmp_name" array */
- C_MAKE(rmp_name, rmp_head->name_size, char);
-
- /* Read the "rmp_name" array */
- fd_read(fd, (char*)(rmp_name), rmp_head->name_size);
-
- /* Allocate the "rmp_text" array */
- C_MAKE(rmp_text, rmp_head->text_size, char);
-
- /* Read the "rmp_text" array */
- fd_read(fd, (char*)(rmp_text), rmp_head->text_size);
-
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != c_head->v_major) ||
- (test.v_minor != c_head->v_minor) ||
- (test.v_patch != c_head->v_patch) ||
- (test.v_extra != c_head->v_extra) ||
- (test.info_num != c_head->info_num) ||
- (test.info_len != c_head->info_len) ||
- (test.head_size != c_head->head_size) ||
- (test.info_size != c_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*c_head) = test;
-
-
- /* Allocate the "c_info" array */
- C_MAKE(class_info, c_head->info_num, player_class);
-
- /* Read the "c_info" array */
- fd_read(fd, (char*)(class_info), c_head->info_size);
-
-
- /* Allocate the "c_name" array */
- C_MAKE(c_name, c_head->name_size, char);
-
- /* Read the "c_name" array */
- fd_read(fd, (char*)(c_name), c_head->name_size);
-
- /* Allocate the "c_text" array */
- C_MAKE(c_text, c_head->text_size, char);
-
- /* Read the "c_text" array */
- fd_read(fd, (char*)(c_text), c_head->text_size);
-
- /* Allocate the "bg" array */
- C_MAKE(bg, max_bg_idx, hist_type);
-
- /* Read the "bg" array */
- fd_read(fd, (char*)bg, max_bg_idx * sizeof(hist_type));
-
- /* Allocate the "meta_class" array */
- C_MAKE(meta_class_info, max_mc_idx, meta_class_type);
-
- /* Read the "meta_class" array */
- fd_read(fd, (char*)meta_class_info, max_mc_idx * sizeof(meta_class_type));
- for (i = 0; i < max_mc_idx; i++)
- {
- C_MAKE(meta_class_info[i].classes, max_c_idx, s16b);
- fd_read(fd, (char*)meta_class_info[i].classes, max_c_idx * sizeof(s16b));
- }
-
- /* Read the "gen skills" array */
- fd_read(fd, (char*)(gen_skill_base), MAX_SKILLS * sizeof(u32b));
- fd_read(fd, (char*)(gen_skill_mod), MAX_SKILLS * sizeof(s16b));
- fd_read(fd, (char*)(gen_skill_basem), MAX_SKILLS * sizeof(char));
- fd_read(fd, (char*)(gen_skill_modm), MAX_SKILLS * sizeof(char));
-
- /* Success */
- return (0);
-}
/*
* Initialise the "r_info" array
@@ -3058,10 +1123,6 @@ static errr init_player_info_raw(int fd)
*/
static errr init_r_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -3089,48 +1150,6 @@ static errr init_r_info(void)
r_head->head_size = sizeof(header);
r_head->info_size = r_head->info_num * r_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "r_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_r_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'r_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "r_name" and "r_text" */
@@ -3186,88 +1205,9 @@ static errr init_r_info(void)
quit("Error in 'r_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(r_head), r_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(r_info), r_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(r_name), r_head->name_size);
-
- /* Dump the "r_text" array */
- fd_write(fd, (char*)(r_text), r_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "r_info" array */
- C_KILL(r_info, r_head->info_num, monster_race);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(r_name, fake_name_size, char);
- C_KILL(r_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'r_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_r_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'r_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&r_name, r_head->name_size);
+ z_realloc(&r_text, r_head->text_size);
/* Success */
return (0);
@@ -3282,10 +1222,6 @@ static errr init_r_info(void)
*/
static errr init_re_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -3313,48 +1249,6 @@ static errr init_re_info(void)
re_head->head_size = sizeof(header);
re_head->info_size = re_head->info_num * re_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "re_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "re_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_re_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 're_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "re_name" */
@@ -3408,83 +1302,8 @@ static errr init_re_info(void)
quit("Error in 're_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "re_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(re_head), re_head->head_size);
-
- /* Dump the "re_info" array */
- fd_write(fd, (char*)(re_info), re_head->info_size);
-
- /* Dump the "re_name" array */
- fd_write(fd, (char*)(re_name), re_head->name_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "re_info" array */
- C_KILL(re_info, re_head->info_num, monster_ego);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(re_name, fake_name_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "re_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 're_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_re_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 're_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&re_name, re_head->name_size);
/* Success */
return (0);
@@ -3499,10 +1318,6 @@ static errr init_re_info(void)
*/
static errr init_d_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -3530,48 +1345,6 @@ static errr init_d_info(void)
d_head->head_size = sizeof(header);
d_head->info_size = d_head->info_num * d_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "d_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_d_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'd_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "d_name" and "d_text" */
@@ -3627,88 +1400,9 @@ static errr init_d_info(void)
quit("Error in 'd_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(d_head), d_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(d_info), d_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(d_name), d_head->name_size);
-
- /* Dump the "r_text" array */
- fd_write(fd, (char*)(d_text), d_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "d_info" array */
- C_KILL(d_info, d_head->info_num, dungeon_info_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(d_name, fake_name_size, char);
- C_KILL(d_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'd_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_d_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'd_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&d_name, d_head->name_size);
+ z_realloc(&d_text, d_head->text_size);
/* Success */
return (0);
@@ -3723,12 +1417,8 @@ static errr init_d_info(void)
*/
static errr init_player_info(void)
{
- int fd;
-
int i;
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -3794,48 +1484,6 @@ static errr init_player_info(void)
c_head->head_size = sizeof(header);
c_head->info_size = c_head->info_num * c_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "p_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "p_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_player_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'p_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "rp_name" and "rp_text" */
@@ -3868,14 +1516,9 @@ static errr init_player_info(void)
/* Allocate the "meta_class" array */
C_MAKE(meta_class_info, max_mc_idx, meta_class_type);
-
- /* Read the "meta_class" array */
- fd_read(fd, (char*)meta_class_info, max_mc_idx * sizeof(meta_class_type));
-
for (i = 0; i < max_mc_idx; i++)
{
C_MAKE(meta_class_info[i].classes, max_c_idx, s16b);
- fd_read(fd, (char*)meta_class_info[i].classes, max_c_idx * sizeof(s16b));
}
/*** Load the ascii template file ***/
@@ -3919,153 +1562,13 @@ static errr init_player_info(void)
quit("Error in 'p_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "p_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(rp_head), rp_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(race_info), rp_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(rp_name), rp_head->name_size);
-
- /* Dump the "r_text" array */
- fd_write(fd, (char*)(rp_text), rp_head->text_size);
-
- /* Dump it */
- fd_write(fd, (char*)(rmp_head), rmp_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(race_mod_info), rmp_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(rmp_name), rmp_head->name_size);
-
- /* Dump the "r_text" array */
- fd_write(fd, (char*)(rmp_text), rmp_head->text_size);
-
- /* Dump it */
- fd_write(fd, (char*)(c_head), c_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(class_info), c_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(c_name), c_head->name_size);
-
- /* Dump the "r_text" array */
- fd_write(fd, (char*)(c_text), c_head->text_size);
-
- /* Dump the "bg" array */
- fd_write(fd, (char*)bg, max_bg_idx * sizeof(hist_type));
-
- /* Dump the "meta_class" array */
- fd_write(fd, (char*)meta_class_info, max_mc_idx * sizeof(meta_class_type));
-
- for (i = 0; i < max_mc_idx; i++)
- {
- fd_write(fd, (char*)meta_class_info[i].classes, max_c_idx * sizeof(s16b));
- }
-
- /* Read the "gen skills" array */
- fd_write(fd, (char*)(gen_skill_base), MAX_SKILLS * sizeof(u32b));
- fd_write(fd, (char*)(gen_skill_mod), MAX_SKILLS * sizeof(s16b));
- fd_write(fd, (char*)(gen_skill_basem), MAX_SKILLS * sizeof(char));
- fd_write(fd, (char*)(gen_skill_modm), MAX_SKILLS * sizeof(char));
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "rp_info" array */
- C_KILL(race_info, rp_head->info_num, player_race);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(rp_name, fake_name_size, char);
- C_KILL(rp_text, fake_text_size, char);
-
- /* Free the "c_info" array */
- C_KILL(class_info, c_head->info_num, player_class);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(c_name, fake_name_size, char);
- C_KILL(c_text, fake_text_size, char);
-
- /* Free the "rp_info" array */
- C_KILL(race_mod_info, rmp_head->info_num, player_race_mod);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(rmp_name, fake_name_size, char);
- C_KILL(rmp_text, fake_text_size, char);
-
- /* Allocate the "rp_text" array */
- C_KILL(bg, max_bg_idx, hist_type);
-
- /* Free the "meta_class" array */
- for (i = 0; i < max_mc_idx; i++)
- {
- C_FREE(meta_class_info[i].classes, max_c_idx, s16b);
- }
- C_FREE(meta_class_info, max_mc_idx, meta_class_type);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "p_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'p_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_player_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'p_info.raw' file.");
+ /* Reallocate arrays. */
+ z_realloc(&rp_name, rp_head->name_size);
+ z_realloc(&rp_text, rp_head->text_size);
+ z_realloc(&rmp_name, rmp_head->name_size);
+ z_realloc(&rmp_text, rmp_head->text_size);
+ z_realloc(&c_name, c_head->name_size);
+ z_realloc(&c_text, c_head->text_size);
/* Success */
return (0);
@@ -4079,10 +1582,6 @@ static errr init_player_info(void)
*/
static errr init_st_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -4110,48 +1609,6 @@ static errr init_st_info(void)
st_head->head_size = sizeof(header);
st_head->info_size = st_head->info_num * st_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "st_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "st_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_st_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'st_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "st_name" and "st_text" */
@@ -4205,84 +1662,8 @@ static errr init_st_info(void)
quit("Error in 'st_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "st_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(st_head), st_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(st_info), st_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(st_name), st_head->name_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "st_info" array */
- C_KILL(st_info, st_head->info_num, store_info_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(st_name, fake_name_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "st_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'st_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_st_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'st_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&st_name, st_head->name_size);
/* Success */
return (0);
@@ -4296,10 +1677,6 @@ static errr init_st_info(void)
*/
static errr init_ow_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -4327,48 +1704,6 @@ static errr init_ow_info(void)
ow_head->head_size = sizeof(header);
ow_head->info_size = ow_head->info_num * ow_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ow_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "ow_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_ow_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'ow_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "ow_name" and "ow_text" */
@@ -4422,84 +1757,8 @@ static errr init_ow_info(void)
quit("Error in 'ow_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ow_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(ow_head), ow_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(ow_info), ow_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(ow_name), ow_head->name_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "ow_info" array */
- C_KILL(ow_info, ow_head->info_num, owner_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(ow_name, fake_name_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ow_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'ow_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_ow_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'ow_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&ow_name, ow_head->name_size);
/* Success */
return (0);
@@ -4513,10 +1772,6 @@ static errr init_ow_info(void)
*/
static errr init_ba_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -4544,48 +1799,6 @@ static errr init_ba_info(void)
ba_head->head_size = sizeof(header);
ba_head->info_size = ba_head->info_num * ba_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ba_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "ba_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_ba_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'ba_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "ba_name" and "ba_text" */
@@ -4639,84 +1852,8 @@ static errr init_ba_info(void)
quit("Error in 'ba_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ba_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(ba_head), ba_head->head_size);
-
- /* Dump the "r_info" array */
- fd_write(fd, (char*)(ba_info), ba_head->info_size);
-
- /* Dump the "r_name" array */
- fd_write(fd, (char*)(ba_name), ba_head->name_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "ba_info" array */
- C_KILL(ba_info, ba_head->info_num, store_action_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(ba_name, fake_name_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "ba_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'ba_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_ba_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'ba_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&ba_name, ba_head->name_size);
/* Success */
return (0);
@@ -4730,10 +1867,6 @@ static errr init_ba_info(void)
*/
static errr init_wf_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -4761,48 +1894,6 @@ static errr init_wf_info(void)
wf_head->head_size = sizeof(header);
wf_head->info_size = wf_head->info_num * wf_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "wf_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "wf_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_wf_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'wf_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Assume the size of "wf_name" and "wf_text" */
@@ -4858,147 +1949,14 @@ static errr init_wf_info(void)
quit("Error in 'wf_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "wf_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(wf_head), wf_head->head_size);
-
- /* Dump the "wf_info" array */
- fd_write(fd, (char*)(wf_info), wf_head->info_size);
-
- /* Dump the "wf_name" array */
- fd_write(fd, (char*)(wf_name), wf_head->name_size);
-
- /* Dump the "wf_text" array */
- fd_write(fd, (char*)(wf_text), wf_head->text_size);
-
- /* Dump the "wildc2i" array */
- fd_write(fd, (char*)(wildc2i), 256 * sizeof(int));
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "wf_info" array */
- C_KILL(wf_info, wf_head->info_num, wilderness_type_info);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(wf_name, fake_name_size, char);
- C_KILL(wf_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "wf_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'wf_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_wf_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'wf_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&wf_name, wf_head->name_size);
+ z_realloc(&wf_text, wf_head->text_size);
/* Success */
return (0);
}
-/*
- * Initialise the "t_info" array, by parsing a binary "image" file
- */
-static errr init_t_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != t_head->v_major) ||
- (test.v_minor != t_head->v_minor) ||
- (test.v_patch != t_head->v_patch) ||
- (test.v_extra != t_head->v_extra) ||
- (test.info_num != t_head->info_num) ||
- (test.info_len != t_head->info_len) ||
- (test.head_size != t_head->head_size) ||
- (test.info_size != t_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*t_head) = test;
-
-
- /* Allocate the "f_info" array */
- C_MAKE(t_info, t_head->info_num, trap_type);
-
- /* Read the "t_info" array */
- fd_read(fd, (char*)(t_info), t_head->info_size);
-
-
- /* Allocate the "t_name" array */
- C_MAKE(t_name, t_head->name_size, char);
-
- /* Read the "t_name" array */
- fd_read(fd, (char*)(t_name), t_head->name_size);
-
-
- /* Allocate the "t_text" array */
- C_MAKE(t_text, t_head->text_size, char);
-
- /* Read the "t_text" array */
- fd_read(fd, (char*)(t_text), t_head->text_size);
-
-
- /* Success */
- return (0);
-}
/*
* Initialise the "t_info" array
@@ -5008,10 +1966,6 @@ static errr init_t_info_raw(int fd)
*/
static errr init_t_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err = 0;
FILE *fp;
@@ -5039,46 +1993,6 @@ static errr init_t_info(void)
t_head->head_size = sizeof(header);
t_head->info_size = t_head->info_num * t_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "tr_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "tr_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_t_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'tr_info.raw' file.");
- msg_print(NULL);
- }
-
/*** Make the fake arrays ***/
/* Fake the size of "t_name" and "t_text" */
@@ -5134,138 +2048,14 @@ static errr init_t_info(void)
quit("Error in 'tr_info.txt' file.");
}
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "tr_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(t_head), t_head->head_size);
-
- /* Dump the "f_info" array */
- fd_write(fd, (char*)(t_info), t_head->info_size);
-
- /* Dump the "f_name" array */
- fd_write(fd, (char*)(t_name), t_head->name_size);
-
- /* Dump the "f_text" array */
- fd_write(fd, (char*)(t_text), t_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "h_info" array */
- C_KILL(t_info, t_head->info_num, trap_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(t_name, fake_name_size, char);
- C_KILL(t_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-#endif /* ALLOW_TEMPLATES */
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "tr_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'tr_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_t_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'tr_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&t_name, t_head->name_size);
+ z_realloc(&t_text, t_head->text_size);
/* Success */
return (0);
}
-/*
- * Initialise the "al_info" array, by parsing a binary "image" file
- */
-static errr init_al_info_raw(int fd)
-{
- header test;
- char *hack;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != al_head->v_major) ||
- (test.v_minor != al_head->v_minor) ||
- (test.v_patch != al_head->v_patch) ||
- (test.v_extra != al_head->v_extra) ||
- (test.info_num != al_head->info_num) ||
- (test.info_len != al_head->info_len) ||
- (test.head_size != al_head->head_size) ||
- (test.info_size != al_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
- /* Accept the header */
- (*al_head) = test;
-
- /* Allocate the "al_info" array */
- C_MAKE(alchemist_recipes, al_head->info_num, alchemist_recipe);
-
- /* Read the "al_info" array */
- fd_read(fd, (char*)(alchemist_recipes), al_head->info_size);
-
- /* Allocate the "al_name" array */
- C_MAKE(al_name, al_head->name_size, char );
-
- /* Read the "al_info" array */
- fd_read(fd, (char*)(al_name), al_head->name_size);
-
- /* Allocate the "al_text" array */
- C_MAKE(hack, al_head->text_size, char );
- a_select_flags = (artifact_select_flag *) hack;
-
- /* Read the "al_info" array */
- fd_read(fd, (char*)(a_select_flags), al_head->text_size);
-
- /* Success */
- return (0);
-}
/*
* Initialise the "al_info" array
@@ -5274,10 +2064,6 @@ static errr init_al_info_raw(int fd)
*/
errr init_al_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err;
FILE *fp;
@@ -5306,53 +2092,6 @@ errr init_al_info(void)
al_head->info_size = al_head->info_num * al_head->info_len;
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "al_info.raw");
-
-#if 0
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
-#else
-
-fd = -1;
-
-#endif
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "al_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_al_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'v_info.raw' file.");
- msg_print(NULL);
- }
fake_text_size = FAKE_TEXT_SIZE;
fake_name_size = FAKE_NAME_SIZE;
@@ -5416,143 +2155,8 @@ fd = -1;
quit("Error in 'al_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "al_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(al_head), al_head->head_size);
-
- /* Dump the "al_info" array */
- fd_write(fd, (char*)(alchemist_recipes), al_head->info_size);
-
- /* Dump the "al_name" array */
- fd_write(fd, (char*)(al_name), al_head->name_size);
-
- /* Dump the "al_info" array */
- fd_write(fd, (char*)(a_select_flags), al_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "al_info" array */
- C_KILL(alchemist_recipes, al_head->info_num, alchemist_recipe);
-
- /* Free the 'Fake' arrays */
- C_KILL(al_name, al_head->name_size, char);
- {
- char *hack = (char *) a_select_flags;
- C_KILL(hack, al_head->text_size, char);
- }
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "al_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'al_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_al_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'al_info.raw' file.");
-
- /* Success */
- return (0);
-}
-
-/*
- * Initialise the "v_info" array, by parsing a binary "image" file
- */
-static errr init_v_info_raw(int fd)
-{
- header test;
-
- /* Read and Verify the header */
- if (fd_read(fd, (char*)(&test), sizeof(header)) ||
- (test.v_major != v_head->v_major) ||
- (test.v_minor != v_head->v_minor) ||
- (test.v_patch != v_head->v_patch) ||
- (test.v_extra != v_head->v_extra) ||
- (test.info_num != v_head->info_num) ||
- (test.info_len != v_head->info_len) ||
- (test.head_size != v_head->head_size) ||
- (test.info_size != v_head->info_size))
- {
- /* Error */
- return ( -1);
- }
-
-
- /* Accept the header */
- (*v_head) = test;
-
-
- /* Allocate the "v_info" array */
- C_MAKE(v_info, v_head->info_num, vault_type);
-
- /* Read the "v_info" array */
- fd_read(fd, (char*)(v_info), v_head->info_size);
-
-
- /* Allocate the "v_name" array */
- C_MAKE(v_name, v_head->name_size, char);
-
- /* Read the "v_name" array */
- fd_read(fd, (char*)(v_name), v_head->name_size);
-
-
- /* Allocate the "v_text" array */
- C_MAKE(v_text, v_head->text_size, char);
-
- /* Read the "v_text" array */
- fd_read(fd, (char*)(v_text), v_head->text_size);
-
+ /* Reduce sizes of the arrays */
+ z_realloc(&al_name, al_head->name_size);
/* Success */
return (0);
@@ -5567,10 +2171,6 @@ static errr init_v_info_raw(int fd)
*/
errr init_v_info(void)
{
- int fd;
-
- int mode = FILE_MODE;
-
errr err;
FILE *fp;
@@ -5598,56 +2198,6 @@ errr init_v_info(void)
v_head->head_size = sizeof(header);
v_head->info_size = v_head->info_num * v_head->info_len;
-
-#ifdef ALLOW_TEMPLATES
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info.raw");
-
-#if 0
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
-#else
-
- fd = -1;
-
-#endif
-
- /* Process existing "raw" file */
- if (fd >= 0)
- {
-#ifdef CHECK_MODIFICATION_TIME
-
- err = check_modification_date(fd, "v_info.txt");
-
-#endif /* CHECK_MODIFICATION_TIME */
-
- /* Attempt to parse the "raw" file */
- if (!err)
- err = init_v_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Success */
- if (!err) return (0);
-
- /* Information */
- msg_print("Ignoring obsolete/defective 'v_info.raw' file.");
- msg_print(NULL);
- }
-
-
/*** Make the fake arrays ***/
/* Fake the size of "v_name" and "v_text" */
@@ -5703,88 +2253,9 @@ errr init_v_info(void)
quit("Error in 'v_info.txt' file.");
}
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Kill the old file */
- (void)fd_kill(buf);
-
- /* Attempt to create the raw file */
- fd = fd_make(buf, mode);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (char*)(v_head), v_head->head_size);
-
- /* Dump the "v_info" array */
- fd_write(fd, (char*)(v_info), v_head->info_size);
-
- /* Dump the "v_name" array */
- fd_write(fd, (char*)(v_name), v_head->name_size);
-
- /* Dump the "v_text" array */
- fd_write(fd, (char*)(v_text), v_head->text_size);
-
- /* Close */
- (void)fd_close(fd);
- }
-
-
- /*** Kill the fake arrays ***/
-
- /* Free the "v_info" array */
- C_KILL(v_info, v_head->info_num, vault_type);
-
- /* Hack -- Free the "fake" arrays */
- C_KILL(v_name, fake_name_size, char);
- C_KILL(v_text, fake_text_size, char);
-
- /* Forget the array sizes */
- fake_name_size = 0;
- fake_text_size = 0;
-
-#endif /* ALLOW_TEMPLATES */
-
-
- /*** Load the binary image file ***/
-
- /* Build the filename */
- path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info.raw");
-
- /* Grab permission */
- safe_setuid_grab();
-
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
-
- /* Drop permission */
- safe_setuid_drop();
-
- /* Process existing "raw" file */
- if (fd < 0) quit("Cannot load 'v_info.raw' file.");
-
- /* Attempt to parse the "raw" file */
- err = init_v_info_raw(fd);
-
- /* Close it */
- (void)fd_close(fd);
-
- /* Error */
- if (err) quit("Cannot parse 'v_info.raw' file.");
+ /* Reduce sizes of the arrays */
+ z_realloc(&v_name, v_head->name_size);
+ z_realloc(&v_text, v_head->text_size);
/* Success */
return (0);