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);
118 lyxvc().buffer(this);
119 if (read_only || lyxrc.use_tempdir) {
120 temppath_ = 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 (!temppath().empty() && destroyDir(temppath()) != 0) {
139 Alert::warning(_("Could not remove temporary directory"),
140 bformat(_("Could not remove the temporary directory %1$s"), temppath()));
143 paragraphs().clear();
145 // Remove any previewed LaTeX snippets associated with this buffer.
146 lyx::graphics::Previews::get().removeLoader(*this);
150 limited_stack<Undo> & Buffer::undostack()
156 limited_stack<Undo> const & Buffer::undostack() const
162 limited_stack<Undo> & Buffer::redostack()
168 limited_stack<Undo> const & Buffer::redostack() const
174 BufferParams & Buffer::params()
180 BufferParams const & Buffer::params() const
186 ParagraphList & Buffer::paragraphs()
192 ParagraphList const & Buffer::paragraphs() const
198 LyXVC & Buffer::lyxvc()
204 LyXVC const & Buffer::lyxvc() const
210 string const & Buffer::temppath() const
216 bool & Buffer::niceFile()
222 bool Buffer::niceFile() const
228 TexRow & Buffer::texrow()
234 TexRow const & Buffer::texrow() const
240 string const Buffer::getLatexName(bool no_path) const
242 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
243 return no_path ? OnlyFilename(name) : name;
247 pair<Buffer::LogType, string> const Buffer::getLogName() const
249 string const filename = getLatexName(false);
251 if (filename.empty())
252 return make_pair(Buffer::latexlog, string());
254 string path = OnlyPath(filename);
256 if (lyxrc.use_tempdir || !IsDirWriteable(path))
259 string const fname = AddName(path,
260 OnlyFilename(ChangeExtension(filename,
263 AddName(path, OnlyFilename(
264 ChangeExtension(filename,
265 formats.extension("literate") + ".out")));
267 // If no Latex log or Build log is newer, show Build log
269 FileInfo const f_fi(fname);
270 FileInfo const b_fi(bname);
273 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
274 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
275 return make_pair(Buffer::buildlog, bname);
277 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
278 return make_pair(Buffer::latexlog, fname);
282 void Buffer::setReadonly(bool flag)
284 if (read_only != flag) {
291 AuthorList & Buffer::authors()
293 return params().authorlist;
297 void Buffer::setFileName(string const & newfile)
299 filename_ = MakeAbsPath(newfile);
300 filepath_ = OnlyPath(filename_);
301 setReadonly(IsFileWriteable(filename_) == 0);
306 // We'll remove this later. (Lgb)
309 void unknownClass(string const & unknown)
311 Alert::warning(_("Unknown document class"),
312 bformat(_("Using the default document class, because the "
313 "class %1$s is unknown."), unknown));
318 int Buffer::readHeader(LyXLex & lex)
320 int unknown_tokens = 0;
324 string const token = lex.getString();
329 if (token == "\\end_header")
332 lyxerr[Debug::PARSER] << "Handling header token: `"
333 << token << '\'' << endl;
336 string unknown = params().readToken(lex, token);
337 if (!unknown.empty()) {
338 if (unknown[0] != '\\') {
339 unknownClass(unknown);
342 string const s = bformat(_("Unknown token: "
346 error(ErrorItem(_("Header error"), s,
351 return unknown_tokens;
355 // candidate for move to BufferView
356 // (at least some parts in the beginning of the func)
359 // changed to be public and have one parameter
360 // if par = 0 normal behavior
361 // else insert behavior
362 // Returns false if "\end_document" is not read (Asger)
363 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
365 Paragraph::depth_type depth = 0;
366 bool the_end_read = false;
368 if (paragraphs().empty()) {
370 if (!params().getLyXTextClass().load()) {
371 string theclass = params().getLyXTextClass().name();
372 Alert::error(_("Can't load document class"), bformat(
373 "Using the default document class, because the "
374 " class %1$s could not be loaded.", theclass));
375 params().textclass = 0;
378 // We don't want to adopt the parameters from the
379 // document we insert, so read them into a temporary buffer
380 // and then discard it
382 Buffer tmpbuf("", false);
383 tmpbuf.readHeader(lex);
388 string const token = lex.getString();
393 lyxerr[Debug::PARSER] << "Handling token: `"
394 << token << '\'' << endl;
396 if (token == "\\end_document") {
401 readParagraph(lex, token, paragraphs(), pit, depth);
408 int Buffer::readParagraph(LyXLex & lex, string const & token,
409 ParagraphList & pars, ParagraphList::iterator & pit,
410 Paragraph::depth_type & depth)
412 static Change current_change;
415 if (token == "\\begin_layout") {
416 lex.pushToken(token);
419 par.params().depth(depth);
420 if (params().tracking_changes)
422 LyXFont f(LyXFont::ALL_INHERIT, params().language);
426 if (pit != pars.end())
429 pit = pars.insert(pit, par);
431 // FIXME: goddamn InsetTabular makes us pass a Buffer
433 ::readParagraph(*this, *pit, lex);
435 } else if (token == "\\begin_deeper") {
437 } else if (token == "\\end_deeper") {
439 lex.printError("\\end_deeper: " "depth is already null");
450 // needed to insert the selection
451 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
452 LyXFont const & fn,string const & str)
454 LyXLayout_ptr const & layout = par->layout();
458 par->checkInsertChar(font);
459 // insert the string, don't insert doublespace
460 bool space_inserted = true;
461 bool autobreakrows = !par->inInset() ||
462 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
463 for(string::const_iterator cit = str.begin();
464 cit != str.end(); ++cit) {
466 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
467 breakParagraph(params(), paragraphs(), par, pos,
468 layout->isEnvironment());
471 space_inserted = true;
475 // do not insert consecutive spaces if !free_spacing
476 } else if ((*cit == ' ' || *cit == '\t') &&
477 space_inserted && !par->isFreeSpacing()) {
479 } else if (*cit == '\t') {
480 if (!par->isFreeSpacing()) {
481 // tabs are like spaces here
482 par->insertChar(pos, ' ', font);
484 space_inserted = true;
486 const pos_type nb = 8 - pos % 8;
487 for (pos_type a = 0; a < nb ; ++a) {
488 par->insertChar(pos, ' ', font);
491 space_inserted = true;
493 } else if (!IsPrintable(*cit)) {
494 // Ignore unprintables
497 // just insert the character
498 par->insertChar(pos, *cit, font);
500 space_inserted = (*cit == ' ');
507 bool Buffer::readFile(string const & filename)
509 // Check if the file is compressed.
510 string const format = getExtFromContents(filename);
511 if (format == "gzip" || format == "zip" || format == "compress") {
512 params().compressed = true;
515 bool ret = readFile(filename, paragraphs().begin());
517 // After we have read a file, we must ensure that the buffer
518 // language is set and used in the gui.
519 // If you know of a better place to put this, please tell me. (Lgb)
520 updateDocLang(params().language);
526 bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
529 lex.setFile(filename);
531 return readFile(lex, filename, pit);
535 bool Buffer::readFile(LyXLex & lex, string const & filename,
536 ParagraphList::iterator pit)
538 Assert(!filename.empty());
541 Alert::error(_("Document could not be read"),
542 bformat(_("%1$s could not be read."), filename));
547 string const token(lex.getString());
550 Alert::error(_("Document could not be read"),
551 bformat(_("%1$s could not be read."), filename));
555 // the first token _must_ be...
556 if (token != "\\lyxformat") {
557 lyxerr << "Token: " << token << endl;
559 Alert::error(_("Document format failure"),
560 bformat(_("%1$s is not a LyX document."),
566 string tmp_format = lex.getString();
567 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
568 // if present remove ".," from string.
569 string::size_type dot = tmp_format.find_first_of(".,");
570 //lyxerr << " dot found at " << dot << endl;
571 if (dot != string::npos)
572 tmp_format.erase(dot, 1);
573 int file_format = strToInt(tmp_format);
574 //lyxerr << "format: " << file_format << endl;
576 if (file_format > LYX_FORMAT) {
577 Alert::warning(_("Document format failure"),
578 bformat(_("%1$s was created with a newer"
579 " version of LyX. This is likely to"
582 } else if (file_format < LYX_FORMAT) {
583 string const tmpfile = tempName();
584 string command = LibFileSearch("lyx2lyx", "lyx2lyx");
585 if (command.empty()) {
586 Alert::error(_("Conversion script not found"),
587 bformat(_("%1$s is from an earlier"
588 " version of LyX, but the"
589 " conversion script lyx2lyx"
590 " could not be found."),
596 + " -o " + tmpfile + ' '
597 + QuoteName(filename);
598 lyxerr[Debug::INFO] << "Running '"
601 cmd_ret const ret = RunCommand(command);
602 if (ret.first != 0) {
603 Alert::error(_("Conversion script failed"),
604 bformat(_("%1$s is from an earlier version"
605 " of LyX, but the lyx2lyx script"
606 " failed to convert it."),
610 bool ret = readFile(tmpfile, pit);
611 // Do stuff with tmpfile name and buffer name here.
617 bool the_end = readBody(lex, pit);
618 params().setPaperStuff();
621 Alert::error(_("Document format failure"),
622 bformat(_("%1$s ended unexpectedly, which means"
623 " that it is probably corrupted."),
630 // Should probably be moved to somewhere else: BufferView? LyXView?
631 bool Buffer::save() const
633 // We don't need autosaves in the immediate future. (Asger)
634 resetAutosaveTimers();
638 if (lyxrc.make_backup) {
639 s = fileName() + '~';
640 if (!lyxrc.backupdir_path.empty())
641 s = AddName(lyxrc.backupdir_path,
642 subst(os::slashify_path(s),'/','!'));
644 // Rename is the wrong way of making a backup,
645 // this is the correct way.
646 /* truss cp fil fil2:
647 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
648 stat("LyXVC.lyx", 0xEFFFF688) = 0
649 open("LyXVC.lyx", O_RDONLY) = 3
650 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
651 fstat(4, 0xEFFFF508) = 0
652 fstat(3, 0xEFFFF508) = 0
653 read(3, " # T h i s f i l e w".., 8192) = 5579
654 write(4, " # T h i s f i l e w".., 5579) = 5579
655 read(3, 0xEFFFD4A0, 8192) = 0
658 chmod("LyXVC3.lyx", 0100644) = 0
659 lseek(0, 0, SEEK_CUR) = 46440
663 // Should probably have some more error checking here.
664 // Doing it this way, also makes the inodes stay the same.
665 // This is still not a very good solution, in particular we
666 // might loose the owner of the backup.
667 FileInfo finfo(fileName());
669 mode_t fmode = finfo.getMode();
670 struct utimbuf times = {
671 finfo.getAccessTime(),
672 finfo.getModificationTime() };
674 ifstream ifs(fileName().c_str());
675 ofstream ofs(s.c_str(), ios::out|ios::trunc);
680 ::chmod(s.c_str(), fmode);
682 if (::utime(s.c_str(), ×)) {
683 lyxerr << "utime error." << endl;
686 lyxerr << "LyX was not able to make "
687 "backup copy. Beware." << endl;
692 if (writeFile(fileName())) {
694 removeAutosaveFile(fileName());
696 // Saving failed, so backup is not backup
697 if (lyxrc.make_backup) {
698 rename(s, fileName());
706 bool Buffer::writeFile(string const & fname) const
708 if (read_only && (fname == fileName())) {
712 FileInfo finfo(fname);
713 if (finfo.exist() && !finfo.writable()) {
719 if (params().compressed) {
720 gz::ogzstream ofs(fname.c_str());
725 retval = do_writeFile(ofs);
728 ofstream ofs(fname.c_str());
732 retval = do_writeFile(ofs);
739 bool Buffer::do_writeFile(ostream & ofs) const
743 // Use the standard "C" locale for file output.
744 ofs.imbue(std::locale::classic());
747 // The top of the file should not be written by params().
749 // write out a comment in the top of the file
750 ofs << "#LyX " << lyx_version
751 << " created this file. For more info see http://www.lyx.org/\n"
752 << "\\lyxformat " << LYX_FORMAT << "\n";
754 // now write out the buffer paramters.
755 params().writeFile(ofs);
757 ofs << "\\end_header\n";
759 Paragraph::depth_type depth = 0;
761 // this will write out all the paragraphs
762 // using recursive descent.
763 ParagraphList::const_iterator pit = paragraphs().begin();
764 ParagraphList::const_iterator pend = paragraphs().end();
765 for (; pit != pend; ++pit)
766 pit->write(*this, ofs, params(), depth);
768 // Write marker that shows file is complete
769 ofs << "\n\\end_document" << endl;
771 // Shouldn't really be needed....
774 // how to check if close went ok?
775 // Following is an attempt... (BE 20001011)
777 // good() returns false if any error occured, including some
779 // bad() returns true if something bad happened in the buffer,
780 // which should include file system full errors.
787 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
789 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
801 pair<int, string> const addDepth(int depth, int ldepth)
805 d += (ldepth - depth) * 2;
806 return make_pair(d, string(d, ' '));
812 string const Buffer::asciiParagraph(Paragraph const & par,
813 unsigned int linelen,
814 bool noparbreak) const
816 ostringstream buffer;
818 Paragraph::depth_type ltype_depth = 0;
819 bool ref_printed = false;
820 Paragraph::depth_type depth = par.params().depth();
822 // First write the layout
823 string const & tmp = par.layout()->name();
824 if (compare_no_case(tmp, "itemize") == 0) {
826 ltype_depth = depth + 1;
827 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
829 ltype_depth = depth + 1;
830 } else if (contains(ascii_lowercase(tmp), "ection")) {
832 ltype_depth = depth + 1;
833 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
835 ltype_depth = depth + 1;
836 } else if (compare_ascii_no_case(tmp, "description") == 0) {
838 ltype_depth = depth + 1;
839 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
842 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
850 /* maybe some vertical spaces */
852 /* the labelwidthstring used in lists */
856 /* some pagebreaks? */
860 /* what about the alignment */
862 // linelen <= 0 is special and means we don't have paragraph breaks
864 string::size_type currlinelen = 0;
870 buffer << string(depth * 2, ' ');
871 currlinelen += depth * 2;
874 // we should probably change to the paragraph language in the
875 // gettext here (if possible) so that strings are outputted in
876 // the correct language! (20012712 Jug)
880 case 4: // (Sub)Paragraph
881 case 5: // Description
885 buffer << _("Abstract") << "\n\n";
888 string const abst = _("Abstract: ");
890 currlinelen += abst.length();
893 case 7: // Bibliography
896 buffer << _("References") << "\n\n";
899 string const refs = _("References: ");
901 currlinelen += refs.length();
909 string const parlab = par.params().labelString();
910 buffer << parlab << ' ';
911 currlinelen += parlab.length() + 1;
919 pair<int, string> p = addDepth(depth, ltype_depth);
921 currlinelen += p.first;
924 // this is to change the linebreak to do it by word a bit more
925 // intelligent hopefully! (only in the case where we have a
926 // max linelength!) (Jug)
930 for (pos_type i = 0; i < par.size(); ++i) {
931 char c = par.getUChar(params(), i);
933 case Paragraph::META_INSET:
935 InsetOld const * inset = par.getInset(i);
939 currlinelen += word.length();
942 if (inset->ascii(*this, buffer, linelen)) {
943 // to be sure it breaks paragraph
944 currlinelen += linelen;
953 currlinelen + word.length() > linelen - 10) {
955 pair<int, string> p = addDepth(depth, ltype_depth);
957 currlinelen = p.first;
960 buffer << word << ' ';
961 currlinelen += word.length() + 1;
968 lyxerr[Debug::INFO] <<
969 "writeAsciiFile: NULL char in structure." << endl;
972 (currlinelen + word.length()) > linelen)
976 pair<int, string> p =
977 addDepth(depth, ltype_depth);
979 currlinelen = p.first;
986 return STRCONV(buffer.str());
990 void Buffer::writeFileAscii(string const & fname, int linelen)
993 if (!::openFileWrite(ofs, fname))
995 writeFileAscii(ofs, linelen);
999 void Buffer::writeFileAscii(ostream & os, int linelen)
1001 ParagraphList::iterator beg = paragraphs().begin();
1002 ParagraphList::iterator end = paragraphs().end();
1003 ParagraphList::iterator it = beg;
1004 for (; it != end; ++it) {
1005 os << asciiParagraph(*it, linelen, it == beg);
1011 void Buffer::makeLaTeXFile(string const & fname,
1012 string const & original_path,
1013 LatexRunParams const & runparams,
1014 bool output_preamble, bool output_body)
1016 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1019 if (!::openFileWrite(ofs, fname))
1022 makeLaTeXFile(ofs, original_path,
1023 runparams, output_preamble, output_body);
1027 lyxerr << "File was not closed properly." << endl;
1032 void Buffer::makeLaTeXFile(ostream & os,
1033 string const & original_path,
1034 LatexRunParams const & runparams_in,
1035 bool output_preamble, bool output_body)
1037 LatexRunParams runparams = runparams_in;
1038 niceFile() = runparams.nice; // this will be used by Insetincludes.
1040 // validate the buffer.
1041 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1042 LaTeXFeatures features(params());
1044 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1047 // The starting paragraph of the coming rows is the
1048 // first paragraph of the document. (Asger)
1049 texrow().start(paragraphs().begin()->id(), 0);
1051 if (output_preamble && runparams.nice) {
1052 os << "%% LyX " << lyx_version << " created this file. "
1053 "For more info, see http://www.lyx.org/.\n"
1054 "%% Do not edit unless you really know what "
1059 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1060 // There are a few differences between nice LaTeX and usual files:
1061 // usual is \batchmode and has a
1062 // special input@path to allow the including of figures
1063 // with either \input or \includegraphics (what figinsets do).
1064 // input@path is set when the actual parameter
1065 // original_path is set. This is done for usual tex-file, but not
1066 // for nice-latex-file. (Matthias 250696)
1067 if (output_preamble) {
1068 if (!runparams.nice) {
1069 // code for usual, NOT nice-latex-file
1070 os << "\\batchmode\n"; // changed
1071 // from \nonstopmode
1074 if (!original_path.empty()) {
1075 string inputpath = os::external_path(original_path);
1076 subst(inputpath, "~", "\\string~");
1077 os << "\\makeatletter\n"
1078 << "\\def\\input@path{{"
1079 << inputpath << "/}}\n"
1080 << "\\makeatother\n";
1086 // Write the preamble
1087 runparams.use_babel = params().writeLaTeX(os, features, texrow());
1093 os << "\\begin{document}\n";
1095 } // output_preamble
1096 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1098 if (!lyxrc.language_auto_begin) {
1099 os << subst(lyxrc.language_command_begin, "$$lang",
1100 params().language->babel())
1105 latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
1107 // add this just in case after all the paragraphs
1111 if (!lyxrc.language_auto_end) {
1112 os << subst(lyxrc.language_command_end, "$$lang",
1113 params().language->babel())
1118 if (output_preamble) {
1119 os << "\\end{document}\n";
1122 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1124 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1128 // Just to be sure. (Asger)
1131 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1132 lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
1135 // we want this to be true outside previews (for insetexternal)
1140 bool Buffer::isLatex() const
1142 return params().getLyXTextClass().outputType() == LATEX;
1146 bool Buffer::isLinuxDoc() const
1148 return params().getLyXTextClass().outputType() == LINUXDOC;
1152 bool Buffer::isLiterate() const
1154 return params().getLyXTextClass().outputType() == LITERATE;
1158 bool Buffer::isDocBook() const
1160 return params().getLyXTextClass().outputType() == DOCBOOK;
1164 bool Buffer::isSGML() const
1166 LyXTextClass const & tclass = params().getLyXTextClass();
1168 return tclass.outputType() == LINUXDOC ||
1169 tclass.outputType() == DOCBOOK;
1173 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1176 if (!::openFileWrite(ofs, fname))
1179 niceFile() = nice; // this will be used by included files.
1181 LaTeXFeatures features(params());
1187 LyXTextClass const & tclass = params().getLyXTextClass();
1189 string top_element = tclass.latexname();
1192 ofs << "<!doctype linuxdoc system";
1194 string preamble = params().preamble;
1195 string const name = nice ? ChangeExtension(filename_, ".sgml")
1197 preamble += features.getIncludedFiles(name);
1198 preamble += features.getLyXSGMLEntities();
1200 if (!preamble.empty()) {
1201 ofs << " [ " << preamble << " ]";
1205 if (params().options.empty())
1206 sgml::openTag(ofs, 0, false, top_element);
1208 string top = top_element;
1210 top += params().options;
1211 sgml::openTag(ofs, 0, false, top);
1215 ofs << "<!-- LyX " << lyx_version
1216 << " created this file. For more info see http://www.lyx.org/"
1219 Paragraph::depth_type depth = 0; // paragraph depth
1221 vector<string> environment_stack(5);
1223 ParagraphList::iterator pit = paragraphs().begin();
1224 ParagraphList::iterator pend = paragraphs().end();
1225 for (; pit != pend; ++pit) {
1226 LyXLayout_ptr const & style = pit->layout();
1227 // treat <toc> as a special case for compatibility with old code
1228 if (pit->isInset(0)) {
1229 InsetOld * inset = pit->getInset(0);
1230 InsetOld::Code lyx_code = inset->lyxCode();
1231 if (lyx_code == InsetOld::TOC_CODE) {
1232 string const temp = "toc";
1233 sgml::openTag(ofs, depth, false, temp);
1238 // environment tag closing
1239 for (; depth > pit->params().depth(); --depth) {
1240 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1241 environment_stack[depth].erase();
1244 // write opening SGML tags
1245 switch (style->latextype) {
1246 case LATEX_PARAGRAPH:
1247 if (depth == pit->params().depth()
1248 && !environment_stack[depth].empty()) {
1249 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1250 environment_stack[depth].erase();
1256 sgml::openTag(ofs, depth, false, style->latexname());
1261 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1263 if (!environment_stack[depth].empty()) {
1264 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1268 environment_stack[depth].erase();
1269 sgml::openTag(ofs, depth, false, style->latexname());
1272 case LATEX_ENVIRONMENT:
1273 case LATEX_ITEM_ENVIRONMENT:
1274 case LATEX_BIB_ENVIRONMENT:
1276 string const & latexname = style->latexname();
1278 if (depth == pit->params().depth()
1279 && environment_stack[depth] != latexname) {
1280 sgml::closeTag(ofs, depth, false,
1281 environment_stack[depth]);
1282 environment_stack[depth].erase();
1284 if (depth < pit->params().depth()) {
1285 depth = pit->params().depth();
1286 environment_stack[depth].erase();
1288 if (environment_stack[depth] != latexname) {
1290 sgml::openTag(ofs, depth, false, "p");
1292 sgml::openTag(ofs, depth, false, latexname);
1294 if (environment_stack.size() == depth + 1)
1295 environment_stack.push_back("!-- --");
1296 environment_stack[depth] = latexname;
1299 if (style->latexparam() == "CDATA")
1302 if (style->latextype == LATEX_ENVIRONMENT) break;
1304 if (style->labeltype == LABEL_MANUAL)
1309 sgml::openTag(ofs, depth + 1, false, item_name);
1314 sgml::openTag(ofs, depth, false, style->latexname());
1318 simpleLinuxDocOnePar(ofs, pit, depth);
1321 // write closing SGML tags
1322 switch (style->latextype) {
1325 case LATEX_ENVIRONMENT:
1326 case LATEX_ITEM_ENVIRONMENT:
1327 case LATEX_BIB_ENVIRONMENT:
1328 if (style->latexparam() == "CDATA")
1332 sgml::closeTag(ofs, depth, false, style->latexname());
1338 for (int i = depth; i >= 0; --i)
1339 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1343 sgml::closeTag(ofs, 0, false, top_element);
1347 // How to check for successful close
1349 // we want this to be true outside previews (for insetexternal)
1354 // checks, if newcol chars should be put into this line
1355 // writes newline, if necessary.
1358 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1359 string::size_type newcol)
1362 if (colcount > lyxrc.ascii_linelen) {
1364 colcount = newcol; // assume write after this call
1379 string tag_name(PAR_TAG const & pt) {
1381 case NONE: return "!-- --";
1382 case TT: return "tt";
1383 case SF: return "sf";
1384 case BF: return "bf";
1385 case IT: return "it";
1386 case SL: return "sl";
1387 case EM: return "em";
1394 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1396 p1 = static_cast<PAR_TAG>(p1 | p2);
1401 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1403 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1409 // Handle internal paragraph parsing -- layout already processed.
1410 void Buffer::simpleLinuxDocOnePar(ostream & os,
1411 ParagraphList::iterator par,
1412 Paragraph::depth_type /*depth*/) const
1414 LyXLayout_ptr const & style = par->layout();
1416 string::size_type char_line_count = 5; // Heuristic choice ;-)
1418 // gets paragraph main font
1421 if (style->labeltype == LABEL_MANUAL) {
1422 font_old = style->labelfont;
1425 font_old = style->font;
1429 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1430 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1431 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1434 stack<PAR_TAG> tag_state;
1435 // parsing main loop
1436 for (pos_type i = 0; i < par->size(); ++i) {
1438 PAR_TAG tag_close = NONE;
1439 list < PAR_TAG > tag_open;
1441 LyXFont const font = par->getFont(params(), i, outerFont(par, paragraphs()));
1443 if (font_old.family() != font.family()) {
1444 switch (family_type) {
1445 case LyXFont::SANS_FAMILY:
1448 case LyXFont::TYPEWRITER_FAMILY:
1455 family_type = font.family();
1457 switch (family_type) {
1458 case LyXFont::SANS_FAMILY:
1459 tag_open.push_back(SF);
1461 case LyXFont::TYPEWRITER_FAMILY:
1462 tag_open.push_back(TT);
1469 if (font_old.series() != font.series()) {
1470 switch (series_type) {
1471 case LyXFont::BOLD_SERIES:
1478 series_type = font.series();
1480 switch (series_type) {
1481 case LyXFont::BOLD_SERIES:
1482 tag_open.push_back(BF);
1490 if (font_old.shape() != font.shape()) {
1491 switch (shape_type) {
1492 case LyXFont::ITALIC_SHAPE:
1495 case LyXFont::SLANTED_SHAPE:
1502 shape_type = font.shape();
1504 switch (shape_type) {
1505 case LyXFont::ITALIC_SHAPE:
1506 tag_open.push_back(IT);
1508 case LyXFont::SLANTED_SHAPE:
1509 tag_open.push_back(SL);
1516 if (font_old.emph() != font.emph()) {
1517 if (font.emph() == LyXFont::ON) {
1518 tag_open.push_back(EM);
1527 list < PAR_TAG > temp;
1528 while (!tag_state.empty() && tag_close) {
1529 PAR_TAG k = tag_state.top();
1531 os << "</" << tag_name(k) << '>';
1538 for(list< PAR_TAG >::const_iterator j = temp.begin();
1539 j != temp.end(); ++j) {
1541 os << '<' << tag_name(*j) << '>';
1544 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1545 j != tag_open.end(); ++j) {
1547 os << '<' << tag_name(*j) << '>';
1550 char c = par->getChar(i);
1552 if (c == Paragraph::META_INSET) {
1553 InsetOld * inset = par->getInset(i);
1554 inset->linuxdoc(*this, os);
1559 if (style->latexparam() == "CDATA") {
1560 // "TeX"-Mode on == > SGML-Mode on.
1567 boost::tie(ws, str) = sgml::escapeChar(c);
1568 if (ws && !par->isFreeSpacing()) {
1569 // in freespacing mode, spaces are
1570 // non-breaking characters
1571 if (desc_on) {// if char is ' ' then...
1574 sgmlLineBreak(os, char_line_count, 6);
1578 sgmlLineBreak(os, char_line_count, 1);
1583 char_line_count += str.length();
1589 while (!tag_state.empty()) {
1590 os << "</" << tag_name(tag_state.top()) << '>';
1594 // resets description flag correctly
1596 // <tag> not closed...
1597 sgmlLineBreak(os, char_line_count, 6);
1603 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1606 if (!::openFileWrite(ofs, fname))
1609 niceFile() = nice; // this will be used by Insetincludes.
1611 LaTeXFeatures features(params());
1616 LyXTextClass const & tclass = params().getLyXTextClass();
1617 string top_element = tclass.latexname();
1620 ofs << "<!DOCTYPE " << top_element
1621 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1623 string preamble = params().preamble;
1624 string const name = nice ? ChangeExtension(filename_, ".sgml")
1626 preamble += features.getIncludedFiles(name);
1627 preamble += features.getLyXSGMLEntities();
1629 if (!preamble.empty()) {
1630 ofs << "\n [ " << preamble << " ]";
1635 string top = top_element;
1637 top += params().language->code();
1640 if (!params().options.empty()) {
1642 top += params().options;
1644 sgml::openTag(ofs, 0, false, top);
1646 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1647 << "\n See http://www.lyx.org/ for more information -->\n";
1649 vector<string> environment_stack(10);
1650 vector<string> environment_inner(10);
1651 vector<string> command_stack(10);
1653 bool command_flag = false;
1654 Paragraph::depth_type command_depth = 0;
1655 Paragraph::depth_type command_base = 0;
1656 Paragraph::depth_type cmd_depth = 0;
1657 Paragraph::depth_type depth = 0; // paragraph depth
1660 string command_name;
1662 ParagraphList::iterator par = paragraphs().begin();
1663 ParagraphList::iterator pend = paragraphs().end();
1665 for (; par != pend; ++par) {
1669 int desc_on = 0; // description mode
1671 LyXLayout_ptr const & style = par->layout();
1673 // environment tag closing
1674 for (; depth > par->params().depth(); --depth) {
1675 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1676 item_name = "listitem";
1677 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1678 if (environment_inner[depth] == "varlistentry")
1679 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1681 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1682 environment_stack[depth].erase();
1683 environment_inner[depth].erase();
1686 if (depth == par->params().depth()
1687 && environment_stack[depth] != style->latexname()
1688 && !environment_stack[depth].empty()) {
1689 if (environment_inner[depth] != "!-- --") {
1690 item_name= "listitem";
1691 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1692 if (environment_inner[depth] == "varlistentry")
1693 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1696 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1698 environment_stack[depth].erase();
1699 environment_inner[depth].erase();
1702 // Write opening SGML tags.
1703 switch (style->latextype) {
1704 case LATEX_PARAGRAPH:
1705 sgml::openTag(ofs, depth + command_depth,
1706 false, style->latexname());
1711 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1713 command_name = style->latexname();
1715 sgmlparam = style->latexparam();
1716 c_params = split(sgmlparam, c_depth,'|');
1718 cmd_depth = atoi(c_depth);
1721 if (cmd_depth < command_base) {
1722 for (Paragraph::depth_type j = command_depth;
1723 j >= command_base; --j) {
1724 sgml::closeTag(ofs, j, false, command_stack[j]);
1727 command_depth = command_base = cmd_depth;
1728 } else if (cmd_depth <= command_depth) {
1729 for (int j = command_depth;
1730 j >= int(cmd_depth); --j) {
1731 sgml::closeTag(ofs, j, false, command_stack[j]);
1734 command_depth = cmd_depth;
1736 command_depth = cmd_depth;
1738 command_depth = command_base = cmd_depth;
1739 command_flag = true;
1741 if (command_stack.size() == command_depth + 1)
1742 command_stack.push_back(string());
1743 command_stack[command_depth] = command_name;
1745 // treat label as a special case for
1746 // more WYSIWYM handling.
1747 // This is a hack while paragraphs can't have
1748 // attributes, like id in this case.
1749 if (par->isInset(0)) {
1750 InsetOld * inset = par->getInset(0);
1751 InsetOld::Code lyx_code = inset->lyxCode();
1752 if (lyx_code == InsetOld::LABEL_CODE) {
1753 command_name += " id=\"";
1754 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1755 command_name += '"';
1760 sgml::openTag(ofs, depth + command_depth, false, command_name);
1762 item_name = c_params.empty() ? "title" : c_params;
1763 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1766 case LATEX_ENVIRONMENT:
1767 case LATEX_ITEM_ENVIRONMENT:
1768 if (depth < par->params().depth()) {
1769 depth = par->params().depth();
1770 environment_stack[depth].erase();
1773 if (environment_stack[depth] != style->latexname()) {
1774 if (environment_stack.size() == depth + 1) {
1775 environment_stack.push_back("!-- --");
1776 environment_inner.push_back("!-- --");
1778 environment_stack[depth] = style->latexname();
1779 environment_inner[depth] = "!-- --";
1780 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1782 if (environment_inner[depth] != "!-- --") {
1783 item_name= "listitem";
1784 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1785 if (environment_inner[depth] == "varlistentry")
1786 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1790 if (style->latextype == LATEX_ENVIRONMENT) {
1791 if (!style->latexparam().empty()) {
1792 if (style->latexparam() == "CDATA")
1795 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1800 desc_on = (style->labeltype == LABEL_MANUAL);
1802 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1803 sgml::openTag(ofs, depth + 1 + command_depth,
1804 false, environment_inner[depth]);
1806 item_name = desc_on ? "term" : "para";
1807 sgml::openTag(ofs, depth + 1 + command_depth,
1811 sgml::openTag(ofs, depth + command_depth,
1812 false, style->latexname());
1816 simpleDocBookOnePar(ofs, par, desc_on,
1817 depth + 1 + command_depth);
1820 // write closing SGML tags
1821 switch (style->latextype) {
1823 end_tag = c_params.empty() ? "title" : c_params;
1824 sgml::closeTag(ofs, depth + command_depth,
1827 case LATEX_ENVIRONMENT:
1828 if (!style->latexparam().empty()) {
1829 if (style->latexparam() == "CDATA")
1832 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1835 case LATEX_ITEM_ENVIRONMENT:
1836 if (desc_on == 1) break;
1838 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1840 case LATEX_PARAGRAPH:
1841 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1844 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1850 for (int d = depth; d >= 0; --d) {
1851 if (!environment_stack[depth].empty()) {
1852 if (environment_inner[depth] != "!-- --") {
1853 item_name = "listitem";
1854 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1855 if (environment_inner[depth] == "varlistentry")
1856 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1859 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1863 for (int j = command_depth; j >= 0 ; --j)
1864 if (!command_stack[j].empty()) {
1865 sgml::closeTag(ofs, j, false, command_stack[j]);
1870 sgml::closeTag(ofs, 0, false, top_element);
1873 // How to check for successful close
1875 // we want this to be true outside previews (for insetexternal)
1880 void Buffer::simpleDocBookOnePar(ostream & os,
1881 ParagraphList::iterator par, int & desc_on,
1882 Paragraph::depth_type depth) const
1884 bool emph_flag = false;
1886 LyXLayout_ptr const & style = par->layout();
1888 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1890 int char_line_count = depth;
1891 //if (!style.free_spacing)
1892 // os << string(depth,' ');
1894 // parsing main loop
1895 for (pos_type i = 0; i < par->size(); ++i) {
1896 LyXFont font = par->getFont(params(), i, outerFont(par, paragraphs()));
1898 // handle <emphasis> tag
1899 if (font_old.emph() != font.emph()) {
1900 if (font.emph() == LyXFont::ON) {
1901 if (style->latexparam() == "CDATA")
1904 if (style->latexparam() == "CDATA")
1908 if (style->latexparam() == "CDATA")
1910 os << "</emphasis>";
1911 if (style->latexparam() == "CDATA")
1918 if (par->isInset(i)) {
1919 InsetOld * inset = par->getInset(i);
1920 // don't print the inset in position 0 if desc_on == 3 (label)
1921 if (i || desc_on != 3) {
1922 if (style->latexparam() == "CDATA")
1924 inset->docbook(*this, os, false);
1925 if (style->latexparam() == "CDATA")
1929 char c = par->getChar(i);
1932 boost::tie(ws, str) = sgml::escapeChar(c);
1934 if (style->pass_thru) {
1936 } else if (par->isFreeSpacing() || c != ' ') {
1938 } else if (desc_on == 1) {
1940 os << "\n</term><listitem><para>";
1950 if (style->latexparam() == "CDATA")
1952 os << "</emphasis>";
1953 if (style->latexparam() == "CDATA")
1957 // resets description flag correctly
1959 // <term> not closed...
1960 os << "</term>\n<listitem><para> </para>";
1962 if (style->free_spacing)
1967 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1968 // Other flags: -wall -v0 -x
1969 int Buffer::runChktex()
1973 // get LaTeX-Filename
1974 string const name = getLatexName();
1975 string path = filePath();
1977 string const org_path = path;
1978 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1982 Path p(path); // path to LaTeX file
1983 message(_("Running chktex..."));
1985 // Generate the LaTeX file if neccessary
1986 LatexRunParams runparams;
1987 runparams.flavor = LatexRunParams::LATEX;
1988 runparams.nice = false;
1989 makeLaTeXFile(name, org_path, runparams);
1992 Chktex chktex(lyxrc.chktex_command, name, filePath());
1993 int res = chktex.run(terr); // run chktex
1996 Alert::error(_("chktex failure"),
1997 _("Could not run chktex successfully."));
1998 } else if (res > 0) {
1999 // Insert all errors as errors boxes
2000 bufferErrors(*this, terr);
2009 void Buffer::validate(LaTeXFeatures & features) const
2011 LyXTextClass const & tclass = params().getLyXTextClass();
2013 if (params().tracking_changes) {
2014 features.require("dvipost");
2015 features.require("color");
2018 // AMS Style is at document level
2019 if (params().use_amsmath == BufferParams::AMS_ON
2020 || tclass.provides(LyXTextClass::amsmath))
2021 features.require("amsmath");
2023 for_each(paragraphs().begin(), paragraphs().end(),
2024 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2026 // the bullet shapes are buffer level not paragraph level
2027 // so they are tested here
2028 for (int i = 0; i < 4; ++i) {
2029 if (params().user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2030 int const font = params().user_defined_bullets[i].getFont();
2032 int const c = params()
2033 .user_defined_bullets[i]
2040 features.require("latexsym");
2042 } else if (font == 1) {
2043 features.require("amssymb");
2044 } else if ((font >= 2 && font <= 5)) {
2045 features.require("pifont");
2050 if (lyxerr.debugging(Debug::LATEX)) {
2051 features.showStruct();
2056 void Buffer::getLabelList(std::vector<string> & list) const
2058 /// if this is a child document and the parent is already loaded
2059 /// Use the parent's list instead [ale990407]
2060 if (!params().parentname.empty()
2061 && bufferlist.exists(params().parentname)) {
2062 Buffer const * tmp = bufferlist.getBuffer(params().parentname);
2064 tmp->getLabelList(list);
2069 for (inset_iterator it = inset_const_iterator_begin();
2070 it != inset_const_iterator_end(); ++it) {
2071 it->getLabelList(list);
2076 // This is also a buffer property (ale)
2077 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
2079 /// if this is a child document and the parent is already loaded
2080 /// use the parent's list instead [ale990412]
2081 if (!params().parentname.empty() &&
2082 bufferlist.exists(params().parentname)) {
2083 Buffer const * tmp = bufferlist.getBuffer(params().parentname);
2085 tmp->fillWithBibKeys(keys);
2090 for (inset_iterator it = inset_const_iterator_begin();
2091 it != inset_const_iterator_end(); ++it) {
2092 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2093 static_cast<InsetBibtex &>(*it).fillWithBibKeys(*this, keys);
2094 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2095 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2096 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2097 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2098 string const key = bib.getContents();
2099 string const opt = bib.getOptions();
2100 string const ref; // = pit->asString(this, false);
2101 string const info = opt + "TheBibliographyRef" + ref;
2102 keys.push_back(pair<string, string>(key, info));
2108 bool Buffer::isDepClean(string const & name) const
2110 DepClean::const_iterator it = dep_clean_.find(name);
2111 if (it == dep_clean_.end())
2117 void Buffer::markDepClean(string const & name)
2119 dep_clean_[name] = true;
2123 bool Buffer::dispatch(string const & command, bool * result)
2125 // Split command string into command and argument
2127 string line = ltrim(command);
2128 string const arg = trim(split(line, cmd, ' '));
2130 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2134 bool Buffer::dispatch(int action, string const & argument, bool * result)
2136 bool dispatched = true;
2140 bool const tmp = Exporter::Export(this, argument, false);
2153 void Buffer::changeLanguage(Language const * from, Language const * to)
2155 lyxerr << "Changing Language!" << endl;
2157 // Take care of l10n/i18n
2160 ParIterator end = par_iterator_end();
2161 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2162 it->changeLanguage(params(), from, to);
2166 void Buffer::updateDocLang(Language const * nlang)
2168 messages_.reset(new Messages(nlang->code()));
2172 bool Buffer::isMultiLingual()
2174 ParIterator end = par_iterator_end();
2175 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2176 if (it->isMultiLingual(params()))
2183 void Buffer::inset_iterator::setParagraph()
2185 while (pit != pend) {
2186 it = pit->insetlist.begin();
2187 if (it != pit->insetlist.end())
2194 InsetOld * Buffer::getInsetFromID(int id_arg) const
2196 for (inset_iterator it = inset_const_iterator_begin();
2197 it != inset_const_iterator_end(); ++it)
2199 if (it->id() == id_arg)
2201 InsetOld * in = it->getInsetFromID(id_arg);
2209 ParIterator Buffer::getParFromID(int id) const
2211 #warning FIXME: const correctness! (Andre)
2212 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2213 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2215 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2217 // John says this is called with id == -1 from undo
2218 lyxerr << "getParFromID(), id: " << id << endl;
2222 for (; it != end; ++it)
2230 bool Buffer::hasParWithID(int id) const
2232 ParConstIterator it = par_iterator_begin();
2233 ParConstIterator end = par_iterator_end();
2236 // John says this is called with id == -1 from undo
2237 lyxerr << "hasParWithID(), id: " << id << endl;
2241 for (; it != end; ++it)
2249 ParIterator Buffer::par_iterator_begin()
2251 return ParIterator(paragraphs().begin(), paragraphs());
2255 ParIterator Buffer::par_iterator_end()
2257 return ParIterator(paragraphs().end(), paragraphs());
2261 ParConstIterator Buffer::par_iterator_begin() const
2263 ParagraphList const & pars = paragraphs();
2264 return ParConstIterator(const_cast<ParagraphList&>(pars).begin(), pars);
2268 ParConstIterator Buffer::par_iterator_end() const
2270 ParagraphList const & pars = paragraphs();
2271 return ParConstIterator(const_cast<ParagraphList&>(pars).end(), pars);
2275 Language const * Buffer::getLanguage() const
2277 return params().language;
2281 string const Buffer::B_(string const & l10n) const
2283 if (messages_.get()) {
2284 return messages_->get(l10n);
2291 bool Buffer::isClean() const
2297 bool Buffer::isBakClean() const
2303 void Buffer::markClean() const
2309 // if the .lyx file has been saved, we don't need an
2315 void Buffer::markBakClean()
2321 void Buffer::setUnnamed(bool flag)
2327 bool Buffer::isUnnamed()
2333 void Buffer::markDirty()
2341 DepClean::iterator it = dep_clean_.begin();
2342 DepClean::const_iterator const end = dep_clean_.end();
2344 for (; it != end; ++it) {
2350 string const & Buffer::fileName() const
2356 string const & Buffer::filePath() const
2362 bool Buffer::isReadonly() const
2368 void Buffer::setParentName(string const & name)
2370 params().parentname = name;
2374 Buffer::inset_iterator::inset_iterator()
2379 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2386 Buffer::inset_iterator Buffer::inset_iterator_begin()
2388 return inset_iterator(paragraphs().begin(), paragraphs().end());
2392 Buffer::inset_iterator Buffer::inset_iterator_end()
2394 return inset_iterator(paragraphs().end(), paragraphs().end());
2398 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2400 ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
2401 return inset_iterator(pars.begin(), pars.end());
2405 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2407 ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
2408 return inset_iterator(pars.end(), pars.end());
2412 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2416 if (it == pit->insetlist.end()) {
2425 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2427 inset_iterator tmp = *this;
2433 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2439 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2445 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2451 lyx::pos_type Buffer::inset_iterator::getPos() const
2457 bool operator==(Buffer::inset_iterator const & iter1,
2458 Buffer::inset_iterator const & iter2)
2460 return iter1.pit == iter2.pit
2461 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2465 bool operator!=(Buffer::inset_iterator const & iter1,
2466 Buffer::inset_iterator const & iter2)
2468 return !(iter1 == iter2);