*** empty log message ***

This commit is contained in:
David Rose 2001-01-10 23:28:14 +00:00
parent 88d6d4469e
commit b357529610
4 changed files with 61 additions and 71 deletions

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
AC_INIT(ppremake.cxx) AC_INIT(ppremake.cxx)
AM_INIT_AUTOMAKE(ppremake, 0.58) AM_INIT_AUTOMAKE(ppremake, 0.60)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
AC_PREFIX_DEFAULT(/usr/local/panda) AC_PREFIX_DEFAULT(/usr/local/panda)

View File

@ -15,6 +15,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <utime.h> #include <utime.h>
#include <assert.h> #include <assert.h>
#include <strstream.h>
static const string begin_comment(BEGIN_COMMENT); static const string begin_comment(BEGIN_COMMENT);
@ -181,7 +182,6 @@ BlockNesting(BlockState state, const string &name) :
_if = (PPCommandFile::IfNesting *)NULL; _if = (PPCommandFile::IfNesting *)NULL;
_write_state = (PPCommandFile::WriteState *)NULL; _write_state = (PPCommandFile::WriteState *)NULL;
_scope = (PPScope *)NULL; _scope = (PPScope *)NULL;
_tempnam = (char *)NULL;
_flags = 0; _flags = 0;
_next = (PPCommandFile::BlockNesting *)NULL; _next = (PPCommandFile::BlockNesting *)NULL;
} }
@ -1005,33 +1005,9 @@ handle_output_command() {
filename = prefix + filename; filename = prefix + filename;
} }
nest->_true_name = filename; nest->_filename = filename;
nest->_tempnam = (char *)NULL;
if (access(filename.c_str(), F_OK) == 0) {
// If the file already exists, create a temporary file first.
nest->_tempnam = tempnam((prefix + ".").c_str(), "pptmp");
assert(nest->_tempnam != (char *)NULL);
nest->_output.open(nest->_tempnam);
if (nest->_output.fail()) {
cerr << "Unable to open output file " << nest->_tempnam << "\n";
return false;
}
} else {
// If the file does not already exist, create it directly instead
// of monkeying around with temporary files.
cerr << "Generating " << filename << "\n";
nest->_output.open(filename.c_str(), ios::out, 0666);
if (nest->_output.fail()) {
cerr << "Unable to open output file " << filename << "\n";
return false;
}
}
// Generate an in-memory copy of the file first.
_write_state = new WriteState(*_write_state); _write_state = new WriteState(*_write_state);
_write_state->_out = &nest->_output; _write_state->_out = &nest->_output;
} }
@ -1110,19 +1086,19 @@ handle_end_command() {
} else if (nest->_state == BS_output) { } else if (nest->_state == BS_output) {
if (!_in_for) { if (!_in_for) {
if (!nest->_output) { if (!nest->_output) {
cerr << "Error while writing " << nest->_true_name << "\n"; cerr << "Error while writing " << nest->_filename << "\n";
return false; return false;
} }
nest->_output.close();
// Verify the output file. // Now compare the file we generated to the file that's already
if (nest->_tempnam != (char *)NULL) { // there, if there is one.
if (!compare_output(nest->_tempnam, nest->_true_name,
nest->_output << ends;
const char *generated_file = nest->_output.str();
if (!compare_output(generated_file, nest->_filename,
(nest->_flags & OF_notouch) != 0)) { (nest->_flags & OF_notouch) != 0)) {
return false; return false;
} }
free(nest->_tempnam);
}
} }
} }
@ -1646,56 +1622,68 @@ replay_formap(const string &varname, const string &mapvar) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PPCommandFile::compare_output // Function: PPCommandFile::compare_output
// Access: Protected // Access: Protected
// Description: After a temporary file has been written due to an // Description: After a file has been written to a (potentially
// #output command, compare the results to the original // large) string via an #output command, compare the
// file. If they are different, remove the original // results to the original file. If they are different,
// file and rename the temporary file; if they are the // remove the original file and replace it with the new
// same, remove the temporary file. // contents; otherwise, leave the original alone.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool PPCommandFile:: bool PPCommandFile::
compare_output(const string &temp_name, const string &true_name, compare_output(const string &new_contents, const string &filename,
bool notouch) { bool notouch) {
ifstream in_a(temp_name.c_str()); bool exists = (access(filename.c_str(), F_OK) == 0);
ifstream in_b(true_name.c_str()); bool differ = false;
int a = in_a.get(); if (exists) {
int b = in_b.get(); size_t len = new_contents.length();
bool differ = (a != b); size_t want_bytes = len + 1;
while (!in_a.eof() && !in_b.eof() && !differ) {
a = in_a.get();
b = in_b.get();
differ = (a != b);
}
in_a.close(); char *orig_contents = new char[want_bytes];
in_b.close(); ifstream in(filename.c_str());
in.read(orig_contents, want_bytes);
if (differ) { if (in.gcount() != len) {
cerr << "Generating " << true_name << "\n"; // The wrong number of bytes.
differ = true;
if (unlink(true_name.c_str()) < 0) {
cerr << "Unable to remove old " << true_name << "\n";
return false;
}
if (rename(temp_name.c_str(), true_name.c_str()) < 0) {
cerr << "Unable to rename temporary file " << temp_name
<< " to " << true_name << "\n";
return false;
}
} else { } else {
// cerr << "File " << true_name << " is unchanged.\n"; differ = !(new_contents == string(orig_contents, len));
if (unlink(temp_name.c_str()) < 0) {
cerr << "Warning: unable to remove temporary file " << temp_name << "\n";
} }
}
if (differ || !exists) {
cerr << "Generating " << filename << "\n";
if (exists) {
if (unlink(filename.c_str()) < 0) {
cerr << "Unable to remove old " << filename << "\n";
return false;
}
}
ofstream out_b(filename.c_str(), ios::out, 0666);
if (!out_b) {
cerr << "Unable to open file " << filename << " for writing.\n";
return false;
}
out_b.write(new_contents.data(), new_contents.length());
if (!out_b) {
cerr << "Unable to write to file " << filename << "\n";
return false;
}
out_b.close();
} else {
// cerr << "File " << filename << " is unchanged.\n";
// Even though the file is unchanged, unless the "notouch" flag is // Even though the file is unchanged, unless the "notouch" flag is
// set, we want to update the modification time. This helps the // set, we want to update the modification time. This helps the
// makefiles know we did something. // makefiles know we did something.
if (!notouch) { if (!notouch) {
if (utime(true_name.c_str(), (struct utimbuf *)NULL) < 0) { if (utime(filename.c_str(), (struct utimbuf *)NULL) < 0) {
cerr << "Warning: unable to touch " << true_name << "\n"; cerr << "Warning: unable to touch " << filename << "\n";
} }
} }
} }

View File

@ -68,7 +68,7 @@ protected:
bool replay_forscopes(const string &name); bool replay_forscopes(const string &name);
bool replay_foreach(const string &varname, const vector<string> &words); bool replay_foreach(const string &varname, const vector<string> &words);
bool replay_formap(const string &varname, const string &mapvar); bool replay_formap(const string &varname, const string &mapvar);
bool compare_output(const string &temp_name, const string &true_name, bool compare_output(const string &new_contents, const string &filename,
bool notouch); bool notouch);
bool failed_if() const; bool failed_if() const;
@ -153,9 +153,8 @@ private:
IfNesting *_if; IfNesting *_if;
WriteState *_write_state; WriteState *_write_state;
PPScope *_scope; PPScope *_scope;
string _true_name; string _filename;
char *_tempnam; ostrstream _output;
ofstream _output;
vector<string> _words; vector<string> _words;
int _flags; int _flags;
BlockNesting *_next; BlockNesting *_next;

View File

@ -2107,6 +2107,9 @@ expand_subst(const string &params) {
// Function: PPScope::expand_findstrnig // Function: PPScope::expand_findstrnig
// Access: Private // Access: Private
// Description: Expands the "findstring" function variable. // Description: Expands the "findstring" function variable.
// $[findstring a,b] returns b if and only if it is a
// substring of a; otherwise, it returns the empty
// string.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
string PPScope:: string PPScope::
expand_findstring(const string &params) { expand_findstring(const string &params) {