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"
68 #include "support/gzstream.h"
70 #include <boost/bind.hpp>
71 #include <boost/tuple/tuple.hpp>
83 #include <sys/types.h>
90 using namespace lyx::support;
92 #ifndef CXX_GLOBAL_CSTD
104 using std::make_pair;
112 using lyx::textclass_type;
114 // all these externs should eventually be removed.
115 extern BufferList bufferlist;
119 const int LYX_FORMAT = 225;
121 bool openFileWrite(ofstream & ofs, string const & fname)
123 ofs.open(fname.c_str());
125 string const file = MakeDisplayPath(fname, 50);
126 string text = bformat(_("Could not open the specified "
127 "document\n%1$s."), file);
128 Alert::error(_("Could not open file"), text);
137 Buffer::Buffer(string const & file, bool ronly)
138 : niceFile(true), lyx_clean(true), bak_clean(true),
139 unnamed(false), read_only(ronly),
142 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
143 filepath_ = OnlyPath(file);
145 if (read_only || lyxrc.use_tempdir) {
146 tmppath = CreateBufferTmpDir();
151 // set initial author
152 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
158 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
159 // here the buffer should take care that it is
160 // saved properly, before it goes into the void.
164 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
165 Alert::warning(_("Could not remove temporary directory"),
166 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
171 // Remove any previewed LaTeX snippets assocoated with this buffer.
172 lyx::graphics::Previews::get().removeLoader(this);
176 string const Buffer::getLatexName(bool no_path) const
178 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
179 return no_path ? OnlyFilename(name) : name;
183 pair<Buffer::LogType, string> const Buffer::getLogName() const
185 string const filename = getLatexName(false);
187 if (filename.empty())
188 return make_pair(Buffer::latexlog, string());
190 string path = OnlyPath(filename);
192 if (lyxrc.use_tempdir || !IsDirWriteable(path))
195 string const fname = AddName(path,
196 OnlyFilename(ChangeExtension(filename,
199 AddName(path, OnlyFilename(
200 ChangeExtension(filename,
201 formats.extension("literate") + ".out")));
203 // If no Latex log or Build log is newer, show Build log
205 FileInfo const f_fi(fname);
206 FileInfo const b_fi(bname);
209 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
210 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
211 return make_pair(Buffer::buildlog, bname);
213 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
214 return make_pair(Buffer::latexlog, fname);
218 void Buffer::setReadonly(bool flag)
220 if (read_only != flag) {
227 AuthorList & Buffer::authors()
229 return params.authorlist;
233 void Buffer::setFileName(string const & newfile)
235 filename_ = MakeAbsPath(newfile);
236 filepath_ = OnlyPath(filename_);
237 setReadonly(IsFileWriteable(filename_) == 0);
242 // We'll remove this later. (Lgb)
245 void unknownClass(string const & unknown)
247 Alert::warning(_("Unknown document class"),
248 bformat(_("Using the default document class, because the "
249 " class %1$s is unknown."), unknown));
254 int Buffer::readHeader(LyXLex & lex)
256 int unknown_tokens = 0;
260 string const token = lex.getString();
265 if (token == "\\end_header")
268 lyxerr[Debug::PARSER] << "Handling header token: `"
269 << token << '\'' << endl;
272 string unknown = params.readToken(lex, token);
273 if (!unknown.empty()) {
274 if (unknown[0] != '\\') {
275 unknownClass(unknown);
278 string const s = bformat(_("Unknown token: "
282 error(ErrorItem(_("Header error"), s,
287 return unknown_tokens;
291 // candidate for move to BufferView
292 // (at least some parts in the beginning of the func)
295 // changed to be public and have one parameter
296 // if par = 0 normal behavior
297 // else insert behavior
298 // Returns false if "\the_end" is not read (Asger)
299 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
301 Paragraph::depth_type depth = 0;
302 bool the_end_read = false;
304 if (paragraphs.empty()) {
306 if (!params.getLyXTextClass().load()) {
307 string theclass = params.getLyXTextClass().name();
308 Alert::error(_("Can't load document class"), bformat(
309 "Using the default document class, because the "
310 " class %1$s could not be loaded.", theclass));
311 params.textclass = 0;
314 // We don't want to adopt the parameters from the
315 // document we insert, so read them into a temporary buffer
316 // and then discard it
318 Buffer tmpbuf("", false);
319 tmpbuf.readHeader(lex);
324 string const token = lex.getString();
329 lyxerr[Debug::PARSER] << "Handling token: `"
330 << token << '\'' << endl;
332 if (token == "\\the_end") {
337 readParagraph(lex, token, paragraphs, pit, depth);
344 int Buffer::readParagraph(LyXLex & lex, string const & token,
345 ParagraphList & pars, ParagraphList::iterator & pit,
346 Paragraph::depth_type & depth)
348 static Change current_change;
351 if (token == "\\layout") {
352 lex.pushToken(token);
355 par.params().depth(depth);
356 if (params.tracking_changes)
358 LyXFont f(LyXFont::ALL_INHERIT, params.language);
362 if (pit != pars.end())
365 pit = pars.insert(pit, par);
367 // FIXME: goddamn InsetTabular makes us pass a Buffer
369 ::readParagraph(*this, *pit, lex);
371 } else if (token == "\\begin_deeper") {
373 } else if (token == "\\end_deeper") {
375 lex.printError("\\end_deeper: " "depth is already null");
386 // needed to insert the selection
387 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
388 LyXFont const & fn,string const & str)
390 LyXLayout_ptr const & layout = par->layout();
394 par->checkInsertChar(font);
395 // insert the string, don't insert doublespace
396 bool space_inserted = true;
397 bool autobreakrows = !par->inInset() ||
398 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
399 for(string::const_iterator cit = str.begin();
400 cit != str.end(); ++cit) {
402 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
403 breakParagraph(params, paragraphs, par, pos,
404 layout->isEnvironment());
407 space_inserted = true;
411 // do not insert consecutive spaces if !free_spacing
412 } else if ((*cit == ' ' || *cit == '\t') &&
413 space_inserted && !par->isFreeSpacing()) {
415 } else if (*cit == '\t') {
416 if (!par->isFreeSpacing()) {
417 // tabs are like spaces here
418 par->insertChar(pos, ' ', font);
420 space_inserted = true;
422 const pos_type nb = 8 - pos % 8;
423 for (pos_type a = 0; a < nb ; ++a) {
424 par->insertChar(pos, ' ', font);
427 space_inserted = true;
429 } else if (!IsPrintable(*cit)) {
430 // Ignore unprintables
433 // just insert the character
434 par->insertChar(pos, *cit, font);
436 space_inserted = (*cit == ' ');
443 bool Buffer::readFile(LyXLex & lex, string const & filename)
445 bool ret = readFile(lex, filename, paragraphs.begin());
447 // After we have read a file, we must ensure that the buffer
448 // language is set and used in the gui.
449 // If you know of a better place to put this, please tell me. (Lgb)
450 updateDocLang(params.language);
456 // FIXME: all the below Alerts should give the filename..
457 bool Buffer::readFile(LyXLex & lex, string const & filename,
458 ParagraphList::iterator pit)
461 Alert::error(_("Document could not be read"),
462 _("The specified document could not be read."));
467 string const token(lex.getString());
470 Alert::error(_("Document could not be read"),
471 _("The specified document could not be read."));
475 // the first token _must_ be...
476 if (token != "\\lyxformat") {
477 Alert::error(_("Document format failure"),
478 _("The specified document is not a LyX document."));
483 string tmp_format = lex.getString();
484 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
485 // if present remove ".," from string.
486 string::size_type dot = tmp_format.find_first_of(".,");
487 //lyxerr << " dot found at " << dot << endl;
488 if (dot != string::npos)
489 tmp_format.erase(dot, 1);
490 file_format = strToInt(tmp_format);
491 //lyxerr << "format: " << file_format << endl;
492 if (file_format == LYX_FORMAT) {
494 } else if (file_format > LYX_FORMAT) {
495 Alert::warning(_("Document format failure"),
496 _("This document was created with a newer version of "
497 "LyX. This is likely to cause problems."));
498 } else if (file_format < LYX_FORMAT) {
500 if (file_format < 200) {
501 Alert::error(_("Document format failure"),
502 _("This LyX document is too old to be read "
503 "by this version of LyX. Try LyX 0.10."));
505 } else if (!filename.empty()) {
507 LibFileSearch("lyx2lyx", "lyx2lyx");
508 if (command.empty()) {
509 Alert::error(_("Conversion script not found"),
510 _("The document is from an earlier version "
511 "of LyX, but the conversion script lyx2lyx "
512 "could not be found."));
516 +tostr(LYX_FORMAT) + ' '
517 + QuoteName(filename);
518 lyxerr[Debug::INFO] << "Running '"
521 cmd_ret const ret = RunCommand(command);
523 Alert::error(_("Conversion script failed"),
524 _("The document is from an earlier version "
525 "of LyX, but the lyx2lyx script failed "
529 istringstream is(STRCONV(ret.second));
531 tmplex.setStream(is);
532 return readFile(tmplex, string(), pit);
534 // This code is reached if lyx2lyx failed (for
535 // some reason) to change the file format of
541 bool the_end = readBody(lex, pit);
542 params.setPaperStuff();
545 Alert::error(_("Document format failure"),
546 _("The document ended unexpectedly, which means "
547 "that it is probably corrupted."));
553 // Should probably be moved to somewhere else: BufferView? LyXView?
554 bool Buffer::save() const
556 // We don't need autosaves in the immediate future. (Asger)
557 resetAutosaveTimers();
561 if (lyxrc.make_backup) {
562 s = fileName() + '~';
563 if (!lyxrc.backupdir_path.empty())
564 s = AddName(lyxrc.backupdir_path,
565 subst(os::slashify_path(s),'/','!'));
567 // Rename is the wrong way of making a backup,
568 // this is the correct way.
569 /* truss cp fil fil2:
570 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
571 stat("LyXVC.lyx", 0xEFFFF688) = 0
572 open("LyXVC.lyx", O_RDONLY) = 3
573 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
574 fstat(4, 0xEFFFF508) = 0
575 fstat(3, 0xEFFFF508) = 0
576 read(3, " # T h i s f i l e w".., 8192) = 5579
577 write(4, " # T h i s f i l e w".., 5579) = 5579
578 read(3, 0xEFFFD4A0, 8192) = 0
581 chmod("LyXVC3.lyx", 0100644) = 0
582 lseek(0, 0, SEEK_CUR) = 46440
586 // Should probably have some more error checking here.
587 // Doing it this way, also makes the inodes stay the same.
588 // This is still not a very good solution, in particular we
589 // might loose the owner of the backup.
590 FileInfo finfo(fileName());
592 mode_t fmode = finfo.getMode();
593 struct utimbuf times = {
594 finfo.getAccessTime(),
595 finfo.getModificationTime() };
597 ifstream ifs(fileName().c_str());
598 ofstream ofs(s.c_str(), ios::out|ios::trunc);
603 ::chmod(s.c_str(), fmode);
605 if (::utime(s.c_str(), ×)) {
606 lyxerr << "utime error." << endl;
609 lyxerr << "LyX was not able to make "
610 "backup copy. Beware." << endl;
615 if (writeFile(fileName())) {
617 removeAutosaveFile(fileName());
619 // Saving failed, so backup is not backup
620 if (lyxrc.make_backup) {
621 rename(s, fileName());
629 bool Buffer::writeFile(string const & fname) const
631 if (read_only && (fname == fileName())) {
635 FileInfo finfo(fname);
636 if (finfo.exist() && !finfo.writable()) {
640 bool const compressed = (fname.substr(fname.size() - 3, 3) == ".gz");
643 gz::ogzstream ofs(fname.c_str());
648 return do_writeFile(ofs);
652 ofstream ofs(fname.c_str());
656 return do_writeFile(ofs);
660 bool Buffer::do_writeFile(ostream & ofs) const
664 // Use the standard "C" locale for file output.
665 ofs.imbue(std::locale::classic());
668 // The top of the file should not be written by params.
670 // write out a comment in the top of the file
671 ofs << '#' << lyx_docversion
672 << " created this file. For more info see http://www.lyx.org/\n"
673 << "\\lyxformat " << LYX_FORMAT << "\n";
675 // now write out the buffer paramters.
676 params.writeFile(ofs);
678 ofs << "\\end_header\n";
680 Paragraph::depth_type depth = 0;
682 // this will write out all the paragraphs
683 // using recursive descent.
684 ParagraphList::const_iterator pit = paragraphs.begin();
685 ParagraphList::const_iterator pend = paragraphs.end();
686 for (; pit != pend; ++pit)
687 pit->write(this, ofs, params, depth);
689 // Write marker that shows file is complete
690 ofs << "\n\\the_end" << endl;
692 // Shouldn't really be needed....
695 // how to check if close went ok?
696 // Following is an attempt... (BE 20001011)
698 // good() returns false if any error occured, including some
700 // bad() returns true if something bad happened in the buffer,
701 // which should include file system full errors.
708 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
710 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
722 pair<int, string> const addDepth(int depth, int ldepth)
726 d += (ldepth - depth) * 2;
727 return make_pair(d, string(d, ' '));
733 string const Buffer::asciiParagraph(Paragraph const & par,
734 unsigned int linelen,
735 bool noparbreak) const
737 ostringstream buffer;
739 Paragraph::depth_type ltype_depth = 0;
740 bool ref_printed = false;
741 Paragraph::depth_type depth = par.params().depth();
743 // First write the layout
744 string const & tmp = par.layout()->name();
745 if (compare_no_case(tmp, "itemize") == 0) {
747 ltype_depth = depth + 1;
748 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
750 ltype_depth = depth + 1;
751 } else if (contains(ascii_lowercase(tmp), "ection")) {
753 ltype_depth = depth + 1;
754 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
756 ltype_depth = depth + 1;
757 } else if (compare_ascii_no_case(tmp, "description") == 0) {
759 ltype_depth = depth + 1;
760 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
763 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
771 /* maybe some vertical spaces */
773 /* the labelwidthstring used in lists */
777 /* some pagebreaks? */
781 /* what about the alignment */
783 // linelen <= 0 is special and means we don't have paragraph breaks
785 string::size_type currlinelen = 0;
791 buffer << string(depth * 2, ' ');
792 currlinelen += depth * 2;
795 // we should probably change to the paragraph language in the
796 // gettext here (if possible) so that strings are outputted in
797 // the correct language! (20012712 Jug)
801 case 4: // (Sub)Paragraph
802 case 5: // Description
806 buffer << _("Abstract") << "\n\n";
809 string const abst = _("Abstract: ");
811 currlinelen += abst.length();
814 case 7: // Bibliography
817 buffer << _("References") << "\n\n";
820 string const refs = _("References: ");
822 currlinelen += refs.length();
830 string const parlab = par.params().labelString();
831 buffer << parlab << ' ';
832 currlinelen += parlab.length() + 1;
840 pair<int, string> p = addDepth(depth, ltype_depth);
842 currlinelen += p.first;
845 // this is to change the linebreak to do it by word a bit more
846 // intelligent hopefully! (only in the case where we have a
847 // max linelength!) (Jug)
851 for (pos_type i = 0; i < par.size(); ++i) {
852 char c = par.getUChar(params, i);
854 case Paragraph::META_INSET:
856 InsetOld const * inset = par.getInset(i);
860 currlinelen += word.length();
863 if (inset->ascii(this, buffer, linelen)) {
864 // to be sure it breaks paragraph
865 currlinelen += linelen;
874 currlinelen + word.length() > linelen - 10) {
876 pair<int, string> p = addDepth(depth, ltype_depth);
878 currlinelen = p.first;
881 buffer << word << ' ';
882 currlinelen += word.length() + 1;
889 lyxerr[Debug::INFO] <<
890 "writeAsciiFile: NULL char in structure." << endl;
893 (currlinelen + word.length()) > linelen)
897 pair<int, string> p =
898 addDepth(depth, ltype_depth);
900 currlinelen = p.first;
907 return STRCONV(buffer.str());
911 void Buffer::writeFileAscii(string const & fname, int linelen)
914 if (!::openFileWrite(ofs, fname))
916 writeFileAscii(ofs, linelen);
920 void Buffer::writeFileAscii(ostream & os, int linelen)
922 ParagraphList::iterator beg = paragraphs.begin();
923 ParagraphList::iterator end = paragraphs.end();
924 ParagraphList::iterator it = beg;
925 for (; it != end; ++it) {
926 os << asciiParagraph(*it, linelen, it == beg);
932 void Buffer::makeLaTeXFile(string const & fname,
933 string const & original_path,
934 LatexRunParams const & runparams,
935 bool output_preamble, bool output_body)
937 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
940 if (!::openFileWrite(ofs, fname))
943 makeLaTeXFile(ofs, original_path,
944 runparams, output_preamble, output_body);
948 lyxerr << "File was not closed properly." << endl;
953 void Buffer::makeLaTeXFile(ostream & os,
954 string const & original_path,
955 LatexRunParams const & runparams_in,
956 bool output_preamble, bool output_body)
958 LatexRunParams runparams = runparams_in;
959 niceFile = runparams.nice; // this will be used by Insetincludes.
961 // validate the buffer.
962 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
963 LaTeXFeatures features(params);
965 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
968 // The starting paragraph of the coming rows is the
969 // first paragraph of the document. (Asger)
970 texrow.start(paragraphs.begin()->id(), 0);
972 if (output_preamble && runparams.nice) {
973 os << "%% " << lyx_docversion << " created this file. "
974 "For more info, see http://www.lyx.org/.\n"
975 "%% Do not edit unless you really know what "
980 lyxerr[Debug::INFO] << "lyx header finished" << endl;
981 // There are a few differences between nice LaTeX and usual files:
982 // usual is \batchmode and has a
983 // special input@path to allow the including of figures
984 // with either \input or \includegraphics (what figinsets do).
985 // input@path is set when the actual parameter
986 // original_path is set. This is done for usual tex-file, but not
987 // for nice-latex-file. (Matthias 250696)
988 if (output_preamble) {
989 if (!runparams.nice) {
990 // code for usual, NOT nice-latex-file
991 os << "\\batchmode\n"; // changed
995 if (!original_path.empty()) {
996 string inputpath = os::external_path(original_path);
997 subst(inputpath, "~", "\\string~");
998 os << "\\makeatletter\n"
999 << "\\def\\input@path{{"
1000 << inputpath << "/}}\n"
1001 << "\\makeatother\n";
1007 // Write the preamble
1008 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1014 os << "\\begin{document}\n";
1016 } // output_preamble
1017 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1019 if (!lyxrc.language_auto_begin) {
1020 os << subst(lyxrc.language_command_begin, "$$lang",
1021 params.language->babel())
1026 latexParagraphs(this, paragraphs, os, texrow, runparams);
1028 // add this just in case after all the paragraphs
1032 if (!lyxrc.language_auto_end) {
1033 os << subst(lyxrc.language_command_end, "$$lang",
1034 params.language->babel())
1039 if (output_preamble) {
1040 os << "\\end{document}\n";
1043 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1045 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1049 // Just to be sure. (Asger)
1052 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1053 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1056 // we want this to be true outside previews (for insetexternal)
1061 bool Buffer::isLatex() const
1063 return params.getLyXTextClass().outputType() == LATEX;
1067 bool Buffer::isLinuxDoc() const
1069 return params.getLyXTextClass().outputType() == LINUXDOC;
1073 bool Buffer::isLiterate() const
1075 return params.getLyXTextClass().outputType() == LITERATE;
1079 bool Buffer::isDocBook() const
1081 return params.getLyXTextClass().outputType() == DOCBOOK;
1085 bool Buffer::isSGML() const
1087 LyXTextClass const & tclass = params.getLyXTextClass();
1089 return tclass.outputType() == LINUXDOC ||
1090 tclass.outputType() == DOCBOOK;
1094 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1097 if (!::openFileWrite(ofs, fname))
1100 niceFile = nice; // this will be used by included files.
1102 LaTeXFeatures features(params);
1108 LyXTextClass const & tclass = params.getLyXTextClass();
1110 string top_element = tclass.latexname();
1113 ofs << "<!doctype linuxdoc system";
1115 string preamble = params.preamble;
1116 string const name = nice ? ChangeExtension(filename_, ".sgml")
1118 preamble += features.getIncludedFiles(name);
1119 preamble += features.getLyXSGMLEntities();
1121 if (!preamble.empty()) {
1122 ofs << " [ " << preamble << " ]";
1126 if (params.options.empty())
1127 sgml::openTag(ofs, 0, false, top_element);
1129 string top = top_element;
1131 top += params.options;
1132 sgml::openTag(ofs, 0, false, top);
1136 ofs << "<!-- " << lyx_docversion
1137 << " created this file. For more info see http://www.lyx.org/"
1140 Paragraph::depth_type depth = 0; // paragraph depth
1142 vector<string> environment_stack(5);
1144 ParagraphList::iterator pit = paragraphs.begin();
1145 ParagraphList::iterator pend = paragraphs.end();
1146 for (; pit != pend; ++pit) {
1147 LyXLayout_ptr const & style = pit->layout();
1148 // treat <toc> as a special case for compatibility with old code
1149 if (pit->isInset(0)) {
1150 InsetOld * inset = pit->getInset(0);
1151 InsetOld::Code lyx_code = inset->lyxCode();
1152 if (lyx_code == InsetOld::TOC_CODE) {
1153 string const temp = "toc";
1154 sgml::openTag(ofs, depth, false, temp);
1159 // environment tag closing
1160 for (; depth > pit->params().depth(); --depth) {
1161 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1162 environment_stack[depth].erase();
1165 // write opening SGML tags
1166 switch (style->latextype) {
1167 case LATEX_PARAGRAPH:
1168 if (depth == pit->params().depth()
1169 && !environment_stack[depth].empty()) {
1170 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1171 environment_stack[depth].erase();
1177 sgml::openTag(ofs, depth, false, style->latexname());
1182 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1184 if (!environment_stack[depth].empty()) {
1185 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1189 environment_stack[depth].erase();
1190 sgml::openTag(ofs, depth, false, style->latexname());
1193 case LATEX_ENVIRONMENT:
1194 case LATEX_ITEM_ENVIRONMENT:
1195 case LATEX_BIB_ENVIRONMENT:
1197 string const & latexname = style->latexname();
1199 if (depth == pit->params().depth()
1200 && environment_stack[depth] != latexname) {
1201 sgml::closeTag(ofs, depth, false,
1202 environment_stack[depth]);
1203 environment_stack[depth].erase();
1205 if (depth < pit->params().depth()) {
1206 depth = pit->params().depth();
1207 environment_stack[depth].erase();
1209 if (environment_stack[depth] != latexname) {
1211 sgml::openTag(ofs, depth, false, "p");
1213 sgml::openTag(ofs, depth, false, latexname);
1215 if (environment_stack.size() == depth + 1)
1216 environment_stack.push_back("!-- --");
1217 environment_stack[depth] = latexname;
1220 if (style->latexparam() == "CDATA")
1223 if (style->latextype == LATEX_ENVIRONMENT) break;
1225 if (style->labeltype == LABEL_MANUAL)
1230 sgml::openTag(ofs, depth + 1, false, item_name);
1235 sgml::openTag(ofs, depth, false, style->latexname());
1239 simpleLinuxDocOnePar(ofs, pit, depth);
1242 // write closing SGML tags
1243 switch (style->latextype) {
1246 case LATEX_ENVIRONMENT:
1247 case LATEX_ITEM_ENVIRONMENT:
1248 case LATEX_BIB_ENVIRONMENT:
1249 if (style->latexparam() == "CDATA")
1253 sgml::closeTag(ofs, depth, false, style->latexname());
1259 for (int i = depth; i >= 0; --i)
1260 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1264 sgml::closeTag(ofs, 0, false, top_element);
1268 // How to check for successful close
1270 // we want this to be true outside previews (for insetexternal)
1275 // checks, if newcol chars should be put into this line
1276 // writes newline, if necessary.
1279 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1280 string::size_type newcol)
1283 if (colcount > lyxrc.ascii_linelen) {
1285 colcount = newcol; // assume write after this call
1300 string tag_name(PAR_TAG const & pt) {
1302 case NONE: return "!-- --";
1303 case TT: return "tt";
1304 case SF: return "sf";
1305 case BF: return "bf";
1306 case IT: return "it";
1307 case SL: return "sl";
1308 case EM: return "em";
1315 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1317 p1 = static_cast<PAR_TAG>(p1 | p2);
1322 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1324 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1330 // Handle internal paragraph parsing -- layout already processed.
1331 void Buffer::simpleLinuxDocOnePar(ostream & os,
1332 ParagraphList::iterator par,
1333 Paragraph::depth_type /*depth*/) const
1335 LyXLayout_ptr const & style = par->layout();
1337 string::size_type char_line_count = 5; // Heuristic choice ;-)
1339 // gets paragraph main font
1342 if (style->labeltype == LABEL_MANUAL) {
1343 font_old = style->labelfont;
1346 font_old = style->font;
1350 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1351 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1352 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1355 stack<PAR_TAG> tag_state;
1356 // parsing main loop
1357 for (pos_type i = 0; i < par->size(); ++i) {
1359 PAR_TAG tag_close = NONE;
1360 list < PAR_TAG > tag_open;
1362 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1364 if (font_old.family() != font.family()) {
1365 switch (family_type) {
1366 case LyXFont::SANS_FAMILY:
1369 case LyXFont::TYPEWRITER_FAMILY:
1376 family_type = font.family();
1378 switch (family_type) {
1379 case LyXFont::SANS_FAMILY:
1380 tag_open.push_back(SF);
1382 case LyXFont::TYPEWRITER_FAMILY:
1383 tag_open.push_back(TT);
1390 if (font_old.series() != font.series()) {
1391 switch (series_type) {
1392 case LyXFont::BOLD_SERIES:
1399 series_type = font.series();
1401 switch (series_type) {
1402 case LyXFont::BOLD_SERIES:
1403 tag_open.push_back(BF);
1411 if (font_old.shape() != font.shape()) {
1412 switch (shape_type) {
1413 case LyXFont::ITALIC_SHAPE:
1416 case LyXFont::SLANTED_SHAPE:
1423 shape_type = font.shape();
1425 switch (shape_type) {
1426 case LyXFont::ITALIC_SHAPE:
1427 tag_open.push_back(IT);
1429 case LyXFont::SLANTED_SHAPE:
1430 tag_open.push_back(SL);
1437 if (font_old.emph() != font.emph()) {
1438 if (font.emph() == LyXFont::ON) {
1439 tag_open.push_back(EM);
1448 list < PAR_TAG > temp;
1449 while (!tag_state.empty() && tag_close) {
1450 PAR_TAG k = tag_state.top();
1452 os << "</" << tag_name(k) << '>';
1459 for(list< PAR_TAG >::const_iterator j = temp.begin();
1460 j != temp.end(); ++j) {
1462 os << '<' << tag_name(*j) << '>';
1465 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1466 j != tag_open.end(); ++j) {
1468 os << '<' << tag_name(*j) << '>';
1471 char c = par->getChar(i);
1473 if (c == Paragraph::META_INSET) {
1474 InsetOld * inset = par->getInset(i);
1475 inset->linuxdoc(this, os);
1480 if (style->latexparam() == "CDATA") {
1481 // "TeX"-Mode on == > SGML-Mode on.
1488 boost::tie(ws, str) = sgml::escapeChar(c);
1489 if (ws && !par->isFreeSpacing()) {
1490 // in freespacing mode, spaces are
1491 // non-breaking characters
1492 if (desc_on) {// if char is ' ' then...
1495 sgmlLineBreak(os, char_line_count, 6);
1499 sgmlLineBreak(os, char_line_count, 1);
1504 char_line_count += str.length();
1510 while (!tag_state.empty()) {
1511 os << "</" << tag_name(tag_state.top()) << '>';
1515 // resets description flag correctly
1517 // <tag> not closed...
1518 sgmlLineBreak(os, char_line_count, 6);
1524 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1527 if (!::openFileWrite(ofs, fname))
1530 niceFile = nice; // this will be used by Insetincludes.
1532 LaTeXFeatures features(params);
1537 LyXTextClass const & tclass = params.getLyXTextClass();
1538 string top_element = tclass.latexname();
1541 ofs << "<!DOCTYPE " << top_element
1542 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1544 string preamble = params.preamble;
1545 string const name = nice ? ChangeExtension(filename_, ".sgml")
1547 preamble += features.getIncludedFiles(name);
1548 preamble += features.getLyXSGMLEntities();
1550 if (!preamble.empty()) {
1551 ofs << "\n [ " << preamble << " ]";
1556 string top = top_element;
1558 top += params.language->code();
1561 if (!params.options.empty()) {
1563 top += params.options;
1565 sgml::openTag(ofs, 0, false, top);
1567 ofs << "<!-- DocBook file was created by " << lyx_docversion
1568 << "\n See http://www.lyx.org/ for more information -->\n";
1570 vector<string> environment_stack(10);
1571 vector<string> environment_inner(10);
1572 vector<string> command_stack(10);
1574 bool command_flag = false;
1575 Paragraph::depth_type command_depth = 0;
1576 Paragraph::depth_type command_base = 0;
1577 Paragraph::depth_type cmd_depth = 0;
1578 Paragraph::depth_type depth = 0; // paragraph depth
1581 string command_name;
1583 ParagraphList::iterator par = paragraphs.begin();
1584 ParagraphList::iterator pend = paragraphs.end();
1586 for (; par != pend; ++par) {
1590 int desc_on = 0; // description mode
1592 LyXLayout_ptr const & style = par->layout();
1594 // environment tag closing
1595 for (; depth > par->params().depth(); --depth) {
1596 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1597 item_name = "listitem";
1598 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1599 if (environment_inner[depth] == "varlistentry")
1600 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1602 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1603 environment_stack[depth].erase();
1604 environment_inner[depth].erase();
1607 if (depth == par->params().depth()
1608 && environment_stack[depth] != style->latexname()
1609 && !environment_stack[depth].empty()) {
1610 if (environment_inner[depth] != "!-- --") {
1611 item_name= "listitem";
1612 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1613 if (environment_inner[depth] == "varlistentry")
1614 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1617 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1619 environment_stack[depth].erase();
1620 environment_inner[depth].erase();
1623 // Write opening SGML tags.
1624 switch (style->latextype) {
1625 case LATEX_PARAGRAPH:
1626 sgml::openTag(ofs, depth + command_depth,
1627 false, style->latexname());
1632 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1634 command_name = style->latexname();
1636 sgmlparam = style->latexparam();
1637 c_params = split(sgmlparam, c_depth,'|');
1639 cmd_depth = atoi(c_depth);
1642 if (cmd_depth < command_base) {
1643 for (Paragraph::depth_type j = command_depth;
1644 j >= command_base; --j) {
1645 sgml::closeTag(ofs, j, false, command_stack[j]);
1648 command_depth = command_base = cmd_depth;
1649 } else if (cmd_depth <= command_depth) {
1650 for (int j = command_depth;
1651 j >= int(cmd_depth); --j) {
1652 sgml::closeTag(ofs, j, false, command_stack[j]);
1655 command_depth = cmd_depth;
1657 command_depth = cmd_depth;
1659 command_depth = command_base = cmd_depth;
1660 command_flag = true;
1662 if (command_stack.size() == command_depth + 1)
1663 command_stack.push_back(string());
1664 command_stack[command_depth] = command_name;
1666 // treat label as a special case for
1667 // more WYSIWYM handling.
1668 // This is a hack while paragraphs can't have
1669 // attributes, like id in this case.
1670 if (par->isInset(0)) {
1671 InsetOld * inset = par->getInset(0);
1672 InsetOld::Code lyx_code = inset->lyxCode();
1673 if (lyx_code == InsetOld::LABEL_CODE) {
1674 command_name += " id=\"";
1675 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1676 command_name += '"';
1681 sgml::openTag(ofs, depth + command_depth, false, command_name);
1683 item_name = c_params.empty() ? "title" : c_params;
1684 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1687 case LATEX_ENVIRONMENT:
1688 case LATEX_ITEM_ENVIRONMENT:
1689 if (depth < par->params().depth()) {
1690 depth = par->params().depth();
1691 environment_stack[depth].erase();
1694 if (environment_stack[depth] != style->latexname()) {
1695 if (environment_stack.size() == depth + 1) {
1696 environment_stack.push_back("!-- --");
1697 environment_inner.push_back("!-- --");
1699 environment_stack[depth] = style->latexname();
1700 environment_inner[depth] = "!-- --";
1701 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1703 if (environment_inner[depth] != "!-- --") {
1704 item_name= "listitem";
1705 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1706 if (environment_inner[depth] == "varlistentry")
1707 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1711 if (style->latextype == LATEX_ENVIRONMENT) {
1712 if (!style->latexparam().empty()) {
1713 if (style->latexparam() == "CDATA")
1716 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1721 desc_on = (style->labeltype == LABEL_MANUAL);
1723 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1724 sgml::openTag(ofs, depth + 1 + command_depth,
1725 false, environment_inner[depth]);
1727 item_name = desc_on ? "term" : "para";
1728 sgml::openTag(ofs, depth + 1 + command_depth,
1732 sgml::openTag(ofs, depth + command_depth,
1733 false, style->latexname());
1737 simpleDocBookOnePar(ofs, par, desc_on,
1738 depth + 1 + command_depth);
1741 // write closing SGML tags
1742 switch (style->latextype) {
1744 end_tag = c_params.empty() ? "title" : c_params;
1745 sgml::closeTag(ofs, depth + command_depth,
1748 case LATEX_ENVIRONMENT:
1749 if (!style->latexparam().empty()) {
1750 if (style->latexparam() == "CDATA")
1753 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1756 case LATEX_ITEM_ENVIRONMENT:
1757 if (desc_on == 1) break;
1759 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1761 case LATEX_PARAGRAPH:
1762 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1765 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1771 for (int d = depth; d >= 0; --d) {
1772 if (!environment_stack[depth].empty()) {
1773 if (environment_inner[depth] != "!-- --") {
1774 item_name = "listitem";
1775 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1776 if (environment_inner[depth] == "varlistentry")
1777 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1780 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1784 for (int j = command_depth; j >= 0 ; --j)
1785 if (!command_stack[j].empty()) {
1786 sgml::closeTag(ofs, j, false, command_stack[j]);
1791 sgml::closeTag(ofs, 0, false, top_element);
1794 // How to check for successful close
1796 // we want this to be true outside previews (for insetexternal)
1801 void Buffer::simpleDocBookOnePar(ostream & os,
1802 ParagraphList::iterator par, int & desc_on,
1803 Paragraph::depth_type depth) const
1805 bool emph_flag = false;
1807 LyXLayout_ptr const & style = par->layout();
1809 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1811 int char_line_count = depth;
1812 //if (!style.free_spacing)
1813 // os << string(depth,' ');
1815 // parsing main loop
1816 for (pos_type i = 0; i < par->size(); ++i) {
1817 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1819 // handle <emphasis> tag
1820 if (font_old.emph() != font.emph()) {
1821 if (font.emph() == LyXFont::ON) {
1822 if (style->latexparam() == "CDATA")
1825 if (style->latexparam() == "CDATA")
1829 if (style->latexparam() == "CDATA")
1831 os << "</emphasis>";
1832 if (style->latexparam() == "CDATA")
1839 if (par->isInset(i)) {
1840 InsetOld * inset = par->getInset(i);
1841 // don't print the inset in position 0 if desc_on == 3 (label)
1842 if (i || desc_on != 3) {
1843 if (style->latexparam() == "CDATA")
1845 inset->docbook(this, os, false);
1846 if (style->latexparam() == "CDATA")
1850 char c = par->getChar(i);
1853 boost::tie(ws, str) = sgml::escapeChar(c);
1855 if (style->pass_thru) {
1857 } else if (par->isFreeSpacing() || c != ' ') {
1859 } else if (desc_on == 1) {
1861 os << "\n</term><listitem><para>";
1871 if (style->latexparam() == "CDATA")
1873 os << "</emphasis>";
1874 if (style->latexparam() == "CDATA")
1878 // resets description flag correctly
1880 // <term> not closed...
1881 os << "</term>\n<listitem><para> </para>";
1883 if (style->free_spacing)
1888 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1889 // Other flags: -wall -v0 -x
1890 int Buffer::runChktex()
1894 // get LaTeX-Filename
1895 string const name = getLatexName();
1896 string path = filePath();
1898 string const org_path = path;
1899 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1903 Path p(path); // path to LaTeX file
1904 message(_("Running chktex..."));
1906 // Generate the LaTeX file if neccessary
1907 LatexRunParams runparams;
1908 runparams.flavor = LatexRunParams::LATEX;
1909 runparams.nice = false;
1910 makeLaTeXFile(name, org_path, runparams);
1913 Chktex chktex(lyxrc.chktex_command, name, filePath());
1914 int res = chktex.run(terr); // run chktex
1917 Alert::error(_("chktex failure"),
1918 _("Could not run chktex successfully."));
1919 } else if (res > 0) {
1920 // Insert all errors as errors boxes
1921 bufferErrors(*this, terr);
1930 void Buffer::validate(LaTeXFeatures & features) const
1932 LyXTextClass const & tclass = params.getLyXTextClass();
1934 if (params.tracking_changes) {
1935 features.require("dvipost");
1936 features.require("color");
1939 // AMS Style is at document level
1940 if (params.use_amsmath == BufferParams::AMS_ON
1941 || tclass.provides(LyXTextClass::amsmath))
1942 features.require("amsmath");
1944 for_each(paragraphs.begin(), paragraphs.end(),
1945 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1947 // the bullet shapes are buffer level not paragraph level
1948 // so they are tested here
1949 for (int i = 0; i < 4; ++i) {
1950 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1951 int const font = params.user_defined_bullets[i].getFont();
1953 int const c = params
1954 .user_defined_bullets[i]
1961 features.require("latexsym");
1963 } else if (font == 1) {
1964 features.require("amssymb");
1965 } else if ((font >= 2 && font <= 5)) {
1966 features.require("pifont");
1971 if (lyxerr.debugging(Debug::LATEX)) {
1972 features.showStruct();
1977 void Buffer::getLabelList(std::vector<string> & list) const
1979 /// if this is a child document and the parent is already loaded
1980 /// Use the parent's list instead [ale990407]
1981 if (!params.parentname.empty()
1982 && bufferlist.exists(params.parentname)) {
1983 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1985 tmp->getLabelList(list);
1990 for (inset_iterator it = inset_const_iterator_begin();
1991 it != inset_const_iterator_end(); ++it) {
1992 it->getLabelList(list);
1997 // This is also a buffer property (ale)
1998 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
2000 /// if this is a child document and the parent is already loaded
2001 /// use the parent's list instead [ale990412]
2002 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2003 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2005 tmp->fillWithBibKeys(keys);
2010 for (inset_iterator it = inset_const_iterator_begin();
2011 it != inset_const_iterator_end(); ++it) {
2012 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2013 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2014 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2015 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2016 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2017 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2018 string const key = bib.getContents();
2019 string const opt = bib.getOptions();
2020 string const ref; // = pit->asString(this, false);
2021 string const info = opt + "TheBibliographyRef" + ref;
2022 keys.push_back(pair<string, string>(key, info));
2028 bool Buffer::isDepClean(string const & name) const
2030 DepClean::const_iterator it = dep_clean_.find(name);
2031 if (it == dep_clean_.end())
2037 void Buffer::markDepClean(string const & name)
2039 dep_clean_[name] = true;
2043 bool Buffer::dispatch(string const & command, bool * result)
2045 // Split command string into command and argument
2047 string line = ltrim(command);
2048 string const arg = trim(split(line, cmd, ' '));
2050 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2054 bool Buffer::dispatch(int action, string const & argument, bool * result)
2056 bool dispatched = true;
2060 bool const tmp = Exporter::Export(this, argument, false);
2073 void Buffer::changeLanguage(Language const * from, Language const * to)
2075 lyxerr << "Changing Language!" << endl;
2077 // Take care of l10n/i18n
2080 ParIterator end = par_iterator_end();
2081 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2082 it->changeLanguage(params, from, to);
2086 void Buffer::updateDocLang(Language const * nlang)
2088 messages_.reset(new Messages(nlang->code()));
2092 bool Buffer::isMultiLingual()
2094 ParIterator end = par_iterator_end();
2095 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2096 if (it->isMultiLingual(params))
2103 void Buffer::inset_iterator::setParagraph()
2105 while (pit != pend) {
2106 it = pit->insetlist.begin();
2107 if (it != pit->insetlist.end())
2114 InsetOld * Buffer::getInsetFromID(int id_arg) const
2116 for (inset_iterator it = inset_const_iterator_begin();
2117 it != inset_const_iterator_end(); ++it)
2119 if (it->id() == id_arg)
2121 InsetOld * in = it->getInsetFromID(id_arg);
2129 ParIterator Buffer::getParFromID(int id) const
2131 #warning FIXME: const correctness! (Andre)
2132 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2133 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2135 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2137 // John says this is called with id == -1 from undo
2138 lyxerr << "getParFromID(), id: " << id << endl;
2142 for (; it != end; ++it)
2150 bool Buffer::hasParWithID(int id) const
2152 ParConstIterator it = par_iterator_begin();
2153 ParConstIterator end = par_iterator_end();
2156 // John says this is called with id == -1 from undo
2157 lyxerr << "hasParWithID(), id: " << id << endl;
2161 for (; it != end; ++it)
2169 ParIterator Buffer::par_iterator_begin()
2171 return ParIterator(paragraphs.begin(), paragraphs);
2175 ParIterator Buffer::par_iterator_end()
2177 return ParIterator(paragraphs.end(), paragraphs);
2180 ParConstIterator Buffer::par_iterator_begin() const
2182 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2186 ParConstIterator Buffer::par_iterator_end() const
2188 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2192 Language const * Buffer::getLanguage() const
2194 return params.language;
2198 string const Buffer::B_(string const & l10n) const
2200 if (messages_.get()) {
2201 return messages_->get(l10n);
2208 bool Buffer::isClean() const
2214 bool Buffer::isBakClean() const
2220 void Buffer::markClean() const
2226 // if the .lyx file has been saved, we don't need an
2232 void Buffer::markBakClean()
2238 void Buffer::setUnnamed(bool flag)
2244 bool Buffer::isUnnamed()
2250 void Buffer::markDirty()
2258 DepClean::iterator it = dep_clean_.begin();
2259 DepClean::const_iterator const end = dep_clean_.end();
2261 for (; it != end; ++it) {
2267 string const & Buffer::fileName() const
2273 string const & Buffer::filePath() const
2279 bool Buffer::isReadonly() const
2285 void Buffer::setParentName(string const & name)
2287 params.parentname = name;
2291 Buffer::inset_iterator::inset_iterator()
2296 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2303 Buffer::inset_iterator Buffer::inset_iterator_begin()
2305 return inset_iterator(paragraphs.begin(), paragraphs.end());
2309 Buffer::inset_iterator Buffer::inset_iterator_end()
2311 return inset_iterator(paragraphs.end(), paragraphs.end());
2315 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2317 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2318 const_cast<ParagraphList&>(paragraphs).end());
2322 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2324 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2325 const_cast<ParagraphList&>(paragraphs).end());
2329 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2333 if (it == pit->insetlist.end()) {
2342 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2344 inset_iterator tmp = *this;
2350 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2356 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2362 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2368 lyx::pos_type Buffer::inset_iterator::getPos() const
2374 bool operator==(Buffer::inset_iterator const & iter1,
2375 Buffer::inset_iterator const & iter2)
2377 return iter1.pit == iter2.pit
2378 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2382 bool operator!=(Buffer::inset_iterator const & iter1,
2383 Buffer::inset_iterator const & iter2)
2385 return !(iter1 == iter2);