From: Richard Kimberly Heck Date: Sat, 25 Apr 2020 21:34:27 +0000 (-0400) Subject: Buffer methods for dealing with recursive includes. X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=470f0e35a33315721b5e98059f0b5f73157f7ca5;p=features.git Buffer methods for dealing with recursive includes. --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 4be7e21197..ebb302f3ec 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -297,6 +297,8 @@ public: /// CloneList_ptr clone_list_; + /// + std::list include_list_; private: /// So we can force access via the accessors. mutable Buffer const * parent_buffer; @@ -5591,4 +5593,55 @@ void Buffer::clearExternalModification() const } +void Buffer::pushIncludedBuffer(Buffer const * buf) const +{ + masterBuffer()->d->include_list_.push_back(buf); + if (lyxerr.debugging(Debug::FILES)) { + LYXERR0("Pushed. Stack now:"); + if (masterBuffer()->d->include_list_.empty()) + LYXERR0("EMPTY!"); + else + for (auto const & b : masterBuffer()->d->include_list_) + LYXERR0(b->fileName()); + } +} + + +void Buffer::popIncludedBuffer() const +{ + masterBuffer()->d->include_list_.pop_back(); + if (lyxerr.debugging(Debug::FILES)) { + LYXERR0("Popped. Stack now:"); + if (masterBuffer()->d->include_list_.empty()) + LYXERR0("EMPTY!"); + else + for (auto const & b : masterBuffer()->d->include_list_) + LYXERR0(b->fileName()); + } +} + + +bool Buffer::isBufferIncluded(Buffer const * buf) const +{ + if (!buf) + return false; + if (lyxerr.debugging(Debug::FILES)) { + LYXERR0("Checking for " << buf->fileName() << ". Stack now:"); + if (masterBuffer()->d->include_list_.empty()) + LYXERR0("EMPTY!"); + else + for (auto const & b : masterBuffer()->d->include_list_) + LYXERR0(b->fileName()); + } + list const & blist = masterBuffer()->d->include_list_; + return find(blist.begin(), blist.end(), buf) != blist.end(); +} + + +void Buffer::clearIncludeList() const +{ + LYXERR(Debug::FILES, "Clearing include list for " << fileName()); + d->include_list_.clear(); +} + } // namespace lyx diff --git a/src/Buffer.h b/src/Buffer.h index e717e463bd..8eb6e06494 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -783,6 +783,13 @@ public: /// support::FileName getBibfilePath(docstring const & bibid) const; + /// routines for dealing with possible self-inclusion + void pushIncludedBuffer(Buffer const * buf) const; + void popIncludedBuffer() const; + bool isBufferIncluded(Buffer const * buf) const; +private: + void clearIncludeList() const; + private: friend class MarkAsExporting; /// mark the buffer as busy exporting something, or not