3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
15 #include "buffer_funcs.h"
16 #include "bufferlist.h"
19 #include "errorlist.h"
23 #include "iterators.h"
26 #include "LaTeXFeatures.h"
27 #include "LyXAction.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
37 #include "insets/insetbibitem.h"
38 #include "insets/insetbibtex.h"
39 #include "insets/insetinclude.h"
40 #include "insets/insettext.h"
42 #include "frontends/Alert.h"
44 #include "graphics/Previews.h"
46 #include "support/FileInfo.h"
47 #include "support/filetools.h"
48 #include "support/gzstream.h"
49 #include "support/LAssert.h"
50 #include "support/lyxlib.h"
51 #include "support/os.h"
52 #include "support/path.h"
53 #include "support/textutils.h"
54 #include "support/tostr.h"
56 #include <boost/bind.hpp>
57 #include <boost/tuple/tuple.hpp>
59 #include "support/std_sstream.h"
69 using namespace lyx::support;
79 using std::ostringstream;
88 // all these externs should eventually be removed.
89 extern BufferList bufferlist;
93 const int LYX_FORMAT = 225;
95 bool openFileWrite(ofstream & ofs, string const & fname)
97 ofs.open(fname.c_str());
99 string const file = MakeDisplayPath(fname, 50);
100 string text = bformat(_("Could not open the specified "
101 "document\n%1$s."), file);
102 Alert::error(_("Could not open file"), text);
111 Buffer::Buffer(string const & file, bool ronly)
112 : niceFile(true), lyx_clean(true), bak_clean(true),
113 unnamed(false), read_only(ronly),
116 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
117 filepath_ = OnlyPath(file);
119 if (read_only || lyxrc.use_tempdir) {
120 tmppath = CreateBufferTmpDir();
125 // set initial author
126 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
132 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
133 // here the buffer should take care that it is
134 // saved properly, before it goes into the void.
138 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
139 Alert::warning(_("Could not remove temporary directory"),
140 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
145 // Remove any previewed LaTeX snippets associated with this buffer.
146 lyx::graphics::Previews::get().removeLoader(*this);
150 string const Buffer::getLatexName(bool no_path) const
152 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
153 return no_path ? OnlyFilename(name) : name;
157 pair<Buffer::LogType, string> const Buffer::getLogName() const
159 string const filename = getLatexName(false);
161 if (filename.empty())
162 return make_pair(Buffer::latexlog, string());
164 string path = OnlyPath(filename);
166 if (lyxrc.use_tempdir || !IsDirWriteable(path))
169 string const fname = AddName(path,
170 OnlyFilename(ChangeExtension(filename,
173 AddName(path, OnlyFilename(
174 ChangeExtension(filename,
175 formats.extension("literate") + ".out")));
177 // If no Latex log or Build log is newer, show Build log
179 FileInfo const f_fi(fname);
180 FileInfo const b_fi(bname);
183 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
184 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
185 return make_pair(Buffer::buildlog, bname);
187 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
188 return make_pair(Buffer::latexlog, fname);
192 void Buffer::setReadonly(bool flag)
194 if (read_only != flag) {
201 AuthorList & Buffer::authors()
203 return params.authorlist;
207 void Buffer::setFileName(string const & newfile)
209 filename_ = MakeAbsPath(newfile);
210 filepath_ = OnlyPath(filename_);
211 setReadonly(IsFileWriteable(filename_) == 0);
216 // We'll remove this later. (Lgb)
219 void unknownClass(string const & unknown)
221 Alert::warning(_("Unknown document class"),
222 bformat(_("Using the default document class, because the "
223 "class %1$s is unknown."), unknown));
228 int Buffer::readHeader(LyXLex & lex)
230 int unknown_tokens = 0;
234 string const token = lex.getString();
239 if (token == "\\end_header")
242 lyxerr[Debug::PARSER] << "Handling header token: `"
243 << token << '\'' << endl;
246 string unknown = params.readToken(lex, token);
247 if (!unknown.empty()) {
248 if (unknown[0] != '\\') {
249 unknownClass(unknown);
252 string const s = bformat(_("Unknown token: "
256 error(ErrorItem(_("Header error"), s,
261 return unknown_tokens;
265 // candidate for move to BufferView
266 // (at least some parts in the beginning of the func)
269 // changed to be public and have one parameter
270 // if par = 0 normal behavior
271 // else insert behavior
272 // Returns false if "\end_document" is not read (Asger)
273 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
275 Paragraph::depth_type depth = 0;
276 bool the_end_read = false;
278 if (paragraphs.empty()) {
280 if (!params.getLyXTextClass().load()) {
281 string theclass = params.getLyXTextClass().name();
282 Alert::error(_("Can't load document class"), bformat(
283 "Using the default document class, because the "
284 " class %1$s could not be loaded.", theclass));
285 params.textclass = 0;
288 // We don't want to adopt the parameters from the
289 // document we insert, so read them into a temporary buffer
290 // and then discard it
292 Buffer tmpbuf("", false);
293 tmpbuf.readHeader(lex);
298 string const token = lex.getString();
303 lyxerr[Debug::PARSER] << "Handling token: `"
304 << token << '\'' << endl;
306 if (token == "\\end_document") {
311 readParagraph(lex, token, paragraphs, pit, depth);
318 int Buffer::readParagraph(LyXLex & lex, string const & token,
319 ParagraphList & pars, ParagraphList::iterator & pit,
320 Paragraph::depth_type & depth)
322 static Change current_change;
325 if (token == "\\begin_layout") {
326 lex.pushToken(token);
329 par.params().depth(depth);
330 if (params.tracking_changes)
332 LyXFont f(LyXFont::ALL_INHERIT, params.language);
336 if (pit != pars.end())
339 pit = pars.insert(pit, par);
341 // FIXME: goddamn InsetTabular makes us pass a Buffer
343 ::readParagraph(*this, *pit, lex);
345 } else if (token == "\\begin_deeper") {
347 } else if (token == "\\end_deeper") {
349 lex.printError("\\end_deeper: " "depth is already null");
360 // needed to insert the selection
361 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
362 LyXFont const & fn,string const & str)
364 LyXLayout_ptr const & layout = par->layout();
368 par->checkInsertChar(font);
369 // insert the string, don't insert doublespace
370 bool space_inserted = true;
371 bool autobreakrows = !par->inInset() ||
372 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
373 for(string::const_iterator cit = str.begin();
374 cit != str.end(); ++cit) {
376 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
377 breakParagraph(params, paragraphs, par, pos,
378 layout->isEnvironment());
381 space_inserted = true;
385 // do not insert consecutive spaces if !free_spacing
386 } else if ((*cit == ' ' || *cit == '\t') &&
387 space_inserted && !par->isFreeSpacing()) {
389 } else if (*cit == '\t') {
390 if (!par->isFreeSpacing()) {
391 // tabs are like spaces here
392 par->insertChar(pos, ' ', font);
394 space_inserted = true;
396 const pos_type nb = 8 - pos % 8;
397 for (pos_type a = 0; a < nb ; ++a) {
398 par->insertChar(pos, ' ', font);
401 space_inserted = true;
403 } else if (!IsPrintable(*cit)) {
404 // Ignore unprintables
407 // just insert the character
408 par->insertChar(pos, *cit, font);
410 space_inserted = (*cit == ' ');
417 bool Buffer::readFile(string const & filename)
419 // Check if the file is compressed.
420 string const format = getExtFromContents(filename);
421 if (format == "gzip" || format == "zip" || format == "compress") {
422 params.compressed = true;
425 bool ret = readFile(filename, paragraphs.begin());
427 // After we have read a file, we must ensure that the buffer
428 // language is set and used in the gui.
429 // If you know of a better place to put this, please tell me. (Lgb)
430 updateDocLang(params.language);
436 bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
439 lex.setFile(filename);
441 return readFile(lex, filename, pit);
445 bool Buffer::readFile(LyXLex & lex, string const & filename,
446 ParagraphList::iterator pit)
448 Assert(!filename.empty());
451 Alert::error(_("Document could not be read"),
452 bformat(_("%1$s could not be read."), filename));
457 string const token(lex.getString());
460 Alert::error(_("Document could not be read"),
461 bformat(_("%1$s could not be read."), filename));
465 // the first token _must_ be...
466 if (token != "\\lyxformat") {
467 lyxerr << "Token: " << token << endl;
469 Alert::error(_("Document format failure"),
470 bformat(_("%1$s is not a LyX document."),
476 string tmp_format = lex.getString();
477 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
478 // if present remove ".," from string.
479 string::size_type dot = tmp_format.find_first_of(".,");
480 //lyxerr << " dot found at " << dot << endl;
481 if (dot != string::npos)
482 tmp_format.erase(dot, 1);
483 int file_format = strToInt(tmp_format);
484 //lyxerr << "format: " << file_format << endl;
486 if (file_format > LYX_FORMAT) {
487 Alert::warning(_("Document format failure"),
488 bformat(_("%1$s was created with a newer"
489 " version of LyX. This is likely to"
492 } else if (file_format < LYX_FORMAT) {
493 string const tmpfile = tempName();
494 string command = LibFileSearch("lyx2lyx", "lyx2lyx");
495 if (command.empty()) {
496 Alert::error(_("Conversion script not found"),
497 bformat(_("%1$s is from an earlier"
498 " version of LyX, but the"
499 " conversion script lyx2lyx"
500 " could not be found."),
506 + " -o " + tmpfile + ' '
507 + QuoteName(filename);
508 lyxerr[Debug::INFO] << "Running '"
511 cmd_ret const ret = RunCommand(command);
512 if (ret.first != 0) {
513 Alert::error(_("Conversion script failed"),
514 bformat(_("%1$s is from an earlier version"
515 " of LyX, but the lyx2lyx script"
516 " failed to convert it."),
520 bool ret = readFile(tmpfile, pit);
521 // Do stuff with tmpfile name and buffer name here.
527 bool the_end = readBody(lex, pit);
528 params.setPaperStuff();
531 Alert::error(_("Document format failure"),
532 bformat(_("%1$s ended unexpectedly, which means"
533 " that it is probably corrupted."),
540 // Should probably be moved to somewhere else: BufferView? LyXView?
541 bool Buffer::save() const
543 // We don't need autosaves in the immediate future. (Asger)
544 resetAutosaveTimers();
548 if (lyxrc.make_backup) {
549 s = fileName() + '~';
550 if (!lyxrc.backupdir_path.empty())
551 s = AddName(lyxrc.backupdir_path,
552 subst(os::slashify_path(s),'/','!'));
554 // Rename is the wrong way of making a backup,
555 // this is the correct way.
556 /* truss cp fil fil2:
557 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
558 stat("LyXVC.lyx", 0xEFFFF688) = 0
559 open("LyXVC.lyx", O_RDONLY) = 3
560 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
561 fstat(4, 0xEFFFF508) = 0
562 fstat(3, 0xEFFFF508) = 0
563 read(3, " # T h i s f i l e w".., 8192) = 5579
564 write(4, " # T h i s f i l e w".., 5579) = 5579
565 read(3, 0xEFFFD4A0, 8192) = 0
568 chmod("LyXVC3.lyx", 0100644) = 0
569 lseek(0, 0, SEEK_CUR) = 46440
573 // Should probably have some more error checking here.
574 // Doing it this way, also makes the inodes stay the same.
575 // This is still not a very good solution, in particular we
576 // might loose the owner of the backup.
577 FileInfo finfo(fileName());
579 mode_t fmode = finfo.getMode();
580 struct utimbuf times = {
581 finfo.getAccessTime(),
582 finfo.getModificationTime() };
584 ifstream ifs(fileName().c_str());
585 ofstream ofs(s.c_str(), ios::out|ios::trunc);
590 ::chmod(s.c_str(), fmode);
592 if (::utime(s.c_str(), ×)) {
593 lyxerr << "utime error." << endl;
596 lyxerr << "LyX was not able to make "
597 "backup copy. Beware." << endl;
602 if (writeFile(fileName())) {
604 removeAutosaveFile(fileName());
606 // Saving failed, so backup is not backup
607 if (lyxrc.make_backup) {
608 rename(s, fileName());
616 bool Buffer::writeFile(string const & fname) const
618 if (read_only && (fname == fileName())) {
622 FileInfo finfo(fname);
623 if (finfo.exist() && !finfo.writable()) {
629 if (params.compressed) {
630 gz::ogzstream ofs(fname.c_str());
635 retval = do_writeFile(ofs);
638 ofstream ofs(fname.c_str());
642 retval = do_writeFile(ofs);
649 bool Buffer::do_writeFile(ostream & ofs) const
653 // Use the standard "C" locale for file output.
654 ofs.imbue(std::locale::classic());
657 // The top of the file should not be written by params.
659 // write out a comment in the top of the file
660 ofs << "#LyX " << lyx_version
661 << " created this file. For more info see http://www.lyx.org/\n"
662 << "\\lyxformat " << LYX_FORMAT << "\n";
664 // now write out the buffer paramters.
665 params.writeFile(ofs);
667 ofs << "\\end_header\n";
669 Paragraph::depth_type depth = 0;
671 // this will write out all the paragraphs
672 // using recursive descent.
673 ParagraphList::const_iterator pit = paragraphs.begin();
674 ParagraphList::const_iterator pend = paragraphs.end();
675 for (; pit != pend; ++pit)
676 pit->write(*this, ofs, params, depth);
678 // Write marker that shows file is complete
679 ofs << "\n\\end_document" << endl;
681 // Shouldn't really be needed....
684 // how to check if close went ok?
685 // Following is an attempt... (BE 20001011)
687 // good() returns false if any error occured, including some
689 // bad() returns true if something bad happened in the buffer,
690 // which should include file system full errors.
697 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
699 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
711 pair<int, string> const addDepth(int depth, int ldepth)
715 d += (ldepth - depth) * 2;
716 return make_pair(d, string(d, ' '));
722 string const Buffer::asciiParagraph(Paragraph const & par,
723 unsigned int linelen,
724 bool noparbreak) const
726 ostringstream buffer;
728 Paragraph::depth_type ltype_depth = 0;
729 bool ref_printed = false;
730 Paragraph::depth_type depth = par.params().depth();
732 // First write the layout
733 string const & tmp = par.layout()->name();
734 if (compare_no_case(tmp, "itemize") == 0) {
736 ltype_depth = depth + 1;
737 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
739 ltype_depth = depth + 1;
740 } else if (contains(ascii_lowercase(tmp), "ection")) {
742 ltype_depth = depth + 1;
743 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
745 ltype_depth = depth + 1;
746 } else if (compare_ascii_no_case(tmp, "description") == 0) {
748 ltype_depth = depth + 1;
749 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
752 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
760 /* maybe some vertical spaces */
762 /* the labelwidthstring used in lists */
766 /* some pagebreaks? */
770 /* what about the alignment */
772 // linelen <= 0 is special and means we don't have paragraph breaks
774 string::size_type currlinelen = 0;
780 buffer << string(depth * 2, ' ');
781 currlinelen += depth * 2;
784 // we should probably change to the paragraph language in the
785 // gettext here (if possible) so that strings are outputted in
786 // the correct language! (20012712 Jug)
790 case 4: // (Sub)Paragraph
791 case 5: // Description
795 buffer << _("Abstract") << "\n\n";
798 string const abst = _("Abstract: ");
800 currlinelen += abst.length();
803 case 7: // Bibliography
806 buffer << _("References") << "\n\n";
809 string const refs = _("References: ");
811 currlinelen += refs.length();
819 string const parlab = par.params().labelString();
820 buffer << parlab << ' ';
821 currlinelen += parlab.length() + 1;
829 pair<int, string> p = addDepth(depth, ltype_depth);
831 currlinelen += p.first;
834 // this is to change the linebreak to do it by word a bit more
835 // intelligent hopefully! (only in the case where we have a
836 // max linelength!) (Jug)
840 for (pos_type i = 0; i < par.size(); ++i) {
841 char c = par.getUChar(params, i);
843 case Paragraph::META_INSET:
845 InsetOld const * inset = par.getInset(i);
849 currlinelen += word.length();
852 if (inset->ascii(*this, buffer, linelen)) {
853 // to be sure it breaks paragraph
854 currlinelen += linelen;
863 currlinelen + word.length() > linelen - 10) {
865 pair<int, string> p = addDepth(depth, ltype_depth);
867 currlinelen = p.first;
870 buffer << word << ' ';
871 currlinelen += word.length() + 1;
878 lyxerr[Debug::INFO] <<
879 "writeAsciiFile: NULL char in structure." << endl;
882 (currlinelen + word.length()) > linelen)
886 pair<int, string> p =
887 addDepth(depth, ltype_depth);
889 currlinelen = p.first;
896 return STRCONV(buffer.str());
900 void Buffer::writeFileAscii(string const & fname, int linelen)
903 if (!::openFileWrite(ofs, fname))
905 writeFileAscii(ofs, linelen);
909 void Buffer::writeFileAscii(ostream & os, int linelen)
911 ParagraphList::iterator beg = paragraphs.begin();
912 ParagraphList::iterator end = paragraphs.end();
913 ParagraphList::iterator it = beg;
914 for (; it != end; ++it) {
915 os << asciiParagraph(*it, linelen, it == beg);
921 void Buffer::makeLaTeXFile(string const & fname,
922 string const & original_path,
923 LatexRunParams const & runparams,
924 bool output_preamble, bool output_body)
926 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
929 if (!::openFileWrite(ofs, fname))
932 makeLaTeXFile(ofs, original_path,
933 runparams, output_preamble, output_body);
937 lyxerr << "File was not closed properly." << endl;
942 void Buffer::makeLaTeXFile(ostream & os,
943 string const & original_path,
944 LatexRunParams const & runparams_in,
945 bool output_preamble, bool output_body)
947 LatexRunParams runparams = runparams_in;
948 niceFile = runparams.nice; // this will be used by Insetincludes.
950 // validate the buffer.
951 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
952 LaTeXFeatures features(params);
954 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
957 // The starting paragraph of the coming rows is the
958 // first paragraph of the document. (Asger)
959 texrow.start(paragraphs.begin()->id(), 0);
961 if (output_preamble && runparams.nice) {
962 os << "%% LyX " << lyx_version << " created this file. "
963 "For more info, see http://www.lyx.org/.\n"
964 "%% Do not edit unless you really know what "
969 lyxerr[Debug::INFO] << "lyx header finished" << endl;
970 // There are a few differences between nice LaTeX and usual files:
971 // usual is \batchmode and has a
972 // special input@path to allow the including of figures
973 // with either \input or \includegraphics (what figinsets do).
974 // input@path is set when the actual parameter
975 // original_path is set. This is done for usual tex-file, but not
976 // for nice-latex-file. (Matthias 250696)
977 if (output_preamble) {
978 if (!runparams.nice) {
979 // code for usual, NOT nice-latex-file
980 os << "\\batchmode\n"; // changed
984 if (!original_path.empty()) {
985 string inputpath = os::external_path(original_path);
986 subst(inputpath, "~", "\\string~");
987 os << "\\makeatletter\n"
988 << "\\def\\input@path{{"
989 << inputpath << "/}}\n"
990 << "\\makeatother\n";
996 // Write the preamble
997 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1003 os << "\\begin{document}\n";
1005 } // output_preamble
1006 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1008 if (!lyxrc.language_auto_begin) {
1009 os << subst(lyxrc.language_command_begin, "$$lang",
1010 params.language->babel())
1015 latexParagraphs(*this, paragraphs, os, texrow, runparams);
1017 // add this just in case after all the paragraphs
1021 if (!lyxrc.language_auto_end) {
1022 os << subst(lyxrc.language_command_end, "$$lang",
1023 params.language->babel())
1028 if (output_preamble) {
1029 os << "\\end{document}\n";
1032 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1034 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1038 // Just to be sure. (Asger)
1041 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1042 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1045 // we want this to be true outside previews (for insetexternal)
1050 bool Buffer::isLatex() const
1052 return params.getLyXTextClass().outputType() == LATEX;
1056 bool Buffer::isLinuxDoc() const
1058 return params.getLyXTextClass().outputType() == LINUXDOC;
1062 bool Buffer::isLiterate() const
1064 return params.getLyXTextClass().outputType() == LITERATE;
1068 bool Buffer::isDocBook() const
1070 return params.getLyXTextClass().outputType() == DOCBOOK;
1074 bool Buffer::isSGML() const
1076 LyXTextClass const & tclass = params.getLyXTextClass();
1078 return tclass.outputType() == LINUXDOC ||
1079 tclass.outputType() == DOCBOOK;
1083 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1086 if (!::openFileWrite(ofs, fname))
1089 niceFile = nice; // this will be used by included files.
1091 LaTeXFeatures features(params);
1097 LyXTextClass const & tclass = params.getLyXTextClass();
1099 string top_element = tclass.latexname();
1102 ofs << "<!doctype linuxdoc system";
1104 string preamble = params.preamble;
1105 string const name = nice ? ChangeExtension(filename_, ".sgml")
1107 preamble += features.getIncludedFiles(name);
1108 preamble += features.getLyXSGMLEntities();
1110 if (!preamble.empty()) {
1111 ofs << " [ " << preamble << " ]";
1115 if (params.options.empty())
1116 sgml::openTag(ofs, 0, false, top_element);
1118 string top = top_element;
1120 top += params.options;
1121 sgml::openTag(ofs, 0, false, top);
1125 ofs << "<!-- LyX " << lyx_version
1126 << " created this file. For more info see http://www.lyx.org/"
1129 Paragraph::depth_type depth = 0; // paragraph depth
1131 vector<string> environment_stack(5);
1133 ParagraphList::iterator pit = paragraphs.begin();
1134 ParagraphList::iterator pend = paragraphs.end();
1135 for (; pit != pend; ++pit) {
1136 LyXLayout_ptr const & style = pit->layout();
1137 // treat <toc> as a special case for compatibility with old code
1138 if (pit->isInset(0)) {
1139 InsetOld * inset = pit->getInset(0);
1140 InsetOld::Code lyx_code = inset->lyxCode();
1141 if (lyx_code == InsetOld::TOC_CODE) {
1142 string const temp = "toc";
1143 sgml::openTag(ofs, depth, false, temp);
1148 // environment tag closing
1149 for (; depth > pit->params().depth(); --depth) {
1150 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1151 environment_stack[depth].erase();
1154 // write opening SGML tags
1155 switch (style->latextype) {
1156 case LATEX_PARAGRAPH:
1157 if (depth == pit->params().depth()
1158 && !environment_stack[depth].empty()) {
1159 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1160 environment_stack[depth].erase();
1166 sgml::openTag(ofs, depth, false, style->latexname());
1171 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1173 if (!environment_stack[depth].empty()) {
1174 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1178 environment_stack[depth].erase();
1179 sgml::openTag(ofs, depth, false, style->latexname());
1182 case LATEX_ENVIRONMENT:
1183 case LATEX_ITEM_ENVIRONMENT:
1184 case LATEX_BIB_ENVIRONMENT:
1186 string const & latexname = style->latexname();
1188 if (depth == pit->params().depth()
1189 && environment_stack[depth] != latexname) {
1190 sgml::closeTag(ofs, depth, false,
1191 environment_stack[depth]);
1192 environment_stack[depth].erase();
1194 if (depth < pit->params().depth()) {
1195 depth = pit->params().depth();
1196 environment_stack[depth].erase();
1198 if (environment_stack[depth] != latexname) {
1200 sgml::openTag(ofs, depth, false, "p");
1202 sgml::openTag(ofs, depth, false, latexname);
1204 if (environment_stack.size() == depth + 1)
1205 environment_stack.push_back("!-- --");
1206 environment_stack[depth] = latexname;
1209 if (style->latexparam() == "CDATA")
1212 if (style->latextype == LATEX_ENVIRONMENT) break;
1214 if (style->labeltype == LABEL_MANUAL)
1219 sgml::openTag(ofs, depth + 1, false, item_name);
1224 sgml::openTag(ofs, depth, false, style->latexname());
1228 simpleLinuxDocOnePar(ofs, pit, depth);
1231 // write closing SGML tags
1232 switch (style->latextype) {
1235 case LATEX_ENVIRONMENT:
1236 case LATEX_ITEM_ENVIRONMENT:
1237 case LATEX_BIB_ENVIRONMENT:
1238 if (style->latexparam() == "CDATA")
1242 sgml::closeTag(ofs, depth, false, style->latexname());
1248 for (int i = depth; i >= 0; --i)
1249 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1253 sgml::closeTag(ofs, 0, false, top_element);
1257 // How to check for successful close
1259 // we want this to be true outside previews (for insetexternal)
1264 // checks, if newcol chars should be put into this line
1265 // writes newline, if necessary.
1268 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1269 string::size_type newcol)
1272 if (colcount > lyxrc.ascii_linelen) {
1274 colcount = newcol; // assume write after this call
1289 string tag_name(PAR_TAG const & pt) {
1291 case NONE: return "!-- --";
1292 case TT: return "tt";
1293 case SF: return "sf";
1294 case BF: return "bf";
1295 case IT: return "it";
1296 case SL: return "sl";
1297 case EM: return "em";
1304 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1306 p1 = static_cast<PAR_TAG>(p1 | p2);
1311 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1313 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1319 // Handle internal paragraph parsing -- layout already processed.
1320 void Buffer::simpleLinuxDocOnePar(ostream & os,
1321 ParagraphList::iterator par,
1322 Paragraph::depth_type /*depth*/) const
1324 LyXLayout_ptr const & style = par->layout();
1326 string::size_type char_line_count = 5; // Heuristic choice ;-)
1328 // gets paragraph main font
1331 if (style->labeltype == LABEL_MANUAL) {
1332 font_old = style->labelfont;
1335 font_old = style->font;
1339 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1340 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1341 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1344 stack<PAR_TAG> tag_state;
1345 // parsing main loop
1346 for (pos_type i = 0; i < par->size(); ++i) {
1348 PAR_TAG tag_close = NONE;
1349 list < PAR_TAG > tag_open;
1351 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1353 if (font_old.family() != font.family()) {
1354 switch (family_type) {
1355 case LyXFont::SANS_FAMILY:
1358 case LyXFont::TYPEWRITER_FAMILY:
1365 family_type = font.family();
1367 switch (family_type) {
1368 case LyXFont::SANS_FAMILY:
1369 tag_open.push_back(SF);
1371 case LyXFont::TYPEWRITER_FAMILY:
1372 tag_open.push_back(TT);
1379 if (font_old.series() != font.series()) {
1380 switch (series_type) {
1381 case LyXFont::BOLD_SERIES:
1388 series_type = font.series();
1390 switch (series_type) {
1391 case LyXFont::BOLD_SERIES:
1392 tag_open.push_back(BF);
1400 if (font_old.shape() != font.shape()) {
1401 switch (shape_type) {
1402 case LyXFont::ITALIC_SHAPE:
1405 case LyXFont::SLANTED_SHAPE:
1412 shape_type = font.shape();
1414 switch (shape_type) {
1415 case LyXFont::ITALIC_SHAPE:
1416 tag_open.push_back(IT);
1418 case LyXFont::SLANTED_SHAPE:
1419 tag_open.push_back(SL);
1426 if (font_old.emph() != font.emph()) {
1427 if (font.emph() == LyXFont::ON) {
1428 tag_open.push_back(EM);
1437 list < PAR_TAG > temp;
1438 while (!tag_state.empty() && tag_close) {
1439 PAR_TAG k = tag_state.top();
1441 os << "</" << tag_name(k) << '>';
1448 for(list< PAR_TAG >::const_iterator j = temp.begin();
1449 j != temp.end(); ++j) {
1451 os << '<' << tag_name(*j) << '>';
1454 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1455 j != tag_open.end(); ++j) {
1457 os << '<' << tag_name(*j) << '>';
1460 char c = par->getChar(i);
1462 if (c == Paragraph::META_INSET) {
1463 InsetOld * inset = par->getInset(i);
1464 inset->linuxdoc(*this, os);
1469 if (style->latexparam() == "CDATA") {
1470 // "TeX"-Mode on == > SGML-Mode on.
1477 boost::tie(ws, str) = sgml::escapeChar(c);
1478 if (ws && !par->isFreeSpacing()) {
1479 // in freespacing mode, spaces are
1480 // non-breaking characters
1481 if (desc_on) {// if char is ' ' then...
1484 sgmlLineBreak(os, char_line_count, 6);
1488 sgmlLineBreak(os, char_line_count, 1);
1493 char_line_count += str.length();
1499 while (!tag_state.empty()) {
1500 os << "</" << tag_name(tag_state.top()) << '>';
1504 // resets description flag correctly
1506 // <tag> not closed...
1507 sgmlLineBreak(os, char_line_count, 6);
1513 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1516 if (!::openFileWrite(ofs, fname))
1519 niceFile = nice; // this will be used by Insetincludes.
1521 LaTeXFeatures features(params);
1526 LyXTextClass const & tclass = params.getLyXTextClass();
1527 string top_element = tclass.latexname();
1530 ofs << "<!DOCTYPE " << top_element
1531 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1533 string preamble = params.preamble;
1534 string const name = nice ? ChangeExtension(filename_, ".sgml")
1536 preamble += features.getIncludedFiles(name);
1537 preamble += features.getLyXSGMLEntities();
1539 if (!preamble.empty()) {
1540 ofs << "\n [ " << preamble << " ]";
1545 string top = top_element;
1547 top += params.language->code();
1550 if (!params.options.empty()) {
1552 top += params.options;
1554 sgml::openTag(ofs, 0, false, top);
1556 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1557 << "\n See http://www.lyx.org/ for more information -->\n";
1559 vector<string> environment_stack(10);
1560 vector<string> environment_inner(10);
1561 vector<string> command_stack(10);
1563 bool command_flag = false;
1564 Paragraph::depth_type command_depth = 0;
1565 Paragraph::depth_type command_base = 0;
1566 Paragraph::depth_type cmd_depth = 0;
1567 Paragraph::depth_type depth = 0; // paragraph depth
1570 string command_name;
1572 ParagraphList::iterator par = paragraphs.begin();
1573 ParagraphList::iterator pend = paragraphs.end();
1575 for (; par != pend; ++par) {
1579 int desc_on = 0; // description mode
1581 LyXLayout_ptr const & style = par->layout();
1583 // environment tag closing
1584 for (; depth > par->params().depth(); --depth) {
1585 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1586 item_name = "listitem";
1587 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1588 if (environment_inner[depth] == "varlistentry")
1589 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1591 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1592 environment_stack[depth].erase();
1593 environment_inner[depth].erase();
1596 if (depth == par->params().depth()
1597 && environment_stack[depth] != style->latexname()
1598 && !environment_stack[depth].empty()) {
1599 if (environment_inner[depth] != "!-- --") {
1600 item_name= "listitem";
1601 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1602 if (environment_inner[depth] == "varlistentry")
1603 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1606 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1608 environment_stack[depth].erase();
1609 environment_inner[depth].erase();
1612 // Write opening SGML tags.
1613 switch (style->latextype) {
1614 case LATEX_PARAGRAPH:
1615 sgml::openTag(ofs, depth + command_depth,
1616 false, style->latexname());
1621 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1623 command_name = style->latexname();
1625 sgmlparam = style->latexparam();
1626 c_params = split(sgmlparam, c_depth,'|');
1628 cmd_depth = atoi(c_depth);
1631 if (cmd_depth < command_base) {
1632 for (Paragraph::depth_type j = command_depth;
1633 j >= command_base; --j) {
1634 sgml::closeTag(ofs, j, false, command_stack[j]);
1637 command_depth = command_base = cmd_depth;
1638 } else if (cmd_depth <= command_depth) {
1639 for (int j = command_depth;
1640 j >= int(cmd_depth); --j) {
1641 sgml::closeTag(ofs, j, false, command_stack[j]);
1644 command_depth = cmd_depth;
1646 command_depth = cmd_depth;
1648 command_depth = command_base = cmd_depth;
1649 command_flag = true;
1651 if (command_stack.size() == command_depth + 1)
1652 command_stack.push_back(string());
1653 command_stack[command_depth] = command_name;
1655 // treat label as a special case for
1656 // more WYSIWYM handling.
1657 // This is a hack while paragraphs can't have
1658 // attributes, like id in this case.
1659 if (par->isInset(0)) {
1660 InsetOld * inset = par->getInset(0);
1661 InsetOld::Code lyx_code = inset->lyxCode();
1662 if (lyx_code == InsetOld::LABEL_CODE) {
1663 command_name += " id=\"";
1664 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1665 command_name += '"';
1670 sgml::openTag(ofs, depth + command_depth, false, command_name);
1672 item_name = c_params.empty() ? "title" : c_params;
1673 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1676 case LATEX_ENVIRONMENT:
1677 case LATEX_ITEM_ENVIRONMENT:
1678 if (depth < par->params().depth()) {
1679 depth = par->params().depth();
1680 environment_stack[depth].erase();
1683 if (environment_stack[depth] != style->latexname()) {
1684 if (environment_stack.size() == depth + 1) {
1685 environment_stack.push_back("!-- --");
1686 environment_inner.push_back("!-- --");
1688 environment_stack[depth] = style->latexname();
1689 environment_inner[depth] = "!-- --";
1690 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1692 if (environment_inner[depth] != "!-- --") {
1693 item_name= "listitem";
1694 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1695 if (environment_inner[depth] == "varlistentry")
1696 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1700 if (style->latextype == LATEX_ENVIRONMENT) {
1701 if (!style->latexparam().empty()) {
1702 if (style->latexparam() == "CDATA")
1705 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1710 desc_on = (style->labeltype == LABEL_MANUAL);
1712 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1713 sgml::openTag(ofs, depth + 1 + command_depth,
1714 false, environment_inner[depth]);
1716 item_name = desc_on ? "term" : "para";
1717 sgml::openTag(ofs, depth + 1 + command_depth,
1721 sgml::openTag(ofs, depth + command_depth,
1722 false, style->latexname());
1726 simpleDocBookOnePar(ofs, par, desc_on,
1727 depth + 1 + command_depth);
1730 // write closing SGML tags
1731 switch (style->latextype) {
1733 end_tag = c_params.empty() ? "title" : c_params;
1734 sgml::closeTag(ofs, depth + command_depth,
1737 case LATEX_ENVIRONMENT:
1738 if (!style->latexparam().empty()) {
1739 if (style->latexparam() == "CDATA")
1742 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1745 case LATEX_ITEM_ENVIRONMENT:
1746 if (desc_on == 1) break;
1748 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1750 case LATEX_PARAGRAPH:
1751 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1754 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1760 for (int d = depth; d >= 0; --d) {
1761 if (!environment_stack[depth].empty()) {
1762 if (environment_inner[depth] != "!-- --") {
1763 item_name = "listitem";
1764 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1765 if (environment_inner[depth] == "varlistentry")
1766 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1769 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1773 for (int j = command_depth; j >= 0 ; --j)
1774 if (!command_stack[j].empty()) {
1775 sgml::closeTag(ofs, j, false, command_stack[j]);
1780 sgml::closeTag(ofs, 0, false, top_element);
1783 // How to check for successful close
1785 // we want this to be true outside previews (for insetexternal)
1790 void Buffer::simpleDocBookOnePar(ostream & os,
1791 ParagraphList::iterator par, int & desc_on,
1792 Paragraph::depth_type depth) const
1794 bool emph_flag = false;
1796 LyXLayout_ptr const & style = par->layout();
1798 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1800 int char_line_count = depth;
1801 //if (!style.free_spacing)
1802 // os << string(depth,' ');
1804 // parsing main loop
1805 for (pos_type i = 0; i < par->size(); ++i) {
1806 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1808 // handle <emphasis> tag
1809 if (font_old.emph() != font.emph()) {
1810 if (font.emph() == LyXFont::ON) {
1811 if (style->latexparam() == "CDATA")
1814 if (style->latexparam() == "CDATA")
1818 if (style->latexparam() == "CDATA")
1820 os << "</emphasis>";
1821 if (style->latexparam() == "CDATA")
1828 if (par->isInset(i)) {
1829 InsetOld * inset = par->getInset(i);
1830 // don't print the inset in position 0 if desc_on == 3 (label)
1831 if (i || desc_on != 3) {
1832 if (style->latexparam() == "CDATA")
1834 inset->docbook(*this, os, false);
1835 if (style->latexparam() == "CDATA")
1839 char c = par->getChar(i);
1842 boost::tie(ws, str) = sgml::escapeChar(c);
1844 if (style->pass_thru) {
1846 } else if (par->isFreeSpacing() || c != ' ') {
1848 } else if (desc_on == 1) {
1850 os << "\n</term><listitem><para>";
1860 if (style->latexparam() == "CDATA")
1862 os << "</emphasis>";
1863 if (style->latexparam() == "CDATA")
1867 // resets description flag correctly
1869 // <term> not closed...
1870 os << "</term>\n<listitem><para> </para>";
1872 if (style->free_spacing)
1877 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1878 // Other flags: -wall -v0 -x
1879 int Buffer::runChktex()
1883 // get LaTeX-Filename
1884 string const name = getLatexName();
1885 string path = filePath();
1887 string const org_path = path;
1888 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1892 Path p(path); // path to LaTeX file
1893 message(_("Running chktex..."));
1895 // Generate the LaTeX file if neccessary
1896 LatexRunParams runparams;
1897 runparams.flavor = LatexRunParams::LATEX;
1898 runparams.nice = false;
1899 makeLaTeXFile(name, org_path, runparams);
1902 Chktex chktex(lyxrc.chktex_command, name, filePath());
1903 int res = chktex.run(terr); // run chktex
1906 Alert::error(_("chktex failure"),
1907 _("Could not run chktex successfully."));
1908 } else if (res > 0) {
1909 // Insert all errors as errors boxes
1910 bufferErrors(*this, terr);
1919 void Buffer::validate(LaTeXFeatures & features) const
1921 LyXTextClass const & tclass = params.getLyXTextClass();
1923 if (params.tracking_changes) {
1924 features.require("dvipost");
1925 features.require("color");
1928 // AMS Style is at document level
1929 if (params.use_amsmath == BufferParams::AMS_ON
1930 || tclass.provides(LyXTextClass::amsmath))
1931 features.require("amsmath");
1933 for_each(paragraphs.begin(), paragraphs.end(),
1934 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1936 // the bullet shapes are buffer level not paragraph level
1937 // so they are tested here
1938 for (int i = 0; i < 4; ++i) {
1939 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1940 int const font = params.user_defined_bullets[i].getFont();
1942 int const c = params
1943 .user_defined_bullets[i]
1950 features.require("latexsym");
1952 } else if (font == 1) {
1953 features.require("amssymb");
1954 } else if ((font >= 2 && font <= 5)) {
1955 features.require("pifont");
1960 if (lyxerr.debugging(Debug::LATEX)) {
1961 features.showStruct();
1966 void Buffer::getLabelList(std::vector<string> & list) const
1968 /// if this is a child document and the parent is already loaded
1969 /// Use the parent's list instead [ale990407]
1970 if (!params.parentname.empty()
1971 && bufferlist.exists(params.parentname)) {
1972 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1974 tmp->getLabelList(list);
1979 for (inset_iterator it = inset_const_iterator_begin();
1980 it != inset_const_iterator_end(); ++it) {
1981 it->getLabelList(list);
1986 // This is also a buffer property (ale)
1987 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1989 /// if this is a child document and the parent is already loaded
1990 /// use the parent's list instead [ale990412]
1991 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1992 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1994 tmp->fillWithBibKeys(keys);
1999 for (inset_iterator it = inset_const_iterator_begin();
2000 it != inset_const_iterator_end(); ++it) {
2001 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2002 static_cast<InsetBibtex &>(*it).fillWithBibKeys(*this, keys);
2003 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2004 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2005 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2006 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2007 string const key = bib.getContents();
2008 string const opt = bib.getOptions();
2009 string const ref; // = pit->asString(this, false);
2010 string const info = opt + "TheBibliographyRef" + ref;
2011 keys.push_back(pair<string, string>(key, info));
2017 bool Buffer::isDepClean(string const & name) const
2019 DepClean::const_iterator it = dep_clean_.find(name);
2020 if (it == dep_clean_.end())
2026 void Buffer::markDepClean(string const & name)
2028 dep_clean_[name] = true;
2032 bool Buffer::dispatch(string const & command, bool * result)
2034 // Split command string into command and argument
2036 string line = ltrim(command);
2037 string const arg = trim(split(line, cmd, ' '));
2039 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2043 bool Buffer::dispatch(int action, string const & argument, bool * result)
2045 bool dispatched = true;
2049 bool const tmp = Exporter::Export(this, argument, false);
2062 void Buffer::changeLanguage(Language const * from, Language const * to)
2064 lyxerr << "Changing Language!" << endl;
2066 // Take care of l10n/i18n
2069 ParIterator end = par_iterator_end();
2070 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2071 it->changeLanguage(params, from, to);
2075 void Buffer::updateDocLang(Language const * nlang)
2077 messages_.reset(new Messages(nlang->code()));
2081 bool Buffer::isMultiLingual()
2083 ParIterator end = par_iterator_end();
2084 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2085 if (it->isMultiLingual(params))
2092 void Buffer::inset_iterator::setParagraph()
2094 while (pit != pend) {
2095 it = pit->insetlist.begin();
2096 if (it != pit->insetlist.end())
2103 InsetOld * Buffer::getInsetFromID(int id_arg) const
2105 for (inset_iterator it = inset_const_iterator_begin();
2106 it != inset_const_iterator_end(); ++it)
2108 if (it->id() == id_arg)
2110 InsetOld * in = it->getInsetFromID(id_arg);
2118 ParIterator Buffer::getParFromID(int id) const
2120 #warning FIXME: const correctness! (Andre)
2121 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2122 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2124 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2126 // John says this is called with id == -1 from undo
2127 lyxerr << "getParFromID(), id: " << id << endl;
2131 for (; it != end; ++it)
2139 bool Buffer::hasParWithID(int id) const
2141 ParConstIterator it = par_iterator_begin();
2142 ParConstIterator end = par_iterator_end();
2145 // John says this is called with id == -1 from undo
2146 lyxerr << "hasParWithID(), id: " << id << endl;
2150 for (; it != end; ++it)
2158 ParIterator Buffer::par_iterator_begin()
2160 return ParIterator(paragraphs.begin(), paragraphs);
2164 ParIterator Buffer::par_iterator_end()
2166 return ParIterator(paragraphs.end(), paragraphs);
2170 ParConstIterator Buffer::par_iterator_begin() const
2172 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2176 ParConstIterator Buffer::par_iterator_end() const
2178 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2182 Language const * Buffer::getLanguage() const
2184 return params.language;
2188 string const Buffer::B_(string const & l10n) const
2190 if (messages_.get()) {
2191 return messages_->get(l10n);
2198 bool Buffer::isClean() const
2204 bool Buffer::isBakClean() const
2210 void Buffer::markClean() const
2216 // if the .lyx file has been saved, we don't need an
2222 void Buffer::markBakClean()
2228 void Buffer::setUnnamed(bool flag)
2234 bool Buffer::isUnnamed()
2240 void Buffer::markDirty()
2248 DepClean::iterator it = dep_clean_.begin();
2249 DepClean::const_iterator const end = dep_clean_.end();
2251 for (; it != end; ++it) {
2257 string const & Buffer::fileName() const
2263 string const & Buffer::filePath() const
2269 bool Buffer::isReadonly() const
2275 void Buffer::setParentName(string const & name)
2277 params.parentname = name;
2281 Buffer::inset_iterator::inset_iterator()
2286 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2293 Buffer::inset_iterator Buffer::inset_iterator_begin()
2295 return inset_iterator(paragraphs.begin(), paragraphs.end());
2299 Buffer::inset_iterator Buffer::inset_iterator_end()
2301 return inset_iterator(paragraphs.end(), paragraphs.end());
2305 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2307 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2308 const_cast<ParagraphList&>(paragraphs).end());
2312 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2314 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2315 const_cast<ParagraphList&>(paragraphs).end());
2319 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2323 if (it == pit->insetlist.end()) {
2332 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2334 inset_iterator tmp = *this;
2340 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2346 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2352 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2358 lyx::pos_type Buffer::inset_iterator::getPos() const
2364 bool operator==(Buffer::inset_iterator const & iter1,
2365 Buffer::inset_iterator const & iter2)
2367 return iter1.pit == iter2.pit
2368 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2372 bool operator!=(Buffer::inset_iterator const & iter1,
2373 Buffer::inset_iterator const & iter2)
2375 return !(iter1 == iter2);