summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2019-02-15 19:20:25 +0100
committerBardur Arantsson <bardur@scientician.net>2019-02-15 19:20:25 +0100
commit1d7bd3f3169d03fcb2f9f127f97bb78942523d79 (patch)
tree9bc2eb00cb27a3829c13a0a58d7e0418bbd32121
parent3eacc4f9835c697c50838b0f341355b5600d0256 (diff)
Simplify and combine the h-* headers
They were -- at best -- extremely dangerous to include separately because of order-dependence. There were also quite a few (apparent) workarounds for extremely old and non-standard systems.
-rw-r--r--src/birth.cc1
-rw-r--r--src/config.h34
-rw-r--r--src/dice.cc1
-rw-r--r--src/files.cc1
-rw-r--r--src/h-basic.h188
-rw-r--r--src/h-config.h84
-rw-r--r--src/h-define.h93
-rw-r--r--src/h-system.h88
-rw-r--r--src/h-type.h78
-rw-r--r--src/hiscore.cc1
-rw-r--r--src/init2.cc6
-rw-r--r--src/loadsave.cc1
-rw-r--r--src/main-gcu.cc1
-rw-r--r--src/main-x11.cc2
-rw-r--r--src/modules.cc3
-rw-r--r--src/monster3.hpp2
-rw-r--r--src/util.cc6
-rw-r--r--src/z-form.cc8
-rw-r--r--src/z-form.h2
19 files changed, 203 insertions, 397 deletions
diff --git a/src/birth.cc b/src/birth.cc
index 60df3113..9b3d83d9 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -61,6 +61,7 @@
#include <algorithm>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
+#include <fcntl.h>
#include <fmt/format.h>
#include <numeric>
#include <string>
diff --git a/src/config.h b/src/config.h
index 290ec624..eb7795b4 100644
--- a/src/config.h
+++ b/src/config.h
@@ -68,34 +68,6 @@
#define MONSTER_FLOW_DEPTH 32
-
-
-/*
- * OPTION: Set the "default" path to the angband "lib" directory.
- *
- * See "main.c" for usage, and note that this value is only used on
- * certain machines, primarily Unix machines. If this value is used,
- * it will be over-ridden by the "ANGBAND_PATH" environment variable,
- * if that variable is defined and accessable. The final slash is
- * optional, but it may eventually be required.
- *
- * Using the value "./lib/" below tells Angband that, by default,
- * the user will run "angband" from the same directory that contains
- * the "lib" directory. This is a reasonable (but imperfect) default.
- *
- * If at all possible, you should change this value to refer to the
- * actual location of the "lib" folder, for example, "/tmp/angband/lib/"
- * or "/usr/games/lib/angband/", or "/pkg/angband/lib".
- *
- * Additional note -- if you are planning to use makefile.org, don't bother
- * setting this variable, as it is overridden by a value set near the top of
- * that file.
- */
-#ifndef DEFAULT_PATH
-# define DEFAULT_PATH "./lib/"
-#endif
-
-
/*
* Where to put the user's files.
*/
@@ -103,12 +75,6 @@
/*
- * OPTION: Person to bother if something goes wrong.
- */
-#define MAINTAINER "darkgod@t-o-m-e.net"
-
-
-/*
* OPTION: Default font (when using X11).
*/
#define DEFAULT_X11_FONT "9x15"
diff --git a/src/dice.cc b/src/dice.cc
index 0e2f48e6..45f139b2 100644
--- a/src/dice.cc
+++ b/src/dice.cc
@@ -3,6 +3,7 @@
#include "z-rand.hpp"
#include <cassert>
+#include <cstring>
void dice_init(dice_type *dice, long base, long num, long sides)
{
diff --git a/src/files.cc b/src/files.cc
index 186cc9e4..a8d70694 100644
--- a/src/files.cc
+++ b/src/files.cc
@@ -63,6 +63,7 @@
#include <boost/algorithm/string.hpp>
#include <iostream>
+#include <fcntl.h>
#include <fmt/format.h>
#include <fstream>
#include <limits>
diff --git a/src/h-basic.h b/src/h-basic.h
index a65780a5..7811867c 100644
--- a/src/h-basic.h
+++ b/src/h-basic.h
@@ -5,22 +5,190 @@ extern "C" {
#endif
/*
- * The most basic "include" file.
+ * Choose the hardware, operating system, and compiler.
+ * Also, choose various "system level" compilation options.
+ * A lot of these definitions take effect in "h-system.h"
*
- * This file simply includes other low level header files.
+ * Note that you may find it simpler to define some of these
+ * options in the "Makefile", especially any options describing
+ * what "system" is being used.
+ */
+
+/*
+ * Extract the "WINDOWS" flag from the compiler
+ */
+#if defined(_Windows) || defined(__WINDOWS__) || \
+ defined(__WIN32__) || defined(WIN32) || \
+ defined(__WINNT__) || defined(__NT__)
+# ifndef WINDOWS
+# define WINDOWS
+# endif
+#endif
+
+
+
+/*
+ * OPTION: Define "L64" if a "long" is 64-bits. See "h-types.h".
+ * The only such platform that angband is ported to is currently
+ * DEC Alpha AXP running OSF/1 (OpenVMS uses 32-bit longs).
+ */
+#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__ia64) || defined(__ia64__) || defined(__mips64) || defined(__ppc64__) || defined(__PPC64__) || defined(__powerpc64__) || defined(__64BIT__) || defined(__sparc64__) || defined(__LP64__)
+# define L64
+#endif
+
+
+
+/*
+ * OPTION: set "SET_UID" if the machine is a "multi-user" machine.
+ * This option is used to verify the use of "uids" and "gids" for
+ * various "Unix" calls, and of "pids" for getting a random seed,
+ * and of the "umask()" call for various reasons, and to guess if
+ * the "kill()" function is available, and for permission to use
+ * functions to extract user names and expand "tildes" in filenames.
+ * Basically, SET_UID should *only* be set for "Unix" machines.
+ */
+#if !defined(WINDOWS)
+# define SET_UID
+#endif
+
+
+/*
+ * Every system seems to use its own symbol as a path separator.
+ * Default to the standard Unix slash, but attempt to change this
+ * for various other systems. Note that any system that uses the
+ * "period" as a separator (i.e. ACORN) will have to pretend that
+ * it uses the slash, and do its own mapping of period <-> slash.
+ */
+#undef PATH_SEP
+#define PATH_SEP "/"
+#if defined(WINDOWS) || defined(WINNT)
+# undef PATH_SEP
+# define PATH_SEP "\\"
+#endif
+
+
+
+/*
+ * Basic "types".
+ *
+ * Note the attempt to make all basic types have 4 letters.
+ * This improves readibility and standardizes the code.
+ *
+ * Likewise, all complex types are at least 4 letters.
+ * Thus, almost every three letter word is a legal variable.
+ * But beware of certain reserved words ('for' and 'if' and 'do').
+ *
+ * Note that the type used in structures for bit flags should be unsigned int.
+ * As long as these bit flags are sequential, they will be space smart.
+ *
+ * Note that on some machines, apparently "signed char" is illegal.
+ *
+ * It must be true that char/byte takes exactly 1 byte
+ * It must be true that sind/uind takes exactly 2 bytes
+ * It must be true that sbig/ubig takes exactly 4 bytes
+ *
+ * On Sparc's, a sint takes 4 bytes (2 is legal)
+ * On Sparc's, a long takes 4 bytes (8 is legal)
+ * On Sparc's, a real takes 8 bytes (4 is legal)
+ *
+ * Note that some files have already been included by "h-include.h"
+ * These include <stdio.h> and <sys/types>, which define some types
*/
-/* System Configuration */
-#include "h-config.h"
-/* System includes/externs */
-#include "h-system.h"
+/* Error codes for function return values */
+/* Success = 0, Failure = -N, Problem = +N */
+typedef int errr;
-/* Basic types */
-#include "h-type.h"
-/* Basic constants and macros */
-#include "h-define.h"
+/* Note that unsigned values can cause math problems */
+/* An unsigned byte of memory */
+typedef unsigned char byte;
+
+/* Note that a bool is smaller than a full "int" */
+/* Simple True/False type */
+typedef char bool_;
+
+
+/* Signed/Unsigned 16 bit value */
+typedef signed short s16b;
+typedef unsigned short u16b;
+#define FMTs16b "%hd"
+#define FMTu16b "%hu"
+
+/* Signed/Unsigned 32 bit value */
+#ifdef L64 /* 64 bit longs */
+typedef signed int s32b;
+typedef unsigned int u32b;
+#define FMTs32b "%d"
+#define FMTu32b "%u"
+#else
+typedef signed long s32b;
+typedef unsigned long u32b;
+#define FMTs32b "%ld"
+#define FMTu32b "%lu"
+#endif
+
+
+
+/*
+ * Hack -- Define NULL
+ */
+#ifndef NULL
+# ifdef __STDC__
+# define NULL ((void*)0)
+# else
+# define NULL ((char*)0)
+# endif /* __STDC__ */
+#endif /* NULL */
+
+
+/*
+ * The constants "TRUE" and "FALSE"
+ */
+
+#undef TRUE
+#define TRUE 1
+
+#undef FALSE
+#define FALSE 0
+
+
+
+
+/**** Simple "Macros" ****/
+
+/*
+ * Non-typed minimum value macro
+ */
+#undef MIN
+#define MIN(a,b) (((a) > (b)) ? (b) : (a))
+
+/*
+ * Non-typed maximum value macro
+ */
+#undef MAX
+#define MAX(a,b) (((a) < (b)) ? (b) : (a))
+
+/*
+ * Non-typed absolute value macro
+ */
+#undef ABS
+#define ABS(a) (((a) < 0) ? (-(a)) : (a))
+
+
+/*
+ * Note that all "index" values must be "lowercase letters", while
+ * all "digits" must be "digits". Control characters can be made
+ * from any legal characters. XXX XXX XXX
+ */
+#define A2I(X) ((X) - 'a')
+#define I2A(X) ((X) + 'a')
+#define I2C(X) (static_cast<char>(I2A(X)))
+#define D2I(X) ((X) - '0')
+#define I2D(X) ((X) + '0')
+#define KTRL(X) ((X) & 0x1F)
+#define ESCAPE '\033'
#ifdef __cplusplus
} // extern "C"
diff --git a/src/h-config.h b/src/h-config.h
deleted file mode 100644
index 09e9bac8..00000000
--- a/src/h-config.h
+++ /dev/null
@@ -1,84 +0,0 @@
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Choose the hardware, operating system, and compiler.
- * Also, choose various "system level" compilation options.
- * A lot of these definitions take effect in "h-system.h"
- *
- * Note that you may find it simpler to define some of these
- * options in the "Makefile", especially any options describing
- * what "system" is being used.
- */
-
-
-/*
- * no system definitions are needed for 4.3BSD, SUN OS, DG/UX
- */
-
-/*
- * OPTION: Compile on Windows (automatic)
- */
-#ifndef WINDOWS
-/* #define WINDOWS */
-#endif
-
-
-/*
- * Extract the "WINDOWS" flag from the compiler
- */
-#if defined(_Windows) || defined(__WINDOWS__) || \
- defined(__WIN32__) || defined(WIN32) || \
- defined(__WINNT__) || defined(__NT__)
-# ifndef WINDOWS
-# define WINDOWS
-# endif
-#endif
-
-
-
-/*
- * OPTION: Define "L64" if a "long" is 64-bits. See "h-types.h".
- * The only such platform that angband is ported to is currently
- * DEC Alpha AXP running OSF/1 (OpenVMS uses 32-bit longs).
- */
-#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__ia64) || defined(__ia64__) || defined(__mips64) || defined(__ppc64__) || defined(__PPC64__) || defined(__powerpc64__) || defined(__64BIT__) || defined(__sparc64__) || defined(__LP64__)
-# define L64
-#endif
-
-
-
-/*
- * OPTION: set "SET_UID" if the machine is a "multi-user" machine.
- * This option is used to verify the use of "uids" and "gids" for
- * various "Unix" calls, and of "pids" for getting a random seed,
- * and of the "umask()" call for various reasons, and to guess if
- * the "kill()" function is available, and for permission to use
- * functions to extract user names and expand "tildes" in filenames.
- * Basically, SET_UID should *only* be set for "Unix" machines.
- */
-#if !defined(WINDOWS)
-# define SET_UID
-#endif
-
-
-/*
- * Every system seems to use its own symbol as a path separator.
- * Default to the standard Unix slash, but attempt to change this
- * for various other systems. Note that any system that uses the
- * "period" as a separator (i.e. ACORN) will have to pretend that
- * it uses the slash, and do its own mapping of period <-> slash.
- */
-#undef PATH_SEP
-#define PATH_SEP "/"
-#if defined(WINDOWS) || defined(WINNT)
-# undef PATH_SEP
-# define PATH_SEP "\\"
-#endif
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
diff --git a/src/h-define.h b/src/h-define.h
deleted file mode 100644
index f3d5b76a..00000000
--- a/src/h-define.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* File: h-define.h */
-
-#ifndef INCLUDED_H_DEFINE_H
-#define INCLUDED_H_DEFINE_H
-
-/*
- * Define some simple constants
- */
-
-
-/*
- * Hack -- Define NULL
- */
-#ifndef NULL
-# ifdef __STDC__
-# define NULL ((void*)0)
-# else
-# define NULL ((char*)0)
-# endif /* __STDC__ */
-#endif /* NULL */
-
-
-/*
- * Hack -- force definitions -- see fd_seek()
- */
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-#ifndef SEEK_CUR
-# define SEEK_CUR 1
-#endif
-#ifndef SEEK_END
-# define SEEK_END 2
-#endif
-
-
-/*
- * The constants "TRUE" and "FALSE"
- */
-
-#undef TRUE
-#define TRUE 1
-
-#undef FALSE
-#define FALSE 0
-
-
-
-
-/**** Simple "Macros" ****/
-
-/*
- * Force a character to lowercase/uppercase
- */
-#define FORCELOWER(A) ((isupper((A))) ? tolower((A)) : (A))
-#define FORCEUPPER(A) ((islower((A))) ? toupper((A)) : (A))
-
-
-/*
- * Non-typed minimum value macro
- */
-#undef MIN
-#define MIN(a,b) (((a) > (b)) ? (b) : (a))
-
-/*
- * Non-typed maximum value macro
- */
-#undef MAX
-#define MAX(a,b) (((a) < (b)) ? (b) : (a))
-
-/*
- * Non-typed absolute value macro
- */
-#undef ABS
-#define ABS(a) (((a) < 0) ? (-(a)) : (a))
-
-
-/*
- * Note that all "index" values must be "lowercase letters", while
- * all "digits" must be "digits". Control characters can be made
- * from any legal characters. XXX XXX XXX
- */
-#define A2I(X) ((X) - 'a')
-#define I2A(X) ((X) + 'a')
-#define I2C(X) (static_cast<char>(I2A(X)))
-#define D2I(X) ((X) - '0')
-#define I2D(X) ((X) + '0')
-#define KTRL(X) ((X) & 0x1F)
-#define ESCAPE '\033'
-
-
-#endif
-
diff --git a/src/h-system.h b/src/h-system.h
deleted file mode 100644
index be576a6b..00000000
--- a/src/h-system.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* File: h-system.h */
-
-#ifndef INCLUDED_H_SYSTEM_H
-#define INCLUDED_H_SYSTEM_H
-
-/*
- * Include the basic "system" files.
- *
- * Make sure all "system" constants/macros are defined.
- * Make sure all "system" functions have "extern" declarations.
- *
- * This file is a big hack to make other files less of a hack.
- * This file has been rebuilt -- it may need a little more work.
- */
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include <stdlib.h>
-
-
-#ifdef SET_UID
-
-# include <sys/types.h>
-
-# if defined(linux)
-# include <sys/time.h>
-# endif
-
-#endif
-
-
-#include <time.h>
-
-
-
-#if defined(WINDOWS)
-# include <io.h>
-#endif
-
-#include <memory.h>
-
-
-# include <fcntl.h>
-
-
-#ifdef SET_UID
-
-# include <sys/param.h>
-# include <sys/file.h>
-
-# ifdef linux
-# include <sys/file.h>
-# endif
-
-# include <pwd.h>
-
-# include <unistd.h>
-
-# include <sys/stat.h>
-
-
-#endif
-
-#ifdef SET_UID
-
-# include <strings.h>
-
-#else
-
-# include <string.h>
-
-#endif
-
-
-
-
-#include <stdarg.h>
-
-
-#endif
-
-/* There was a bug introduced in 10.4.11; working around it */
-#ifdef __APPLE__
-#define GETLOGIN_BROKEN
-#endif
diff --git a/src/h-type.h b/src/h-type.h
deleted file mode 100644
index 6c62301b..00000000
--- a/src/h-type.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* File: h-type.h */
-
-#ifndef INCLUDED_H_TYPE_H
-#define INCLUDED_H_TYPE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*
- * Basic "types".
- *
- * Note the attempt to make all basic types have 4 letters.
- * This improves readibility and standardizes the code.
- *
- * Likewise, all complex types are at least 4 letters.
- * Thus, almost every three letter word is a legal variable.
- * But beware of certain reserved words ('for' and 'if' and 'do').
- *
- * Note that the type used in structures for bit flags should be unsigned int.
- * As long as these bit flags are sequential, they will be space smart.
- *
- * Note that on some machines, apparently "signed char" is illegal.
- *
- * It must be true that char/byte takes exactly 1 byte
- * It must be true that sind/uind takes exactly 2 bytes
- * It must be true that sbig/ubig takes exactly 4 bytes
- *
- * On Sparc's, a sint takes 4 bytes (2 is legal)
- * On Sparc's, a long takes 4 bytes (8 is legal)
- * On Sparc's, a real takes 8 bytes (4 is legal)
- *
- * Note that some files have already been included by "h-include.h"
- * These include <stdio.h> and <sys/types>, which define some types
- */
-
-
-/* Error codes for function return values */
-/* Success = 0, Failure = -N, Problem = +N */
-typedef int errr;
-
-
-/* Note that unsigned values can cause math problems */
-/* An unsigned byte of memory */
-typedef unsigned char byte;
-
-/* Note that a bool is smaller than a full "int" */
-/* Simple True/False type */
-typedef char bool_;
-
-
-/* Signed/Unsigned 16 bit value */
-typedef signed short s16b;
-typedef unsigned short u16b;
-#define FMTs16b "%hd"
-#define FMTu16b "%hu"
-
-/* Signed/Unsigned 32 bit value */
-#ifdef L64 /* 64 bit longs */
-typedef signed int s32b;
-typedef unsigned int u32b;
-#define FMTs32b "%d"
-#define FMTu32b "%u"
-#else
-typedef signed long s32b;
-typedef unsigned long u32b;
-#define FMTs32b "%ld"
-#define FMTu32b "%lu"
-#endif
-
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif
-
diff --git a/src/hiscore.cc b/src/hiscore.cc
index d4e54a33..acbbbe28 100644
--- a/src/hiscore.cc
+++ b/src/hiscore.cc
@@ -3,6 +3,7 @@
#include "util.hpp"
#include <cassert>
+#include <cstring>
int highscore_seek(int highscore_fd, int i)
{
diff --git a/src/init2.cc b/src/init2.cc
index ab1bd00a..240b8f49 100644
--- a/src/init2.cc
+++ b/src/init2.cc
@@ -59,6 +59,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include <cassert>
+#include <fcntl.h>
#include <fmt/format.h>
#include <type_traits>
@@ -673,11 +674,6 @@ static errr init_other()
g.insert({ "life", level_generate_life });
}
- /*** Pre-allocate space for the "format()" buffer ***/
-
- /* Hack -- Just call the "format()" function */
- format("%s (%s).", "Dark God <darkgod@t-o-m-e.net>", MAINTAINER);
-
/* Success */
return (0);
}
diff --git a/src/loadsave.cc b/src/loadsave.cc
index 4db24ca7..1b08a075 100644
--- a/src/loadsave.cc
+++ b/src/loadsave.cc
@@ -41,6 +41,7 @@
#include <boost/filesystem.hpp>
#include <cassert>
+#include <fcntl.h>
#include <fmt/format.h>
#include <memory>
diff --git a/src/main-gcu.cc b/src/main-gcu.cc
index 885e2f3f..bdcd15f0 100644
--- a/src/main-gcu.cc
+++ b/src/main-gcu.cc
@@ -43,6 +43,7 @@
#include "variable.h"
#include "z-util.h"
+#include <fcntl.h>
#include <boost/algorithm/string/predicate.hpp>
#include <limits.h>
diff --git a/src/main-x11.cc b/src/main-x11.cc
index 9ac920bc..e847a4a6 100644
--- a/src/main-x11.cc
+++ b/src/main-x11.cc
@@ -121,6 +121,8 @@
using boost::algorithm::equals;
using boost::algorithm::starts_with;
+#define FORCELOWER(A) ((isupper((A))) ? tolower((A)) : (A))
+
/*
* This file is designed to be "included" by "main-x11.c" or "main-xaw.c",
* which will have already "included" several relevant header files.
diff --git a/src/modules.cc b/src/modules.cc
index c8d1d100..ff6fad4e 100644
--- a/src/modules.cc
+++ b/src/modules.cc
@@ -43,7 +43,10 @@
#include <boost/algorithm/string/predicate.hpp>
#include <cassert>
#include <chrono>
+#include <fcntl.h>
+#include <sys/stat.h>
#include <thread>
+#include <unistd.h>
using boost::algorithm::equals;
using std::this_thread::sleep_for;
diff --git a/src/monster3.hpp b/src/monster3.hpp
index 2d4b2073..d462e0a5 100644
--- a/src/monster3.hpp
+++ b/src/monster3.hpp
@@ -3,6 +3,8 @@
#include "h-basic.h"
#include "monster_type_fwd.hpp"
+#include <cstdio>
+
void dump_companions(FILE *outfile);
void do_cmd_companion();
bool do_control_reconnect();
diff --git a/src/util.cc b/src/util.cc
index b187b41b..2b9f1a3e 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -28,9 +28,15 @@
#include <boost/algorithm/string/predicate.hpp>
#include <chrono>
+#include <cstdio>
+#include <fcntl.h>
#include <sstream>
#include <thread>
+#ifdef SET_UID
+#include <pwd.h>
+#endif
+
using boost::algorithm::iequals;
using boost::algorithm::equals;
using boost::algorithm::starts_with;
diff --git a/src/z-form.cc b/src/z-form.cc
index faaa2917..01b9642e 100644
--- a/src/z-form.cc
+++ b/src/z-form.cc
@@ -1,13 +1,11 @@
-/* File: z-form.c */
-
-/* Purpose: Low level text formatting -BEN- */
-
#include "z-form.h"
#include "z-util.h"
#include "z-util.hpp"
-#include <stdlib.h>
+#include <cctype>
+#include <cstdlib>
+#include <cstdio>
/*
* Here is some information about the routines in this file.
diff --git a/src/z-form.h b/src/z-form.h
index ee2b1832..647a51a1 100644
--- a/src/z-form.h
+++ b/src/z-form.h
@@ -2,6 +2,8 @@
#include "h-basic.h"
+#include <cstdarg>
+
#ifdef __cplusplus
extern "C" {
#endif