-rw-r--r-- | lib/srchilite/fileutil.cc | 48 | ||||
-rw-r--r-- | src/source-highlight.cc | 41 |
diff --git a/lib/srchilite/fileutil.cc b/lib/srchilite/fileutil.cc index b4b95a6..59a6d64 100644 --- a/lib/srchilite/fileutil.cc +++ b/lib/srchilite/fileutil.cc @@ -206,29 +206,17 @@ istream *open_data_file_istream(const string &path, throw IOException("empty file name", input_file_name); istream *in = 0; - if (input_file_name.size() && contains_path(input_file_name)) { + if (contains_path(input_file_name)) { in = _open_data_file_istream("", input_file_name); - if (!in) { - throw IOException("cannot open", input_file_name); - } - } else if (path.size() && input_file_name.size()) { - const string file = (path.size() ? path + "/" : "") + input_file_name; + } else if (path.size()) { in = _open_data_file_istream(path, input_file_name); - if (!in) { - throw IOException("cannot open", file); - } } else { - string _path = path; - string _file = input_file_name; - bool has_path = contains_path(input_file_name); - if (!path.size() && !has_path) - _path = "."; - - in = _open_data_file_istream(_path, _file); - if (!in && !path.size() && !has_path) - in = _open_data_file_istream(start, _file); + in = _open_data_file_istream(".", input_file_name); } + if (!in) // falback if all else failed, start defaults to start_path + in = _open_data_file_istream(start, input_file_name); + if (!in) throw IOException("cannot find input file anywhere", input_file_name); @@ -248,29 +236,17 @@ FILE *open_data_file_stream(const string &path, const string &input_file_name, throw IOException("empty file name", input_file_name); FILE *in = 0; - if (input_file_name.size() && contains_path(input_file_name)) { + if (contains_path(input_file_name)) { in = _open_data_file_stream("", input_file_name); - if (!in) { - throw IOException("cannot open", input_file_name); - } - } else if (path.size() && input_file_name.size()) { - const string file = (path.size() ? path + "/" : "") + input_file_name; + } else if (path.size()) { in = _open_data_file_stream(path, input_file_name); - if (!in) { - throw IOException("cannot open", file); - } } else { - string _path = path; - string _file = input_file_name; - bool has_path = contains_path(input_file_name); - if (!path.size() && !has_path) - _path = "."; - - in = _open_data_file_stream(_path, _file); - if (!in && !path.size() && !has_path) - in = _open_data_file_stream(start, _file); + in = _open_data_file_stream(".", input_file_name); } + if (!in) // falback if all else failed, start defaults to start_path + in = _open_data_file_stream(start, input_file_name); + if (!in) throw IOException("cannot find input file anywhere", input_file_name); diff --git a/src/source-highlight.cc b/src/source-highlight.cc index 4f813e6..4feba30 100644 --- a/src/source-highlight.cc +++ b/src/source-highlight.cc @@ -203,34 +203,35 @@ int main(int argc, char * argv[]) { // the default for output format is html outputFormat = args_info.out_format_arg; - if (args_info.data_dir_given) { - dataDir = args_info.data_dir_arg; - } - if (args_info.output_dir_given) { outputDir = args_info.output_dir_arg; } /* - the starting default path to search for files is computed at - run-time: it is - the path of the binary + ".." + RELATIVEDATADIR - this should make the package relocable (i.e., not stuck - with a fixed installation directory). + The starting default path is from Settings::retrieveDataDir() which + does the heavy lifting of finding the data dir by looking at config-time + values, environment variables, user settings at $HOME, etc. See settings.h + + From here, invoking with --data-dir=<my-datadir> overrides the above value. + + We also use a fallback dir which is calculated in runtime relative to this + executable (by default <executable-dir>/../share/source-highlight/). + + this should make the package relocatable (i.e., not stuck with a fixed + installation directory). Of course, the GNU standards for installation directories should be followed, but this is not a problem if you use configure and make install features. - If no path is specified in the running program we go back to - the absolute datadir. - */ - // this is defined in fileutil.cc - string prefix_dir = get_file_path(argv[0]); - if (prefix_dir.size()) - start_path = get_file_path(argv[0]) + RELATIVEDATADIR; - else - start_path = Settings::retrieveDataDir(); - - // if datadir is not specified, we rely on start_path? + */ + + dataDir = Settings::retrieveDataDir(); + if (args_info.data_dir_given) + dataDir = args_info.data_dir_arg; + + // start_path is global fallback for dataDir - used at fileutil.h + string executable_dir = get_file_path(argv[0]); + if (executable_dir.size()) + start_path = executable_dir + RELATIVEDATADIR; try { // initialize map files |