diff options
-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 | ||||
-rw-r--r-- | crawl-ref/source/travel.cc | 2 |
9 files changed, 79 insertions, 19 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 3521e5dc55..151f75155a 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -189,6 +189,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 51e2dc6d59..e6396ba90d 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -958,6 +958,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, @@ -965,9 +977,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 += strip_filename_unsafe_chars(fname); diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 7278c08c5b..78bc398bd4 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -700,6 +700,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 757783a045..82e4c75259 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -404,10 +404,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; @@ -421,11 +421,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 1e50891e80..c2e8666d89 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 d5d0a7abc9..2476147206 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -1153,7 +1153,8 @@ void game_options::read_options(InitLineInput &il, bool runscript) Options.explore_stop |= Options.explore_stop_prompt; // 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) @@ -1607,7 +1608,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 @@ -1640,7 +1641,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; @@ -2214,13 +2215,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]; @@ -2319,6 +2323,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) return (false); 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 diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 936e080998..2e60997633 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -735,7 +735,7 @@ bool prompt_stop_explore(int es_why) inline static void check_interesting_square(int x, int y, explore_discoveries &ed) { - coord_def pos(x + 1, y + 1); + const coord_def pos(x + 1, y + 1); if (ES_item && igrd(pos) != NON_ITEM) ed.found_item( pos, mitm[ igrd(pos) ] ); |