From f57fe99b6aa3dd5aa3b0ad7407fbfe6a48ac4f3c Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Fri, 30 Sep 2005 07:19:18 +0000 Subject: [PATCH] Fixes to interrogate -srcdir --- dtool/src/dtoolutil/filename.cxx | 16 ++++++++++++++-- dtool/src/dtoolutil/filename.h | 4 ++-- dtool/src/interrogate/interrogate.cxx | 26 ++++++++++++++++++++------ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index 7679bc73e5..7351a51e88 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -1669,6 +1669,18 @@ touch() const { #endif // WIN32, HAVE_UTIME_H } +//////////////////////////////////////////////////////////////////// +// Function: Filename::chdir +// Access: Published +// Description: Changes directory to the specified location. +// Returns true if successful, false if failure. +//////////////////////////////////////////////////////////////////// +bool Filename:: +chdir() const { + Filename os_specific = to_os_specific(); + return (::chdir(os_specific.c_str()) >= 0); +} + //////////////////////////////////////////////////////////////////// // Function: Filename::unlink // Access: Published @@ -1964,13 +1976,13 @@ r_make_canonical(const Filename &cwd) { // First, try to cd to the filename directly. string os_specific = to_os_specific(); - if (chdir(os_specific.c_str()) >= 0) { + if (::chdir(os_specific.c_str()) >= 0) { // That worked, save the full path string. (*this) = ExecutionEnvironment::get_cwd(); // And restore the current working directory. string osdir = cwd.to_os_specific(); - if (chdir(osdir.c_str()) < 0) { + if (::chdir(osdir.c_str()) < 0) { cerr << "Error! Cannot change back to " << cwd << "\n"; } return true; diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index 6b146c7998..833b159d14 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -163,7 +163,7 @@ PUBLISHED: const string &default_extension = string()); bool make_relative_to(Filename directory, bool allow_backups = true); int find_on_searchpath(const DSearchPath &searchpath); - + bool scan_directory(vector_string &contents) const; bool open_read(ifstream &stream) const; @@ -171,8 +171,8 @@ PUBLISHED: bool open_append(ofstream &stream) const; bool open_read_write(fstream &stream) const; + bool chdir() const; bool touch() const; - bool unlink() const; bool rename_to(const Filename &other) const; diff --git a/dtool/src/interrogate/interrogate.cxx b/dtool/src/interrogate/interrogate.cxx index fa140167e2..e6af81d09a 100644 --- a/dtool/src/interrogate/interrogate.cxx +++ b/dtool/src/interrogate/interrogate.cxx @@ -316,6 +316,7 @@ main(int argc, char *argv[]) { command_line += string(argv[i]) + " "; } + Filename fn; extern char *optarg; extern int optind; int flag; @@ -324,11 +325,15 @@ main(int argc, char *argv[]) { while (flag != EOF) { switch (flag) { case 'I': - parser._include_path.append_directory(optarg); + fn = Filename::from_os_specific(optarg); + fn.make_absolute(); + parser._include_path.append_directory(fn); break; case 'S': - parser._system_include_path.append_directory(optarg); + fn = Filename::from_os_specific(optarg); + fn.make_absolute(); + parser._system_include_path.append_directory(fn); break; case 'D': @@ -345,14 +350,17 @@ main(int argc, char *argv[]) { case CO_oc: output_code_filename = Filename::from_os_specific(optarg); + output_code_filename.make_absolute(); break; case CO_od: output_data_filename = Filename::from_os_specific(optarg); + output_data_filename.make_absolute(); break; case CO_srcdir: source_file_directory = Filename::from_os_specific(optarg); + source_file_directory.make_absolute(); break; case CO_module: @@ -450,6 +458,13 @@ main(int argc, char *argv[]) { exit(1); } + // If requested, change directory to the source-file directory. + if (source_file_directory != "") { + if (!source_file_directory.chdir()) { + cerr << "Could not change directory to " << source_file_directory << "\n"; + exit(1); + } + } // if(!output_code_filename.empty()) // { @@ -479,8 +494,7 @@ main(int argc, char *argv[]) { for (i = 1; i < argc; ++i) { Filename filename = Filename::from_os_specific(argv[i]); - if (!parser.parse_file(Filename(source_file_directory, filename))) - { + if (!parser.parse_file(filename)) { cerr << "Error parsing file: '" << argv[i] << "'\n"; exit(1); } @@ -495,7 +509,8 @@ main(int argc, char *argv[]) { // Now look for the .N files. for (i = 1; i < argc; ++i) { - Filename nfilename = Filename::from_os_specific(argv[i]); + Filename filename = Filename::from_os_specific(argv[i]); + Filename nfilename = filename; nfilename.set_extension("N"); nfilename.set_text(); ifstream nfile; @@ -504,7 +519,6 @@ main(int argc, char *argv[]) { } } - builder.build(); // Make up a file identifier. This is just some bogus number that