summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-01-11 07:03:20 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-01-11 07:03:20 +0000
commitabc565d0ca078f1d6214c447f41de3b5589155c2 (patch)
tree847a6ad3351ed7359888191b9e397cd9cedb8e67
parent12daab03d032a6f81f739da7932ce0a0f4094b4e (diff)
downloadcrawl-ref-abc565d0ca078f1d6214c447f41de3b5589155c2.tar.gz
crawl-ref-abc565d0ca078f1d6214c447f41de3b5589155c2.zip
Changed error message + exit() sequences to end() calls so that the user can
see the error message on the console. Added docs/ to the data search path for the Windows builds. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@829 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/acr.cc18
-rw-r--r--crawl-ref/source/dungeon.cc13
-rw-r--r--crawl-ref/source/files.cc7
-rw-r--r--crawl-ref/source/initfile.cc2
-rw-r--r--crawl-ref/source/libutil.cc5
-rw-r--r--crawl-ref/source/maps.cc6
-rw-r--r--crawl-ref/source/monstuff.cc3
-rw-r--r--crawl-ref/source/stuff.cc29
-rw-r--r--crawl-ref/source/stuff.h3
9 files changed, 40 insertions, 46 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 3b4acebf86..24de663cae 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -160,7 +160,6 @@ static void open_door(int move_x, int move_y, bool check_confused = true);
static void start_running( int dir, int mode );
static void close_door(int move_x, int move_y);
-static void init_io();
static void prep_input();
static void input();
static void middle_input();
@@ -324,21 +323,6 @@ int main( int argc, char *argv[] )
return 0;
} // end main()
-static void init_io()
-{
-#ifdef UNIX
- unixcurses_startup();
-#endif
-
-#ifdef WIN32CONSOLE
- init_libw32c();
-#endif
-
-#ifdef DOS
- init_libdos();
-#endif
-}
-
#ifdef WIZARD
static void handle_wizard_command( void )
{
@@ -2682,7 +2666,7 @@ static bool initialise(void)
// Read special levels and vaults.
read_maps();
- init_io();
+ cio_init();
#ifdef USE_MACROS
// Load macros
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index 55eff94f62..1b38f80aeb 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -3717,11 +3717,8 @@ static int builder_by_type(int level_number, char level_type)
ASSERT(vault != -1);
if (vault == -1)
- {
- fprintf(stderr, "Failed to find Pandemonium level %s!\n",
- pandemon_level_names[(int) which_demon]);
- exit(1);
- }
+ end(1, false, "Failed to find Pandemonium level %s!\n",
+ pandemon_level_names[(int) which_demon]);
build_vaults(level_number, vault);
}
@@ -3731,10 +3728,8 @@ static int builder_by_type(int level_number, char level_type)
int vault = random_map_for_tag("pan", true);
ASSERT( vault != -1 );
if (vault == -1)
- {
- fprintf(stderr, "Failed to build Pandemonium minivault!\n");
- exit(1);
- }
+ end(1, false, "Failed to build Pandemonium minivault!\n");
+
build_minivaults(level_number, vault);
}
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index 78db7bf7d5..1d613e7c7a 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -366,7 +366,7 @@ std::string datafile_path(const std::string &basename)
const std::string prefixes[] = {
std::string("dat") + FILE_SEPARATOR,
std::string("data") + FILE_SEPARATOR,
- std::string("crawl-data") + FILE_SEPARATOR,
+ std::string("docs") + FILE_SEPARATOR,
std::string("..")+FILE_SEPARATOR+std::string("docs")+FILE_SEPARATOR,
std::string("..") + FILE_SEPARATOR,
std::string(".") + FILE_SEPARATOR,
@@ -400,9 +400,8 @@ std::string datafile_path(const std::string &basename)
}
// Die horribly.
- fprintf(stderr, "Cannot find data file '%s' anywhere, aborting\n",
- basename.c_str());
- exit(1);
+ end(1, false, "Cannot find data file '%s' anywhere, aborting\n",
+ basename.c_str());
return ("");
}
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 7781784149..e6300d9c21 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -1176,7 +1176,7 @@ void game_options::read_options(InitLineInput &il, bool runscript)
// Validate save_dir
if (!check_dir("Save directory", save_dir))
- exit(1);
+ end(1);
}
static int str_to_killcategory(const std::string &s)
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index f59eab1ee7..5e2752de6d 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -416,10 +416,7 @@ int snprintf( char *str, size_t size, const char *format, ... )
char *buff = new char [ 10 * size ]; // hopefully enough
if (!buff)
- {
- fprintf(stderr, "Out of memory\n");
- exit(1);
- }
+ end(1, false, "Out of memory\n");
vsprintf( buff, format, argp );
strncpy( str, buff, size );
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index 6edf4981b0..0637a11742 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -315,11 +315,7 @@ static void parse_maps(const std::string &s)
{
FILE *dat = fopen(s.c_str(), "r");
if (!dat)
- {
- fprintf(stderr, "Failed to open %s for reading: %d\n", s.c_str(),
- errno);
- exit(1);
- }
+ end(1, true, "Failed to open %s for reading: %d\n", s.c_str());
reset_map_parser();
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index b0b01329b4..8d1b061b83 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -4964,8 +4964,7 @@ static void mons_in_cloud(struct monsters *monster)
switch (env.cloud[wc].type)
{
case CLOUD_DEBUGGING:
- cprintf("Fatal error: monster steps on nonexistent cloud!");
- exit(0);
+ end(1, false, "Fatal error: monster steps on nonexistent cloud!");
return;
case CLOUD_FIRE:
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 9ac888df8b..e4c6c64d43 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -463,28 +463,51 @@ bool see_grid(unsigned char grx, unsigned char gry)
return false;
} // end see_grid()
-void io_cleanup()
+static bool io_inited = false;
+void cio_init()
{
#ifdef UNIX
+ unixcurses_startup();
+#endif
+
+#ifdef WIN32CONSOLE
+ init_libw32c();
+#endif
+
+#ifdef DOS
+ init_libdos();
+#endif
+
+ io_inited = true;
+}
+
+void cio_cleanup()
+{
+ if (!io_inited)
+ return;
+
+#ifdef UNIX
unixcurses_shutdown();
#endif
#ifdef WIN32CONSOLE
deinit_libw32c();
#endif
+
+ io_inited = false;
}
void end(int exit_code, bool print_error, const char *format, ...)
{
std::string error = print_error? strerror(errno) : "";
- io_cleanup();
+ cio_cleanup();
if (format)
{
va_list arg;
va_start(arg, format);
- char buffer[500];
+ char buffer[100];
vsnprintf(buffer, sizeof buffer, format, arg);
va_end(arg);
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 9bda9bfabb..1b1bffcbeb 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -51,7 +51,8 @@ int stat_div( int stat_level, int value, int div = 20, int shift = 3 );
int skill_bump( int skill );
unsigned char get_ch(void);
-void io_cleanup();
+void cio_init();
+void cio_cleanup();
void end(int exit_code, bool print_err = false,
const char *message = NULL, ...);