summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c389
1 files changed, 36 insertions, 353 deletions
diff --git a/src/main.c b/src/main.c
index 48ab3f04..680e5c5a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,7 +8,14 @@
* are included in all such copies.
*/
-#include "angband.h"
+#include "birth.h"
+#include "dungeon.h"
+#include "files.h"
+#include "init2.h"
+#include "modules.h"
+#include "script.h"
+#include "util.h"
+#include "variable.h"
@@ -18,7 +25,7 @@
*/
-#if !defined(MACINTOSH) && !defined(WINDOWS)
+#if !defined(WINDOWS)
/*
@@ -44,51 +51,11 @@ static void quit_hook(cptr s)
/*
- * Check and create if needed the directory dirpath
- */
-bool_ private_check_user_directory(cptr dirpath)
-{
- /* Is this used anywhere else in *bands? */
- struct stat stat_buf;
-
- int ret;
-
- /* See if it already exists */
- ret = stat(dirpath, &stat_buf);
-
- /* It does */
- if (ret == 0)
- {
- /* Now we see if it's a directory */
- if ((stat_buf.st_mode & S_IFMT) == S_IFDIR) return (TRUE);
-
- /*
- * Something prevents us from create a directory with
- * the same pathname
- */
- return (FALSE);
- }
-
- /* No - this maybe the first time. Try to create a directory */
- else
- {
- /* Create the ~/.ToME directory */
- ret = mkdir(dirpath, 0700);
-
- /* An error occured */
- if (ret == -1) return (FALSE);
-
- /* Success */
- return (TRUE);
- }
-}
-
-/*
* Check existence of ".ToME/" directory in the user's
* home directory or try to create it if it doesn't exist.
* Returns FALSE if all the attempts fail.
*/
-static bool_ check_create_user_dir(void)
+static void init_save_dir(void)
{
char dirpath[1024];
char versionpath[1024];
@@ -101,139 +68,34 @@ static bool_ check_create_user_dir(void)
strcpy(savepath, versionpath);
strcat(savepath, "/save");
- return private_check_user_directory(dirpath) && private_check_user_directory(versionpath) && private_check_user_directory(savepath);
-}
-
-
-/*
- * Initialize and verify the file paths, and the score file.
- *
- * Use the ANGBAND_PATH environment var if possible, else use
- * DEFAULT_PATH, and in either case, branch off appropriately.
- *
- * First, we'll look for the ANGBAND_PATH environment variable,
- * and then look for the files in there. If that doesn't work,
- * we'll try the DEFAULT_PATH constant. So be sure that one of
- * these two things works...
- *
- * We must ensure that the path ends with "PATH_SEP" if needed,
- * since the "init_file_paths()" function will simply append the
- * relevant "sub-directory names" to the given path.
- */
-static void init_stuff(void)
-{
- char path[1024];
-
- cptr tail;
-
- /* Get the environment variable */
- tail = getenv("TOME_PATH");
-
- /* Use the angband_path, or a default */
- strcpy(path, tail ? tail : DEFAULT_PATH);
+ if (!private_check_user_directory(dirpath))
+ {
+ quit_fmt("Cannot create directory '%s'", dirpath);
+ }
- /* Hack -- Add a path separator (only if needed) */
- if (!suffix(path, PATH_SEP)) strcat(path, PATH_SEP);
+ if (!private_check_user_directory(versionpath))
+ {
+ quit_fmt("Cannot create directory '%s'", versionpath);
+ }
- /* Initialize */
- init_file_paths(path);
+ if (!private_check_user_directory(savepath))
+ {
+ quit_fmt("Cannot create directory '%s'", savepath);
+ }
}
-
-/*
- * Handle a "-d<what>=<path>" option
- *
- * The "<what>" can be any string starting with the same letter as the
- * name of a subdirectory of the "lib" folder (i.e. "i" or "info").
- *
- * The "<path>" can be any legal path for the given system, and should
- * not end in any special path separator (i.e. "/tmp" or "~/.ang-info").
- */
-static void change_path(cptr info)
+static void init_player_name()
{
- cptr s;
-
- /* Find equal sign */
- s = strchr(info, '=');
-
- /* Verify equal sign */
- if (!s) quit_fmt("Try '-d<what>=<path>' not '-d%s'", info);
-
- /* Analyze */
- switch (tolower(info[0]))
- {
- case 'a':
- {
- string_free(ANGBAND_DIR_APEX);
- ANGBAND_DIR_APEX = string_make(s + 1);
- break;
- }
-
- case 'f':
- {
- string_free(ANGBAND_DIR_FILE);
- ANGBAND_DIR_FILE = string_make(s + 1);
- break;
- }
-
- case 'h':
- {
- string_free(ANGBAND_DIR_HELP);
- ANGBAND_DIR_HELP = string_make(s + 1);
- break;
- }
-
- case 'i':
- {
- string_free(ANGBAND_DIR_INFO);
- ANGBAND_DIR_INFO = string_make(s + 1);
- break;
- }
-
- case 'u':
- {
- string_free(ANGBAND_DIR_USER);
- ANGBAND_DIR_USER = string_make(s + 1);
- break;
- }
-
- case 'x':
- {
- string_free(ANGBAND_DIR_XTRA);
- ANGBAND_DIR_XTRA = string_make(s + 1);
- break;
- }
-
- case 'd':
- {
- string_free(ANGBAND_DIR_DATA);
- ANGBAND_DIR_DATA = string_make(s + 1);
- break;
- }
-
- case 'e':
- {
- string_free(ANGBAND_DIR_EDIT);
- ANGBAND_DIR_EDIT = string_make(s + 1);
- break;
- }
-
- case 's':
- {
- string_free(ANGBAND_DIR_SAVE);
- ANGBAND_DIR_SAVE = string_make(s + 1);
- break;
- }
+ /* Get the user id (?) */
+ int player_uid = getuid();
- default:
- {
- quit_fmt("Bad semantics in '-d%s'", info);
- }
- }
+ /* Acquire the "user name" as a default player name */
+ user_name(player_name, player_uid);
}
+
/*
* Simple "main" function for multiple platforms.
*
@@ -249,51 +111,18 @@ int main(int argc, char *argv[])
bool_ new_game = FALSE;
- int show_score = 0;
-
cptr mstr = NULL;
bool_ args = TRUE;
-#ifdef CHECK_MEMORY_LEAKS
- GC_find_leak = 1;
-#endif /* CHECK_MEMORY_LEAKS */
-
-
- /* Save the "program name" XXX XXX XXX */
- argv0 = argv[0];
-
-
- /* Default permissions on files */
- (void)umask(022);
-
-
/* Get the file paths */
- init_stuff();
-
-
- /* Get the user id (?) */
- player_uid = getuid();
-
- /* Acquire the "user name" as a default player name */
- user_name(player_name, player_uid);
-
-
- /*
- * On multiuser systems, users' private directories are
- * used to store pref files, chardumps etc.
- */
- {
- bool_ ret;
-
- /* Create a directory for the user's files */
- ret = check_create_user_dir();
-
- /* Oops */
- if (ret == FALSE) quit("Cannot create directory " PRIVATE_USER_PATH);
- }
+ init_file_paths_with_env();
+ /* Initialize the player name */
+ init_player_name();
+ /* Make sure save directory exists */
+ init_save_dir();
/* Process the command line arguments */
@@ -312,13 +141,6 @@ int main(int argc, char *argv[])
break;
}
- case 'F':
- case 'f':
- {
- arg_fiddle = TRUE;
- break;
- }
-
case 'W':
case 'w':
{
@@ -326,20 +148,6 @@ int main(int argc, char *argv[])
break;
}
- case 'V':
- case 'v':
- {
- arg_sound = TRUE;
- break;
- }
-
- case 'G':
- case 'g':
- {
- arg_graphics = TRUE;
- break;
- }
-
case 'R':
case 'r':
{
@@ -354,14 +162,6 @@ int main(int argc, char *argv[])
break;
}
- case 'S':
- case 's':
- {
- show_score = atoi(&argv[i][2]);
- if (show_score <= 0) show_score = 10;
- break;
- }
-
case 'u':
case 'U':
{
@@ -382,7 +182,7 @@ int main(int argc, char *argv[])
case 'M':
{
if (!argv[i][2]) goto usage;
- force_module = string_make(&argv[i][2]);
+ force_module = &argv[i][2];
break;
}
@@ -397,7 +197,8 @@ int main(int argc, char *argv[])
char *s;
int j;
- init_lua();
+ init_lua_init();
+
for (j = i + 1; j < argc; j++)
{
s = argv[j];
@@ -411,13 +212,6 @@ int main(int argc, char *argv[])
return 0;
}
- case 'd':
- case 'D':
- {
- change_path(&argv[i][2]);
- break;
- }
-
case '-':
{
if (argv[i][2] == 'h' && !strcmp((argv[i] + 2), "help"))
@@ -443,53 +237,26 @@ usage:
puts("Usage: tome [options] [-- subopts]");
puts(" -h This help");
puts(" -n Start a new character");
- puts(" -f Request fiddle mode");
puts(" -w Request wizard mode");
- puts(" -v Request sound mode");
- puts(" -g Request graphics mode");
puts(" -o Request original keyset");
puts(" -r Request rogue-like keyset");
puts(" -H <list of files> Convert helpfile to html");
- puts(" -s<num> Show <num> high scores");
puts(" -u<who> Use your <who> savefile");
puts(" -M<which> Use the <which> module");
puts(" -m<sys> Force 'main-<sys>.c' usage");
- puts(" -d<def> Define a 'lib' dir sub-path");
#ifdef USE_GTK2
puts(" -mgtk2 To use GTK2");
puts(" -- Sub options");
puts(" -- -n# Number of terms to use");
puts(" -- -b Turn off software backing store");
-# ifdef USE_GRAPHICS
- puts(" -- -s Turn off smoothscaling graphics");
- puts(" -- -o Requests \"old\" graphics");
- puts(" -- -g Requests \"new\" graphics");
- puts(" -- -t Enable transparency effect");
-# endif /* USE_GRAPHICS */
#endif /* USE_GTK2 */
-#ifdef USE_XAW
- puts(" -mxaw To use XAW");
- puts(" -- Sub options");
- puts(" -- -n# Number of terms to use");
- puts(" -- -d<name> Display to use");
-# ifdef USE_GRAPHICS
- puts(" -- -s Turn off smoothscaling graphics");
- puts(" -- -o Requests \"old\" graphics");
-# endif /* USE_GRAPHICS */
-#endif /* USE_XAW */
-
#ifdef USE_X11
puts(" -mx11 To use X11");
puts(" -- Sub options");
puts(" -- -n# Number of terms to use");
puts(" -- -d<name> Display to use");
-# ifdef USE_GRAPHICS
- puts(" -- -s Turn off smoothscaling graphics");
- puts(" -- -o Requests \"old\" graphics");
- puts(" -- -b Requests double-width tiles");
-# endif /* USE_GRAPHICS */
#endif /* USE_X11 */
#ifdef USE_GCU
@@ -498,17 +265,10 @@ usage:
puts(" -- -b Requests big screen");
#endif /* USE_GCU */
-#ifdef USE_SLA
- puts(" -msla To use SLang");
-#endif /* USE_SLA */
-
#ifdef USE_SDL
puts(" -msdl To use SDL");
puts(" -- Sub options");
puts(" -- -n # Number of virtual consoles to use");
- puts(" -- -g Request new graphics (16x16)");
- puts(" -- -o Request old graphics (8x8)");
- puts(" -- -b Requests double-width tiles");
puts(" -- -w # Request screen width in pixels");
puts(" -- -h # Request screen height in pixels");
puts(" -- -bpp # Request screen color depth in bits");
@@ -539,19 +299,6 @@ usage:
quit_aux = quit_hook;
-#ifdef USE_GLU
- /* Attempt to use the "main-glu.c" support */
- if (!done && (!mstr || (streq(mstr, "glu"))))
- {
- extern errr init_glu(int, char**);
- if (0 == init_glu(argc, argv))
- {
- ANGBAND_SYS = "glu";
- done = TRUE;
- }
- }
-#endif
-
#ifdef USE_GTK2
/* Attempt to use the "main-gtk2.c" support */
if (!done && (!mstr || (streq(mstr, "gtk2"))))
@@ -565,32 +312,6 @@ usage:
}
#endif
-#ifdef USE_GTK
- /* Attempt to use the "main-gtk.c" support */
- if (!done && (!mstr || (streq(mstr, "gtk"))))
- {
- extern errr init_gtk(int, char**);
- if (0 == init_gtk(argc, argv))
- {
- ANGBAND_SYS = "gtk";
- done = TRUE;
- }
- }
-#endif
-
-#ifdef USE_XAW
- /* Attempt to use the "main-xaw.c" support */
- if (!done && (!mstr || (streq(mstr, "xaw"))))
- {
- extern errr init_xaw(int, char**);
- if (0 == init_xaw(argc, argv))
- {
- ANGBAND_SYS = "xaw";
- done = TRUE;
- }
- }
-#endif
-
#ifdef USE_X11
/* Attempt to use the "main-x11.c" support */
if (!done && (!mstr || (streq(mstr, "x11"))))
@@ -617,34 +338,6 @@ usage:
}
#endif
-#ifdef USE_GLU
- /* Attempt to use the "main-glu.c" support */
- if (!done && (!mstr || (streq(mstr, "glu"))))
- {
- extern errr init_glu(int, char**);
- if (0 == init_glu(argc, argv))
- {
- ANGBAND_SYS = "glu";
- done = TRUE;
- }
- }
-#endif
-
-
-#ifdef USE_SLA
- /* Attempt to use the "main-sla.c" support */
- if (!done && (!mstr || (streq(mstr, "sla"))))
- {
- extern errr init_sla(void);
- if (0 == init_sla())
- {
- ANGBAND_SYS = "sla";
- done = TRUE;
- }
- }
-#endif
-
-
#ifdef USE_SDL
/* Attempt to use the "main-sdl.c" support */
if (!done && (!mstr || (streq(mstr, "sdl"))))
@@ -662,25 +355,15 @@ usage:
if (!done) quit("Unable to prepare any 'display module'!");
- /* Catch nasty signals */
- signals_init();
-
/* Initialize */
init_angband();
- /* Hack -- If requested, display scores and quit */
- if (show_score > 0) display_scores(0, show_score);
-
/* Wait for response */
pause_line(23);
/* Play the game */
play_game(new_game);
-#ifdef CHECK_MEMORY_LEAKS
- CHECK_LEAKS();
-#endif
-
/* Quit */
quit(NULL);