This also addresses the new bug 3659. Richard Heck wrote: > The attached patch partially addresses this bug. Not completely, because > it only checks if a file is including itself and not if a file includes > a file that includes it (etc). The places where the more general check > would need to be done are identified with FIXME RECURSIVE INPUT so that > this can be done later, but I don't have any sense what to do here, and > it's not a terribly common issue, so I'm not going to pursue it now. > > As for what to do about recursive includes, I'm issuing a warning when > there's an attempt to output LaTeX or Docbook and then ignoring the > inset. Something similar could be done at the other places, too, so that > the user would be alerted ASAP to the problem. But maybe that should > just be done when the more general fix is in place rather than littering > the code with this kind of warning. > > Comments welcome, as always. Seeking OK to commit. > > Richard > > > ------------------------------------------------------------------------ > > Index: Buffer.cpp > =================================================================== > --- Buffer.cpp (revision 18423) > +++ Buffer.cpp (working copy) > @@ -1621,7 +1621,10 @@ > if (!params().parentname.empty() > && theBufferList().exists(params().parentname)) { > Buffer const * buf = > theBufferList().getBuffer(params().parentname); > - if (buf) > + //We need to check if the parent is us... > + //FIXME RECURSIVE INCLUDE > + //This is not sufficient, since recursive includes could be > downstream. > + if (buf && buf != this) > return buf->getMasterBuffer(); > } > > Index: insets/InsetInclude.cpp > =================================================================== > --- insets/InsetInclude.cpp (revision 18423) > +++ insets/InsetInclude.cpp (working copy) > @@ -363,7 +363,12 @@ > if (!isLyXFilename(included_file)) > return 0; > > - return theBufferList().getBuffer(included_file); > + Buffer * childBuffer = theBufferList().getBuffer(included_file); > + > + //FIXME RECURSIVE INCLUDES > + if (childBuffer == & buffer) > + return 0; > + else return childBuffer; > } > > > @@ -405,6 +410,18 @@ > return 0; > > FileName const included_file(includedFilename(buffer, params_)); > + > + //Check we're not trying to include ourselves. > + //FIXME RECURSIVE INCLUDE > + //This isn't sufficient, as the inclusion could be downstream. > + //But it'll have to do for now. > + if (buffer.fileName() == included_file.toFilesystemEncoding()) { > + Alert::error(_("Recursive input"), > + > bformat(_("Attempted to include file %1$s in itself! " > + > "Ignoring inclusion."), from_utf8(incfile))); > + return 0; > + } > + > Buffer const * const m_buffer = buffer.getMasterBuffer(); > > // if incfile is relative, make it relative to the master > @@ -560,6 +577,17 @@ > > string const included_file = includedFilename(buffer, > params_).absFilename(); > > + //Check we're not trying to include ourselves. > + //FIXME RECURSIVE INCLUDE > + //This isn't sufficient, as the inclusion could be downstream. > + //But it'll have to do for now. > + if (buffer.fileName() == included_file.toFilesystemEncoding()) { > + Alert::error(_("Recursive input"), > + > bformat(_("Attempted to include file %1$s in itself! " > + > "Ignoring inclusion."), from_utf8(incfile))); > + return 0; > + } > + > // write it to a file (so far the complete file) > string const exportfile = changeExtension(incfile, ".sgml"); > DocFileName writefile(changeExtension(included_file, ".sgml")); > @@ -629,7 +657,11 @@ > if (loadIfNeeded(buffer, params_)) { > // a file got loaded > Buffer * const tmp = theBufferList().getBuffer(included_file); > - if (tmp) { > + // make sure the buffer isn't us > + // FIXME RECURSIVE INCLUDES > + // This is not sufficient, as recursive includes could be > + // more than a file away. But it will do for now. > + if (tmp && tmp != & buffer) { > // We must temporarily change features.buffer, > // otherwise it would always be the master buffer, > // and nested includes would not work. >
-- ================================================================== Richard G Heck, Jr Professor of Philosophy Brown University http://frege.brown.edu/heck/ ================================================================== Get my public key from http://sks.keyserver.penguin.de Hash: 0x1DE91F1E66FFBDEC Learn how to sign your email using Thunderbird and GnuPG at: http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto