+ LASSERT(parent, return false);
+ LASSERT(child, return false);
+ LASSERT(parent->isChild(child), return false);
+
+ // Does child document have a different parent?
+ Buffer const * parent_ = child->parent();
+ if (parent_ && parent_ != parent)
+ return true;
+
+ for(Buffer const * buf : bstore)
+ if (buf != parent && buf->isChild(child))
+ return true;
+ return false;
+}
+
+
+Buffer * BufferList::getBuffer(support::FileName const & fname, bool internal) const
+{
+ // 1) cheap test, using string comparison of file names
+ for (Buffer * b : bstore)
+ if (b->fileName() == fname)
+ return b;
+ // 2) possibly expensive test, using equivalence test of file names
+ for (Buffer * b : bstore)
+ if (equivalent(b->fileName(), fname))
+ return b;
+ if (internal) {
+ // 1) cheap test, using string comparison of file names
+ for (Buffer * b : binternal)
+ if (b->fileName() == fname)
+ return b;
+ // 2) possibly expensive test, using equivalence test of file names
+ for (Buffer * b : binternal)
+ if (equivalent(b->fileName(), fname))
+ return b;
+ }
+ return nullptr;
+}
+
+
+Buffer * BufferList::getBufferFromTmp(string const & s, bool realpath)
+{
+ for (Buffer * buf : bstore) {
+ string const temppath = realpath ? FileName(buf->temppath()).realPath() : buf->temppath();
+ if (prefixIs(s, temppath)) {
+ // check whether the filename matches the master
+ string const master_name = buf->latexName();
+ if (suffixIs(s, master_name))
+ return buf;
+ // if not, try with the children
+ for (Buffer * child : buf->getDescendants()) {
+ string const mangled_child_name = DocFileName(
+ changeExtension(child->absFileName(),
+ ".tex")).mangledFileName();
+ if (suffixIs(s, mangled_child_name))
+ return child;
+ }
+ }
+ }
+ return nullptr;