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"
19 #include "tex-strings.h"
21 #include "bufferview_funcs.h"
27 #include "LaTeXFeatures.h"
32 #include "errorlist.h"
35 #include "ParagraphParameters.h"
36 #include "iterators.h"
37 #include "lyxtextclasslist.h"
39 #include "paragraph_funcs.h"
43 #include "frontends/LyXView.h"
45 #include "mathed/formulamacro.h"
46 #include "mathed/formula.h"
48 #include "insets/insetbibitem.h"
49 #include "insets/insetbibtex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insettext.h"
53 #include "frontends/Dialogs.h"
54 #include "frontends/Alert.h"
56 #include "graphics/Previews.h"
58 #include "support/LAssert.h"
59 #include "support/textutils.h"
60 #include "support/filetools.h"
61 #include "support/path.h"
62 #include "support/os.h"
63 #include "support/tostr.h"
64 #include "support/lyxlib.h"
65 #include "support/FileInfo.h"
66 #include "support/lyxmanip.h"
67 #include "support/lyxtime.h"
69 #include <boost/bind.hpp>
70 #include <boost/tuple/tuple.hpp>
82 #include <sys/types.h>
89 using namespace lyx::support;
91 #ifndef CXX_GLOBAL_CSTD
103 using std::make_pair;
111 using lyx::textclass_type;
113 // all these externs should eventually be removed.
114 extern BufferList bufferlist;
118 const int LYX_FORMAT = 224;
120 bool openFileWrite(ofstream & ofs, string const & fname)
122 ofs.open(fname.c_str());
124 string const file = MakeDisplayPath(fname, 50);
125 string text = bformat(_("Could not open the specified "
126 "document\n%1$s."), file);
127 Alert::error(_("Could not open file"), text);
136 Buffer::Buffer(string const & file, bool ronly)
137 : niceFile(true), lyx_clean(true), bak_clean(true),
138 unnamed(false), read_only(ronly),
141 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
142 filepath_ = OnlyPath(file);
144 if (read_only || lyxrc.use_tempdir) {
145 tmppath = CreateBufferTmpDir();
150 // set initial author
151 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
157 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
158 // here the buffer should take care that it is
159 // saved properly, before it goes into the void.
163 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
164 Alert::warning(_("Could not remove temporary directory"),
165 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
170 // Remove any previewed LaTeX snippets assocoated with this buffer.
171 lyx::graphics::Previews::get().removeLoader(this);
175 string const Buffer::getLatexName(bool no_path) const
177 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
178 return no_path ? OnlyFilename(name) : name;
182 pair<Buffer::LogType, string> const Buffer::getLogName() const
184 string const filename = getLatexName(false);
186 if (filename.empty())
187 return make_pair(Buffer::latexlog, string());
189 string path = OnlyPath(filename);
191 if (lyxrc.use_tempdir || !IsDirWriteable(path))
194 string const fname = AddName(path,
195 OnlyFilename(ChangeExtension(filename,
198 AddName(path, OnlyFilename(
199 ChangeExtension(filename,
200 formats.extension("literate") + ".out")));
202 // If no Latex log or Build log is newer, show Build log
204 FileInfo const f_fi(fname);
205 FileInfo const b_fi(bname);
208 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
209 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
210 return make_pair(Buffer::buildlog, bname);
212 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
213 return make_pair(Buffer::latexlog, fname);
217 void Buffer::setReadonly(bool flag)
219 if (read_only != flag) {
226 AuthorList & Buffer::authors()
228 return params.authorlist;
232 void Buffer::setFileName(string const & newfile)
234 filename_ = MakeAbsPath(newfile);
235 filepath_ = OnlyPath(filename_);
236 setReadonly(IsFileWriteable(filename_) == 0);
241 // We'll remove this later. (Lgb)
244 void unknownClass(string const & unknown)
246 Alert::warning(_("Unknown document class"),
247 bformat(_("Using the default document class, because the "
248 " class %1$s is unknown."), unknown));
253 int Buffer::readHeader(LyXLex & lex)
255 int unknown_tokens = 0;
259 string const token = lex.getString();
264 if (token == "\\end_header")
267 lyxerr[Debug::PARSER] << "Handling header token: `"
268 << token << '\'' << endl;
271 string unknown = params.readToken(lex, token);
272 if (!unknown.empty()) {
273 if (unknown[0] != '\\') {
274 unknownClass(unknown);
277 string const s = bformat(_("Unknown token: "
281 error(ErrorItem(_("Header error"), s,
286 return unknown_tokens;
290 // candidate for move to BufferView
291 // (at least some parts in the beginning of the func)
294 // changed to be public and have one parameter
295 // if par = 0 normal behavior
296 // else insert behavior
297 // Returns false if "\the_end" is not read (Asger)
298 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
300 Paragraph::depth_type depth = 0;
301 bool the_end_read = false;
303 if (paragraphs.empty()) {
305 if (!params.getLyXTextClass().load()) {
306 string theclass = params.getLyXTextClass().name();
307 Alert::error(_("Can't load document class"), bformat(
308 "Using the default document class, because the "
309 " class %1$s could not be loaded.", theclass));
310 params.textclass = 0;
313 // We don't want to adopt the parameters from the
314 // document we insert, so read them into a temporary buffer
315 // and then discard it
317 Buffer tmpbuf("", false);
318 tmpbuf.readHeader(lex);
323 string const token = lex.getString();
328 lyxerr[Debug::PARSER] << "Handling token: `"
329 << token << '\'' << endl;
331 if (token == "\\the_end") {
336 readParagraph(lex, token, paragraphs, pit, depth);
343 int Buffer::readParagraph(LyXLex & lex, string const & token,
344 ParagraphList & pars, ParagraphList::iterator & pit,
345 Paragraph::depth_type & depth)
347 static Change current_change;
350 if (token == "\\layout") {
351 lex.pushToken(token);
354 par.params().depth(depth);
355 if (params.tracking_changes)
357 LyXFont f(LyXFont::ALL_INHERIT, params.language);
361 if (pit != pars.end())
364 pit = pars.insert(pit, par);
366 // FIXME: goddamn InsetTabular makes us pass a Buffer
368 ::readParagraph(*this, *pit, lex);
370 } else if (token == "\\begin_deeper") {
372 } else if (token == "\\end_deeper") {
374 lex.printError("\\end_deeper: " "depth is already null");
385 // needed to insert the selection
386 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
387 LyXFont const & fn,string const & str)
389 LyXLayout_ptr const & layout = par->layout();
393 par->checkInsertChar(font);
394 // insert the string, don't insert doublespace
395 bool space_inserted = true;
396 bool autobreakrows = !par->inInset() ||
397 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
398 for(string::const_iterator cit = str.begin();
399 cit != str.end(); ++cit) {
401 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
402 breakParagraph(params, paragraphs, par, pos,
403 layout->isEnvironment());
406 space_inserted = true;
410 // do not insert consecutive spaces if !free_spacing
411 } else if ((*cit == ' ' || *cit == '\t') &&
412 space_inserted && !par->isFreeSpacing()) {
414 } else if (*cit == '\t') {
415 if (!par->isFreeSpacing()) {
416 // tabs are like spaces here
417 par->insertChar(pos, ' ', font);
419 space_inserted = true;
421 const pos_type nb = 8 - pos % 8;
422 for (pos_type a = 0; a < nb ; ++a) {
423 par->insertChar(pos, ' ', font);
426 space_inserted = true;
428 } else if (!IsPrintable(*cit)) {
429 // Ignore unprintables
432 // just insert the character
433 par->insertChar(pos, *cit, font);
435 space_inserted = (*cit == ' ');
442 bool Buffer::readFile(LyXLex & lex, string const & filename)
444 bool ret = readFile(lex, filename, paragraphs.begin());
446 // After we have read a file, we must ensure that the buffer
447 // language is set and used in the gui.
448 // If you know of a better place to put this, please tell me. (Lgb)
449 updateDocLang(params.language);
455 // FIXME: all the below Alerts should give the filename..
456 bool Buffer::readFile(LyXLex & lex, string const & filename,
457 ParagraphList::iterator pit)
460 Alert::error(_("Document could not be read"),
461 _("The specified document could not be read."));
466 string const token(lex.getString());
469 Alert::error(_("Document could not be read"),
470 _("The specified document could not be read."));
474 // the first token _must_ be...
475 if (token != "\\lyxformat") {
476 Alert::error(_("Document format failure"),
477 _("The specified document 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 file_format = strToInt(tmp_format);
490 //lyxerr << "format: " << file_format << endl;
491 if (file_format == LYX_FORMAT) {
493 } else if (file_format > LYX_FORMAT) {
494 Alert::warning(_("Document format failure"),
495 _("This document was created with a newer version of "
496 "LyX. This is likely to cause problems."));
497 } else if (file_format < LYX_FORMAT) {
499 if (file_format < 200) {
500 Alert::error(_("Document format failure"),
501 _("This LyX document is too old to be read "
502 "by this version of LyX. Try LyX 0.10."));
504 } else if (!filename.empty()) {
506 LibFileSearch("lyx2lyx", "lyx2lyx");
507 if (command.empty()) {
508 Alert::error(_("Conversion script not found"),
509 _("The document is from an earlier version "
510 "of LyX, but the conversion script lyx2lyx "
511 "could not be found."));
515 +tostr(LYX_FORMAT) + ' '
516 + QuoteName(filename);
517 lyxerr[Debug::INFO] << "Running '"
520 cmd_ret const ret = RunCommand(command);
522 Alert::error(_("Conversion script failed"),
523 _("The document is from an earlier version "
524 "of LyX, but the lyx2lyx script failed "
528 istringstream is(STRCONV(ret.second));
530 tmplex.setStream(is);
531 return readFile(tmplex, string(), pit);
533 // This code is reached if lyx2lyx failed (for
534 // some reason) to change the file format of
540 bool the_end = readBody(lex, pit);
541 params.setPaperStuff();
544 Alert::error(_("Document format failure"),
545 _("The document ended unexpectedly, which means "
546 "that it is probably corrupted."));
552 // Should probably be moved to somewhere else: BufferView? LyXView?
553 bool Buffer::save() const
555 // We don't need autosaves in the immediate future. (Asger)
556 resetAutosaveTimers();
560 if (lyxrc.make_backup) {
561 s = fileName() + '~';
562 if (!lyxrc.backupdir_path.empty())
563 s = AddName(lyxrc.backupdir_path,
564 subst(os::slashify_path(s),'/','!'));
566 // Rename is the wrong way of making a backup,
567 // this is the correct way.
568 /* truss cp fil fil2:
569 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
570 stat("LyXVC.lyx", 0xEFFFF688) = 0
571 open("LyXVC.lyx", O_RDONLY) = 3
572 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
573 fstat(4, 0xEFFFF508) = 0
574 fstat(3, 0xEFFFF508) = 0
575 read(3, " # T h i s f i l e w".., 8192) = 5579
576 write(4, " # T h i s f i l e w".., 5579) = 5579
577 read(3, 0xEFFFD4A0, 8192) = 0
580 chmod("LyXVC3.lyx", 0100644) = 0
581 lseek(0, 0, SEEK_CUR) = 46440
585 // Should probably have some more error checking here.
586 // Doing it this way, also makes the inodes stay the same.
587 // This is still not a very good solution, in particular we
588 // might loose the owner of the backup.
589 FileInfo finfo(fileName());
591 mode_t fmode = finfo.getMode();
592 struct utimbuf times = {
593 finfo.getAccessTime(),
594 finfo.getModificationTime() };
596 ifstream ifs(fileName().c_str());
597 ofstream ofs(s.c_str(), ios::out|ios::trunc);
602 ::chmod(s.c_str(), fmode);
604 if (::utime(s.c_str(), ×)) {
605 lyxerr << "utime error." << endl;
608 lyxerr << "LyX was not able to make "
609 "backup copy. Beware." << endl;
614 if (writeFile(fileName())) {
616 removeAutosaveFile(fileName());
618 // Saving failed, so backup is not backup
619 if (lyxrc.make_backup) {
620 rename(s, fileName());
628 bool Buffer::writeFile(string const & fname) const
630 if (read_only && (fname == fileName())) {
634 FileInfo finfo(fname);
635 if (finfo.exist() && !finfo.writable()) {
639 ofstream ofs(fname.c_str());
644 // Use the standard "C" locale for file output.
645 ofs.imbue(std::locale::classic());
648 // The top of the file should not be written by params.
650 // write out a comment in the top of the file
651 ofs << '#' << lyx_docversion
652 << " created this file. For more info see http://www.lyx.org/\n"
653 << "\\lyxformat " << LYX_FORMAT << "\n";
655 // now write out the buffer paramters.
656 params.writeFile(ofs);
658 ofs << "\\end_header\n";
660 Paragraph::depth_type depth = 0;
662 // this will write out all the paragraphs
663 // using recursive descent.
664 ParagraphList::const_iterator pit = paragraphs.begin();
665 ParagraphList::const_iterator pend = paragraphs.end();
666 for (; pit != pend; ++pit)
667 pit->write(this, ofs, params, depth);
669 // Write marker that shows file is complete
670 ofs << "\n\\the_end" << endl;
674 // how to check if close went ok?
675 // Following is an attempt... (BE 20001011)
677 // good() returns false if any error occured, including some
679 // bad() returns true if something bad happened in the buffer,
680 // which should include file system full errors.
687 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
689 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
701 pair<int, string> const addDepth(int depth, int ldepth)
705 d += (ldepth - depth) * 2;
706 return make_pair(d, string(d, ' '));
712 string const Buffer::asciiParagraph(Paragraph const & par,
713 unsigned int linelen,
714 bool noparbreak) const
716 ostringstream buffer;
718 Paragraph::depth_type ltype_depth = 0;
719 bool ref_printed = false;
720 Paragraph::depth_type depth = par.params().depth();
722 // First write the layout
723 string const & tmp = par.layout()->name();
724 if (compare_no_case(tmp, "itemize") == 0) {
726 ltype_depth = depth + 1;
727 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
729 ltype_depth = depth + 1;
730 } else if (contains(ascii_lowercase(tmp), "ection")) {
732 ltype_depth = depth + 1;
733 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
735 ltype_depth = depth + 1;
736 } else if (compare_ascii_no_case(tmp, "description") == 0) {
738 ltype_depth = depth + 1;
739 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
742 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
750 /* maybe some vertical spaces */
752 /* the labelwidthstring used in lists */
756 /* some pagebreaks? */
760 /* what about the alignment */
762 // linelen <= 0 is special and means we don't have paragraph breaks
764 string::size_type currlinelen = 0;
770 buffer << string(depth * 2, ' ');
771 currlinelen += depth * 2;
774 // we should probably change to the paragraph language in the
775 // gettext here (if possible) so that strings are outputted in
776 // the correct language! (20012712 Jug)
780 case 4: // (Sub)Paragraph
781 case 5: // Description
785 buffer << _("Abstract") << "\n\n";
788 string const abst = _("Abstract: ");
790 currlinelen += abst.length();
793 case 7: // Bibliography
796 buffer << _("References") << "\n\n";
799 string const refs = _("References: ");
801 currlinelen += refs.length();
809 string const parlab = par.params().labelString();
810 buffer << parlab << ' ';
811 currlinelen += parlab.length() + 1;
819 pair<int, string> p = addDepth(depth, ltype_depth);
821 currlinelen += p.first;
824 // this is to change the linebreak to do it by word a bit more
825 // intelligent hopefully! (only in the case where we have a
826 // max linelength!) (Jug)
830 for (pos_type i = 0; i < par.size(); ++i) {
831 char c = par.getUChar(params, i);
833 case Paragraph::META_INSET:
835 InsetOld const * inset = par.getInset(i);
839 currlinelen += word.length();
842 if (inset->ascii(this, buffer, linelen)) {
843 // to be sure it breaks paragraph
844 currlinelen += linelen;
853 currlinelen + word.length() > linelen - 10) {
855 pair<int, string> p = addDepth(depth, ltype_depth);
857 currlinelen = p.first;
860 buffer << word << ' ';
861 currlinelen += word.length() + 1;
868 lyxerr[Debug::INFO] <<
869 "writeAsciiFile: NULL char in structure." << endl;
872 (currlinelen + word.length()) > linelen)
876 pair<int, string> p =
877 addDepth(depth, ltype_depth);
879 currlinelen = p.first;
886 return STRCONV(buffer.str());
890 void Buffer::writeFileAscii(string const & fname, int linelen)
893 if (!::openFileWrite(ofs, fname))
895 writeFileAscii(ofs, linelen);
899 void Buffer::writeFileAscii(ostream & os, int linelen)
901 ParagraphList::iterator beg = paragraphs.begin();
902 ParagraphList::iterator end = paragraphs.end();
903 ParagraphList::iterator it = beg;
904 for (; it != end; ++it) {
905 os << asciiParagraph(*it, linelen, it == beg);
911 void Buffer::makeLaTeXFile(string const & fname,
912 string const & original_path,
913 LatexRunParams const & runparams,
914 bool output_preamble, bool output_body)
916 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
919 if (!::openFileWrite(ofs, fname))
922 makeLaTeXFile(ofs, original_path,
923 runparams, output_preamble, output_body);
927 lyxerr << "File was not closed properly." << endl;
932 void Buffer::makeLaTeXFile(ostream & os,
933 string const & original_path,
934 LatexRunParams const & runparams_in,
935 bool output_preamble, bool output_body)
937 LatexRunParams runparams = runparams_in;
938 niceFile = runparams.nice; // this will be used by Insetincludes.
940 // validate the buffer.
941 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
942 LaTeXFeatures features(params);
944 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
947 // The starting paragraph of the coming rows is the
948 // first paragraph of the document. (Asger)
949 texrow.start(paragraphs.begin()->id(), 0);
951 if (output_preamble && runparams.nice) {
952 os << "%% " << lyx_docversion << " created this file. "
953 "For more info, see http://www.lyx.org/.\n"
954 "%% Do not edit unless you really know what "
959 lyxerr[Debug::INFO] << "lyx header finished" << endl;
960 // There are a few differences between nice LaTeX and usual files:
961 // usual is \batchmode and has a
962 // special input@path to allow the including of figures
963 // with either \input or \includegraphics (what figinsets do).
964 // input@path is set when the actual parameter
965 // original_path is set. This is done for usual tex-file, but not
966 // for nice-latex-file. (Matthias 250696)
967 if (output_preamble) {
968 if (!runparams.nice) {
969 // code for usual, NOT nice-latex-file
970 os << "\\batchmode\n"; // changed
974 if (!original_path.empty()) {
975 string inputpath = os::external_path(original_path);
976 subst(inputpath, "~", "\\string~");
977 os << "\\makeatletter\n"
978 << "\\def\\input@path{{"
979 << inputpath << "/}}\n"
980 << "\\makeatother\n";
986 // Write the preamble
987 runparams.use_babel = params.writeLaTeX(os, features, texrow);
993 os << "\\begin{document}\n";
996 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
998 if (!lyxrc.language_auto_begin) {
999 os << subst(lyxrc.language_command_begin, "$$lang",
1000 params.language->babel())
1005 latexParagraphs(this, paragraphs, os, texrow, runparams);
1007 // add this just in case after all the paragraphs
1011 if (!lyxrc.language_auto_end) {
1012 os << subst(lyxrc.language_command_end, "$$lang",
1013 params.language->babel())
1018 if (output_preamble) {
1019 os << "\\end{document}\n";
1022 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1024 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1028 // Just to be sure. (Asger)
1031 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1032 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1035 // we want this to be true outside previews (for insetexternal)
1040 bool Buffer::isLatex() const
1042 return params.getLyXTextClass().outputType() == LATEX;
1046 bool Buffer::isLinuxDoc() const
1048 return params.getLyXTextClass().outputType() == LINUXDOC;
1052 bool Buffer::isLiterate() const
1054 return params.getLyXTextClass().outputType() == LITERATE;
1058 bool Buffer::isDocBook() const
1060 return params.getLyXTextClass().outputType() == DOCBOOK;
1064 bool Buffer::isSGML() const
1066 LyXTextClass const & tclass = params.getLyXTextClass();
1068 return tclass.outputType() == LINUXDOC ||
1069 tclass.outputType() == DOCBOOK;
1073 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1076 if (!::openFileWrite(ofs, fname))
1079 niceFile = nice; // this will be used by included files.
1081 LaTeXFeatures features(params);
1087 LyXTextClass const & tclass = params.getLyXTextClass();
1089 string top_element = tclass.latexname();
1092 ofs << "<!doctype linuxdoc system";
1094 string preamble = params.preamble;
1095 string const name = nice ? ChangeExtension(filename_, ".sgml")
1097 preamble += features.getIncludedFiles(name);
1098 preamble += features.getLyXSGMLEntities();
1100 if (!preamble.empty()) {
1101 ofs << " [ " << preamble << " ]";
1105 if (params.options.empty())
1106 sgml::openTag(ofs, 0, false, top_element);
1108 string top = top_element;
1110 top += params.options;
1111 sgml::openTag(ofs, 0, false, top);
1115 ofs << "<!-- " << lyx_docversion
1116 << " created this file. For more info see http://www.lyx.org/"
1119 Paragraph::depth_type depth = 0; // paragraph depth
1121 vector<string> environment_stack(5);
1123 ParagraphList::iterator pit = paragraphs.begin();
1124 ParagraphList::iterator pend = paragraphs.end();
1125 for (; pit != pend; ++pit) {
1126 LyXLayout_ptr const & style = pit->layout();
1127 // treat <toc> as a special case for compatibility with old code
1128 if (pit->isInset(0)) {
1129 InsetOld * inset = pit->getInset(0);
1130 InsetOld::Code lyx_code = inset->lyxCode();
1131 if (lyx_code == InsetOld::TOC_CODE) {
1132 string const temp = "toc";
1133 sgml::openTag(ofs, depth, false, temp);
1138 // environment tag closing
1139 for (; depth > pit->params().depth(); --depth) {
1140 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1141 environment_stack[depth].erase();
1144 // write opening SGML tags
1145 switch (style->latextype) {
1146 case LATEX_PARAGRAPH:
1147 if (depth == pit->params().depth()
1148 && !environment_stack[depth].empty()) {
1149 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1150 environment_stack[depth].erase();
1156 sgml::openTag(ofs, depth, false, style->latexname());
1161 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1163 if (!environment_stack[depth].empty()) {
1164 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1168 environment_stack[depth].erase();
1169 sgml::openTag(ofs, depth, false, style->latexname());
1172 case LATEX_ENVIRONMENT:
1173 case LATEX_ITEM_ENVIRONMENT:
1174 case LATEX_BIB_ENVIRONMENT:
1176 string const & latexname = style->latexname();
1178 if (depth == pit->params().depth()
1179 && environment_stack[depth] != latexname) {
1180 sgml::closeTag(ofs, depth, false,
1181 environment_stack[depth]);
1182 environment_stack[depth].erase();
1184 if (depth < pit->params().depth()) {
1185 depth = pit->params().depth();
1186 environment_stack[depth].erase();
1188 if (environment_stack[depth] != latexname) {
1190 sgml::openTag(ofs, depth, false, "p");
1192 sgml::openTag(ofs, depth, false, latexname);
1194 if (environment_stack.size() == depth + 1)
1195 environment_stack.push_back("!-- --");
1196 environment_stack[depth] = latexname;
1199 if (style->latexparam() == "CDATA")
1202 if (style->latextype == LATEX_ENVIRONMENT) break;
1204 if (style->labeltype == LABEL_MANUAL)
1209 sgml::openTag(ofs, depth + 1, false, item_name);
1214 sgml::openTag(ofs, depth, false, style->latexname());
1218 simpleLinuxDocOnePar(ofs, pit, depth);
1221 // write closing SGML tags
1222 switch (style->latextype) {
1225 case LATEX_ENVIRONMENT:
1226 case LATEX_ITEM_ENVIRONMENT:
1227 case LATEX_BIB_ENVIRONMENT:
1228 if (style->latexparam() == "CDATA")
1232 sgml::closeTag(ofs, depth, false, style->latexname());
1238 for (int i = depth; i >= 0; --i)
1239 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1243 sgml::closeTag(ofs, 0, false, top_element);
1247 // How to check for successful close
1249 // we want this to be true outside previews (for insetexternal)
1254 // checks, if newcol chars should be put into this line
1255 // writes newline, if necessary.
1258 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1259 string::size_type newcol)
1262 if (colcount > lyxrc.ascii_linelen) {
1264 colcount = newcol; // assume write after this call
1279 string tag_name(PAR_TAG const & pt) {
1281 case NONE: return "!-- --";
1282 case TT: return "tt";
1283 case SF: return "sf";
1284 case BF: return "bf";
1285 case IT: return "it";
1286 case SL: return "sl";
1287 case EM: return "em";
1294 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1296 p1 = static_cast<PAR_TAG>(p1 | p2);
1301 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1303 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1309 // Handle internal paragraph parsing -- layout already processed.
1310 void Buffer::simpleLinuxDocOnePar(ostream & os,
1311 ParagraphList::iterator par,
1312 Paragraph::depth_type /*depth*/) const
1314 LyXLayout_ptr const & style = par->layout();
1316 string::size_type char_line_count = 5; // Heuristic choice ;-)
1318 // gets paragraph main font
1321 if (style->labeltype == LABEL_MANUAL) {
1322 font_old = style->labelfont;
1325 font_old = style->font;
1329 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1330 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1331 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1334 stack<PAR_TAG> tag_state;
1335 // parsing main loop
1336 for (pos_type i = 0; i < par->size(); ++i) {
1338 PAR_TAG tag_close = NONE;
1339 list < PAR_TAG > tag_open;
1341 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1343 if (font_old.family() != font.family()) {
1344 switch (family_type) {
1345 case LyXFont::SANS_FAMILY:
1348 case LyXFont::TYPEWRITER_FAMILY:
1355 family_type = font.family();
1357 switch (family_type) {
1358 case LyXFont::SANS_FAMILY:
1359 tag_open.push_back(SF);
1361 case LyXFont::TYPEWRITER_FAMILY:
1362 tag_open.push_back(TT);
1369 if (font_old.series() != font.series()) {
1370 switch (series_type) {
1371 case LyXFont::BOLD_SERIES:
1378 series_type = font.series();
1380 switch (series_type) {
1381 case LyXFont::BOLD_SERIES:
1382 tag_open.push_back(BF);
1390 if (font_old.shape() != font.shape()) {
1391 switch (shape_type) {
1392 case LyXFont::ITALIC_SHAPE:
1395 case LyXFont::SLANTED_SHAPE:
1402 shape_type = font.shape();
1404 switch (shape_type) {
1405 case LyXFont::ITALIC_SHAPE:
1406 tag_open.push_back(IT);
1408 case LyXFont::SLANTED_SHAPE:
1409 tag_open.push_back(SL);
1416 if (font_old.emph() != font.emph()) {
1417 if (font.emph() == LyXFont::ON) {
1418 tag_open.push_back(EM);
1427 list < PAR_TAG > temp;
1428 while (!tag_state.empty() && tag_close) {
1429 PAR_TAG k = tag_state.top();
1431 os << "</" << tag_name(k) << '>';
1438 for(list< PAR_TAG >::const_iterator j = temp.begin();
1439 j != temp.end(); ++j) {
1441 os << '<' << tag_name(*j) << '>';
1444 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1445 j != tag_open.end(); ++j) {
1447 os << '<' << tag_name(*j) << '>';
1450 char c = par->getChar(i);
1452 if (c == Paragraph::META_INSET) {
1453 InsetOld * inset = par->getInset(i);
1454 inset->linuxdoc(this, os);
1459 if (style->latexparam() == "CDATA") {
1460 // "TeX"-Mode on == > SGML-Mode on.
1467 boost::tie(ws, str) = sgml::escapeChar(c);
1468 if (ws && !par->isFreeSpacing()) {
1469 // in freespacing mode, spaces are
1470 // non-breaking characters
1471 if (desc_on) {// if char is ' ' then...
1474 sgmlLineBreak(os, char_line_count, 6);
1478 sgmlLineBreak(os, char_line_count, 1);
1483 char_line_count += str.length();
1489 while (!tag_state.empty()) {
1490 os << "</" << tag_name(tag_state.top()) << '>';
1494 // resets description flag correctly
1496 // <tag> not closed...
1497 sgmlLineBreak(os, char_line_count, 6);
1503 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1506 if (!::openFileWrite(ofs, fname))
1509 niceFile = nice; // this will be used by Insetincludes.
1511 LaTeXFeatures features(params);
1516 LyXTextClass const & tclass = params.getLyXTextClass();
1517 string top_element = tclass.latexname();
1520 ofs << "<!DOCTYPE " << top_element
1521 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1523 string preamble = params.preamble;
1524 string const name = nice ? ChangeExtension(filename_, ".sgml")
1526 preamble += features.getIncludedFiles(name);
1527 preamble += features.getLyXSGMLEntities();
1529 if (!preamble.empty()) {
1530 ofs << "\n [ " << preamble << " ]";
1535 string top = top_element;
1537 top += params.language->code();
1540 if (!params.options.empty()) {
1542 top += params.options;
1544 sgml::openTag(ofs, 0, false, top);
1546 ofs << "<!-- DocBook file was created by " << lyx_docversion
1547 << "\n See http://www.lyx.org/ for more information -->\n";
1549 vector<string> environment_stack(10);
1550 vector<string> environment_inner(10);
1551 vector<string> command_stack(10);
1553 bool command_flag = false;
1554 Paragraph::depth_type command_depth = 0;
1555 Paragraph::depth_type command_base = 0;
1556 Paragraph::depth_type cmd_depth = 0;
1557 Paragraph::depth_type depth = 0; // paragraph depth
1560 string command_name;
1562 ParagraphList::iterator par = paragraphs.begin();
1563 ParagraphList::iterator pend = paragraphs.end();
1565 for (; par != pend; ++par) {
1569 int desc_on = 0; // description mode
1571 LyXLayout_ptr const & style = par->layout();
1573 // environment tag closing
1574 for (; depth > par->params().depth(); --depth) {
1575 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1576 item_name = "listitem";
1577 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1578 if (environment_inner[depth] == "varlistentry")
1579 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1581 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1582 environment_stack[depth].erase();
1583 environment_inner[depth].erase();
1586 if (depth == par->params().depth()
1587 && environment_stack[depth] != style->latexname()
1588 && !environment_stack[depth].empty()) {
1589 if (environment_inner[depth] != "!-- --") {
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]);
1596 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1598 environment_stack[depth].erase();
1599 environment_inner[depth].erase();
1602 // Write opening SGML tags.
1603 switch (style->latextype) {
1604 case LATEX_PARAGRAPH:
1605 sgml::openTag(ofs, depth + command_depth,
1606 false, style->latexname());
1611 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1613 command_name = style->latexname();
1615 sgmlparam = style->latexparam();
1616 c_params = split(sgmlparam, c_depth,'|');
1618 cmd_depth = atoi(c_depth);
1621 if (cmd_depth < command_base) {
1622 for (Paragraph::depth_type j = command_depth;
1623 j >= command_base; --j) {
1624 sgml::closeTag(ofs, j, false, command_stack[j]);
1627 command_depth = command_base = cmd_depth;
1628 } else if (cmd_depth <= command_depth) {
1629 for (int j = command_depth;
1630 j >= int(cmd_depth); --j) {
1631 sgml::closeTag(ofs, j, false, command_stack[j]);
1634 command_depth = cmd_depth;
1636 command_depth = cmd_depth;
1638 command_depth = command_base = cmd_depth;
1639 command_flag = true;
1641 if (command_stack.size() == command_depth + 1)
1642 command_stack.push_back(string());
1643 command_stack[command_depth] = command_name;
1645 // treat label as a special case for
1646 // more WYSIWYM handling.
1647 // This is a hack while paragraphs can't have
1648 // attributes, like id in this case.
1649 if (par->isInset(0)) {
1650 InsetOld * inset = par->getInset(0);
1651 InsetOld::Code lyx_code = inset->lyxCode();
1652 if (lyx_code == InsetOld::LABEL_CODE) {
1653 command_name += " id=\"";
1654 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1655 command_name += '"';
1660 sgml::openTag(ofs, depth + command_depth, false, command_name);
1662 item_name = c_params.empty() ? "title" : c_params;
1663 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1666 case LATEX_ENVIRONMENT:
1667 case LATEX_ITEM_ENVIRONMENT:
1668 if (depth < par->params().depth()) {
1669 depth = par->params().depth();
1670 environment_stack[depth].erase();
1673 if (environment_stack[depth] != style->latexname()) {
1674 if (environment_stack.size() == depth + 1) {
1675 environment_stack.push_back("!-- --");
1676 environment_inner.push_back("!-- --");
1678 environment_stack[depth] = style->latexname();
1679 environment_inner[depth] = "!-- --";
1680 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1682 if (environment_inner[depth] != "!-- --") {
1683 item_name= "listitem";
1684 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1685 if (environment_inner[depth] == "varlistentry")
1686 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1690 if (style->latextype == LATEX_ENVIRONMENT) {
1691 if (!style->latexparam().empty()) {
1692 if (style->latexparam() == "CDATA")
1695 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1700 desc_on = (style->labeltype == LABEL_MANUAL);
1702 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1703 sgml::openTag(ofs, depth + 1 + command_depth,
1704 false, environment_inner[depth]);
1706 item_name = desc_on ? "term" : "para";
1707 sgml::openTag(ofs, depth + 1 + command_depth,
1711 sgml::openTag(ofs, depth + command_depth,
1712 false, style->latexname());
1716 simpleDocBookOnePar(ofs, par, desc_on,
1717 depth + 1 + command_depth);
1720 // write closing SGML tags
1721 switch (style->latextype) {
1723 end_tag = c_params.empty() ? "title" : c_params;
1724 sgml::closeTag(ofs, depth + command_depth,
1727 case LATEX_ENVIRONMENT:
1728 if (!style->latexparam().empty()) {
1729 if (style->latexparam() == "CDATA")
1732 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1735 case LATEX_ITEM_ENVIRONMENT:
1736 if (desc_on == 1) break;
1738 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1740 case LATEX_PARAGRAPH:
1741 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1744 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1750 for (int d = depth; d >= 0; --d) {
1751 if (!environment_stack[depth].empty()) {
1752 if (environment_inner[depth] != "!-- --") {
1753 item_name = "listitem";
1754 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1755 if (environment_inner[depth] == "varlistentry")
1756 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1759 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1763 for (int j = command_depth; j >= 0 ; --j)
1764 if (!command_stack[j].empty()) {
1765 sgml::closeTag(ofs, j, false, command_stack[j]);
1770 sgml::closeTag(ofs, 0, false, top_element);
1773 // How to check for successful close
1775 // we want this to be true outside previews (for insetexternal)
1780 void Buffer::simpleDocBookOnePar(ostream & os,
1781 ParagraphList::iterator par, int & desc_on,
1782 Paragraph::depth_type depth) const
1784 bool emph_flag = false;
1786 LyXLayout_ptr const & style = par->layout();
1788 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1790 int char_line_count = depth;
1791 //if (!style.free_spacing)
1792 // os << string(depth,' ');
1794 // parsing main loop
1795 for (pos_type i = 0; i < par->size(); ++i) {
1796 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1798 // handle <emphasis> tag
1799 if (font_old.emph() != font.emph()) {
1800 if (font.emph() == LyXFont::ON) {
1801 if (style->latexparam() == "CDATA")
1804 if (style->latexparam() == "CDATA")
1808 if (style->latexparam() == "CDATA")
1810 os << "</emphasis>";
1811 if (style->latexparam() == "CDATA")
1818 if (par->isInset(i)) {
1819 InsetOld * inset = par->getInset(i);
1820 // don't print the inset in position 0 if desc_on == 3 (label)
1821 if (i || desc_on != 3) {
1822 if (style->latexparam() == "CDATA")
1824 inset->docbook(this, os, false);
1825 if (style->latexparam() == "CDATA")
1829 char c = par->getChar(i);
1832 boost::tie(ws, str) = sgml::escapeChar(c);
1834 if (style->pass_thru) {
1836 } else if (par->isFreeSpacing() || c != ' ') {
1838 } else if (desc_on == 1) {
1840 os << "\n</term><listitem><para>";
1850 if (style->latexparam() == "CDATA")
1852 os << "</emphasis>";
1853 if (style->latexparam() == "CDATA")
1857 // resets description flag correctly
1859 // <term> not closed...
1860 os << "</term>\n<listitem><para> </para>";
1862 if (style->free_spacing)
1867 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1868 // Other flags: -wall -v0 -x
1869 int Buffer::runChktex()
1873 // get LaTeX-Filename
1874 string const name = getLatexName();
1875 string path = filePath();
1877 string const org_path = path;
1878 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1882 Path p(path); // path to LaTeX file
1883 message(_("Running chktex..."));
1885 // Generate the LaTeX file if neccessary
1886 LatexRunParams runparams;
1887 runparams.flavor = LatexRunParams::LATEX;
1888 runparams.nice = false;
1889 makeLaTeXFile(name, org_path, runparams);
1892 Chktex chktex(lyxrc.chktex_command, name, filePath());
1893 int res = chktex.run(terr); // run chktex
1896 Alert::error(_("chktex failure"),
1897 _("Could not run chktex successfully."));
1898 } else if (res > 0) {
1899 // Insert all errors as errors boxes
1900 bufferErrors(*this, terr);
1909 void Buffer::validate(LaTeXFeatures & features) const
1911 LyXTextClass const & tclass = params.getLyXTextClass();
1913 if (params.tracking_changes) {
1914 features.require("dvipost");
1915 features.require("color");
1918 // AMS Style is at document level
1919 if (params.use_amsmath == BufferParams::AMS_ON
1920 || tclass.provides(LyXTextClass::amsmath))
1921 features.require("amsmath");
1923 for_each(paragraphs.begin(), paragraphs.end(),
1924 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1926 // the bullet shapes are buffer level not paragraph level
1927 // so they are tested here
1928 for (int i = 0; i < 4; ++i) {
1929 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1930 int const font = params.user_defined_bullets[i].getFont();
1932 int const c = params
1933 .user_defined_bullets[i]
1940 features.require("latexsym");
1942 } else if (font == 1) {
1943 features.require("amssymb");
1944 } else if ((font >= 2 && font <= 5)) {
1945 features.require("pifont");
1950 if (lyxerr.debugging(Debug::LATEX)) {
1951 features.showStruct();
1956 void Buffer::getLabelList(std::vector<string> & list) const
1958 /// if this is a child document and the parent is already loaded
1959 /// Use the parent's list instead [ale990407]
1960 if (!params.parentname.empty()
1961 && bufferlist.exists(params.parentname)) {
1962 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1964 tmp->getLabelList(list);
1969 for (inset_iterator it = inset_const_iterator_begin();
1970 it != inset_const_iterator_end(); ++it) {
1971 it->getLabelList(list);
1976 // This is also a buffer property (ale)
1977 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1979 /// if this is a child document and the parent is already loaded
1980 /// use the parent's list instead [ale990412]
1981 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1982 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1984 tmp->fillWithBibKeys(keys);
1989 for (inset_iterator it = inset_const_iterator_begin();
1990 it != inset_const_iterator_end(); ++it) {
1991 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
1992 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
1993 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
1994 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
1995 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
1996 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
1997 string const key = bib.getContents();
1998 string const opt = bib.getOptions();
1999 string const ref; // = pit->asString(this, false);
2000 string const info = opt + "TheBibliographyRef" + ref;
2001 keys.push_back(pair<string, string>(key, info));
2007 bool Buffer::isDepClean(string const & name) const
2009 DepClean::const_iterator it = dep_clean_.find(name);
2010 if (it == dep_clean_.end())
2016 void Buffer::markDepClean(string const & name)
2018 dep_clean_[name] = true;
2022 bool Buffer::dispatch(string const & command, bool * result)
2024 // Split command string into command and argument
2026 string line = ltrim(command);
2027 string const arg = trim(split(line, cmd, ' '));
2029 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2033 bool Buffer::dispatch(int action, string const & argument, bool * result)
2035 bool dispatched = true;
2039 bool const tmp = Exporter::Export(this, argument, false);
2052 void Buffer::changeLanguage(Language const * from, Language const * to)
2054 lyxerr << "Changing Language!" << endl;
2056 // Take care of l10n/i18n
2059 ParIterator end = par_iterator_end();
2060 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2061 it->changeLanguage(params, from, to);
2065 void Buffer::updateDocLang(Language const * nlang)
2067 messages_.reset(new Messages(nlang->code()));
2071 bool Buffer::isMultiLingual()
2073 ParIterator end = par_iterator_end();
2074 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2075 if (it->isMultiLingual(params))
2082 void Buffer::inset_iterator::setParagraph()
2084 while (pit != pend) {
2085 it = pit->insetlist.begin();
2086 if (it != pit->insetlist.end())
2093 InsetOld * Buffer::getInsetFromID(int id_arg) const
2095 for (inset_iterator it = inset_const_iterator_begin();
2096 it != inset_const_iterator_end(); ++it)
2098 if (it->id() == id_arg)
2100 InsetOld * in = it->getInsetFromID(id_arg);
2108 ParIterator Buffer::getParFromID(int id) const
2110 #warning FIXME: const correctness! (Andre)
2111 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2112 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2114 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2116 // John says this is called with id == -1 from undo
2117 lyxerr << "getParFromID(), id: " << id << endl;
2121 for (; it != end; ++it)
2129 bool Buffer::hasParWithID(int id) const
2131 ParConstIterator it = par_iterator_begin();
2132 ParConstIterator end = par_iterator_end();
2135 // John says this is called with id == -1 from undo
2136 lyxerr << "hasParWithID(), id: " << id << endl;
2140 for (; it != end; ++it)
2148 ParIterator Buffer::par_iterator_begin()
2150 return ParIterator(paragraphs.begin(), paragraphs);
2154 ParIterator Buffer::par_iterator_end()
2156 return ParIterator(paragraphs.end(), paragraphs);
2159 ParConstIterator Buffer::par_iterator_begin() const
2161 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2165 ParConstIterator Buffer::par_iterator_end() const
2167 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2171 Language const * Buffer::getLanguage() const
2173 return params.language;
2177 string const Buffer::B_(string const & l10n) const
2179 if (messages_.get()) {
2180 return messages_->get(l10n);
2187 bool Buffer::isClean() const
2193 bool Buffer::isBakClean() const
2199 void Buffer::markClean() const
2205 // if the .lyx file has been saved, we don't need an
2211 void Buffer::markBakClean()
2217 void Buffer::setUnnamed(bool flag)
2223 bool Buffer::isUnnamed()
2229 void Buffer::markDirty()
2237 DepClean::iterator it = dep_clean_.begin();
2238 DepClean::const_iterator const end = dep_clean_.end();
2240 for (; it != end; ++it) {
2246 string const & Buffer::fileName() const
2252 string const & Buffer::filePath() const
2258 bool Buffer::isReadonly() const
2264 void Buffer::setParentName(string const & name)
2266 params.parentname = name;
2270 Buffer::inset_iterator::inset_iterator()
2275 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2282 Buffer::inset_iterator Buffer::inset_iterator_begin()
2284 return inset_iterator(paragraphs.begin(), paragraphs.end());
2288 Buffer::inset_iterator Buffer::inset_iterator_end()
2290 return inset_iterator(paragraphs.end(), paragraphs.end());
2294 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2296 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2297 const_cast<ParagraphList&>(paragraphs).end());
2301 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2303 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2304 const_cast<ParagraphList&>(paragraphs).end());
2308 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2312 if (it == pit->insetlist.end()) {
2321 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2323 inset_iterator tmp = *this;
2329 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2335 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2341 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2347 lyx::pos_type Buffer::inset_iterator::getPos() const
2353 bool operator==(Buffer::inset_iterator const & iter1,
2354 Buffer::inset_iterator const & iter2)
2356 return iter1.pit == iter2.pit
2357 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2361 bool operator!=(Buffer::inset_iterator const & iter1,
2362 Buffer::inset_iterator const & iter2)
2364 return !(iter1 == iter2);