From ae735f39601423c88be471340dfe88dc3d3d103d Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Thu, 17 Jul 2008 07:19:04 +0000 Subject: Fix 2017893: long file names not working on DOS. Crawl now takes a shot at abbreviating them, and only fails if it can't find that file either. Handles all files included by default in /settings and /docs except changes.stone_soup which is not strictly necessary for the version information. Tested artificially by manually mutilating the file names; not actually tested on DOS. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6578 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/docs/changes.stone_soup | 4 +++- crawl-ref/source/command.cc | 48 +++++++++++++++++++++++++++++++++++---- crawl-ref/source/files.cc | 24 ++++++++++++++++++++ crawl-ref/source/files.h | 1 + crawl-ref/source/initfile.cc | 10 +++++--- crawl-ref/source/makefile | 4 ++-- crawl-ref/source/travel.cc | 5 ++-- 7 files changed, 83 insertions(+), 13 deletions(-) diff --git a/crawl-ref/docs/changes.stone_soup b/crawl-ref/docs/changes.stone_soup index 8bedc795e2..805b74a582 100644 --- a/crawl-ref/docs/changes.stone_soup +++ b/crawl-ref/docs/changes.stone_soup @@ -3,10 +3,12 @@ Stone Soup 0.4.1 (200807??) Disclaimer: These are merely the highlights, not an exhaustive list of changes. -(* Fixed crashes related to mapmark.lua.) +* Fixed crashes related to mapmark.lua. * Fixed crash when attempting to autoinscribe non-artefacts via '{'. * Fixed Crawl looping infinitely upon "good random choice" for Thief/Wanderer. * Fixed crashes when selecting an item with no appropriate items in inventory. +* Fixed tiles not working on Windows 2000 and earlier. +* Fixed DOS problems with long file names. * Fixed targetting prompts being ignored or having the wrong result. * Fixed vampire bat jewellery exploit. * Fixed kills by hell effects counting as player kills. diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index 86879504ea..501e8ada2a 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -202,6 +202,7 @@ static std::string _get_version_changes(void) return (result); } +//#define DEBUG_FILES static void _print_version(void) { formatted_scroller cmd_version; @@ -221,8 +222,28 @@ static void _print_version(void) cmd_version.add_text(_get_version_features()); cmd_version.add_text(_get_version_changes()); + std::string fname = "034_changes.txt"; // Read in information about changes in comparison to the latest version. - FILE* fp = fopen(datafile_path("034_changes.txt", false).c_str(), "r"); + FILE* fp = fopen(datafile_path(fname, false).c_str(), "r"); + +#if defined(DOS) + if (!fp) + { + #ifdef DEBUG_FILES + mprf(MSGCH_DIAGNOSTICS, "File '%s' could not be opened.", + fname.c_str()); + #endif + if (get_dos_compatible_file_name(&fname)) + { + #ifdef DEBUG_FILES + mprf(MSGCH_DIAGNOSTICS, + "Attempting to open file '%s'", fname.c_str()); + #endif + fp = fopen(datafile_path(fname, false).c_str(), "r"); + } + } +#endif + if (fp) { char buf[200]; @@ -1519,7 +1540,7 @@ int help_highlighter::entry_colour(const MenuEntry *entry) const return !pattern.empty() && pattern.matches(entry->text)? WHITE : -1; } -// to highlight species in aptitudes list ('?%') +// To highlight species in aptitudes list. ('?%') std::string help_highlighter::get_species_key() const { if (player_genus(GENPC_DRACONIAN) && you.experience_level < 7) @@ -1631,8 +1652,27 @@ static void _show_keyhelp_menu(const std::vector &lines, for (int i = 0; help_files[i].name != NULL; ++i) { // Attempt to open this file, skip it if unsuccessful. - FILE* fp = - fopen(datafile_path(help_files[i].name, false).c_str(), "r"); + std::string fname = canonicalise_file_separator(help_files[i].name); + FILE* fp = fopen(datafile_path(fname, false).c_str(), "r"); + +#if defined(DOS) + if (!fp) + { + #ifdef DEBUG_FILES + mprf(MSGCH_DIAGNOSTICS, "File '%s' could not be opened.", + help_files[i].name); + #endif + if (get_dos_compatible_file_name(&fname)) + { + #ifdef DEBUG_FILES + mprf(MSGCH_DIAGNOSTICS, + "Attempting to open file '%s'", fname.c_str()); + #endif + fp = fopen(datafile_path(fname, false).c_str(), "r"); + } + } +#endif + if (!fp) continue; diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 4e9a019817..2dbce76869 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -213,6 +213,30 @@ static inline bool _is_good_filename(const std::string &s) return (s != "." && s != ".."); } +#if defined(DOS) +// Abbreviates a given file name to DOS style "xxxxxx~1.txt". +// Does not take into account files with differing suffixes or files +// with a prepended path with more than one separator. +// (It does handle all files included with the distribution except +// changes.stone_soup.) +bool get_dos_compatible_file_name(std::string *fname) +{ + std::string::size_type pos1 = fname->find("\\"); + if (pos1 == std::string::npos) + pos1 = 0; + + const std::string::size_type pos2 = fname->find(".txt"); + // Name already fits DOS requirements, nothing to be done. + if (fname->substr(pos1, pos2).length() <= 8) + return (false); + + *fname = fname->substr(0,pos1) + fname->substr(pos1, pos1 + 6) + "~1.txt"; + + return (true); +} +#endif + + // Returns the names of all files in the given directory. Note that the // filenames returned are relative to the directory. std::vector get_dir_files(const std::string &dirname) diff --git a/crawl-ref/source/files.h b/crawl-ref/source/files.h index 3e28c65a30..95995e9c24 100644 --- a/crawl-ref/source/files.h +++ b/crawl-ref/source/files.h @@ -44,6 +44,7 @@ std::string datafile_path(std::string basename, bool croak_on_fail = true, bool test_base_path = false); +bool get_dos_compatible_file_name(std::string *fname); std::string get_parent_directory(const std::string &filename); std::string get_base_filename(const std::string &filename); std::string get_path_relative_to(const std::string &referencefile, diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 08ca799cb2..f3e9beee74 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -2905,6 +2905,9 @@ std::string game_options::resolve_include( // favoured file separator. parent_file = canonicalise_file_separator(parent_file); included_file = canonicalise_file_separator(included_file); +#if defined(DOS) + get_dos_compatible_file_name(&included_file); +#endif // How we resolve include paths: // 1. If it's an absolute path, use it directly. @@ -2945,9 +2948,8 @@ std::string game_options::resolve_include( return datafile_path(included_file, false, true); } -std::string game_options::resolve_include( - const std::string &file, - const char *type) +std::string game_options::resolve_include( const std::string &file, + const char *type) { try { @@ -2955,9 +2957,11 @@ std::string game_options::resolve_include( resolve_include(this->filename, file, &SysEnv.rcdirs); if (resolved.empty()) + { report_error( make_stringf("Cannot find %sfile \"%s\".", type, file.c_str())); + } return (resolved); } catch (const std::string &err) diff --git a/crawl-ref/source/makefile b/crawl-ref/source/makefile index 9e1ded2ab6..0bb53bc62a 100644 --- a/crawl-ref/source/makefile +++ b/crawl-ref/source/makefile @@ -4,12 +4,12 @@ #Makefile chooser. Choose one: -MAKEFILE ?= makefile.unix +#MAKEFILE ?= makefile.unix #MAKEFILE ?= makefile.dos #MAKEFILE ?= makefile.osx #MAKEFILE ?= makefile.mgw #MAKEFILE ?= makefile_tiles.mgw -#MAKEFILE ?= makefile.x11 +MAKEFILE ?= makefile.x11 #jmf: number of concurrent jobs -- good value is (#_of_CPUs * 2) + 1 # cuts build time a lot on multi-cpu machines diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 680c66f191..da2685d2e0 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -2238,7 +2238,7 @@ static travel_target _parse_travel_target( std::string s, travel_target &targ ) std::string::size_type epos = s.find(ekey); if (!s.empty()) - targ.entrance_only = epos != std::string::npos; + targ.entrance_only = (epos != std::string::npos); if (targ.entrance_only && !s.empty()) s = trimmed_string(s.substr(0, epos) + s.substr(epos + ekey.length())); @@ -2255,8 +2255,7 @@ static travel_target _parse_travel_target( std::string s, travel_target &targ ) return (targ); } -static void _travel_depth_munge(int munge_method, - const std::string &s, +static void _travel_depth_munge(int munge_method, const std::string &s, travel_target &targ) { _parse_travel_target(s, targ); -- cgit v1.2.3-54-g00ecf