3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
15 #include "buffer_funcs.h"
16 #include "bufferlist.h"
19 #include "errorlist.h"
23 #include "iterators.h"
26 #include "LaTeXFeatures.h"
27 #include "LyXAction.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
37 #include "insets/insetbibitem.h"
38 #include "insets/insetbibtex.h"
39 #include "insets/insetinclude.h"
40 #include "insets/insettext.h"
42 #include "frontends/Alert.h"
44 #include "graphics/Previews.h"
46 #include "support/FileInfo.h"
47 #include "support/filetools.h"
48 #include "support/gzstream.h"
49 #include "support/LAssert.h"
50 #include "support/lyxlib.h"
51 #include "support/os.h"
52 #include "support/path.h"
53 #include "support/textutils.h"
54 #include "support/tostr.h"
56 #include <boost/bind.hpp>
57 #include <boost/tuple/tuple.hpp>
59 #include "support/std_sstream.h"
69 using namespace lyx::support;
71 #ifndef CXX_GLOBAL_CSTD
76 using std::ostringstream;
92 using lyx::textclass_type;
94 // all these externs should eventually be removed.
95 extern BufferList bufferlist;
99 const int LYX_FORMAT = 225;
101 bool openFileWrite(ofstream & ofs, string const & fname)
103 ofs.open(fname.c_str());
105 string const file = MakeDisplayPath(fname, 50);
106 string text = bformat(_("Could not open the specified "
107 "document\n%1$s."), file);
108 Alert::error(_("Could not open file"), text);
117 Buffer::Buffer(string const & file, bool ronly)
118 : niceFile(true), lyx_clean(true), bak_clean(true),
119 unnamed(false), read_only(ronly),
122 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
123 filepath_ = OnlyPath(file);
125 if (read_only || lyxrc.use_tempdir) {
126 tmppath = CreateBufferTmpDir();
131 // set initial author
132 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
138 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
139 // here the buffer should take care that it is
140 // saved properly, before it goes into the void.
144 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
145 Alert::warning(_("Could not remove temporary directory"),
146 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
151 // Remove any previewed LaTeX snippets associated with this buffer.
152 lyx::graphics::Previews::get().removeLoader(*this);
156 string const Buffer::getLatexName(bool no_path) const
158 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
159 return no_path ? OnlyFilename(name) : name;
163 pair<Buffer::LogType, string> const Buffer::getLogName() const
165 string const filename = getLatexName(false);
167 if (filename.empty())
168 return make_pair(Buffer::latexlog, string());
170 string path = OnlyPath(filename);
172 if (lyxrc.use_tempdir || !IsDirWriteable(path))
175 string const fname = AddName(path,
176 OnlyFilename(ChangeExtension(filename,
179 AddName(path, OnlyFilename(
180 ChangeExtension(filename,
181 formats.extension("literate") + ".out")));
183 // If no Latex log or Build log is newer, show Build log
185 FileInfo const f_fi(fname);
186 FileInfo const b_fi(bname);
189 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
190 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
191 return make_pair(Buffer::buildlog, bname);
193 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
194 return make_pair(Buffer::latexlog, fname);
198 void Buffer::setReadonly(bool flag)
200 if (read_only != flag) {
207 AuthorList & Buffer::authors()
209 return params.authorlist;
213 void Buffer::setFileName(string const & newfile)
215 filename_ = MakeAbsPath(newfile);
216 filepath_ = OnlyPath(filename_);
217 setReadonly(IsFileWriteable(filename_) == 0);
222 // We'll remove this later. (Lgb)
225 void unknownClass(string const & unknown)
227 Alert::warning(_("Unknown document class"),
228 bformat(_("Using the default document class, because the "
229 "class %1$s is unknown."), unknown));
234 int Buffer::readHeader(LyXLex & lex)
236 int unknown_tokens = 0;
240 string const token = lex.getString();
245 if (token == "\\end_header")
248 lyxerr[Debug::PARSER] << "Handling header token: `"
249 << token << '\'' << endl;
252 string unknown = params.readToken(lex, token);
253 if (!unknown.empty()) {
254 if (unknown[0] != '\\') {
255 unknownClass(unknown);
258 string const s = bformat(_("Unknown token: "
262 error(ErrorItem(_("Header error"), s,
267 return unknown_tokens;
271 // candidate for move to BufferView
272 // (at least some parts in the beginning of the func)
275 // changed to be public and have one parameter
276 // if par = 0 normal behavior
277 // else insert behavior
278 // Returns false if "\end_document" is not read (Asger)
279 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
281 Paragraph::depth_type depth = 0;
282 bool the_end_read = false;
284 if (paragraphs.empty()) {
286 if (!params.getLyXTextClass().load()) {
287 string theclass = params.getLyXTextClass().name();
288 Alert::error(_("Can't load document class"), bformat(
289 "Using the default document class, because the "
290 " class %1$s could not be loaded.", theclass));
291 params.textclass = 0;
294 // We don't want to adopt the parameters from the
295 // document we insert, so read them into a temporary buffer
296 // and then discard it
298 Buffer tmpbuf("", false);
299 tmpbuf.readHeader(lex);
304 string const token = lex.getString();
309 lyxerr[Debug::PARSER] << "Handling token: `"
310 << token << '\'' << endl;
312 if (token == "\\end_document") {
317 readParagraph(lex, token, paragraphs, pit, depth);
324 int Buffer::readParagraph(LyXLex & lex, string const & token,
325 ParagraphList & pars, ParagraphList::iterator & pit,
326 Paragraph::depth_type & depth)
328 static Change current_change;
331 if (token == "\\begin_layout") {
332 lex.pushToken(token);
335 par.params().depth(depth);
336 if (params.tracking_changes)
338 LyXFont f(LyXFont::ALL_INHERIT, params.language);
342 if (pit != pars.end())
345 pit = pars.insert(pit, par);
347 // FIXME: goddamn InsetTabular makes us pass a Buffer
349 ::readParagraph(*this, *pit, lex);
351 } else if (token == "\\begin_deeper") {
353 } else if (token == "\\end_deeper") {
355 lex.printError("\\end_deeper: " "depth is already null");
366 // needed to insert the selection
367 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
368 LyXFont const & fn,string const & str)
370 LyXLayout_ptr const & layout = par->layout();
374 par->checkInsertChar(font);
375 // insert the string, don't insert doublespace
376 bool space_inserted = true;
377 bool autobreakrows = !par->inInset() ||
378 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
379 for(string::const_iterator cit = str.begin();
380 cit != str.end(); ++cit) {
382 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
383 breakParagraph(params, paragraphs, par, pos,
384 layout->isEnvironment());
387 space_inserted = true;
391 // do not insert consecutive spaces if !free_spacing
392 } else if ((*cit == ' ' || *cit == '\t') &&
393 space_inserted && !par->isFreeSpacing()) {
395 } else if (*cit == '\t') {
396 if (!par->isFreeSpacing()) {
397 // tabs are like spaces here
398 par->insertChar(pos, ' ', font);
400 space_inserted = true;
402 const pos_type nb = 8 - pos % 8;
403 for (pos_type a = 0; a < nb ; ++a) {
404 par->insertChar(pos, ' ', font);
407 space_inserted = true;
409 } else if (!IsPrintable(*cit)) {
410 // Ignore unprintables
413 // just insert the character
414 par->insertChar(pos, *cit, font);
416 space_inserted = (*cit == ' ');
423 bool Buffer::readFile(string const & filename)
425 // Check if the file is compressed.
426 string const format = getExtFromContents(filename);
427 if (format == "gzip" || format == "zip" || format == "compress") {
428 params.compressed = true;
431 bool ret = readFile(filename, paragraphs.begin());
433 // After we have read a file, we must ensure that the buffer
434 // language is set and used in the gui.
435 // If you know of a better place to put this, please tell me. (Lgb)
436 updateDocLang(params.language);
442 bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
445 lex.setFile(filename);
447 return readFile(lex, filename, pit);
451 bool Buffer::readFile(LyXLex & lex, string const & filename,
452 ParagraphList::iterator pit)
454 Assert(!filename.empty());
457 Alert::error(_("Document could not be read"),
458 bformat(_("%1$s could not be read."), filename));
463 string const token(lex.getString());
466 Alert::error(_("Document could not be read"),
467 bformat(_("%1$s could not be read."), filename));
471 // the first token _must_ be...
472 if (token != "\\lyxformat") {
473 lyxerr << "Token: " << token << endl;
475 Alert::error(_("Document format failure"),
476 bformat(_("%1$s is not a LyX document."),
482 string tmp_format = lex.getString();
483 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
484 // if present remove ".," from string.
485 string::size_type dot = tmp_format.find_first_of(".,");
486 //lyxerr << " dot found at " << dot << endl;
487 if (dot != string::npos)
488 tmp_format.erase(dot, 1);
489 int file_format = strToInt(tmp_format);
490 //lyxerr << "format: " << file_format << endl;
492 if (file_format > LYX_FORMAT) {
493 Alert::warning(_("Document format failure"),
494 bformat(_("%1$s was created with a newer"
495 " version of LyX. This is likely to"
498 } else if (file_format < LYX_FORMAT) {
499 string const tmpfile = tempName();
500 string command = LibFileSearch("lyx2lyx", "lyx2lyx");
501 if (command.empty()) {
502 Alert::error(_("Conversion script not found"),
503 bformat(_("%1$s is from an earlier"
504 " version of LyX, but the"
505 " conversion script lyx2lyx"
506 " could not be found."),
512 + " -o " + tmpfile + ' '
513 + QuoteName(filename);
514 lyxerr[Debug::INFO] << "Running '"
517 cmd_ret const ret = RunCommand(command);
518 if (ret.first != 0) {
519 Alert::error(_("Conversion script failed"),
520 bformat(_("%1$s is from an earlier version"
521 " of LyX, but the lyx2lyx script"
522 " failed to convert it."),
526 bool ret = readFile(tmpfile, pit);
527 // Do stuff with tmpfile name and buffer name here.
533 bool the_end = readBody(lex, pit);
534 params.setPaperStuff();
537 Alert::error(_("Document format failure"),
538 bformat(_("%1$s ended unexpectedly, which means"
539 " that it is probably corrupted."),
546 // Should probably be moved to somewhere else: BufferView? LyXView?
547 bool Buffer::save() const
549 // We don't need autosaves in the immediate future. (Asger)
550 resetAutosaveTimers();
554 if (lyxrc.make_backup) {
555 s = fileName() + '~';
556 if (!lyxrc.backupdir_path.empty())
557 s = AddName(lyxrc.backupdir_path,
558 subst(os::slashify_path(s),'/','!'));
560 // Rename is the wrong way of making a backup,
561 // this is the correct way.
562 /* truss cp fil fil2:
563 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
564 stat("LyXVC.lyx", 0xEFFFF688) = 0
565 open("LyXVC.lyx", O_RDONLY) = 3
566 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
567 fstat(4, 0xEFFFF508) = 0
568 fstat(3, 0xEFFFF508) = 0
569 read(3, " # T h i s f i l e w".., 8192) = 5579
570 write(4, " # T h i s f i l e w".., 5579) = 5579
571 read(3, 0xEFFFD4A0, 8192) = 0
574 chmod("LyXVC3.lyx", 0100644) = 0
575 lseek(0, 0, SEEK_CUR) = 46440
579 // Should probably have some more error checking here.
580 // Doing it this way, also makes the inodes stay the same.
581 // This is still not a very good solution, in particular we
582 // might loose the owner of the backup.
583 FileInfo finfo(fileName());
585 mode_t fmode = finfo.getMode();
586 struct utimbuf times = {
587 finfo.getAccessTime(),
588 finfo.getModificationTime() };
590 ifstream ifs(fileName().c_str());
591 ofstream ofs(s.c_str(), ios::out|ios::trunc);
596 ::chmod(s.c_str(), fmode);
598 if (::utime(s.c_str(), ×)) {
599 lyxerr << "utime error." << endl;
602 lyxerr << "LyX was not able to make "
603 "backup copy. Beware." << endl;
608 if (writeFile(fileName())) {
610 removeAutosaveFile(fileName());
612 // Saving failed, so backup is not backup
613 if (lyxrc.make_backup) {
614 rename(s, fileName());
622 bool Buffer::writeFile(string const & fname) const
624 if (read_only && (fname == fileName())) {
628 FileInfo finfo(fname);
629 if (finfo.exist() && !finfo.writable()) {
635 if (params.compressed) {
636 gz::ogzstream ofs(fname.c_str());
641 retval = do_writeFile(ofs);
644 ofstream ofs(fname.c_str());
648 retval = do_writeFile(ofs);
655 bool Buffer::do_writeFile(ostream & ofs) const
659 // Use the standard "C" locale for file output.
660 ofs.imbue(std::locale::classic());
663 // The top of the file should not be written by params.
665 // write out a comment in the top of the file
666 ofs << "#LyX " << lyx_version
667 << " created this file. For more info see http://www.lyx.org/\n"
668 << "\\lyxformat " << LYX_FORMAT << "\n";
670 // now write out the buffer paramters.
671 params.writeFile(ofs);
673 ofs << "\\end_header\n";
675 Paragraph::depth_type depth = 0;
677 // this will write out all the paragraphs
678 // using recursive descent.
679 ParagraphList::const_iterator pit = paragraphs.begin();
680 ParagraphList::const_iterator pend = paragraphs.end();
681 for (; pit != pend; ++pit)
682 pit->write(*this, ofs, params, depth);
684 // Write marker that shows file is complete
685 ofs << "\n\\end_document" << endl;
687 // Shouldn't really be needed....
690 // how to check if close went ok?
691 // Following is an attempt... (BE 20001011)
693 // good() returns false if any error occured, including some
695 // bad() returns true if something bad happened in the buffer,
696 // which should include file system full errors.
703 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
705 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
717 pair<int, string> const addDepth(int depth, int ldepth)
721 d += (ldepth - depth) * 2;
722 return make_pair(d, string(d, ' '));
728 string const Buffer::asciiParagraph(Paragraph const & par,
729 unsigned int linelen,
730 bool noparbreak) const
732 ostringstream buffer;
734 Paragraph::depth_type ltype_depth = 0;
735 bool ref_printed = false;
736 Paragraph::depth_type depth = par.params().depth();
738 // First write the layout
739 string const & tmp = par.layout()->name();
740 if (compare_no_case(tmp, "itemize") == 0) {
742 ltype_depth = depth + 1;
743 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
745 ltype_depth = depth + 1;
746 } else if (contains(ascii_lowercase(tmp), "ection")) {
748 ltype_depth = depth + 1;
749 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
751 ltype_depth = depth + 1;
752 } else if (compare_ascii_no_case(tmp, "description") == 0) {
754 ltype_depth = depth + 1;
755 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
758 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
766 /* maybe some vertical spaces */
768 /* the labelwidthstring used in lists */
772 /* some pagebreaks? */
776 /* what about the alignment */
778 // linelen <= 0 is special and means we don't have paragraph breaks
780 string::size_type currlinelen = 0;
786 buffer << string(depth * 2, ' ');
787 currlinelen += depth * 2;
790 // we should probably change to the paragraph language in the
791 // gettext here (if possible) so that strings are outputted in
792 // the correct language! (20012712 Jug)
796 case 4: // (Sub)Paragraph
797 case 5: // Description
801 buffer << _("Abstract") << "\n\n";
804 string const abst = _("Abstract: ");
806 currlinelen += abst.length();
809 case 7: // Bibliography
812 buffer << _("References") << "\n\n";
815 string const refs = _("References: ");
817 currlinelen += refs.length();
825 string const parlab = par.params().labelString();
826 buffer << parlab << ' ';
827 currlinelen += parlab.length() + 1;
835 pair<int, string> p = addDepth(depth, ltype_depth);
837 currlinelen += p.first;
840 // this is to change the linebreak to do it by word a bit more
841 // intelligent hopefully! (only in the case where we have a
842 // max linelength!) (Jug)
846 for (pos_type i = 0; i < par.size(); ++i) {
847 char c = par.getUChar(params, i);
849 case Paragraph::META_INSET:
851 InsetOld const * inset = par.getInset(i);
855 currlinelen += word.length();
858 if (inset->ascii(*this, buffer, linelen)) {
859 // to be sure it breaks paragraph
860 currlinelen += linelen;
869 currlinelen + word.length() > linelen - 10) {
871 pair<int, string> p = addDepth(depth, ltype_depth);
873 currlinelen = p.first;
876 buffer << word << ' ';
877 currlinelen += word.length() + 1;
884 lyxerr[Debug::INFO] <<
885 "writeAsciiFile: NULL char in structure." << endl;
888 (currlinelen + word.length()) > linelen)
892 pair<int, string> p =
893 addDepth(depth, ltype_depth);
895 currlinelen = p.first;
902 return STRCONV(buffer.str());
906 void Buffer::writeFileAscii(string const & fname, int linelen)
909 if (!::openFileWrite(ofs, fname))
911 writeFileAscii(ofs, linelen);
915 void Buffer::writeFileAscii(ostream & os, int linelen)
917 ParagraphList::iterator beg = paragraphs.begin();
918 ParagraphList::iterator end = paragraphs.end();
919 ParagraphList::iterator it = beg;
920 for (; it != end; ++it) {
921 os << asciiParagraph(*it, linelen, it == beg);
927 void Buffer::makeLaTeXFile(string const & fname,
928 string const & original_path,
929 LatexRunParams const & runparams,
930 bool output_preamble, bool output_body)
932 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
935 if (!::openFileWrite(ofs, fname))
938 makeLaTeXFile(ofs, original_path,
939 runparams, output_preamble, output_body);
943 lyxerr << "File was not closed properly." << endl;
948 void Buffer::makeLaTeXFile(ostream & os,
949 string const & original_path,
950 LatexRunParams const & runparams_in,
951 bool output_preamble, bool output_body)
953 LatexRunParams runparams = runparams_in;
954 niceFile = runparams.nice; // this will be used by Insetincludes.
956 // validate the buffer.
957 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
958 LaTeXFeatures features(params);
960 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
963 // The starting paragraph of the coming rows is the
964 // first paragraph of the document. (Asger)
965 texrow.start(paragraphs.begin()->id(), 0);
967 if (output_preamble && runparams.nice) {
968 os << "%% LyX " << lyx_version << " created this file. "
969 "For more info, see http://www.lyx.org/.\n"
970 "%% Do not edit unless you really know what "
975 lyxerr[Debug::INFO] << "lyx header finished" << endl;
976 // There are a few differences between nice LaTeX and usual files:
977 // usual is \batchmode and has a
978 // special input@path to allow the including of figures
979 // with either \input or \includegraphics (what figinsets do).
980 // input@path is set when the actual parameter
981 // original_path is set. This is done for usual tex-file, but not
982 // for nice-latex-file. (Matthias 250696)
983 if (output_preamble) {
984 if (!runparams.nice) {
985 // code for usual, NOT nice-latex-file
986 os << "\\batchmode\n"; // changed
990 if (!original_path.empty()) {
991 string inputpath = os::external_path(original_path);
992 subst(inputpath, "~", "\\string~");
993 os << "\\makeatletter\n"
994 << "\\def\\input@path{{"
995 << inputpath << "/}}\n"
996 << "\\makeatother\n";
1002 // Write the preamble
1003 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1009 os << "\\begin{document}\n";
1011 } // output_preamble
1012 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1014 if (!lyxrc.language_auto_begin) {
1015 os << subst(lyxrc.language_command_begin, "$$lang",
1016 params.language->babel())
1021 latexParagraphs(*this, paragraphs, os, texrow, runparams);
1023 // add this just in case after all the paragraphs
1027 if (!lyxrc.language_auto_end) {
1028 os << subst(lyxrc.language_command_end, "$$lang",
1029 params.language->babel())
1034 if (output_preamble) {
1035 os << "\\end{document}\n";
1038 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1040 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1044 // Just to be sure. (Asger)
1047 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1048 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1051 // we want this to be true outside previews (for insetexternal)
1056 bool Buffer::isLatex() const
1058 return params.getLyXTextClass().outputType() == LATEX;
1062 bool Buffer::isLinuxDoc() const
1064 return params.getLyXTextClass().outputType() == LINUXDOC;
1068 bool Buffer::isLiterate() const
1070 return params.getLyXTextClass().outputType() == LITERATE;
1074 bool Buffer::isDocBook() const
1076 return params.getLyXTextClass().outputType() == DOCBOOK;
1080 bool Buffer::isSGML() const
1082 LyXTextClass const & tclass = params.getLyXTextClass();
1084 return tclass.outputType() == LINUXDOC ||
1085 tclass.outputType() == DOCBOOK;
1089 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1092 if (!::openFileWrite(ofs, fname))
1095 niceFile = nice; // this will be used by included files.
1097 LaTeXFeatures features(params);
1103 LyXTextClass const & tclass = params.getLyXTextClass();
1105 string top_element = tclass.latexname();
1108 ofs << "<!doctype linuxdoc system";
1110 string preamble = params.preamble;
1111 string const name = nice ? ChangeExtension(filename_, ".sgml")
1113 preamble += features.getIncludedFiles(name);
1114 preamble += features.getLyXSGMLEntities();
1116 if (!preamble.empty()) {
1117 ofs << " [ " << preamble << " ]";
1121 if (params.options.empty())
1122 sgml::openTag(ofs, 0, false, top_element);
1124 string top = top_element;
1126 top += params.options;
1127 sgml::openTag(ofs, 0, false, top);
1131 ofs << "<!-- LyX " << lyx_version
1132 << " created this file. For more info see http://www.lyx.org/"
1135 Paragraph::depth_type depth = 0; // paragraph depth
1137 vector<string> environment_stack(5);
1139 ParagraphList::iterator pit = paragraphs.begin();
1140 ParagraphList::iterator pend = paragraphs.end();
1141 for (; pit != pend; ++pit) {
1142 LyXLayout_ptr const & style = pit->layout();
1143 // treat <toc> as a special case for compatibility with old code
1144 if (pit->isInset(0)) {
1145 InsetOld * inset = pit->getInset(0);
1146 InsetOld::Code lyx_code = inset->lyxCode();
1147 if (lyx_code == InsetOld::TOC_CODE) {
1148 string const temp = "toc";
1149 sgml::openTag(ofs, depth, false, temp);
1154 // environment tag closing
1155 for (; depth > pit->params().depth(); --depth) {
1156 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1157 environment_stack[depth].erase();
1160 // write opening SGML tags
1161 switch (style->latextype) {
1162 case LATEX_PARAGRAPH:
1163 if (depth == pit->params().depth()
1164 && !environment_stack[depth].empty()) {
1165 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1166 environment_stack[depth].erase();
1172 sgml::openTag(ofs, depth, false, style->latexname());
1177 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1179 if (!environment_stack[depth].empty()) {
1180 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1184 environment_stack[depth].erase();
1185 sgml::openTag(ofs, depth, false, style->latexname());
1188 case LATEX_ENVIRONMENT:
1189 case LATEX_ITEM_ENVIRONMENT:
1190 case LATEX_BIB_ENVIRONMENT:
1192 string const & latexname = style->latexname();
1194 if (depth == pit->params().depth()
1195 && environment_stack[depth] != latexname) {
1196 sgml::closeTag(ofs, depth, false,
1197 environment_stack[depth]);
1198 environment_stack[depth].erase();
1200 if (depth < pit->params().depth()) {
1201 depth = pit->params().depth();
1202 environment_stack[depth].erase();
1204 if (environment_stack[depth] != latexname) {
1206 sgml::openTag(ofs, depth, false, "p");
1208 sgml::openTag(ofs, depth, false, latexname);
1210 if (environment_stack.size() == depth + 1)
1211 environment_stack.push_back("!-- --");
1212 environment_stack[depth] = latexname;
1215 if (style->latexparam() == "CDATA")
1218 if (style->latextype == LATEX_ENVIRONMENT) break;
1220 if (style->labeltype == LABEL_MANUAL)
1225 sgml::openTag(ofs, depth + 1, false, item_name);
1230 sgml::openTag(ofs, depth, false, style->latexname());
1234 simpleLinuxDocOnePar(ofs, pit, depth);
1237 // write closing SGML tags
1238 switch (style->latextype) {
1241 case LATEX_ENVIRONMENT:
1242 case LATEX_ITEM_ENVIRONMENT:
1243 case LATEX_BIB_ENVIRONMENT:
1244 if (style->latexparam() == "CDATA")
1248 sgml::closeTag(ofs, depth, false, style->latexname());
1254 for (int i = depth; i >= 0; --i)
1255 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1259 sgml::closeTag(ofs, 0, false, top_element);
1263 // How to check for successful close
1265 // we want this to be true outside previews (for insetexternal)
1270 // checks, if newcol chars should be put into this line
1271 // writes newline, if necessary.
1274 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1275 string::size_type newcol)
1278 if (colcount > lyxrc.ascii_linelen) {
1280 colcount = newcol; // assume write after this call
1295 string tag_name(PAR_TAG const & pt) {
1297 case NONE: return "!-- --";
1298 case TT: return "tt";
1299 case SF: return "sf";
1300 case BF: return "bf";
1301 case IT: return "it";
1302 case SL: return "sl";
1303 case EM: return "em";
1310 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1312 p1 = static_cast<PAR_TAG>(p1 | p2);
1317 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1319 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1325 // Handle internal paragraph parsing -- layout already processed.
1326 void Buffer::simpleLinuxDocOnePar(ostream & os,
1327 ParagraphList::iterator par,
1328 Paragraph::depth_type /*depth*/) const
1330 LyXLayout_ptr const & style = par->layout();
1332 string::size_type char_line_count = 5; // Heuristic choice ;-)
1334 // gets paragraph main font
1337 if (style->labeltype == LABEL_MANUAL) {
1338 font_old = style->labelfont;
1341 font_old = style->font;
1345 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1346 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1347 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1350 stack<PAR_TAG> tag_state;
1351 // parsing main loop
1352 for (pos_type i = 0; i < par->size(); ++i) {
1354 PAR_TAG tag_close = NONE;
1355 list < PAR_TAG > tag_open;
1357 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1359 if (font_old.family() != font.family()) {
1360 switch (family_type) {
1361 case LyXFont::SANS_FAMILY:
1364 case LyXFont::TYPEWRITER_FAMILY:
1371 family_type = font.family();
1373 switch (family_type) {
1374 case LyXFont::SANS_FAMILY:
1375 tag_open.push_back(SF);
1377 case LyXFont::TYPEWRITER_FAMILY:
1378 tag_open.push_back(TT);
1385 if (font_old.series() != font.series()) {
1386 switch (series_type) {
1387 case LyXFont::BOLD_SERIES:
1394 series_type = font.series();
1396 switch (series_type) {
1397 case LyXFont::BOLD_SERIES:
1398 tag_open.push_back(BF);
1406 if (font_old.shape() != font.shape()) {
1407 switch (shape_type) {
1408 case LyXFont::ITALIC_SHAPE:
1411 case LyXFont::SLANTED_SHAPE:
1418 shape_type = font.shape();
1420 switch (shape_type) {
1421 case LyXFont::ITALIC_SHAPE:
1422 tag_open.push_back(IT);
1424 case LyXFont::SLANTED_SHAPE:
1425 tag_open.push_back(SL);
1432 if (font_old.emph() != font.emph()) {
1433 if (font.emph() == LyXFont::ON) {
1434 tag_open.push_back(EM);
1443 list < PAR_TAG > temp;
1444 while (!tag_state.empty() && tag_close) {
1445 PAR_TAG k = tag_state.top();
1447 os << "</" << tag_name(k) << '>';
1454 for(list< PAR_TAG >::const_iterator j = temp.begin();
1455 j != temp.end(); ++j) {
1457 os << '<' << tag_name(*j) << '>';
1460 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1461 j != tag_open.end(); ++j) {
1463 os << '<' << tag_name(*j) << '>';
1466 char c = par->getChar(i);
1468 if (c == Paragraph::META_INSET) {
1469 InsetOld * inset = par->getInset(i);
1470 inset->linuxdoc(*this, os);
1475 if (style->latexparam() == "CDATA") {
1476 // "TeX"-Mode on == > SGML-Mode on.
1483 boost::tie(ws, str) = sgml::escapeChar(c);
1484 if (ws && !par->isFreeSpacing()) {
1485 // in freespacing mode, spaces are
1486 // non-breaking characters
1487 if (desc_on) {// if char is ' ' then...
1490 sgmlLineBreak(os, char_line_count, 6);
1494 sgmlLineBreak(os, char_line_count, 1);
1499 char_line_count += str.length();
1505 while (!tag_state.empty()) {
1506 os << "</" << tag_name(tag_state.top()) << '>';
1510 // resets description flag correctly
1512 // <tag> not closed...
1513 sgmlLineBreak(os, char_line_count, 6);
1519 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1522 if (!::openFileWrite(ofs, fname))
1525 niceFile = nice; // this will be used by Insetincludes.
1527 LaTeXFeatures features(params);
1532 LyXTextClass const & tclass = params.getLyXTextClass();
1533 string top_element = tclass.latexname();
1536 ofs << "<!DOCTYPE " << top_element
1537 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1539 string preamble = params.preamble;
1540 string const name = nice ? ChangeExtension(filename_, ".sgml")
1542 preamble += features.getIncludedFiles(name);
1543 preamble += features.getLyXSGMLEntities();
1545 if (!preamble.empty()) {
1546 ofs << "\n [ " << preamble << " ]";
1551 string top = top_element;
1553 top += params.language->code();
1556 if (!params.options.empty()) {
1558 top += params.options;
1560 sgml::openTag(ofs, 0, false, top);
1562 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1563 << "\n See http://www.lyx.org/ for more information -->\n";
1565 vector<string> environment_stack(10);
1566 vector<string> environment_inner(10);
1567 vector<string> command_stack(10);
1569 bool command_flag = false;
1570 Paragraph::depth_type command_depth = 0;
1571 Paragraph::depth_type command_base = 0;
1572 Paragraph::depth_type cmd_depth = 0;
1573 Paragraph::depth_type depth = 0; // paragraph depth
1576 string command_name;
1578 ParagraphList::iterator par = paragraphs.begin();
1579 ParagraphList::iterator pend = paragraphs.end();
1581 for (; par != pend; ++par) {
1585 int desc_on = 0; // description mode
1587 LyXLayout_ptr const & style = par->layout();
1589 // environment tag closing
1590 for (; depth > par->params().depth(); --depth) {
1591 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1592 item_name = "listitem";
1593 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1594 if (environment_inner[depth] == "varlistentry")
1595 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1597 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1598 environment_stack[depth].erase();
1599 environment_inner[depth].erase();
1602 if (depth == par->params().depth()
1603 && environment_stack[depth] != style->latexname()
1604 && !environment_stack[depth].empty()) {
1605 if (environment_inner[depth] != "!-- --") {
1606 item_name= "listitem";
1607 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1608 if (environment_inner[depth] == "varlistentry")
1609 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1612 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1614 environment_stack[depth].erase();
1615 environment_inner[depth].erase();
1618 // Write opening SGML tags.
1619 switch (style->latextype) {
1620 case LATEX_PARAGRAPH:
1621 sgml::openTag(ofs, depth + command_depth,
1622 false, style->latexname());
1627 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1629 command_name = style->latexname();
1631 sgmlparam = style->latexparam();
1632 c_params = split(sgmlparam, c_depth,'|');
1634 cmd_depth = atoi(c_depth);
1637 if (cmd_depth < command_base) {
1638 for (Paragraph::depth_type j = command_depth;
1639 j >= command_base; --j) {
1640 sgml::closeTag(ofs, j, false, command_stack[j]);
1643 command_depth = command_base = cmd_depth;
1644 } else if (cmd_depth <= command_depth) {
1645 for (int j = command_depth;
1646 j >= int(cmd_depth); --j) {
1647 sgml::closeTag(ofs, j, false, command_stack[j]);
1650 command_depth = cmd_depth;
1652 command_depth = cmd_depth;
1654 command_depth = command_base = cmd_depth;
1655 command_flag = true;
1657 if (command_stack.size() == command_depth + 1)
1658 command_stack.push_back(string());
1659 command_stack[command_depth] = command_name;
1661 // treat label as a special case for
1662 // more WYSIWYM handling.
1663 // This is a hack while paragraphs can't have
1664 // attributes, like id in this case.
1665 if (par->isInset(0)) {
1666 InsetOld * inset = par->getInset(0);
1667 InsetOld::Code lyx_code = inset->lyxCode();
1668 if (lyx_code == InsetOld::LABEL_CODE) {
1669 command_name += " id=\"";
1670 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1671 command_name += '"';
1676 sgml::openTag(ofs, depth + command_depth, false, command_name);
1678 item_name = c_params.empty() ? "title" : c_params;
1679 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1682 case LATEX_ENVIRONMENT:
1683 case LATEX_ITEM_ENVIRONMENT:
1684 if (depth < par->params().depth()) {
1685 depth = par->params().depth();
1686 environment_stack[depth].erase();
1689 if (environment_stack[depth] != style->latexname()) {
1690 if (environment_stack.size() == depth + 1) {
1691 environment_stack.push_back("!-- --");
1692 environment_inner.push_back("!-- --");
1694 environment_stack[depth] = style->latexname();
1695 environment_inner[depth] = "!-- --";
1696 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1698 if (environment_inner[depth] != "!-- --") {
1699 item_name= "listitem";
1700 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1701 if (environment_inner[depth] == "varlistentry")
1702 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1706 if (style->latextype == LATEX_ENVIRONMENT) {
1707 if (!style->latexparam().empty()) {
1708 if (style->latexparam() == "CDATA")
1711 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1716 desc_on = (style->labeltype == LABEL_MANUAL);
1718 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1719 sgml::openTag(ofs, depth + 1 + command_depth,
1720 false, environment_inner[depth]);
1722 item_name = desc_on ? "term" : "para";
1723 sgml::openTag(ofs, depth + 1 + command_depth,
1727 sgml::openTag(ofs, depth + command_depth,
1728 false, style->latexname());
1732 simpleDocBookOnePar(ofs, par, desc_on,
1733 depth + 1 + command_depth);
1736 // write closing SGML tags
1737 switch (style->latextype) {
1739 end_tag = c_params.empty() ? "title" : c_params;
1740 sgml::closeTag(ofs, depth + command_depth,
1743 case LATEX_ENVIRONMENT:
1744 if (!style->latexparam().empty()) {
1745 if (style->latexparam() == "CDATA")
1748 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1751 case LATEX_ITEM_ENVIRONMENT:
1752 if (desc_on == 1) break;
1754 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1756 case LATEX_PARAGRAPH:
1757 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1760 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1766 for (int d = depth; d >= 0; --d) {
1767 if (!environment_stack[depth].empty()) {
1768 if (environment_inner[depth] != "!-- --") {
1769 item_name = "listitem";
1770 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1771 if (environment_inner[depth] == "varlistentry")
1772 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1775 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1779 for (int j = command_depth; j >= 0 ; --j)
1780 if (!command_stack[j].empty()) {
1781 sgml::closeTag(ofs, j, false, command_stack[j]);
1786 sgml::closeTag(ofs, 0, false, top_element);
1789 // How to check for successful close
1791 // we want this to be true outside previews (for insetexternal)
1796 void Buffer::simpleDocBookOnePar(ostream & os,
1797 ParagraphList::iterator par, int & desc_on,
1798 Paragraph::depth_type depth) const
1800 bool emph_flag = false;
1802 LyXLayout_ptr const & style = par->layout();
1804 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1806 int char_line_count = depth;
1807 //if (!style.free_spacing)
1808 // os << string(depth,' ');
1810 // parsing main loop
1811 for (pos_type i = 0; i < par->size(); ++i) {
1812 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1814 // handle <emphasis> tag
1815 if (font_old.emph() != font.emph()) {
1816 if (font.emph() == LyXFont::ON) {
1817 if (style->latexparam() == "CDATA")
1820 if (style->latexparam() == "CDATA")
1824 if (style->latexparam() == "CDATA")
1826 os << "</emphasis>";
1827 if (style->latexparam() == "CDATA")
1834 if (par->isInset(i)) {
1835 InsetOld * inset = par->getInset(i);
1836 // don't print the inset in position 0 if desc_on == 3 (label)
1837 if (i || desc_on != 3) {
1838 if (style->latexparam() == "CDATA")
1840 inset->docbook(*this, os, false);
1841 if (style->latexparam() == "CDATA")
1845 char c = par->getChar(i);
1848 boost::tie(ws, str) = sgml::escapeChar(c);
1850 if (style->pass_thru) {
1852 } else if (par->isFreeSpacing() || c != ' ') {
1854 } else if (desc_on == 1) {
1856 os << "\n</term><listitem><para>";
1866 if (style->latexparam() == "CDATA")
1868 os << "</emphasis>";
1869 if (style->latexparam() == "CDATA")
1873 // resets description flag correctly
1875 // <term> not closed...
1876 os << "</term>\n<listitem><para> </para>";
1878 if (style->free_spacing)
1883 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1884 // Other flags: -wall -v0 -x
1885 int Buffer::runChktex()
1889 // get LaTeX-Filename
1890 string const name = getLatexName();
1891 string path = filePath();
1893 string const org_path = path;
1894 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1898 Path p(path); // path to LaTeX file
1899 message(_("Running chktex..."));
1901 // Generate the LaTeX file if neccessary
1902 LatexRunParams runparams;
1903 runparams.flavor = LatexRunParams::LATEX;
1904 runparams.nice = false;
1905 makeLaTeXFile(name, org_path, runparams);
1908 Chktex chktex(lyxrc.chktex_command, name, filePath());
1909 int res = chktex.run(terr); // run chktex
1912 Alert::error(_("chktex failure"),
1913 _("Could not run chktex successfully."));
1914 } else if (res > 0) {
1915 // Insert all errors as errors boxes
1916 bufferErrors(*this, terr);
1925 void Buffer::validate(LaTeXFeatures & features) const
1927 LyXTextClass const & tclass = params.getLyXTextClass();
1929 if (params.tracking_changes) {
1930 features.require("dvipost");
1931 features.require("color");
1934 // AMS Style is at document level
1935 if (params.use_amsmath == BufferParams::AMS_ON
1936 || tclass.provides(LyXTextClass::amsmath))
1937 features.require("amsmath");
1939 for_each(paragraphs.begin(), paragraphs.end(),
1940 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1942 // the bullet shapes are buffer level not paragraph level
1943 // so they are tested here
1944 for (int i = 0; i < 4; ++i) {
1945 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1946 int const font = params.user_defined_bullets[i].getFont();
1948 int const c = params
1949 .user_defined_bullets[i]
1956 features.require("latexsym");
1958 } else if (font == 1) {
1959 features.require("amssymb");
1960 } else if ((font >= 2 && font <= 5)) {
1961 features.require("pifont");
1966 if (lyxerr.debugging(Debug::LATEX)) {
1967 features.showStruct();
1972 void Buffer::getLabelList(std::vector<string> & list) const
1974 /// if this is a child document and the parent is already loaded
1975 /// Use the parent's list instead [ale990407]
1976 if (!params.parentname.empty()
1977 && bufferlist.exists(params.parentname)) {
1978 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1980 tmp->getLabelList(list);
1985 for (inset_iterator it = inset_const_iterator_begin();
1986 it != inset_const_iterator_end(); ++it) {
1987 it->getLabelList(list);
1992 // This is also a buffer property (ale)
1993 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1995 /// if this is a child document and the parent is already loaded
1996 /// use the parent's list instead [ale990412]
1997 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1998 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2000 tmp->fillWithBibKeys(keys);
2005 for (inset_iterator it = inset_const_iterator_begin();
2006 it != inset_const_iterator_end(); ++it) {
2007 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2008 static_cast<InsetBibtex &>(*it).fillWithBibKeys(*this, keys);
2009 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2010 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2011 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2012 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2013 string const key = bib.getContents();
2014 string const opt = bib.getOptions();
2015 string const ref; // = pit->asString(this, false);
2016 string const info = opt + "TheBibliographyRef" + ref;
2017 keys.push_back(pair<string, string>(key, info));
2023 bool Buffer::isDepClean(string const & name) const
2025 DepClean::const_iterator it = dep_clean_.find(name);
2026 if (it == dep_clean_.end())
2032 void Buffer::markDepClean(string const & name)
2034 dep_clean_[name] = true;
2038 bool Buffer::dispatch(string const & command, bool * result)
2040 // Split command string into command and argument
2042 string line = ltrim(command);
2043 string const arg = trim(split(line, cmd, ' '));
2045 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2049 bool Buffer::dispatch(int action, string const & argument, bool * result)
2051 bool dispatched = true;
2055 bool const tmp = Exporter::Export(this, argument, false);
2068 void Buffer::changeLanguage(Language const * from, Language const * to)
2070 lyxerr << "Changing Language!" << endl;
2072 // Take care of l10n/i18n
2075 ParIterator end = par_iterator_end();
2076 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2077 it->changeLanguage(params, from, to);
2081 void Buffer::updateDocLang(Language const * nlang)
2083 messages_.reset(new Messages(nlang->code()));
2087 bool Buffer::isMultiLingual()
2089 ParIterator end = par_iterator_end();
2090 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2091 if (it->isMultiLingual(params))
2098 void Buffer::inset_iterator::setParagraph()
2100 while (pit != pend) {
2101 it = pit->insetlist.begin();
2102 if (it != pit->insetlist.end())
2109 InsetOld * Buffer::getInsetFromID(int id_arg) const
2111 for (inset_iterator it = inset_const_iterator_begin();
2112 it != inset_const_iterator_end(); ++it)
2114 if (it->id() == id_arg)
2116 InsetOld * in = it->getInsetFromID(id_arg);
2124 ParIterator Buffer::getParFromID(int id) const
2126 #warning FIXME: const correctness! (Andre)
2127 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2128 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2130 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2132 // John says this is called with id == -1 from undo
2133 lyxerr << "getParFromID(), id: " << id << endl;
2137 for (; it != end; ++it)
2145 bool Buffer::hasParWithID(int id) const
2147 ParConstIterator it = par_iterator_begin();
2148 ParConstIterator end = par_iterator_end();
2151 // John says this is called with id == -1 from undo
2152 lyxerr << "hasParWithID(), id: " << id << endl;
2156 for (; it != end; ++it)
2164 ParIterator Buffer::par_iterator_begin()
2166 return ParIterator(paragraphs.begin(), paragraphs);
2170 ParIterator Buffer::par_iterator_end()
2172 return ParIterator(paragraphs.end(), paragraphs);
2176 ParConstIterator Buffer::par_iterator_begin() const
2178 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2182 ParConstIterator Buffer::par_iterator_end() const
2184 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2188 Language const * Buffer::getLanguage() const
2190 return params.language;
2194 string const Buffer::B_(string const & l10n) const
2196 if (messages_.get()) {
2197 return messages_->get(l10n);
2204 bool Buffer::isClean() const
2210 bool Buffer::isBakClean() const
2216 void Buffer::markClean() const
2222 // if the .lyx file has been saved, we don't need an
2228 void Buffer::markBakClean()
2234 void Buffer::setUnnamed(bool flag)
2240 bool Buffer::isUnnamed()
2246 void Buffer::markDirty()
2254 DepClean::iterator it = dep_clean_.begin();
2255 DepClean::const_iterator const end = dep_clean_.end();
2257 for (; it != end; ++it) {
2263 string const & Buffer::fileName() const
2269 string const & Buffer::filePath() const
2275 bool Buffer::isReadonly() const
2281 void Buffer::setParentName(string const & name)
2283 params.parentname = name;
2287 Buffer::inset_iterator::inset_iterator()
2292 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2299 Buffer::inset_iterator Buffer::inset_iterator_begin()
2301 return inset_iterator(paragraphs.begin(), paragraphs.end());
2305 Buffer::inset_iterator Buffer::inset_iterator_end()
2307 return inset_iterator(paragraphs.end(), paragraphs.end());
2311 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2313 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2314 const_cast<ParagraphList&>(paragraphs).end());
2318 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2320 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2321 const_cast<ParagraphList&>(paragraphs).end());
2325 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2329 if (it == pit->insetlist.end()) {
2338 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2340 inset_iterator tmp = *this;
2346 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2352 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2358 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2364 lyx::pos_type Buffer::inset_iterator::getPos() const
2370 bool operator==(Buffer::inset_iterator const & iter1,
2371 Buffer::inset_iterator const & iter2)
2373 return iter1.pit == iter2.pit
2374 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2378 bool operator!=(Buffer::inset_iterator const & iter1,
2379 Buffer::inset_iterator const & iter2)
2381 return !(iter1 == iter2);