diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-15 11:59:00 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-15 11:59:00 +0000 |
commit | 4cc4eaf79bd010cfdefd9547bd34d728ff3cc62d (patch) | |
tree | 066bf487f22b57419bbfd76261bb379b0a01b2c4 | |
parent | 1328bd509fa25da1301d4ff6f4b6e9f2a630730e (diff) | |
download | crawl-ref-4cc4eaf79bd010cfdefd9547bd34d728ff3cc62d.tar.gz crawl-ref-4cc4eaf79bd010cfdefd9547bd34d728ff3cc62d.zip |
Added -morgue option to specify where morgues are saved.
Added -macro option to specify location of macro file.
Morgue files are named morgue-<cname>-<time>.txt, provided Crawl is compiled without SHORT_FILE_NAMES.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.1.6@640 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/acr.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/chardump.cc | 16 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/files.cc | 12 | ||||
-rw-r--r-- | crawl-ref/source/files.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 28 | ||||
-rw-r--r-- | crawl-ref/source/macro.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/ouch.cc | 25 |
8 files changed, 78 insertions, 18 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 6ad2f070b8..38460be2b8 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -205,6 +205,8 @@ int main( int argc, char *argv[] ) puts(" -plain don't use IBM extended characters"); puts(" -dir <path> crawl directory"); puts(" -rc <file> init file name"); + puts(" -morgue <dir> directory to save character dumps"); + puts(" -macro <file> macro file name"); puts(""); puts("Command line options override init file options, which override"); puts("environment options (CRAWL_NAME, CRAWL_PIZZA, CRAWL_DIR, CRAWL_RC)."); diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc index e8b028f0c3..d8b35ff94b 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -998,6 +998,18 @@ const char *hunger_level(void) (you.hunger < 11000) ? "full" : "completely stuffed"); } +static std::string morgue_directory() +{ + std::string dir = + !SysEnv.morgue_dir.empty()? SysEnv.morgue_dir : + SysEnv.crawl_dir ? SysEnv.crawl_dir : ""; + + if (!dir.empty() && dir[dir.length() - 1] != FILE_SEPARATOR) + dir += FILE_SEPARATOR; + + return (dir); +} + static bool write_dump( const std::string &fname, const std::string &text, @@ -1005,9 +1017,7 @@ static bool write_dump( { bool succeeded = false; - std::string file_name; - if (SysEnv.crawl_dir) - file_name += SysEnv.crawl_dir; + std::string file_name = morgue_directory(); file_name += fname; diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index b28786f966..dff17a277c 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -660,6 +660,10 @@ struct system_environment bool board_with_nail; // Easter Egg silliness std::string scorefile; + std::string macro_file; // File to read instead of macro.txt + std::string morgue_dir; // Directory where character dumps and morgue + // dumps are saved. Overrides crawl_dir. + }; extern system_environment SysEnv; diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index fc86cc2cc1..241a367fb3 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -412,10 +412,10 @@ std::string datafile_path(const std::string &basename) return (""); } -void check_savedir(std::string &dir) +bool check_dir(const std::string &whatdir, std::string &dir) { if (dir.empty()) - return; + return (true); std::string sep = " "; sep[0] = FILE_SEPARATOR; @@ -429,11 +429,13 @@ void check_savedir(std::string &dir) if (!dir_exists(dir) && !create_dirs(dir)) { - fprintf(stderr, "Save directory \"%s\" does not exist " + fprintf(stderr, "%s \"%s\" does not exist " "and I can't create it.\n", - dir.c_str()); - exit(1); + whatdir.c_str(), dir.c_str()); + return (false); } + + return (true); } // Given a simple (relative) name of a save file, returns the full path of diff --git a/crawl-ref/source/files.h b/crawl-ref/source/files.h index 3bbd358a1e..93a837b659 100644 --- a/crawl-ref/source/files.h +++ b/crawl-ref/source/files.h @@ -31,7 +31,7 @@ extern FixedArray<bool, MAX_LEVELS, MAX_BRANCHES> tmp_file_pairs; std::string datafile_path(const std::string &basename); -void check_savedir(std::string &dir); +bool check_dir(const std::string &what, std::string &dir); bool travel_load_map( char branch, int absdepth ); diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index e67bd2bbdb..205a68f9d5 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -1003,7 +1003,8 @@ void game_options::read_options(InitLineInput &il, bool runscript) #endif // Validate save_dir - check_savedir(save_dir); + if (!check_dir("Save directory", save_dir)) + exit(1); } static int str_to_killcategory(const std::string &s) @@ -1427,7 +1428,7 @@ void game_options::read_option_line(const std::string &str, bool runscript) else if (key == "remember_name") { remember_name = read_bool( field, remember_name ); - } + } else if (key == "save_dir") { // If SAVE_DIR_PATH was defined, there are very likely security issues @@ -1460,7 +1461,7 @@ void game_options::read_option_line(const std::string &str, bool runscript) } else if (key == "note_hp_percent") { - note_hp_percent = atoi( field.c_str() ); + note_hp_percent = atoi( field.c_str() ); if (note_hp_percent < 0 || note_hp_percent > 100) { note_hp_percent = 0; @@ -1984,13 +1985,16 @@ enum commandline_option_type { CLO_TSCORES, CLO_VSCORES, CLO_SCOREFILE, + CLO_MORGUE, + CLO_MACRO, CLO_NOPS }; static const char *cmd_ops[] = { "scores", "name", "race", "class", "pizza", "plain", "dir", "rc", "tscores", - "vscores", "scorefile" }; + "vscores", "scorefile", "morgue", + "macro" }; const int num_cmd_ops = CLO_NOPS; bool arg_seen[num_cmd_ops]; @@ -2089,6 +2093,22 @@ bool parse_args( int argc, char **argv, bool rc_only ) } break; + case CLO_MACRO: + if (!next_is_param) + return (false); + if (!rc_only) + SysEnv.macro_file = next_arg; + nextUsed = true; + break; + + case CLO_MORGUE: + if (!next_is_param) + return (false); + if (!rc_only) + SysEnv.morgue_dir = next_arg; + nextUsed = true; + break; + case CLO_SCOREFILE: if (!next_is_param) { fprintf(stderr, "No parameter to -scorefile, %s\n", diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc index ed03525f9f..9a80fe032a 100644 --- a/crawl-ref/source/macro.cc +++ b/crawl-ref/source/macro.cc @@ -170,11 +170,10 @@ static int userfunc_getindex(const std::string &fname) */ static std::string get_macro_file() { - std::string s; - - if (SysEnv.crawl_dir) - s = SysEnv.crawl_dir; + if (SysEnv.macro_file.length()) + return (SysEnv.macro_file); + std::string s = SysEnv.crawl_dir? SysEnv.crawl_dir : ""; return (s + "macro.txt"); } diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc index 433acb8ce6..a4a93a4383 100644 --- a/crawl-ref/source/ouch.cc +++ b/crawl-ref/source/ouch.cc @@ -804,6 +804,29 @@ void ouch( int dam, int death_source, char death_type, const char *aux ) end_game(se); } +static std::string morgue_name() +{ +#ifdef SHORT_FILE_NAMES + return "morgue"; +#else // !SHORT_FILE_NAMES + std::string name = "morgue-" + std::string(you.your_name); + time_t when_crawl_got_even = time(NULL); + + if (tm *loc = localtime(&when_crawl_got_even)) + { + char buf[25]; + snprintf(buf, sizeof buf, "-%04d%02d%02d-%02d%02d", + loc->tm_year + 1900, + loc->tm_mon + 1, + loc->tm_mday, + loc->tm_hour, + loc->tm_min); + name += buf; + } + return (name); +#endif // SHORT_FILE_NAMES +} + void end_game( struct scorefile_entry &se ) { int i; @@ -874,7 +897,7 @@ void end_game( struct scorefile_entry &se ) invent( -1, dead ); clrscr(); - if (!dump_char( "morgue", !dead, true )) + if (!dump_char( morgue_name(), !dead, true )) mpr("Char dump unsuccessful! Sorry about that."); #if DEBUG_DIAGNOSTICS //jmf: switched logic and moved "success" message to debug-only |