I wrote: > Angus Leeming wrote: > >> The only problem is that multiply-included files might be copies >> several times. Solution: std::map<abs_filename, mangled_name>. > > We would need this anyway, because the mangled filename is queried more > than once for the same file. > > I am going to implement this unless somebody has a better idea.
Here it is (without the '#' in the filename). I tested it, and it works even for multiply-included files. If this is ok, could somebody please apply? I really hope I can go on with the fixes I actually wantend to do without discovering further problems. Georg
Index: src/support/ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/ChangeLog,v retrieving revision 1.238 diff -u -r1.238 ChangeLog --- src/support/ChangeLog 2004/02/25 12:00:53 1.238 +++ src/support/ChangeLog 2004/03/10 17:49:25 @@ -1,3 +1,8 @@ +2004-03-09 Georg Baum <[EMAIL PROTECTED]> + + * filename.[Ch] (mangledFilename): make sure that mangled names are + unique + 2004-02-21 Georg Baum <[EMAIL PROTECTED]> * filetools.[Ch] (CreateBufferTmpDir): rename to createBufferTmpDir, Index: src/support/filename.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/filename.C,v retrieving revision 1.7 diff -u -r1.7 filename.C --- src/support/filename.C 2003/10/06 15:43:17 1.7 +++ src/support/filename.C 2004/03/10 17:49:25 @@ -18,7 +18,11 @@ #include <boost/assert.hpp> +#include <map> +#include <sstream> + +using std::map; using std::string; @@ -65,6 +69,14 @@ string const FileName::mangledFilename() const { + // We need to make sure that every FileName instance for a given + // filename returns the same mangled name. + static map<string, string> mangledNames; + map<string, string>::const_iterator const it = mangledNames.find(name_); + if (it != mangledNames.end()) + return (*it).second; + + // Now the real work string mname = os::slashify_path(name_); // Remove the extension. mname = ChangeExtension(name_, string()); @@ -73,7 +85,15 @@ // Replace '.' in the file name with '_' mname = subst(mname, ".", "_"); // Add the extension back on - return ChangeExtension(mname, GetExtension(name_)); + mname = ChangeExtension(mname, GetExtension(name_)); + // Prepend a counter to the filename. This is necessary to make + // the mangled name unique. + static int counter = 0; + std::ostringstream s; + s << counter++; + mname = s.str() + mname; + mangledNames[name_] = mname; + return mname; } Index: src/support/filename.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/support/filename.h,v retrieving revision 1.7 diff -u -r1.7 filename.h --- src/support/filename.h 2004/02/25 12:00:53 1.7 +++ src/support/filename.h 2004/03/10 17:49:25 @@ -46,6 +46,10 @@ /** \return a mangled version of the absolute file name, * suitable for use in the temp dir when, for example, converting * an image file to another format. + * It is guaranteed that + * - two different filenames have different mangled names + * - two FileName instances with the same filename have identical + * mangled names */ std::string const mangledFilename() const;