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.
14 #include "buffer_funcs.h"
15 #include "bufferlist.h"
16 #include "LyXAction.h"
23 #include "LaTeXFeatures.h"
27 #include "support/std_sstream.h"
29 #include "ParagraphParameters.h"
30 #include "iterators.h"
32 #include "paragraph_funcs.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/LAssert.h"
47 #include "support/textutils.h"
48 #include "support/filetools.h"
49 #include "support/path.h"
50 #include "support/os.h"
51 #include "support/tostr.h"
52 #include "support/lyxlib.h"
53 #include "support/FileInfo.h"
54 #include "support/gzstream.h"
56 #include <boost/bind.hpp>
57 #include <boost/tuple/tuple.hpp>
67 using namespace lyx::support;
69 #ifndef CXX_GLOBAL_CSTD
74 using std::ostringstream;
90 using lyx::textclass_type;
92 // all these externs should eventually be removed.
93 extern BufferList bufferlist;
97 const int LYX_FORMAT = 225;
99 bool openFileWrite(ofstream & ofs, string const & fname)
101 ofs.open(fname.c_str());
103 string const file = MakeDisplayPath(fname, 50);
104 string text = bformat(_("Could not open the specified "
105 "document\n%1$s."), file);
106 Alert::error(_("Could not open file"), text);
115 Buffer::Buffer(string const & file, bool ronly)
116 : niceFile(true), lyx_clean(true), bak_clean(true),
117 unnamed(false), read_only(ronly),
120 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
121 filepath_ = OnlyPath(file);
123 if (read_only || lyxrc.use_tempdir) {
124 tmppath = CreateBufferTmpDir();
129 // set initial author
130 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
136 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
137 // here the buffer should take care that it is
138 // saved properly, before it goes into the void.
142 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
143 Alert::warning(_("Could not remove temporary directory"),
144 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
149 // Remove any previewed LaTeX snippets associated with this buffer.
150 lyx::graphics::Previews::get().removeLoader(*this);
154 string const Buffer::getLatexName(bool no_path) const
156 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
157 return no_path ? OnlyFilename(name) : name;
161 pair<Buffer::LogType, string> const Buffer::getLogName() const
163 string const filename = getLatexName(false);
165 if (filename.empty())
166 return make_pair(Buffer::latexlog, string());
168 string path = OnlyPath(filename);
170 if (lyxrc.use_tempdir || !IsDirWriteable(path))
173 string const fname = AddName(path,
174 OnlyFilename(ChangeExtension(filename,
177 AddName(path, OnlyFilename(
178 ChangeExtension(filename,
179 formats.extension("literate") + ".out")));
181 // If no Latex log or Build log is newer, show Build log
183 FileInfo const f_fi(fname);
184 FileInfo const b_fi(bname);
187 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
188 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
189 return make_pair(Buffer::buildlog, bname);
191 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
192 return make_pair(Buffer::latexlog, fname);
196 void Buffer::setReadonly(bool flag)
198 if (read_only != flag) {
205 AuthorList & Buffer::authors()
207 return params.authorlist;
211 void Buffer::setFileName(string const & newfile)
213 filename_ = MakeAbsPath(newfile);
214 filepath_ = OnlyPath(filename_);
215 setReadonly(IsFileWriteable(filename_) == 0);
220 // We'll remove this later. (Lgb)
223 void unknownClass(string const & unknown)
225 Alert::warning(_("Unknown document class"),
226 bformat(_("Using the default document class, because the "
227 "class %1$s is unknown."), unknown));
232 int Buffer::readHeader(LyXLex & lex)
234 int unknown_tokens = 0;
238 string const token = lex.getString();
243 if (token == "\\end_header")
246 lyxerr[Debug::PARSER] << "Handling header token: `"
247 << token << '\'' << endl;
250 string unknown = params.readToken(lex, token);
251 if (!unknown.empty()) {
252 if (unknown[0] != '\\') {
253 unknownClass(unknown);
256 string const s = bformat(_("Unknown token: "
260 error(ErrorItem(_("Header error"), s,
265 return unknown_tokens;
269 // candidate for move to BufferView
270 // (at least some parts in the beginning of the func)
273 // changed to be public and have one parameter
274 // if par = 0 normal behavior
275 // else insert behavior
276 // Returns false if "\end_document" is not read (Asger)
277 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
279 Paragraph::depth_type depth = 0;
280 bool the_end_read = false;
282 if (paragraphs.empty()) {
284 if (!params.getLyXTextClass().load()) {
285 string theclass = params.getLyXTextClass().name();
286 Alert::error(_("Can't load document class"), bformat(
287 "Using the default document class, because the "
288 " class %1$s could not be loaded.", theclass));
289 params.textclass = 0;
292 // We don't want to adopt the parameters from the
293 // document we insert, so read them into a temporary buffer
294 // and then discard it
296 Buffer tmpbuf("", false);
297 tmpbuf.readHeader(lex);
302 string const token = lex.getString();
307 lyxerr[Debug::PARSER] << "Handling token: `"
308 << token << '\'' << endl;
310 if (token == "\\end_document") {
315 readParagraph(lex, token, paragraphs, pit, depth);
322 int Buffer::readParagraph(LyXLex & lex, string const & token,
323 ParagraphList & pars, ParagraphList::iterator & pit,
324 Paragraph::depth_type & depth)
326 static Change current_change;
329 if (token == "\\begin_layout") {
330 lex.pushToken(token);
333 par.params().depth(depth);
334 if (params.tracking_changes)
336 LyXFont f(LyXFont::ALL_INHERIT, params.language);
340 if (pit != pars.end())
343 pit = pars.insert(pit, par);
345 // FIXME: goddamn InsetTabular makes us pass a Buffer
347 ::readParagraph(*this, *pit, lex);
349 } else if (token == "\\begin_deeper") {
351 } else if (token == "\\end_deeper") {
353 lex.printError("\\end_deeper: " "depth is already null");
364 // needed to insert the selection
365 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
366 LyXFont const & fn,string const & str)
368 LyXLayout_ptr const & layout = par->layout();
372 par->checkInsertChar(font);
373 // insert the string, don't insert doublespace
374 bool space_inserted = true;
375 bool autobreakrows = !par->inInset() ||
376 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
377 for(string::const_iterator cit = str.begin();
378 cit != str.end(); ++cit) {
380 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
381 breakParagraph(params, paragraphs, par, pos,
382 layout->isEnvironment());
385 space_inserted = true;
389 // do not insert consecutive spaces if !free_spacing
390 } else if ((*cit == ' ' || *cit == '\t') &&
391 space_inserted && !par->isFreeSpacing()) {
393 } else if (*cit == '\t') {
394 if (!par->isFreeSpacing()) {
395 // tabs are like spaces here
396 par->insertChar(pos, ' ', font);
398 space_inserted = true;
400 const pos_type nb = 8 - pos % 8;
401 for (pos_type a = 0; a < nb ; ++a) {
402 par->insertChar(pos, ' ', font);
405 space_inserted = true;
407 } else if (!IsPrintable(*cit)) {
408 // Ignore unprintables
411 // just insert the character
412 par->insertChar(pos, *cit, font);
414 space_inserted = (*cit == ' ');
421 bool Buffer::readFile(string const & filename)
423 // Check if the file is compressed.
424 string const format = getExtFromContents(filename);
425 if (format == "gzip" || format == "zip" || format == "compress") {
426 params.compressed = true;
429 bool ret = readFile(filename, paragraphs.begin());
431 // After we have read a file, we must ensure that the buffer
432 // language is set and used in the gui.
433 // If you know of a better place to put this, please tell me. (Lgb)
434 updateDocLang(params.language);
440 bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
443 lex.setFile(filename);
445 return readFile(lex, filename, pit);
449 bool Buffer::readFile(LyXLex & lex, string const & filename,
450 ParagraphList::iterator pit)
452 Assert(!filename.empty());
455 Alert::error(_("Document could not be read"),
456 bformat(_("%1$s could not be read."), filename));
461 string const token(lex.getString());
464 Alert::error(_("Document could not be read"),
465 bformat(_("%1$s could not be read."), filename));
469 // the first token _must_ be...
470 if (token != "\\lyxformat") {
471 lyxerr << "Token: " << token << endl;
473 Alert::error(_("Document format failure"),
474 bformat(_("%1$s is not a LyX document."),
480 string tmp_format = lex.getString();
481 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
482 // if present remove ".," from string.
483 string::size_type dot = tmp_format.find_first_of(".,");
484 //lyxerr << " dot found at " << dot << endl;
485 if (dot != string::npos)
486 tmp_format.erase(dot, 1);
487 int file_format = strToInt(tmp_format);
488 //lyxerr << "format: " << file_format << endl;
490 if (file_format > LYX_FORMAT) {
491 Alert::warning(_("Document format failure"),
492 bformat(_("%1$s was created with a newer"
493 " version of LyX. This is likely to"
496 } else if (file_format < LYX_FORMAT) {
497 string const tmpfile = tempName();
498 string command = LibFileSearch("lyx2lyx", "lyx2lyx");
499 if (command.empty()) {
500 Alert::error(_("Conversion script not found"),
501 bformat(_("%1$s is from an earlier"
502 " version of LyX, but the"
503 " conversion script lyx2lyx"
504 " could not be found."),
510 + " -o " + tmpfile + ' '
511 + QuoteName(filename);
512 lyxerr[Debug::INFO] << "Running '"
515 cmd_ret const ret = RunCommand(command);
516 if (ret.first != 0) {
517 Alert::error(_("Conversion script failed"),
518 bformat(_("%1$s is from an earlier version"
519 " of LyX, but the lyx2lyx script"
520 " failed to convert it."),
524 bool ret = readFile(tmpfile, pit);
525 // Do stuff with tmpfile name and buffer name here.
531 bool the_end = readBody(lex, pit);
532 params.setPaperStuff();
535 Alert::error(_("Document format failure"),
536 bformat(_("%1$s ended unexpectedly, which means"
537 " that it is probably corrupted."),
544 // Should probably be moved to somewhere else: BufferView? LyXView?
545 bool Buffer::save() const
547 // We don't need autosaves in the immediate future. (Asger)
548 resetAutosaveTimers();
552 if (lyxrc.make_backup) {
553 s = fileName() + '~';
554 if (!lyxrc.backupdir_path.empty())
555 s = AddName(lyxrc.backupdir_path,
556 subst(os::slashify_path(s),'/','!'));
558 // Rename is the wrong way of making a backup,
559 // this is the correct way.
560 /* truss cp fil fil2:
561 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
562 stat("LyXVC.lyx", 0xEFFFF688) = 0
563 open("LyXVC.lyx", O_RDONLY) = 3
564 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
565 fstat(4, 0xEFFFF508) = 0
566 fstat(3, 0xEFFFF508) = 0
567 read(3, " # T h i s f i l e w".., 8192) = 5579
568 write(4, " # T h i s f i l e w".., 5579) = 5579
569 read(3, 0xEFFFD4A0, 8192) = 0
572 chmod("LyXVC3.lyx", 0100644) = 0
573 lseek(0, 0, SEEK_CUR) = 46440
577 // Should probably have some more error checking here.
578 // Doing it this way, also makes the inodes stay the same.
579 // This is still not a very good solution, in particular we
580 // might loose the owner of the backup.
581 FileInfo finfo(fileName());
583 mode_t fmode = finfo.getMode();
584 struct utimbuf times = {
585 finfo.getAccessTime(),
586 finfo.getModificationTime() };
588 ifstream ifs(fileName().c_str());
589 ofstream ofs(s.c_str(), ios::out|ios::trunc);
594 ::chmod(s.c_str(), fmode);
596 if (::utime(s.c_str(), ×)) {
597 lyxerr << "utime error." << endl;
600 lyxerr << "LyX was not able to make "
601 "backup copy. Beware." << endl;
606 if (writeFile(fileName())) {
608 removeAutosaveFile(fileName());
610 // Saving failed, so backup is not backup
611 if (lyxrc.make_backup) {
612 rename(s, fileName());
620 bool Buffer::writeFile(string const & fname) const
622 if (read_only && (fname == fileName())) {
626 FileInfo finfo(fname);
627 if (finfo.exist() && !finfo.writable()) {
633 if (params.compressed) {
634 gz::ogzstream ofs(fname.c_str());
639 retval = do_writeFile(ofs);
642 ofstream ofs(fname.c_str());
646 retval = do_writeFile(ofs);
653 bool Buffer::do_writeFile(ostream & ofs) const
657 // Use the standard "C" locale for file output.
658 ofs.imbue(std::locale::classic());
661 // The top of the file should not be written by params.
663 // write out a comment in the top of the file
664 ofs << "#LyX " << lyx_version
665 << " created this file. For more info see http://www.lyx.org/\n"
666 << "\\lyxformat " << LYX_FORMAT << "\n";
668 // now write out the buffer paramters.
669 params.writeFile(ofs);
671 ofs << "\\end_header\n";
673 Paragraph::depth_type depth = 0;
675 // this will write out all the paragraphs
676 // using recursive descent.
677 ParagraphList::const_iterator pit = paragraphs.begin();
678 ParagraphList::const_iterator pend = paragraphs.end();
679 for (; pit != pend; ++pit)
680 pit->write(*this, ofs, params, depth);
682 // Write marker that shows file is complete
683 ofs << "\n\\end_document" << endl;
685 // Shouldn't really be needed....
688 // how to check if close went ok?
689 // Following is an attempt... (BE 20001011)
691 // good() returns false if any error occured, including some
693 // bad() returns true if something bad happened in the buffer,
694 // which should include file system full errors.
701 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
703 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
715 pair<int, string> const addDepth(int depth, int ldepth)
719 d += (ldepth - depth) * 2;
720 return make_pair(d, string(d, ' '));
726 string const Buffer::asciiParagraph(Paragraph const & par,
727 unsigned int linelen,
728 bool noparbreak) const
730 ostringstream buffer;
732 Paragraph::depth_type ltype_depth = 0;
733 bool ref_printed = false;
734 Paragraph::depth_type depth = par.params().depth();
736 // First write the layout
737 string const & tmp = par.layout()->name();
738 if (compare_no_case(tmp, "itemize") == 0) {
740 ltype_depth = depth + 1;
741 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
743 ltype_depth = depth + 1;
744 } else if (contains(ascii_lowercase(tmp), "ection")) {
746 ltype_depth = depth + 1;
747 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
749 ltype_depth = depth + 1;
750 } else if (compare_ascii_no_case(tmp, "description") == 0) {
752 ltype_depth = depth + 1;
753 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
756 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
764 /* maybe some vertical spaces */
766 /* the labelwidthstring used in lists */
770 /* some pagebreaks? */
774 /* what about the alignment */
776 // linelen <= 0 is special and means we don't have paragraph breaks
778 string::size_type currlinelen = 0;
784 buffer << string(depth * 2, ' ');
785 currlinelen += depth * 2;
788 // we should probably change to the paragraph language in the
789 // gettext here (if possible) so that strings are outputted in
790 // the correct language! (20012712 Jug)
794 case 4: // (Sub)Paragraph
795 case 5: // Description
799 buffer << _("Abstract") << "\n\n";
802 string const abst = _("Abstract: ");
804 currlinelen += abst.length();
807 case 7: // Bibliography
810 buffer << _("References") << "\n\n";
813 string const refs = _("References: ");
815 currlinelen += refs.length();
823 string const parlab = par.params().labelString();
824 buffer << parlab << ' ';
825 currlinelen += parlab.length() + 1;
833 pair<int, string> p = addDepth(depth, ltype_depth);
835 currlinelen += p.first;
838 // this is to change the linebreak to do it by word a bit more
839 // intelligent hopefully! (only in the case where we have a
840 // max linelength!) (Jug)
844 for (pos_type i = 0; i < par.size(); ++i) {
845 char c = par.getUChar(params, i);
847 case Paragraph::META_INSET:
849 InsetOld const * inset = par.getInset(i);
853 currlinelen += word.length();
856 if (inset->ascii(*this, buffer, linelen)) {
857 // to be sure it breaks paragraph
858 currlinelen += linelen;
867 currlinelen + word.length() > linelen - 10) {
869 pair<int, string> p = addDepth(depth, ltype_depth);
871 currlinelen = p.first;
874 buffer << word << ' ';
875 currlinelen += word.length() + 1;
882 lyxerr[Debug::INFO] <<
883 "writeAsciiFile: NULL char in structure." << endl;
886 (currlinelen + word.length()) > linelen)
890 pair<int, string> p =
891 addDepth(depth, ltype_depth);
893 currlinelen = p.first;
900 return STRCONV(buffer.str());
904 void Buffer::writeFileAscii(string const & fname, int linelen)
907 if (!::openFileWrite(ofs, fname))
909 writeFileAscii(ofs, linelen);
913 void Buffer::writeFileAscii(ostream & os, int linelen)
915 ParagraphList::iterator beg = paragraphs.begin();
916 ParagraphList::iterator end = paragraphs.end();
917 ParagraphList::iterator it = beg;
918 for (; it != end; ++it) {
919 os << asciiParagraph(*it, linelen, it == beg);
925 void Buffer::makeLaTeXFile(string const & fname,
926 string const & original_path,
927 LatexRunParams const & runparams,
928 bool output_preamble, bool output_body)
930 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
933 if (!::openFileWrite(ofs, fname))
936 makeLaTeXFile(ofs, original_path,
937 runparams, output_preamble, output_body);
941 lyxerr << "File was not closed properly." << endl;
946 void Buffer::makeLaTeXFile(ostream & os,
947 string const & original_path,
948 LatexRunParams const & runparams_in,
949 bool output_preamble, bool output_body)
951 LatexRunParams runparams = runparams_in;
952 niceFile = runparams.nice; // this will be used by Insetincludes.
954 // validate the buffer.
955 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
956 LaTeXFeatures features(params);
958 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
961 // The starting paragraph of the coming rows is the
962 // first paragraph of the document. (Asger)
963 texrow.start(paragraphs.begin()->id(), 0);
965 if (output_preamble && runparams.nice) {
966 os << "%% LyX " << lyx_version << " created this file. "
967 "For more info, see http://www.lyx.org/.\n"
968 "%% Do not edit unless you really know what "
973 lyxerr[Debug::INFO] << "lyx header finished" << endl;
974 // There are a few differences between nice LaTeX and usual files:
975 // usual is \batchmode and has a
976 // special input@path to allow the including of figures
977 // with either \input or \includegraphics (what figinsets do).
978 // input@path is set when the actual parameter
979 // original_path is set. This is done for usual tex-file, but not
980 // for nice-latex-file. (Matthias 250696)
981 if (output_preamble) {
982 if (!runparams.nice) {
983 // code for usual, NOT nice-latex-file
984 os << "\\batchmode\n"; // changed
988 if (!original_path.empty()) {
989 string inputpath = os::external_path(original_path);
990 subst(inputpath, "~", "\\string~");
991 os << "\\makeatletter\n"
992 << "\\def\\input@path{{"
993 << inputpath << "/}}\n"
994 << "\\makeatother\n";
1000 // Write the preamble
1001 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1007 os << "\\begin{document}\n";
1009 } // output_preamble
1010 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1012 if (!lyxrc.language_auto_begin) {
1013 os << subst(lyxrc.language_command_begin, "$$lang",
1014 params.language->babel())
1019 latexParagraphs(*this, paragraphs, os, texrow, runparams);
1021 // add this just in case after all the paragraphs
1025 if (!lyxrc.language_auto_end) {
1026 os << subst(lyxrc.language_command_end, "$$lang",
1027 params.language->babel())
1032 if (output_preamble) {
1033 os << "\\end{document}\n";
1036 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1038 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1042 // Just to be sure. (Asger)
1045 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1046 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1049 // we want this to be true outside previews (for insetexternal)
1054 bool Buffer::isLatex() const
1056 return params.getLyXTextClass().outputType() == LATEX;
1060 bool Buffer::isLinuxDoc() const
1062 return params.getLyXTextClass().outputType() == LINUXDOC;
1066 bool Buffer::isLiterate() const
1068 return params.getLyXTextClass().outputType() == LITERATE;
1072 bool Buffer::isDocBook() const
1074 return params.getLyXTextClass().outputType() == DOCBOOK;
1078 bool Buffer::isSGML() const
1080 LyXTextClass const & tclass = params.getLyXTextClass();
1082 return tclass.outputType() == LINUXDOC ||
1083 tclass.outputType() == DOCBOOK;
1087 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1090 if (!::openFileWrite(ofs, fname))
1093 niceFile = nice; // this will be used by included files.
1095 LaTeXFeatures features(params);
1101 LyXTextClass const & tclass = params.getLyXTextClass();
1103 string top_element = tclass.latexname();
1106 ofs << "<!doctype linuxdoc system";
1108 string preamble = params.preamble;
1109 string const name = nice ? ChangeExtension(filename_, ".sgml")
1111 preamble += features.getIncludedFiles(name);
1112 preamble += features.getLyXSGMLEntities();
1114 if (!preamble.empty()) {
1115 ofs << " [ " << preamble << " ]";
1119 if (params.options.empty())
1120 sgml::openTag(ofs, 0, false, top_element);
1122 string top = top_element;
1124 top += params.options;
1125 sgml::openTag(ofs, 0, false, top);
1129 ofs << "<!-- LyX " << lyx_version
1130 << " created this file. For more info see http://www.lyx.org/"
1133 Paragraph::depth_type depth = 0; // paragraph depth
1135 vector<string> environment_stack(5);
1137 ParagraphList::iterator pit = paragraphs.begin();
1138 ParagraphList::iterator pend = paragraphs.end();
1139 for (; pit != pend; ++pit) {
1140 LyXLayout_ptr const & style = pit->layout();
1141 // treat <toc> as a special case for compatibility with old code
1142 if (pit->isInset(0)) {
1143 InsetOld * inset = pit->getInset(0);
1144 InsetOld::Code lyx_code = inset->lyxCode();
1145 if (lyx_code == InsetOld::TOC_CODE) {
1146 string const temp = "toc";
1147 sgml::openTag(ofs, depth, false, temp);
1152 // environment tag closing
1153 for (; depth > pit->params().depth(); --depth) {
1154 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1155 environment_stack[depth].erase();
1158 // write opening SGML tags
1159 switch (style->latextype) {
1160 case LATEX_PARAGRAPH:
1161 if (depth == pit->params().depth()
1162 && !environment_stack[depth].empty()) {
1163 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1164 environment_stack[depth].erase();
1170 sgml::openTag(ofs, depth, false, style->latexname());
1175 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1177 if (!environment_stack[depth].empty()) {
1178 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1182 environment_stack[depth].erase();
1183 sgml::openTag(ofs, depth, false, style->latexname());
1186 case LATEX_ENVIRONMENT:
1187 case LATEX_ITEM_ENVIRONMENT:
1188 case LATEX_BIB_ENVIRONMENT:
1190 string const & latexname = style->latexname();
1192 if (depth == pit->params().depth()
1193 && environment_stack[depth] != latexname) {
1194 sgml::closeTag(ofs, depth, false,
1195 environment_stack[depth]);
1196 environment_stack[depth].erase();
1198 if (depth < pit->params().depth()) {
1199 depth = pit->params().depth();
1200 environment_stack[depth].erase();
1202 if (environment_stack[depth] != latexname) {
1204 sgml::openTag(ofs, depth, false, "p");
1206 sgml::openTag(ofs, depth, false, latexname);
1208 if (environment_stack.size() == depth + 1)
1209 environment_stack.push_back("!-- --");
1210 environment_stack[depth] = latexname;
1213 if (style->latexparam() == "CDATA")
1216 if (style->latextype == LATEX_ENVIRONMENT) break;
1218 if (style->labeltype == LABEL_MANUAL)
1223 sgml::openTag(ofs, depth + 1, false, item_name);
1228 sgml::openTag(ofs, depth, false, style->latexname());
1232 simpleLinuxDocOnePar(ofs, pit, depth);
1235 // write closing SGML tags
1236 switch (style->latextype) {
1239 case LATEX_ENVIRONMENT:
1240 case LATEX_ITEM_ENVIRONMENT:
1241 case LATEX_BIB_ENVIRONMENT:
1242 if (style->latexparam() == "CDATA")
1246 sgml::closeTag(ofs, depth, false, style->latexname());
1252 for (int i = depth; i >= 0; --i)
1253 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1257 sgml::closeTag(ofs, 0, false, top_element);
1261 // How to check for successful close
1263 // we want this to be true outside previews (for insetexternal)
1268 // checks, if newcol chars should be put into this line
1269 // writes newline, if necessary.
1272 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1273 string::size_type newcol)
1276 if (colcount > lyxrc.ascii_linelen) {
1278 colcount = newcol; // assume write after this call
1293 string tag_name(PAR_TAG const & pt) {
1295 case NONE: return "!-- --";
1296 case TT: return "tt";
1297 case SF: return "sf";
1298 case BF: return "bf";
1299 case IT: return "it";
1300 case SL: return "sl";
1301 case EM: return "em";
1308 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1310 p1 = static_cast<PAR_TAG>(p1 | p2);
1315 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1317 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1323 // Handle internal paragraph parsing -- layout already processed.
1324 void Buffer::simpleLinuxDocOnePar(ostream & os,
1325 ParagraphList::iterator par,
1326 Paragraph::depth_type /*depth*/) const
1328 LyXLayout_ptr const & style = par->layout();
1330 string::size_type char_line_count = 5; // Heuristic choice ;-)
1332 // gets paragraph main font
1335 if (style->labeltype == LABEL_MANUAL) {
1336 font_old = style->labelfont;
1339 font_old = style->font;
1343 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1344 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1345 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1348 stack<PAR_TAG> tag_state;
1349 // parsing main loop
1350 for (pos_type i = 0; i < par->size(); ++i) {
1352 PAR_TAG tag_close = NONE;
1353 list < PAR_TAG > tag_open;
1355 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1357 if (font_old.family() != font.family()) {
1358 switch (family_type) {
1359 case LyXFont::SANS_FAMILY:
1362 case LyXFont::TYPEWRITER_FAMILY:
1369 family_type = font.family();
1371 switch (family_type) {
1372 case LyXFont::SANS_FAMILY:
1373 tag_open.push_back(SF);
1375 case LyXFont::TYPEWRITER_FAMILY:
1376 tag_open.push_back(TT);
1383 if (font_old.series() != font.series()) {
1384 switch (series_type) {
1385 case LyXFont::BOLD_SERIES:
1392 series_type = font.series();
1394 switch (series_type) {
1395 case LyXFont::BOLD_SERIES:
1396 tag_open.push_back(BF);
1404 if (font_old.shape() != font.shape()) {
1405 switch (shape_type) {
1406 case LyXFont::ITALIC_SHAPE:
1409 case LyXFont::SLANTED_SHAPE:
1416 shape_type = font.shape();
1418 switch (shape_type) {
1419 case LyXFont::ITALIC_SHAPE:
1420 tag_open.push_back(IT);
1422 case LyXFont::SLANTED_SHAPE:
1423 tag_open.push_back(SL);
1430 if (font_old.emph() != font.emph()) {
1431 if (font.emph() == LyXFont::ON) {
1432 tag_open.push_back(EM);
1441 list < PAR_TAG > temp;
1442 while (!tag_state.empty() && tag_close) {
1443 PAR_TAG k = tag_state.top();
1445 os << "</" << tag_name(k) << '>';
1452 for(list< PAR_TAG >::const_iterator j = temp.begin();
1453 j != temp.end(); ++j) {
1455 os << '<' << tag_name(*j) << '>';
1458 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1459 j != tag_open.end(); ++j) {
1461 os << '<' << tag_name(*j) << '>';
1464 char c = par->getChar(i);
1466 if (c == Paragraph::META_INSET) {
1467 InsetOld * inset = par->getInset(i);
1468 inset->linuxdoc(*this, os);
1473 if (style->latexparam() == "CDATA") {
1474 // "TeX"-Mode on == > SGML-Mode on.
1481 boost::tie(ws, str) = sgml::escapeChar(c);
1482 if (ws && !par->isFreeSpacing()) {
1483 // in freespacing mode, spaces are
1484 // non-breaking characters
1485 if (desc_on) {// if char is ' ' then...
1488 sgmlLineBreak(os, char_line_count, 6);
1492 sgmlLineBreak(os, char_line_count, 1);
1497 char_line_count += str.length();
1503 while (!tag_state.empty()) {
1504 os << "</" << tag_name(tag_state.top()) << '>';
1508 // resets description flag correctly
1510 // <tag> not closed...
1511 sgmlLineBreak(os, char_line_count, 6);
1517 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1520 if (!::openFileWrite(ofs, fname))
1523 niceFile = nice; // this will be used by Insetincludes.
1525 LaTeXFeatures features(params);
1530 LyXTextClass const & tclass = params.getLyXTextClass();
1531 string top_element = tclass.latexname();
1534 ofs << "<!DOCTYPE " << top_element
1535 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1537 string preamble = params.preamble;
1538 string const name = nice ? ChangeExtension(filename_, ".sgml")
1540 preamble += features.getIncludedFiles(name);
1541 preamble += features.getLyXSGMLEntities();
1543 if (!preamble.empty()) {
1544 ofs << "\n [ " << preamble << " ]";
1549 string top = top_element;
1551 top += params.language->code();
1554 if (!params.options.empty()) {
1556 top += params.options;
1558 sgml::openTag(ofs, 0, false, top);
1560 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1561 << "\n See http://www.lyx.org/ for more information -->\n";
1563 vector<string> environment_stack(10);
1564 vector<string> environment_inner(10);
1565 vector<string> command_stack(10);
1567 bool command_flag = false;
1568 Paragraph::depth_type command_depth = 0;
1569 Paragraph::depth_type command_base = 0;
1570 Paragraph::depth_type cmd_depth = 0;
1571 Paragraph::depth_type depth = 0; // paragraph depth
1574 string command_name;
1576 ParagraphList::iterator par = paragraphs.begin();
1577 ParagraphList::iterator pend = paragraphs.end();
1579 for (; par != pend; ++par) {
1583 int desc_on = 0; // description mode
1585 LyXLayout_ptr const & style = par->layout();
1587 // environment tag closing
1588 for (; depth > par->params().depth(); --depth) {
1589 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1590 item_name = "listitem";
1591 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1592 if (environment_inner[depth] == "varlistentry")
1593 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1595 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1596 environment_stack[depth].erase();
1597 environment_inner[depth].erase();
1600 if (depth == par->params().depth()
1601 && environment_stack[depth] != style->latexname()
1602 && !environment_stack[depth].empty()) {
1603 if (environment_inner[depth] != "!-- --") {
1604 item_name= "listitem";
1605 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1606 if (environment_inner[depth] == "varlistentry")
1607 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1610 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1612 environment_stack[depth].erase();
1613 environment_inner[depth].erase();
1616 // Write opening SGML tags.
1617 switch (style->latextype) {
1618 case LATEX_PARAGRAPH:
1619 sgml::openTag(ofs, depth + command_depth,
1620 false, style->latexname());
1625 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1627 command_name = style->latexname();
1629 sgmlparam = style->latexparam();
1630 c_params = split(sgmlparam, c_depth,'|');
1632 cmd_depth = atoi(c_depth);
1635 if (cmd_depth < command_base) {
1636 for (Paragraph::depth_type j = command_depth;
1637 j >= command_base; --j) {
1638 sgml::closeTag(ofs, j, false, command_stack[j]);
1641 command_depth = command_base = cmd_depth;
1642 } else if (cmd_depth <= command_depth) {
1643 for (int j = command_depth;
1644 j >= int(cmd_depth); --j) {
1645 sgml::closeTag(ofs, j, false, command_stack[j]);
1648 command_depth = cmd_depth;
1650 command_depth = cmd_depth;
1652 command_depth = command_base = cmd_depth;
1653 command_flag = true;
1655 if (command_stack.size() == command_depth + 1)
1656 command_stack.push_back(string());
1657 command_stack[command_depth] = command_name;
1659 // treat label as a special case for
1660 // more WYSIWYM handling.
1661 // This is a hack while paragraphs can't have
1662 // attributes, like id in this case.
1663 if (par->isInset(0)) {
1664 InsetOld * inset = par->getInset(0);
1665 InsetOld::Code lyx_code = inset->lyxCode();
1666 if (lyx_code == InsetOld::LABEL_CODE) {
1667 command_name += " id=\"";
1668 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1669 command_name += '"';
1674 sgml::openTag(ofs, depth + command_depth, false, command_name);
1676 item_name = c_params.empty() ? "title" : c_params;
1677 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1680 case LATEX_ENVIRONMENT:
1681 case LATEX_ITEM_ENVIRONMENT:
1682 if (depth < par->params().depth()) {
1683 depth = par->params().depth();
1684 environment_stack[depth].erase();
1687 if (environment_stack[depth] != style->latexname()) {
1688 if (environment_stack.size() == depth + 1) {
1689 environment_stack.push_back("!-- --");
1690 environment_inner.push_back("!-- --");
1692 environment_stack[depth] = style->latexname();
1693 environment_inner[depth] = "!-- --";
1694 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1696 if (environment_inner[depth] != "!-- --") {
1697 item_name= "listitem";
1698 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1699 if (environment_inner[depth] == "varlistentry")
1700 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1704 if (style->latextype == LATEX_ENVIRONMENT) {
1705 if (!style->latexparam().empty()) {
1706 if (style->latexparam() == "CDATA")
1709 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1714 desc_on = (style->labeltype == LABEL_MANUAL);
1716 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1717 sgml::openTag(ofs, depth + 1 + command_depth,
1718 false, environment_inner[depth]);
1720 item_name = desc_on ? "term" : "para";
1721 sgml::openTag(ofs, depth + 1 + command_depth,
1725 sgml::openTag(ofs, depth + command_depth,
1726 false, style->latexname());
1730 simpleDocBookOnePar(ofs, par, desc_on,
1731 depth + 1 + command_depth);
1734 // write closing SGML tags
1735 switch (style->latextype) {
1737 end_tag = c_params.empty() ? "title" : c_params;
1738 sgml::closeTag(ofs, depth + command_depth,
1741 case LATEX_ENVIRONMENT:
1742 if (!style->latexparam().empty()) {
1743 if (style->latexparam() == "CDATA")
1746 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1749 case LATEX_ITEM_ENVIRONMENT:
1750 if (desc_on == 1) break;
1752 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1754 case LATEX_PARAGRAPH:
1755 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1758 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1764 for (int d = depth; d >= 0; --d) {
1765 if (!environment_stack[depth].empty()) {
1766 if (environment_inner[depth] != "!-- --") {
1767 item_name = "listitem";
1768 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1769 if (environment_inner[depth] == "varlistentry")
1770 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1773 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1777 for (int j = command_depth; j >= 0 ; --j)
1778 if (!command_stack[j].empty()) {
1779 sgml::closeTag(ofs, j, false, command_stack[j]);
1784 sgml::closeTag(ofs, 0, false, top_element);
1787 // How to check for successful close
1789 // we want this to be true outside previews (for insetexternal)
1794 void Buffer::simpleDocBookOnePar(ostream & os,
1795 ParagraphList::iterator par, int & desc_on,
1796 Paragraph::depth_type depth) const
1798 bool emph_flag = false;
1800 LyXLayout_ptr const & style = par->layout();
1802 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1804 int char_line_count = depth;
1805 //if (!style.free_spacing)
1806 // os << string(depth,' ');
1808 // parsing main loop
1809 for (pos_type i = 0; i < par->size(); ++i) {
1810 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1812 // handle <emphasis> tag
1813 if (font_old.emph() != font.emph()) {
1814 if (font.emph() == LyXFont::ON) {
1815 if (style->latexparam() == "CDATA")
1818 if (style->latexparam() == "CDATA")
1822 if (style->latexparam() == "CDATA")
1824 os << "</emphasis>";
1825 if (style->latexparam() == "CDATA")
1832 if (par->isInset(i)) {
1833 InsetOld * inset = par->getInset(i);
1834 // don't print the inset in position 0 if desc_on == 3 (label)
1835 if (i || desc_on != 3) {
1836 if (style->latexparam() == "CDATA")
1838 inset->docbook(*this, os, false);
1839 if (style->latexparam() == "CDATA")
1843 char c = par->getChar(i);
1846 boost::tie(ws, str) = sgml::escapeChar(c);
1848 if (style->pass_thru) {
1850 } else if (par->isFreeSpacing() || c != ' ') {
1852 } else if (desc_on == 1) {
1854 os << "\n</term><listitem><para>";
1864 if (style->latexparam() == "CDATA")
1866 os << "</emphasis>";
1867 if (style->latexparam() == "CDATA")
1871 // resets description flag correctly
1873 // <term> not closed...
1874 os << "</term>\n<listitem><para> </para>";
1876 if (style->free_spacing)
1881 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1882 // Other flags: -wall -v0 -x
1883 int Buffer::runChktex()
1887 // get LaTeX-Filename
1888 string const name = getLatexName();
1889 string path = filePath();
1891 string const org_path = path;
1892 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1896 Path p(path); // path to LaTeX file
1897 message(_("Running chktex..."));
1899 // Generate the LaTeX file if neccessary
1900 LatexRunParams runparams;
1901 runparams.flavor = LatexRunParams::LATEX;
1902 runparams.nice = false;
1903 makeLaTeXFile(name, org_path, runparams);
1906 Chktex chktex(lyxrc.chktex_command, name, filePath());
1907 int res = chktex.run(terr); // run chktex
1910 Alert::error(_("chktex failure"),
1911 _("Could not run chktex successfully."));
1912 } else if (res > 0) {
1913 // Insert all errors as errors boxes
1914 bufferErrors(*this, terr);
1923 void Buffer::validate(LaTeXFeatures & features) const
1925 LyXTextClass const & tclass = params.getLyXTextClass();
1927 if (params.tracking_changes) {
1928 features.require("dvipost");
1929 features.require("color");
1932 // AMS Style is at document level
1933 if (params.use_amsmath == BufferParams::AMS_ON
1934 || tclass.provides(LyXTextClass::amsmath))
1935 features.require("amsmath");
1937 for_each(paragraphs.begin(), paragraphs.end(),
1938 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1940 // the bullet shapes are buffer level not paragraph level
1941 // so they are tested here
1942 for (int i = 0; i < 4; ++i) {
1943 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1944 int const font = params.user_defined_bullets[i].getFont();
1946 int const c = params
1947 .user_defined_bullets[i]
1954 features.require("latexsym");
1956 } else if (font == 1) {
1957 features.require("amssymb");
1958 } else if ((font >= 2 && font <= 5)) {
1959 features.require("pifont");
1964 if (lyxerr.debugging(Debug::LATEX)) {
1965 features.showStruct();
1970 void Buffer::getLabelList(std::vector<string> & list) const
1972 /// if this is a child document and the parent is already loaded
1973 /// Use the parent's list instead [ale990407]
1974 if (!params.parentname.empty()
1975 && bufferlist.exists(params.parentname)) {
1976 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1978 tmp->getLabelList(list);
1983 for (inset_iterator it = inset_const_iterator_begin();
1984 it != inset_const_iterator_end(); ++it) {
1985 it->getLabelList(list);
1990 // This is also a buffer property (ale)
1991 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1993 /// if this is a child document and the parent is already loaded
1994 /// use the parent's list instead [ale990412]
1995 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1996 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1998 tmp->fillWithBibKeys(keys);
2003 for (inset_iterator it = inset_const_iterator_begin();
2004 it != inset_const_iterator_end(); ++it) {
2005 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2006 static_cast<InsetBibtex &>(*it).fillWithBibKeys(*this, keys);
2007 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2008 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2009 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2010 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2011 string const key = bib.getContents();
2012 string const opt = bib.getOptions();
2013 string const ref; // = pit->asString(this, false);
2014 string const info = opt + "TheBibliographyRef" + ref;
2015 keys.push_back(pair<string, string>(key, info));
2021 bool Buffer::isDepClean(string const & name) const
2023 DepClean::const_iterator it = dep_clean_.find(name);
2024 if (it == dep_clean_.end())
2030 void Buffer::markDepClean(string const & name)
2032 dep_clean_[name] = true;
2036 bool Buffer::dispatch(string const & command, bool * result)
2038 // Split command string into command and argument
2040 string line = ltrim(command);
2041 string const arg = trim(split(line, cmd, ' '));
2043 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2047 bool Buffer::dispatch(int action, string const & argument, bool * result)
2049 bool dispatched = true;
2053 bool const tmp = Exporter::Export(this, argument, false);
2066 void Buffer::changeLanguage(Language const * from, Language const * to)
2068 lyxerr << "Changing Language!" << endl;
2070 // Take care of l10n/i18n
2073 ParIterator end = par_iterator_end();
2074 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2075 it->changeLanguage(params, from, to);
2079 void Buffer::updateDocLang(Language const * nlang)
2081 messages_.reset(new Messages(nlang->code()));
2085 bool Buffer::isMultiLingual()
2087 ParIterator end = par_iterator_end();
2088 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2089 if (it->isMultiLingual(params))
2096 void Buffer::inset_iterator::setParagraph()
2098 while (pit != pend) {
2099 it = pit->insetlist.begin();
2100 if (it != pit->insetlist.end())
2107 InsetOld * Buffer::getInsetFromID(int id_arg) const
2109 for (inset_iterator it = inset_const_iterator_begin();
2110 it != inset_const_iterator_end(); ++it)
2112 if (it->id() == id_arg)
2114 InsetOld * in = it->getInsetFromID(id_arg);
2122 ParIterator Buffer::getParFromID(int id) const
2124 #warning FIXME: const correctness! (Andre)
2125 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2126 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2128 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2130 // John says this is called with id == -1 from undo
2131 lyxerr << "getParFromID(), id: " << id << endl;
2135 for (; it != end; ++it)
2143 bool Buffer::hasParWithID(int id) const
2145 ParConstIterator it = par_iterator_begin();
2146 ParConstIterator end = par_iterator_end();
2149 // John says this is called with id == -1 from undo
2150 lyxerr << "hasParWithID(), id: " << id << endl;
2154 for (; it != end; ++it)
2162 ParIterator Buffer::par_iterator_begin()
2164 return ParIterator(paragraphs.begin(), paragraphs);
2168 ParIterator Buffer::par_iterator_end()
2170 return ParIterator(paragraphs.end(), paragraphs);
2174 ParConstIterator Buffer::par_iterator_begin() const
2176 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2180 ParConstIterator Buffer::par_iterator_end() const
2182 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2186 Language const * Buffer::getLanguage() const
2188 return params.language;
2192 string const Buffer::B_(string const & l10n) const
2194 if (messages_.get()) {
2195 return messages_->get(l10n);
2202 bool Buffer::isClean() const
2208 bool Buffer::isBakClean() const
2214 void Buffer::markClean() const
2220 // if the .lyx file has been saved, we don't need an
2226 void Buffer::markBakClean()
2232 void Buffer::setUnnamed(bool flag)
2238 bool Buffer::isUnnamed()
2244 void Buffer::markDirty()
2252 DepClean::iterator it = dep_clean_.begin();
2253 DepClean::const_iterator const end = dep_clean_.end();
2255 for (; it != end; ++it) {
2261 string const & Buffer::fileName() const
2267 string const & Buffer::filePath() const
2273 bool Buffer::isReadonly() const
2279 void Buffer::setParentName(string const & name)
2281 params.parentname = name;
2285 Buffer::inset_iterator::inset_iterator()
2290 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2297 Buffer::inset_iterator Buffer::inset_iterator_begin()
2299 return inset_iterator(paragraphs.begin(), paragraphs.end());
2303 Buffer::inset_iterator Buffer::inset_iterator_end()
2305 return inset_iterator(paragraphs.end(), paragraphs.end());
2309 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2311 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2312 const_cast<ParagraphList&>(paragraphs).end());
2316 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2318 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2319 const_cast<ParagraphList&>(paragraphs).end());
2323 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2327 if (it == pit->insetlist.end()) {
2336 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2338 inset_iterator tmp = *this;
2344 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2350 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2356 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2362 lyx::pos_type Buffer::inset_iterator::getPos() const
2368 bool operator==(Buffer::inset_iterator const & iter1,
2369 Buffer::inset_iterator const & iter2)
2371 return iter1.pit == iter2.pit
2372 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2376 bool operator!=(Buffer::inset_iterator const & iter1,
2377 Buffer::inset_iterator const & iter2)
2379 return !(iter1 == iter2);