Fixes to interrogate -srcdir

This commit is contained in:
Josh Yelon 2005-09-30 07:19:18 +00:00
parent 65e665414d
commit f57fe99b6a
3 changed files with 36 additions and 10 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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