1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * This file is Copyright 1996-2001
12 * ======================================================
18 #include "bufferlist.h"
19 #include "LyXAction.h"
22 #include "tex-strings.h"
24 #include "bufferview_funcs.h"
30 #include "LaTeXFeatures.h"
37 #include "BufferView.h"
38 #include "ParagraphParameters.h"
39 #include "iterators.h"
40 #include "lyxtextclasslist.h"
42 #include "paragraph_funcs.h"
45 #include "frontends/LyXView.h"
47 #include "mathed/formulamacro.h"
48 #include "mathed/formula.h"
50 #include "insets/inset.h"
51 #include "insets/inseterror.h"
52 #include "insets/insethfill.h"
53 #include "insets/insetlabel.h"
54 #include "insets/insetref.h"
55 #include "insets/inseturl.h"
56 #include "insets/insetnote.h"
57 #include "insets/insetquotes.h"
58 #include "insets/insetlatexaccent.h"
59 #include "insets/insetbibitem.h"
60 #include "insets/insetbibtex.h"
61 #include "insets/insetcite.h"
62 #include "insets/insetexternal.h"
63 #include "insets/insetindex.h"
64 #include "insets/insetinclude.h"
65 #include "insets/insettoc.h"
66 #include "insets/insetparent.h"
67 #include "insets/insetspecialchar.h"
68 #include "insets/insettext.h"
69 #include "insets/insetert.h"
70 #include "insets/insetgraphics.h"
71 #include "insets/insetfoot.h"
72 #include "insets/insetmarginal.h"
73 #include "insets/insetoptarg.h"
74 #include "insets/insetminipage.h"
75 #include "insets/insetfloat.h"
76 #include "insets/insetwrap.h"
77 #include "insets/insettabular.h"
79 #include "insets/insettheorem.h"
80 #include "insets/insetlist.h"
82 #include "insets/insetcaption.h"
83 #include "insets/insetfloatlist.h"
85 #include "frontends/Dialogs.h"
86 #include "frontends/Alert.h"
88 #include "graphics/Previews.h"
90 #include "support/textutils.h"
91 #include "support/filetools.h"
92 #include "support/path.h"
93 #include "support/os.h"
94 #include "support/lyxlib.h"
95 #include "support/FileInfo.h"
96 #include "support/lyxmanip.h"
97 #include "support/lyxtime.h"
99 #include <boost/bind.hpp>
100 #include <boost/tuple/tuple.hpp>
101 #include "BoostFormat.h"
113 #include <sys/types.h>
120 #ifndef CXX_GLOBAL_CSTD
132 using std::make_pair;
140 using lyx::textclass_type;
142 // all these externs should eventually be removed.
143 extern BufferList bufferlist;
147 const int LYX_FORMAT = 222;
151 Buffer::Buffer(string const & file, bool ronly)
152 : niceFile(true), lyx_clean(true), bak_clean(true),
153 unnamed(false), read_only(ronly),
154 filename_(file), users(0)
156 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
157 filepath_ = OnlyPath(file);
159 if (read_only || lyxrc.use_tempdir) {
160 tmppath = CreateBufferTmpDir();
165 // set initial author
166 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
172 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
173 // here the buffer should take care that it is
174 // saved properly, before it goes into the void.
176 // make sure that views using this buffer
181 if (!tmppath.empty()) {
182 DestroyBufferTmpDir(tmppath);
187 // Remove any previewed LaTeX snippets assocoated with this buffer.
188 grfx::Previews::get().removeLoader(this);
192 string const Buffer::getLatexName(bool no_path) const
194 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
196 return OnlyFilename(name);
202 pair<Buffer::LogType, string> const Buffer::getLogName() const
204 string const filename = getLatexName(false);
206 if (filename.empty())
207 return make_pair(Buffer::latexlog, string());
209 string path = OnlyPath(filename);
211 if (lyxrc.use_tempdir || !IsDirWriteable(path))
214 string const fname = AddName(path,
215 OnlyFilename(ChangeExtension(filename,
218 AddName(path, OnlyFilename(
219 ChangeExtension(filename,
220 formats.extension("literate") + ".out")));
222 // If no Latex log or Build log is newer, show Build log
224 FileInfo const f_fi(fname);
225 FileInfo const b_fi(bname);
228 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
229 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
230 return make_pair(Buffer::buildlog, bname);
232 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
233 return make_pair(Buffer::latexlog, fname);
237 void Buffer::setReadonly(bool flag)
239 if (read_only != flag) {
242 users->owner()->getDialogs().updateBufferDependent(false);
247 AuthorList & Buffer::authors()
253 /// Update window titles of all users
254 // Should work on a list
255 void Buffer::updateTitles() const
258 users->owner()->updateWindowTitle();
262 /// Reset autosave timer of all users
263 // Should work on a list
264 void Buffer::resetAutosaveTimers() const
267 users->owner()->resetAutosaveTimer();
271 void Buffer::setFileName(string const & newfile)
273 filename_ = MakeAbsPath(newfile);
274 filepath_ = OnlyPath(filename_);
275 setReadonly(IsFileWriteable(filename_) == 0);
280 // We'll remove this later. (Lgb)
283 string last_inset_read;
286 #warning And _why_ is this here? (Lgb)
290 vector<int> author_ids;
295 // candidate for move to BufferView
296 // (at least some parts in the beginning of the func)
299 // changed to be public and have one parameter
300 // if par = 0 normal behavior
301 // else insert behavior
302 // Returns false if "\the_end" is not read (Asger)
303 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
310 Paragraph::depth_type depth = 0;
311 bool the_end_read = false;
313 Paragraph * first_par = 0;
314 LyXFont font(LyXFont::ALL_INHERIT, params.language);
318 par->layout(params.getLyXTextClass().defaultLayout());
320 // We are inserting into an existing document
321 users->text->breakParagraph(users, paragraphs);
322 first_par = users->text->ownerParagraph();
325 // We don't want to adopt the parameters from the
326 // document we insert, so we skip until the text begins:
329 string const pretoken = lex.getString();
330 if (pretoken == "\\layout") {
331 lex.pushToken(pretoken);
339 string const token = lex.getString();
341 if (token.empty()) continue;
343 lyxerr[Debug::PARSER] << "Handling token: `"
344 << token << '\'' << endl;
347 parseSingleLyXformat2Token(lex, par, first_par,
355 paragraphs.set(first_par);
357 if (unknown_layouts > 0) {
358 string s = _("Couldn't set the layout for ");
359 if (unknown_layouts == 1) {
360 s += _("one paragraph");
362 s += tostr(unknown_layouts);
363 s += _(" paragraphs");
366 Alert::alert(_("Textclass Loading Error!"), s,
367 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
369 Alert::alert(_("Textclass Loading Error!"), s,
370 _("When reading ") + fileName());
374 if (unknown_tokens > 0) {
375 string s = _("Encountered ");
376 if (unknown_tokens == 1) {
377 s += _("one unknown token");
379 s += tostr(unknown_tokens);
380 s += _(" unknown tokens");
383 Alert::alert(_("Textclass Loading Error!"), s,
384 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
386 Alert::alert(_("Textclass Loading Error!"), s,
387 _("When reading ") + fileName());
396 // This stuff is, in the traditional LyX terminology, Super UGLY
397 // but this code is too b0rken to admit of a better solution yet
398 Change current_change;
403 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
404 Paragraph *& first_par,
405 string const & token, int & pos,
406 Paragraph::depth_type & depth,
410 bool the_end_read = false;
412 // The order of the tags tested may seem unnatural, but this
413 // has been done in order to reduce the number of string
414 // comparisons needed to recognize a given token. This leads
415 // on large documents like UserGuide to a reduction of a
417 if (token[0] != '\\') {
418 for (string::const_iterator cit = token.begin();
419 cit != token.end(); ++cit) {
420 par->insertChar(pos, (*cit), font, current_change);
423 } else if (token == "\\layout") {
424 // reset the font as we start a new layout and if the font is
425 // not ALL_INHERIT,document_language then it will be set to the
426 // right values after this tag (Jug 20020420)
427 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
430 string layoutname = lex.getString();
432 LyXTextClass const & tclass = params.getLyXTextClass();
434 if (layoutname.empty()) {
435 layoutname = tclass.defaultLayoutName();
437 bool hasLayout = tclass.hasLayout(layoutname);
439 lyxerr << "Layout '" << layoutname << "' does not"
440 << " exist in textclass '" << tclass.name()
442 lyxerr << "Trying to use default layout instead."
444 layoutname = tclass.defaultLayoutName();
448 // The is the compability reading of layout caption.
449 // It can be removed in LyX version 1.3.0. (Lgb)
450 if (compare_ascii_no_case(layoutname, "caption") == 0) {
451 // We expect that the par we are now working on is
452 // really inside a InsetText inside a InsetFloat.
453 // We also know that captions can only be
454 // one paragraph. (Lgb)
456 // We should now read until the next "\layout"
458 // This is probably not good enough, what if the
459 // caption is the last par in the document (Lgb)
460 istream & ist = lex.getStream();
466 if (prefixIs(line, "\\layout")) {
470 if (prefixIs(line, "\\begin_inset"))
472 if (prefixIs(line, "\\end_inset")) {
483 // Now we should have the whole layout in ss
484 // we should now be able to give this to the
486 ss << "\\end_inset\n";
488 // This seems like a bug in stringstream.
489 // We really should be able to use ss
491 istringstream is(ss.str());
493 tmplex.setStream(is);
494 Inset * inset = new InsetCaption;
495 inset->Read(this, tmplex);
496 par->InsertInset(pos, inset, font);
503 par = new Paragraph(par);
504 par->layout(params.getLyXTextClass().defaultLayout());
505 if (params.tracking_changes)
509 par->layout(params.getLyXTextClass()[layoutname]);
510 // Test whether the layout is obsolete.
511 LyXLayout_ptr const & layout = par->layout();
512 if (!layout->obsoleted_by().empty())
513 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
514 par->params().depth(depth);
519 } else if (token == "\\end_inset") {
520 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
521 << "Missing \\begin_inset?.\n"
522 << "Last inset read was: " << last_inset_read
524 // Simply ignore this. The insets do not have
526 // But insets should read it, it is a part of
527 // the inset isn't it? Lgb.
528 } else if (token == "\\begin_inset") {
529 readInset(lex, par, pos, font);
530 } else if (token == "\\family") {
532 font.setLyXFamily(lex.getString());
533 } else if (token == "\\series") {
535 font.setLyXSeries(lex.getString());
536 } else if (token == "\\shape") {
538 font.setLyXShape(lex.getString());
539 } else if (token == "\\size") {
541 font.setLyXSize(lex.getString());
542 } else if (token == "\\lang") {
544 string const tok = lex.getString();
545 Language const * lang = languages.getLanguage(tok);
547 font.setLanguage(lang);
549 font.setLanguage(params.language);
550 lex.printError("Unknown language `$$Token'");
552 } else if (token == "\\numeric") {
554 font.setNumber(font.setLyXMisc(lex.getString()));
555 } else if (token == "\\emph") {
557 font.setEmph(font.setLyXMisc(lex.getString()));
558 } else if (token == "\\bar") {
560 string const tok = lex.getString();
561 // This is dirty, but gone with LyX3. (Asger)
563 font.setUnderbar(LyXFont::ON);
564 else if (tok == "no")
565 font.setUnderbar(LyXFont::OFF);
566 else if (tok == "default")
567 font.setUnderbar(LyXFont::INHERIT);
569 lex.printError("Unknown bar font flag "
571 } else if (token == "\\noun") {
573 font.setNoun(font.setLyXMisc(lex.getString()));
574 } else if (token == "\\color") {
576 font.setLyXColor(lex.getString());
577 } else if (token == "\\SpecialChar") {
578 LyXLayout_ptr const & layout = par->layout();
580 // Insets don't make sense in a free-spacing context! ---Kayvan
581 if (layout->free_spacing || par->isFreeSpacing()) {
584 string const next_token = lex.getString();
585 if (next_token == "\\-") {
586 par->insertChar(pos, '-', font, current_change);
587 } else if (next_token == "~") {
588 par->insertChar(pos, ' ', font, current_change);
590 lex.printError("Token `$$Token' "
592 "paragraph layout!");
597 Inset * inset = new InsetSpecialChar;
598 inset->read(this, lex);
599 par->insertInset(pos, inset, font, current_change);
602 } else if (token == "\\i") {
603 Inset * inset = new InsetLatexAccent;
604 inset->read(this, lex);
605 par->insertInset(pos, inset, font, current_change);
607 } else if (token == "\\backslash") {
608 par->insertChar(pos, '\\', font, current_change);
610 } else if (token == "\\begin_deeper") {
612 } else if (token == "\\end_deeper") {
614 lex.printError("\\end_deeper: "
615 "depth is already null");
619 } else if (token == "\\begin_preamble") {
620 params.readPreamble(lex);
621 } else if (token == "\\textclass") {
623 pair<bool, textclass_type> pp =
624 textclasslist.NumberOfClass(lex.getString());
626 params.textclass = pp.second;
629 Alert::alert(_("Textclass error"),
630 boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
631 _("-- substituting default."));
634 _("Textclass error"),
635 _("The document uses an unknown textclass ")
637 _("-- substituting default."));
639 params.textclass = 0;
641 if (!params.getLyXTextClass().load()) {
642 // if the textclass wasn't loaded properly
643 // we need to either substitute another
644 // or stop loading the file.
645 // I can substitute but I don't see how I can
646 // stop loading... ideas?? ARRae980418
648 Alert::alert(_("Textclass Loading Error!"),
649 boost::io::str(boost::format(_("Can't load textclass %1$s")) %
650 params.getLyXTextClass().name()),
651 _("-- substituting default."));
653 Alert::alert(_("Textclass Loading Error!"),
654 _("Can't load textclass ")
655 + params.getLyXTextClass().name(),
656 _("-- substituting default."));
658 params.textclass = 0;
660 } else if (token == "\\options") {
662 params.options = lex.getString();
663 } else if (token == "\\language") {
664 params.readLanguage(lex);
665 } else if (token == "\\fontencoding") {
667 } else if (token == "\\inputencoding") {
669 params.inputenc = lex.getString();
670 } else if (token == "\\graphics") {
671 params.readGraphicsDriver(lex);
672 } else if (token == "\\fontscheme") {
674 params.fonts = lex.getString();
675 } else if (token == "\\noindent") {
676 par->params().noindent(true);
677 } else if (token == "\\leftindent") {
679 LyXLength value(lex.getString());
680 par->params().leftIndent(value);
681 } else if (token == "\\fill_top") {
682 par->params().spaceTop(VSpace(VSpace::VFILL));
683 } else if (token == "\\fill_bottom") {
684 par->params().spaceBottom(VSpace(VSpace::VFILL));
685 } else if (token == "\\line_top") {
686 par->params().lineTop(true);
687 } else if (token == "\\line_bottom") {
688 par->params().lineBottom(true);
689 } else if (token == "\\pagebreak_top") {
690 par->params().pagebreakTop(true);
691 } else if (token == "\\pagebreak_bottom") {
692 par->params().pagebreakBottom(true);
693 } else if (token == "\\start_of_appendix") {
694 par->params().startOfAppendix(true);
695 } else if (token == "\\paragraph_separation") {
696 int tmpret = lex.findToken(string_paragraph_separation);
699 params.paragraph_separation =
700 static_cast<BufferParams::PARSEP>(tmpret);
701 } else if (token == "\\defskip") {
703 params.defskip = VSpace(lex.getString());
704 } else if (token == "\\quotes_language") {
705 int tmpret = lex.findToken(string_quotes_language);
708 InsetQuotes::quote_language tmpl =
709 InsetQuotes::EnglishQ;
712 tmpl = InsetQuotes::EnglishQ;
715 tmpl = InsetQuotes::SwedishQ;
718 tmpl = InsetQuotes::GermanQ;
721 tmpl = InsetQuotes::PolishQ;
724 tmpl = InsetQuotes::FrenchQ;
727 tmpl = InsetQuotes::DanishQ;
730 params.quotes_language = tmpl;
731 } else if (token == "\\quotes_times") {
733 switch (lex.getInteger()) {
735 params.quotes_times = InsetQuotes::SingleQ;
738 params.quotes_times = InsetQuotes::DoubleQ;
741 } else if (token == "\\papersize") {
742 int tmpret = lex.findToken(string_papersize);
746 params.papersize2 = tmpret;
747 } else if (token == "\\paperpackage") {
748 int tmpret = lex.findToken(string_paperpackages);
751 params.paperpackage = BufferParams::PACKAGE_NONE;
753 params.paperpackage = tmpret;
754 } else if (token == "\\use_geometry") {
756 params.use_geometry = lex.getInteger();
757 } else if (token == "\\use_amsmath") {
759 params.use_amsmath = static_cast<BufferParams::AMS>(
761 } else if (token == "\\use_natbib") {
763 params.use_natbib = lex.getInteger();
764 } else if (token == "\\use_numerical_citations") {
766 params.use_numerical_citations = lex.getInteger();
767 } else if (token == "\\tracking_changes") {
769 params.tracking_changes = lex.getInteger();
770 // mark the first paragraph
771 if (params.tracking_changes)
773 } else if (token == "\\author") {
775 istringstream ss(lex.getString());
778 int aid(authorlist.record(a));
779 lyxerr << "aid is " << aid << endl;
780 lyxerr << "listed aid is " << author_ids.size() << endl;
781 author_ids.push_back(authorlist.record(a));
782 } else if (token == "\\paperorientation") {
783 int tmpret = lex.findToken(string_orientation);
787 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
788 } else if (token == "\\paperwidth") {
790 params.paperwidth = lex.getString();
791 } else if (token == "\\paperheight") {
793 params.paperheight = lex.getString();
794 } else if (token == "\\leftmargin") {
796 params.leftmargin = lex.getString();
797 } else if (token == "\\topmargin") {
799 params.topmargin = lex.getString();
800 } else if (token == "\\rightmargin") {
802 params.rightmargin = lex.getString();
803 } else if (token == "\\bottommargin") {
805 params.bottommargin = lex.getString();
806 } else if (token == "\\headheight") {
808 params.headheight = lex.getString();
809 } else if (token == "\\headsep") {
811 params.headsep = lex.getString();
812 } else if (token == "\\footskip") {
814 params.footskip = lex.getString();
815 } else if (token == "\\paperfontsize") {
817 params.fontsize = rtrim(lex.getString());
818 } else if (token == "\\papercolumns") {
820 params.columns = lex.getInteger();
821 } else if (token == "\\papersides") {
823 switch (lex.getInteger()) {
825 case 1: params.sides = LyXTextClass::OneSide; break;
826 case 2: params.sides = LyXTextClass::TwoSides; break;
828 } else if (token == "\\paperpagestyle") {
830 params.pagestyle = rtrim(lex.getString());
831 } else if (token == "\\bullet") {
833 int const index = lex.getInteger();
835 int temp_int = lex.getInteger();
836 params.user_defined_bullets[index].setFont(temp_int);
837 params.temp_bullets[index].setFont(temp_int);
839 temp_int = lex.getInteger();
840 params.user_defined_bullets[index].setCharacter(temp_int);
841 params.temp_bullets[index].setCharacter(temp_int);
843 temp_int = lex.getInteger();
844 params.user_defined_bullets[index].setSize(temp_int);
845 params.temp_bullets[index].setSize(temp_int);
847 string const temp_str = lex.getString();
848 if (temp_str != "\\end_bullet") {
849 // this element isn't really necessary for
850 // parsing but is easier for humans
851 // to understand bullets. Put it back and
852 // set a debug message?
853 lex.printError("\\end_bullet expected, got" + temp_str);
854 //how can I put it back?
856 } else if (token == "\\bulletLaTeX") {
857 // The bullet class should be able to read this.
859 int const index = lex.getInteger();
861 string temp_str = lex.getString();
863 while (temp_str != "\\end_bullet") {
864 // this loop structure is needed when user
865 // enters an empty string since the first
866 // thing returned will be the \\end_bullet
868 // if the LaTeX entry has spaces. Each element
869 // therefore needs to be read in turn
872 temp_str = lex.getString();
875 params.user_defined_bullets[index].setText(sum_str);
876 params.temp_bullets[index].setText(sum_str);
877 } else if (token == "\\secnumdepth") {
879 params.secnumdepth = lex.getInteger();
880 } else if (token == "\\tocdepth") {
882 params.tocdepth = lex.getInteger();
883 } else if (token == "\\spacing") {
885 string const tmp = rtrim(lex.getString());
886 Spacing::Space tmp_space = Spacing::Default;
888 if (tmp == "single") {
889 tmp_space = Spacing::Single;
890 } else if (tmp == "onehalf") {
891 tmp_space = Spacing::Onehalf;
892 } else if (tmp == "double") {
893 tmp_space = Spacing::Double;
894 } else if (tmp == "other") {
896 tmp_space = Spacing::Other;
897 tmp_val = lex.getFloat();
899 lex.printError("Unknown spacing token: '$$Token'");
901 // Small hack so that files written with klyx will be
904 par->params().spacing(Spacing(tmp_space, tmp_val));
906 params.spacing.set(tmp_space, tmp_val);
908 } else if (token == "\\paragraph_spacing") {
910 string const tmp = rtrim(lex.getString());
911 if (tmp == "single") {
912 par->params().spacing(Spacing(Spacing::Single));
913 } else if (tmp == "onehalf") {
914 par->params().spacing(Spacing(Spacing::Onehalf));
915 } else if (tmp == "double") {
916 par->params().spacing(Spacing(Spacing::Double));
917 } else if (tmp == "other") {
919 par->params().spacing(Spacing(Spacing::Other,
922 lex.printError("Unknown spacing token: '$$Token'");
924 } else if (token == "\\float_placement") {
926 params.float_placement = lex.getString();
927 } else if (token == "\\align") {
928 int tmpret = lex.findToken(string_align);
931 int const tmpret2 = int(pow(2.0, tmpret));
932 par->params().align(LyXAlignment(tmpret2));
933 } else if (token == "\\added_space_top") {
935 VSpace value = VSpace(lex.getString());
936 // only add the length when value > 0 or
938 if ((value.length().len().value() != 0) ||
940 (value.kind() != VSpace::LENGTH))
941 par->params().spaceTop(value);
942 } else if (token == "\\added_space_bottom") {
944 VSpace value = VSpace(lex.getString());
945 // only add the length when value > 0 or
947 if ((value.length().len().value() != 0) ||
949 (value.kind() != VSpace::LENGTH))
950 par->params().spaceBottom(value);
951 } else if (token == "\\labelwidthstring") {
953 par->params().labelWidthString(lex.getString());
954 // do not delete this token, it is still needed!
955 } else if (token == "\\newline") {
956 par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
958 } else if (token == "\\LyXTable") {
959 Inset * inset = new InsetTabular(*this);
960 inset->read(this, lex);
961 par->insertInset(pos, inset, font, current_change);
963 } else if (token == "\\bibitem") { // ale970302
964 InsetCommandParams p("bibitem", "dummy");
965 InsetBibitem * inset = new InsetBibitem(p);
966 inset->read(this, lex);
967 par->insertInset(pos, inset, font, current_change);
969 } else if (token == "\\hfill") {
970 par->insertInset(pos, new InsetHFill(),
971 LyXFont(LyXFont::ALL_INHERIT, params.language));
973 } else if (token == "\\change_unchanged") {
974 // Hack ! Needed for empty paragraphs :/
977 current_change = Change(Change::UNCHANGED);
978 } else if (token == "\\change_inserted") {
980 istringstream istr(lex.getString());
985 current_change = Change(Change::INSERTED, author_ids[aid], ct);
986 } else if (token == "\\change_deleted") {
988 istringstream istr(lex.getString());
993 current_change = Change(Change::DELETED, author_ids[aid], ct);
994 } else if (token == "\\the_end") {
997 // This should be insurance for the future: (Asger)
1000 #if USE_BOOST_FORMAT
1001 boost::format fmt(_("Unknown token: %1$s %2$s\n"));
1002 fmt % token % lex.text();
1003 string const s = fmt.str();
1005 string const s = _("Unknown token: ") + token
1006 + ' ' + lex.text() + '\n';
1008 // we can do this here this way because we're actually reading
1009 // the buffer and don't care about LyXText right now.
1010 InsetError * new_inset = new InsetError(s);
1011 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1016 return the_end_read;
1020 // needed to insert the selection
1021 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1022 LyXFont const & fn,string const & str)
1024 LyXLayout_ptr const & layout = par->layout();
1028 par->checkInsertChar(font);
1029 // insert the string, don't insert doublespace
1030 bool space_inserted = true;
1031 bool autobreakrows = !par->inInset() ||
1032 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1033 for(string::const_iterator cit = str.begin();
1034 cit != str.end(); ++cit) {
1036 if (autobreakrows && (!par->empty() || layout->keepempty)) {
1037 breakParagraph(params, paragraphs, par, pos,
1038 layout->isEnvironment());
1041 space_inserted = true;
1045 // do not insert consecutive spaces if !free_spacing
1046 } else if ((*cit == ' ' || *cit == '\t') &&
1047 space_inserted && !layout->free_spacing &&
1048 !par->isFreeSpacing())
1051 } else if (*cit == '\t') {
1052 if (!layout->free_spacing && !par->isFreeSpacing()) {
1053 // tabs are like spaces here
1054 par->insertChar(pos, ' ', font, current_change);
1056 space_inserted = true;
1058 const pos_type nb = 8 - pos % 8;
1059 for (pos_type a = 0; a < nb ; ++a) {
1060 par->insertChar(pos, ' ', font, current_change);
1063 space_inserted = true;
1065 } else if (!IsPrintable(*cit)) {
1066 // Ignore unprintables
1069 // just insert the character
1070 par->insertChar(pos, *cit, font);
1072 space_inserted = (*cit == ' ');
1079 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1080 int & pos, LyXFont & font)
1082 // consistency check
1083 if (lex.getString() != "\\begin_inset") {
1084 lyxerr << "Buffer::readInset: Consistency check failed."
1091 string const tmptok = lex.getString();
1092 last_inset_read = tmptok;
1094 // test the different insets
1095 if (tmptok == "LatexCommand") {
1096 InsetCommandParams inscmd;
1099 string const cmdName = inscmd.getCmdName();
1101 // This strange command allows LyX to recognize "natbib" style
1102 // citations: citet, citep, Citet etc.
1103 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1104 inset = new InsetCitation(inscmd);
1105 } else if (cmdName == "bibitem") {
1106 lex.printError("Wrong place for bibitem");
1107 inset = new InsetBibitem(inscmd);
1108 } else if (cmdName == "BibTeX") {
1109 inset = new InsetBibtex(inscmd);
1110 } else if (cmdName == "index") {
1111 inset = new InsetIndex(inscmd);
1112 } else if (cmdName == "include") {
1113 inset = new InsetInclude(inscmd, *this);
1114 } else if (cmdName == "label") {
1115 inset = new InsetLabel(inscmd);
1116 } else if (cmdName == "url"
1117 || cmdName == "htmlurl") {
1118 inset = new InsetUrl(inscmd);
1119 } else if (cmdName == "ref"
1120 || cmdName == "pageref"
1121 || cmdName == "vref"
1122 || cmdName == "vpageref"
1123 || cmdName == "prettyref") {
1124 if (!inscmd.getOptions().empty()
1125 || !inscmd.getContents().empty()) {
1126 inset = new InsetRef(inscmd, *this);
1128 } else if (cmdName == "tableofcontents") {
1129 inset = new InsetTOC(inscmd);
1130 } else if (cmdName == "listofalgorithms") {
1131 inset = new InsetFloatList("algorithm");
1132 } else if (cmdName == "listoffigures") {
1133 inset = new InsetFloatList("figure");
1134 } else if (cmdName == "listoftables") {
1135 inset = new InsetFloatList("table");
1136 } else if (cmdName == "printindex") {
1137 inset = new InsetPrintIndex(inscmd);
1138 } else if (cmdName == "lyxparent") {
1139 inset = new InsetParent(inscmd, *this);
1142 if (tmptok == "Quotes") {
1143 inset = new InsetQuotes;
1144 } else if (tmptok == "External") {
1145 inset = new InsetExternal;
1146 } else if (tmptok == "FormulaMacro") {
1147 inset = new InsetFormulaMacro;
1148 } else if (tmptok == "Formula") {
1149 inset = new InsetFormula;
1150 } else if (tmptok == "Graphics") {
1151 inset = new InsetGraphics;
1152 } else if (tmptok == "Note") {
1153 inset = new InsetNote(params);
1154 } else if (tmptok == "Include") {
1155 InsetCommandParams p("Include");
1156 inset = new InsetInclude(p, *this);
1157 } else if (tmptok == "ERT") {
1158 inset = new InsetERT(params);
1159 } else if (tmptok == "Tabular") {
1160 inset = new InsetTabular(*this);
1161 } else if (tmptok == "Text") {
1162 inset = new InsetText(params);
1163 } else if (tmptok == "Foot") {
1164 inset = new InsetFoot(params);
1165 } else if (tmptok == "Marginal") {
1166 inset = new InsetMarginal(params);
1167 } else if (tmptok == "OptArg") {
1168 inset = new InsetOptArg(params);
1169 } else if (tmptok == "Minipage") {
1170 inset = new InsetMinipage(params);
1171 } else if (tmptok == "Float") {
1173 string tmptok = lex.getString();
1174 inset = new InsetFloat(params, tmptok);
1175 } else if (tmptok == "Wrap") {
1177 string tmptok = lex.getString();
1178 inset = new InsetWrap(params, tmptok);
1180 } else if (tmptok == "List") {
1181 inset = new InsetList;
1182 } else if (tmptok == "Theorem") {
1183 inset = new InsetList;
1185 } else if (tmptok == "Caption") {
1186 inset = new InsetCaption(params);
1187 } else if (tmptok == "FloatList") {
1188 inset = new InsetFloatList;
1192 inset->read(this, lex);
1196 par->insertInset(pos, inset, font, current_change);
1202 bool Buffer::readFile(LyXLex & lex, string const & filename, Paragraph * par)
1206 string const token(lex.getString());
1207 if (token == "\\lyxformat") { // the first token _must_ be...
1209 string tmp_format = lex.getString();
1210 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
1211 // if present remove ".," from string.
1212 string::size_type dot = tmp_format.find_first_of(".,");
1213 //lyxerr << " dot found at " << dot << endl;
1214 if (dot != string::npos)
1215 tmp_format.erase(dot, 1);
1216 file_format = strToInt(tmp_format);
1217 //lyxerr << "format: " << file_format << endl;
1218 if (file_format == LYX_FORMAT) {
1220 } else if (file_format > LYX_FORMAT) {
1222 Alert::alert(_("Warning!"),
1223 _("The file was created with a newer version of "
1224 "LyX. This is likely to cause problems."));
1226 } else if (file_format < LYX_FORMAT) {
1228 if (file_format < 200) {
1229 Alert::alert(_("ERROR!"),
1230 _("Old LyX file format found. "
1231 "Use LyX 0.10.x to read this!"));
1233 } else if (!filename.empty()) {
1235 LibFileSearch("lyx2lyx", "lyx2lyx");
1236 if (command.empty()) {
1237 Alert::alert(_("ERROR!"),
1238 _("Can't find conversion script."));
1242 +tostr(LYX_FORMAT) + ' '
1243 + QuoteName(filename);
1244 lyxerr[Debug::INFO] << "Running '"
1247 cmd_ret const ret = RunCommand(command);
1249 Alert::alert(_("ERROR!"),
1250 _("An error occured while "
1251 "running the conversion script."));
1254 istringstream is(STRCONV(ret.second));
1255 LyXLex tmplex(0, 0);
1256 tmplex.setStream(is);
1257 return readFile(tmplex, string(), par);
1259 // This code is reached if lyx2lyx failed (for
1260 // some reason) to change the file format of
1266 bool the_end = readLyXformat2(lex, par);
1267 params.setPaperStuff();
1270 Alert::alert(_("Warning!"),
1271 _("Reading of document is not complete"),
1272 _("Maybe the document is truncated"));
1275 } else { // "\\lyxformat" not found
1276 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1279 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1284 // Should probably be moved to somewhere else: BufferView? LyXView?
1285 bool Buffer::save() const
1287 // We don't need autosaves in the immediate future. (Asger)
1288 resetAutosaveTimers();
1292 if (lyxrc.make_backup) {
1293 s = fileName() + '~';
1294 if (!lyxrc.backupdir_path.empty())
1295 s = AddName(lyxrc.backupdir_path,
1296 subst(os::slashify_path(s),'/','!'));
1298 // Rename is the wrong way of making a backup,
1299 // this is the correct way.
1300 /* truss cp fil fil2:
1301 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1302 stat("LyXVC.lyx", 0xEFFFF688) = 0
1303 open("LyXVC.lyx", O_RDONLY) = 3
1304 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1305 fstat(4, 0xEFFFF508) = 0
1306 fstat(3, 0xEFFFF508) = 0
1307 read(3, " # T h i s f i l e w".., 8192) = 5579
1308 write(4, " # T h i s f i l e w".., 5579) = 5579
1309 read(3, 0xEFFFD4A0, 8192) = 0
1312 chmod("LyXVC3.lyx", 0100644) = 0
1313 lseek(0, 0, SEEK_CUR) = 46440
1317 // Should probably have some more error checking here.
1318 // Doing it this way, also makes the inodes stay the same.
1319 // This is still not a very good solution, in particular we
1320 // might loose the owner of the backup.
1321 FileInfo finfo(fileName());
1322 if (finfo.exist()) {
1323 mode_t fmode = finfo.getMode();
1324 struct utimbuf times = {
1325 finfo.getAccessTime(),
1326 finfo.getModificationTime() };
1328 ifstream ifs(fileName().c_str());
1329 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1334 ::chmod(s.c_str(), fmode);
1336 if (::utime(s.c_str(), ×)) {
1337 lyxerr << "utime error." << endl;
1340 lyxerr << "LyX was not able to make "
1341 "backup copy. Beware." << endl;
1346 if (writeFile(fileName())) {
1348 removeAutosaveFile(fileName());
1350 // Saving failed, so backup is not backup
1351 if (lyxrc.make_backup) {
1352 lyx::rename(s, fileName());
1360 bool Buffer::writeFile(string const & fname) const
1362 if (read_only && (fname == fileName())) {
1366 FileInfo finfo(fname);
1367 if (finfo.exist() && !finfo.writable()) {
1371 ofstream ofs(fname.c_str());
1377 // Use the standard "C" locale for file output.
1378 ofs.imbue(std::locale::classic());
1381 // The top of the file should not be written by params.
1383 // write out a comment in the top of the file
1384 ofs << '#' << lyx_docversion
1385 << " created this file. For more info see http://www.lyx.org/\n"
1386 << "\\lyxformat " << LYX_FORMAT << "\n";
1388 // now write out the buffer paramters.
1389 params.writeFile(ofs);
1391 // if we're tracking, list all possible authors
1392 if (params.tracking_changes) {
1393 AuthorList::Authors::const_iterator it = authorlist.begin();
1394 AuthorList::Authors::const_iterator end = authorlist.end();
1395 for (; it != end; ++it) {
1396 ofs << "\\author " << it->second << "\n";
1400 Paragraph::depth_type depth = 0;
1402 // this will write out all the paragraphs
1403 // using recursive descent.
1404 ParagraphList::iterator pit = paragraphs.begin();
1405 ParagraphList::iterator pend = paragraphs.end();
1406 for (; pit != pend; ++pit)
1407 pit->write(this, ofs, params, depth);
1409 // Write marker that shows file is complete
1410 ofs << "\n\\the_end" << endl;
1414 // how to check if close went ok?
1415 // Following is an attempt... (BE 20001011)
1417 // good() returns false if any error occured, including some
1418 // formatting error.
1419 // bad() returns true if something bad happened in the buffer,
1420 // which should include file system full errors.
1427 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1429 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1441 pair<int, string> const addDepth(int depth, int ldepth)
1445 d += (ldepth - depth) * 2;
1446 return make_pair(d, string(d, ' '));
1452 string const Buffer::asciiParagraph(Paragraph const & par,
1453 unsigned int linelen,
1454 bool noparbreak) const
1456 ostringstream buffer;
1457 Paragraph::depth_type depth = 0;
1459 Paragraph::depth_type ltype_depth = 0;
1460 bool ref_printed = false;
1461 // if (!par->previous()) {
1463 // begins or ends a deeper area ?
1464 if (depth != par->params().depth()) {
1465 if (par->params().depth() > depth) {
1466 while (par->params().depth() > depth) {
1470 while (par->params().depth() < depth) {
1476 depth = par.params().depth();
1479 // First write the layout
1480 string const & tmp = par.layout()->name();
1481 if (compare_no_case(tmp, "itemize") == 0) {
1483 ltype_depth = depth + 1;
1484 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1486 ltype_depth = depth + 1;
1487 } else if (contains(ascii_lowercase(tmp), "ection")) {
1489 ltype_depth = depth + 1;
1490 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1492 ltype_depth = depth + 1;
1493 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1495 ltype_depth = depth + 1;
1496 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1499 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1507 /* maybe some vertical spaces */
1509 /* the labelwidthstring used in lists */
1513 /* some pagebreaks? */
1517 /* what about the alignment */
1519 // lyxerr << "Should this ever happen?" << endl;
1522 // linelen <= 0 is special and means we don't have paragraph breaks
1524 string::size_type currlinelen = 0;
1530 buffer << string(depth * 2, ' ');
1531 currlinelen += depth * 2;
1534 // we should probably change to the paragraph language in the
1535 // gettext here (if possible) so that strings are outputted in
1536 // the correct language! (20012712 Jug)
1540 case 4: // (Sub)Paragraph
1541 case 5: // Description
1545 buffer << _("Abstract") << "\n\n";
1548 string const abst = _("Abstract: ");
1550 currlinelen += abst.length();
1553 case 7: // Bibliography
1556 buffer << _("References") << "\n\n";
1559 string const refs = _("References: ");
1561 currlinelen += refs.length();
1569 string const parlab = par.params().labelString();
1570 buffer << parlab << ' ';
1571 currlinelen += parlab.length() + 1;
1579 pair<int, string> p = addDepth(depth, ltype_depth);
1581 currlinelen += p.first;
1584 // this is to change the linebreak to do it by word a bit more
1585 // intelligent hopefully! (only in the case where we have a
1586 // max linelength!) (Jug)
1590 for (pos_type i = 0; i < par.size(); ++i) {
1591 char c = par.getUChar(params, i);
1593 case Paragraph::META_INSET:
1595 Inset const * inset = par.getInset(i);
1599 currlinelen += word.length();
1602 if (inset->ascii(this, buffer, linelen)) {
1603 // to be sure it breaks paragraph
1604 currlinelen += linelen;
1610 case Paragraph::META_NEWLINE:
1612 buffer << word << "\n";
1615 pair<int, string> p = addDepth(depth,
1618 currlinelen = p.first;
1625 currlinelen + word.length() > linelen - 10) {
1627 pair<int, string> p = addDepth(depth, ltype_depth);
1629 currlinelen = p.first;
1632 buffer << word << ' ';
1633 currlinelen += word.length() + 1;
1640 lyxerr[Debug::INFO] <<
1641 "writeAsciiFile: NULL char in structure." << endl;
1643 if ((linelen > 0) &&
1644 (currlinelen + word.length()) > linelen)
1648 pair<int, string> p =
1649 addDepth(depth, ltype_depth);
1651 currlinelen = p.first;
1658 return STRCONV(buffer.str());
1662 void Buffer::writeFileAscii(string const & fname, int linelen)
1664 ofstream ofs(fname.c_str());
1666 Alert::err_alert(_("Error: Cannot write file:"), fname);
1669 writeFileAscii(ofs, linelen);
1673 void Buffer::writeFileAscii(ostream & os, int linelen)
1675 ParagraphList::iterator beg = paragraphs.begin();
1676 ParagraphList::iterator end = paragraphs.end();
1677 ParagraphList::iterator it = beg;
1678 for (; it != end; ++it) {
1679 os << asciiParagraph(*it, linelen, it == beg);
1686 void Buffer::makeLaTeXFile(string const & fname,
1687 string const & original_path,
1688 bool nice, bool only_body, bool only_preamble)
1690 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1692 ofstream ofs(fname.c_str());
1694 Alert::err_alert(_("Error: Cannot open file: "), fname);
1698 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1702 lyxerr << "File was not closed properly." << endl;
1707 void Buffer::makeLaTeXFile(ostream & os,
1708 string const & original_path,
1709 bool nice, bool only_body, bool only_preamble)
1711 niceFile = nice; // this will be used by Insetincludes.
1713 // validate the buffer.
1714 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1715 LaTeXFeatures features(params);
1717 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1720 // The starting paragraph of the coming rows is the
1721 // first paragraph of the document. (Asger)
1722 texrow.start(&*(paragraphs.begin()), 0);
1724 if (!only_body && nice) {
1725 os << "%% " << lyx_docversion << " created this file. "
1726 "For more info, see http://www.lyx.org/.\n"
1727 "%% Do not edit unless you really know what "
1732 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1733 // There are a few differences between nice LaTeX and usual files:
1734 // usual is \batchmode and has a
1735 // special input@path to allow the including of figures
1736 // with either \input or \includegraphics (what figinsets do).
1737 // input@path is set when the actual parameter
1738 // original_path is set. This is done for usual tex-file, but not
1739 // for nice-latex-file. (Matthias 250696)
1742 // code for usual, NOT nice-latex-file
1743 os << "\\batchmode\n"; // changed
1744 // from \nonstopmode
1747 if (!original_path.empty()) {
1748 string inputpath = os::external_path(original_path);
1749 subst(inputpath, "~", "\\string~");
1750 os << "\\makeatletter\n"
1751 << "\\def\\input@path{{"
1752 << inputpath << "/}}\n"
1753 << "\\makeatother\n";
1759 // Write the preamble
1760 params.writeLaTeX(os, features, texrow);
1766 os << "\\begin{document}\n";
1769 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1771 if (!lyxrc.language_auto_begin) {
1772 os << subst(lyxrc.language_command_begin, "$$lang",
1773 params.language->babel())
1778 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1780 // add this just in case after all the paragraphs
1784 if (!lyxrc.language_auto_end) {
1785 os << subst(lyxrc.language_command_end, "$$lang",
1786 params.language->babel())
1792 os << "\\end{document}\n";
1795 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1797 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1801 // Just to be sure. (Asger)
1804 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1805 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1808 // we want this to be true outside previews (for insetexternal)
1813 bool Buffer::isLatex() const
1815 return params.getLyXTextClass().outputType() == LATEX;
1819 bool Buffer::isLinuxDoc() const
1821 return params.getLyXTextClass().outputType() == LINUXDOC;
1825 bool Buffer::isLiterate() const
1827 return params.getLyXTextClass().outputType() == LITERATE;
1831 bool Buffer::isDocBook() const
1833 return params.getLyXTextClass().outputType() == DOCBOOK;
1837 bool Buffer::isSGML() const
1839 LyXTextClass const & tclass = params.getLyXTextClass();
1841 return tclass.outputType() == LINUXDOC ||
1842 tclass.outputType() == DOCBOOK;
1846 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1848 ofstream ofs(fname.c_str());
1851 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1855 niceFile = nice; // this will be used by included files.
1857 LaTeXFeatures features(params);
1863 LyXTextClass const & tclass = params.getLyXTextClass();
1865 string top_element = tclass.latexname();
1868 ofs << "<!doctype linuxdoc system";
1870 string preamble = params.preamble;
1871 const string name = nice ? ChangeExtension(filename_, ".sgml")
1873 preamble += features.getIncludedFiles(name);
1874 preamble += features.getLyXSGMLEntities();
1876 if (!preamble.empty()) {
1877 ofs << " [ " << preamble << " ]";
1881 if (params.options.empty())
1882 sgml::openTag(ofs, 0, false, top_element);
1884 string top = top_element;
1886 top += params.options;
1887 sgml::openTag(ofs, 0, false, top);
1891 ofs << "<!-- " << lyx_docversion
1892 << " created this file. For more info see http://www.lyx.org/"
1895 Paragraph::depth_type depth = 0; // paragraph depth
1896 Paragraph * par = &*(paragraphs.begin());
1898 vector<string> environment_stack(5);
1901 LyXLayout_ptr const & style = par->layout();
1902 // treat <toc> as a special case for compatibility with old code
1903 if (par->isInset(0)) {
1904 Inset * inset = par->getInset(0);
1905 Inset::Code lyx_code = inset->lyxCode();
1906 if (lyx_code == Inset::TOC_CODE) {
1907 string const temp = "toc";
1908 sgml::openTag(ofs, depth, false, temp);
1915 // environment tag closing
1916 for (; depth > par->params().depth(); --depth) {
1917 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1918 environment_stack[depth].erase();
1921 // write opening SGML tags
1922 switch (style->latextype) {
1923 case LATEX_PARAGRAPH:
1924 if (depth == par->params().depth()
1925 && !environment_stack[depth].empty()) {
1926 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1927 environment_stack[depth].erase();
1933 sgml::openTag(ofs, depth, false, style->latexname());
1939 _("Error: Wrong depth for LatexType Command.\n"));
1941 if (!environment_stack[depth].empty()) {
1942 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1946 environment_stack[depth].erase();
1947 sgml::openTag(ofs, depth, false, style->latexname());
1950 case LATEX_ENVIRONMENT:
1951 case LATEX_ITEM_ENVIRONMENT:
1952 case LATEX_BIB_ENVIRONMENT:
1954 string const & latexname = style->latexname();
1956 if (depth == par->params().depth()
1957 && environment_stack[depth] != latexname) {
1958 sgml::closeTag(ofs, depth, false,
1959 environment_stack[depth]);
1960 environment_stack[depth].erase();
1962 if (depth < par->params().depth()) {
1963 depth = par->params().depth();
1964 environment_stack[depth].erase();
1966 if (environment_stack[depth] != latexname) {
1968 sgml::openTag(ofs, depth, false, "p");
1970 sgml::openTag(ofs, depth, false, latexname);
1972 if (environment_stack.size() == depth + 1)
1973 environment_stack.push_back("!-- --");
1974 environment_stack[depth] = latexname;
1977 if (style->latexparam() == "CDATA")
1980 if (style->latextype == LATEX_ENVIRONMENT) break;
1982 if (style->labeltype == LABEL_MANUAL)
1987 sgml::openTag(ofs, depth + 1, false, item_name);
1992 sgml::openTag(ofs, depth, false, style->latexname());
1996 simpleLinuxDocOnePar(ofs, par, depth);
2001 // write closing SGML tags
2002 switch (style->latextype) {
2005 case LATEX_ENVIRONMENT:
2006 case LATEX_ITEM_ENVIRONMENT:
2007 case LATEX_BIB_ENVIRONMENT:
2008 if (style->latexparam() == "CDATA")
2012 sgml::closeTag(ofs, depth, false, style->latexname());
2018 for (int i = depth; i >= 0; --i)
2019 sgml::closeTag(ofs, depth, false, environment_stack[i]);
2023 sgml::closeTag(ofs, 0, false, top_element);
2027 // How to check for successful close
2029 // we want this to be true outside previews (for insetexternal)
2034 // checks, if newcol chars should be put into this line
2035 // writes newline, if necessary.
2038 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2039 string::size_type newcol)
2042 if (colcount > lyxrc.ascii_linelen) {
2044 colcount = newcol; // assume write after this call
2059 string tag_name(PAR_TAG const & pt) {
2061 case NONE: return "!-- --";
2062 case TT: return "tt";
2063 case SF: return "sf";
2064 case BF: return "bf";
2065 case IT: return "it";
2066 case SL: return "sl";
2067 case EM: return "em";
2074 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2076 p1 = static_cast<PAR_TAG>(p1 | p2);
2081 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2083 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2089 // Handle internal paragraph parsing -- layout already processed.
2090 void Buffer::simpleLinuxDocOnePar(ostream & os,
2092 Paragraph::depth_type /*depth*/)
2094 LyXLayout_ptr const & style = par->layout();
2096 string::size_type char_line_count = 5; // Heuristic choice ;-)
2098 // gets paragraph main font
2101 if (style->labeltype == LABEL_MANUAL) {
2102 font_old = style->labelfont;
2105 font_old = style->font;
2109 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2110 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2111 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2114 stack<PAR_TAG> tag_state;
2115 // parsing main loop
2116 for (pos_type i = 0; i < par->size(); ++i) {
2118 PAR_TAG tag_close = NONE;
2119 list < PAR_TAG > tag_open;
2121 LyXFont const font = par->getFont(params, i);
2123 if (font_old.family() != font.family()) {
2124 switch (family_type) {
2125 case LyXFont::SANS_FAMILY:
2128 case LyXFont::TYPEWRITER_FAMILY:
2135 family_type = font.family();
2137 switch (family_type) {
2138 case LyXFont::SANS_FAMILY:
2139 tag_open.push_back(SF);
2141 case LyXFont::TYPEWRITER_FAMILY:
2142 tag_open.push_back(TT);
2149 if (font_old.series() != font.series()) {
2150 switch (series_type) {
2151 case LyXFont::BOLD_SERIES:
2158 series_type = font.series();
2160 switch (series_type) {
2161 case LyXFont::BOLD_SERIES:
2162 tag_open.push_back(BF);
2170 if (font_old.shape() != font.shape()) {
2171 switch (shape_type) {
2172 case LyXFont::ITALIC_SHAPE:
2175 case LyXFont::SLANTED_SHAPE:
2182 shape_type = font.shape();
2184 switch (shape_type) {
2185 case LyXFont::ITALIC_SHAPE:
2186 tag_open.push_back(IT);
2188 case LyXFont::SLANTED_SHAPE:
2189 tag_open.push_back(SL);
2196 if (font_old.emph() != font.emph()) {
2197 if (font.emph() == LyXFont::ON) {
2198 tag_open.push_back(EM);
2207 list < PAR_TAG > temp;
2208 while (!tag_state.empty() && tag_close) {
2209 PAR_TAG k = tag_state.top();
2211 os << "</" << tag_name(k) << '>';
2218 for(list< PAR_TAG >::const_iterator j = temp.begin();
2219 j != temp.end(); ++j) {
2221 os << '<' << tag_name(*j) << '>';
2224 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2225 j != tag_open.end(); ++j) {
2227 os << '<' << tag_name(*j) << '>';
2230 char c = par->getChar(i);
2232 if (c == Paragraph::META_INSET) {
2233 Inset * inset = par->getInset(i);
2234 inset->linuxdoc(this, os);
2239 if (style->latexparam() == "CDATA") {
2240 // "TeX"-Mode on == > SGML-Mode on.
2247 boost::tie(ws, str) = sgml::escapeChar(c);
2248 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
2249 // in freespacing mode, spaces are
2250 // non-breaking characters
2251 if (desc_on) {// if char is ' ' then...
2254 sgmlLineBreak(os, char_line_count, 6);
2258 sgmlLineBreak(os, char_line_count, 1);
2263 char_line_count += str.length();
2269 while (!tag_state.empty()) {
2270 os << "</" << tag_name(tag_state.top()) << '>';
2274 // resets description flag correctly
2276 // <tag> not closed...
2277 sgmlLineBreak(os, char_line_count, 6);
2283 // Print an error message.
2284 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
2285 string const & /*message*/) const
2287 #ifdef WITH_WARNINGS
2288 #warning This is wrong we cannot insert an inset like this!!!
2289 // I guess this was Jose' so I explain you more or less why this
2290 // is wrong. This way you insert something in the paragraph and
2291 // don't tell it to LyXText (row rebreaking and undo handling!!!)
2292 // I deactivate this code, have a look at BufferView::insertErrors
2293 // how you should do this correctly! (Jug 20020315)
2296 // insert an error marker in text
2297 InsetError * new_inset = new InsetError(message);
2298 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
2304 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2306 ofstream ofs(fname.c_str());
2308 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2312 Paragraph * par = &*(paragraphs.begin());
2314 niceFile = nice; // this will be used by Insetincludes.
2316 LaTeXFeatures features(params);
2321 LyXTextClass const & tclass = params.getLyXTextClass();
2322 string top_element = tclass.latexname();
2325 ofs << "<!DOCTYPE " << top_element
2326 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
2328 string preamble = params.preamble;
2329 const string name = nice ? ChangeExtension(filename_, ".sgml")
2331 preamble += features.getIncludedFiles(name);
2332 preamble += features.getLyXSGMLEntities();
2334 if (!preamble.empty()) {
2335 ofs << "\n [ " << preamble << " ]";
2340 string top = top_element;
2342 top += params.language->code();
2345 if (!params.options.empty()) {
2347 top += params.options;
2349 sgml::openTag(ofs, 0, false, top);
2351 ofs << "<!-- DocBook file was created by " << lyx_docversion
2352 << "\n See http://www.lyx.org/ for more information -->\n";
2354 vector<string> environment_stack(10);
2355 vector<string> environment_inner(10);
2356 vector<string> command_stack(10);
2358 bool command_flag = false;
2359 Paragraph::depth_type command_depth = 0;
2360 Paragraph::depth_type command_base = 0;
2361 Paragraph::depth_type cmd_depth = 0;
2362 Paragraph::depth_type depth = 0; // paragraph depth
2365 string command_name;
2371 int desc_on = 0; // description mode
2373 LyXLayout_ptr const & style = par->layout();
2375 // environment tag closing
2376 for (; depth > par->params().depth(); --depth) {
2377 if (environment_inner[depth] != "!-- --") {
2378 item_name = "listitem";
2379 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2380 if (environment_inner[depth] == "varlistentry")
2381 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
2383 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2384 environment_stack[depth].erase();
2385 environment_inner[depth].erase();
2388 if (depth == par->params().depth()
2389 && environment_stack[depth] != style->latexname()
2390 && !environment_stack[depth].empty()) {
2391 if (environment_inner[depth] != "!-- --") {
2392 item_name= "listitem";
2393 sgml::closeTag(ofs, command_depth+depth, false, item_name);
2394 if (environment_inner[depth] == "varlistentry")
2395 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2398 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2400 environment_stack[depth].erase();
2401 environment_inner[depth].erase();
2404 // Write opening SGML tags.
2405 switch (style->latextype) {
2406 case LATEX_PARAGRAPH:
2407 sgml::openTag(ofs, depth + command_depth,
2408 false, style->latexname());
2414 _("Error: Wrong depth for LatexType Command.\n"));
2416 command_name = style->latexname();
2418 sgmlparam = style->latexparam();
2419 c_params = split(sgmlparam, c_depth,'|');
2421 cmd_depth = lyx::atoi(c_depth);
2424 if (cmd_depth < command_base) {
2425 for (Paragraph::depth_type j = command_depth;
2426 j >= command_base; --j) {
2427 sgml::closeTag(ofs, j, false, command_stack[j]);
2430 command_depth = command_base = cmd_depth;
2431 } else if (cmd_depth <= command_depth) {
2432 for (int j = command_depth;
2433 j >= int(cmd_depth); --j) {
2434 sgml::closeTag(ofs, j, false, command_stack[j]);
2437 command_depth = cmd_depth;
2439 command_depth = cmd_depth;
2441 command_depth = command_base = cmd_depth;
2442 command_flag = true;
2444 if (command_stack.size() == command_depth + 1)
2445 command_stack.push_back(string());
2446 command_stack[command_depth] = command_name;
2448 // treat label as a special case for
2449 // more WYSIWYM handling.
2450 // This is a hack while paragraphs can't have
2451 // attributes, like id in this case.
2452 if (par->isInset(0)) {
2453 Inset * inset = par->getInset(0);
2454 Inset::Code lyx_code = inset->lyxCode();
2455 if (lyx_code == Inset::LABEL_CODE) {
2456 command_name += " id=\"";
2457 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2458 command_name += '"';
2463 sgml::openTag(ofs, depth + command_depth, false, command_name);
2465 item_name = c_params.empty() ? "title" : c_params;
2466 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
2469 case LATEX_ENVIRONMENT:
2470 case LATEX_ITEM_ENVIRONMENT:
2471 if (depth < par->params().depth()) {
2472 depth = par->params().depth();
2473 environment_stack[depth].erase();
2476 if (environment_stack[depth] != style->latexname()) {
2477 if (environment_stack.size() == depth + 1) {
2478 environment_stack.push_back("!-- --");
2479 environment_inner.push_back("!-- --");
2481 environment_stack[depth] = style->latexname();
2482 environment_inner[depth] = "!-- --";
2483 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
2485 if (environment_inner[depth] != "!-- --") {
2486 item_name= "listitem";
2487 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2488 if (environment_inner[depth] == "varlistentry")
2489 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2493 if (style->latextype == LATEX_ENVIRONMENT) {
2494 if (!style->latexparam().empty()) {
2495 if (style->latexparam() == "CDATA")
2498 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
2503 desc_on = (style->labeltype == LABEL_MANUAL);
2505 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
2506 sgml::openTag(ofs, depth + 1 + command_depth,
2507 false, environment_inner[depth]);
2509 item_name = desc_on ? "term" : "para";
2510 sgml::openTag(ofs, depth + 1 + command_depth,
2514 sgml::openTag(ofs, depth + command_depth,
2515 false, style->latexname());
2519 simpleDocBookOnePar(ofs, par, desc_on,
2520 depth + 1 + command_depth);
2524 // write closing SGML tags
2525 switch (style->latextype) {
2527 end_tag = c_params.empty() ? "title" : c_params;
2528 sgml::closeTag(ofs, depth + command_depth,
2531 case LATEX_ENVIRONMENT:
2532 if (!style->latexparam().empty()) {
2533 if (style->latexparam() == "CDATA")
2536 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
2539 case LATEX_ITEM_ENVIRONMENT:
2540 if (desc_on == 1) break;
2542 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
2544 case LATEX_PARAGRAPH:
2545 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2548 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2554 for (int d = depth; d >= 0; --d) {
2555 if (!environment_stack[depth].empty()) {
2556 if (environment_inner[depth] != "!-- --") {
2557 item_name = "listitem";
2558 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2559 if (environment_inner[depth] == "varlistentry")
2560 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2563 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2567 for (int j = command_depth; j >= 0 ; --j)
2568 if (!command_stack[j].empty()) {
2569 sgml::closeTag(ofs, j, false, command_stack[j]);
2574 sgml::closeTag(ofs, 0, false, top_element);
2577 // How to check for successful close
2579 // we want this to be true outside previews (for insetexternal)
2584 void Buffer::simpleDocBookOnePar(ostream & os,
2585 Paragraph * par, int & desc_on,
2586 Paragraph::depth_type depth) const
2588 bool emph_flag = false;
2590 LyXLayout_ptr const & style = par->layout();
2592 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
2594 int char_line_count = depth;
2595 //if (!style.free_spacing)
2596 // os << string(depth,' ');
2598 // parsing main loop
2599 for (pos_type i = 0; i < par->size(); ++i) {
2600 LyXFont font = par->getFont(params, i);
2602 // handle <emphasis> tag
2603 if (font_old.emph() != font.emph()) {
2604 if (font.emph() == LyXFont::ON) {
2605 if (style->latexparam() == "CDATA")
2608 if (style->latexparam() == "CDATA")
2612 if (style->latexparam() == "CDATA")
2614 os << "</emphasis>";
2615 if (style->latexparam() == "CDATA")
2622 if (par->isInset(i)) {
2623 Inset * inset = par->getInset(i);
2624 // don't print the inset in position 0 if desc_on == 3 (label)
2625 if (i || desc_on != 3) {
2626 if (style->latexparam() == "CDATA")
2628 inset->docbook(this, os, false);
2629 if (style->latexparam() == "CDATA")
2633 char c = par->getChar(i);
2636 boost::tie(ws, str) = sgml::escapeChar(c);
2638 if (style->pass_thru) {
2640 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
2642 } else if (desc_on ==1) {
2644 os << "\n</term><listitem><para>";
2654 if (style->latexparam() == "CDATA")
2656 os << "</emphasis>";
2657 if (style->latexparam() == "CDATA")
2661 // resets description flag correctly
2663 // <term> not closed...
2664 os << "</term>\n<listitem><para> </para>";
2666 if (style->free_spacing)
2671 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2672 // Other flags: -wall -v0 -x
2673 int Buffer::runChktex()
2675 if (!users->text) return 0;
2677 users->owner()->busy(true);
2679 // get LaTeX-Filename
2680 string const name = getLatexName();
2681 string path = filePath();
2683 string const org_path = path;
2684 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2688 Path p(path); // path to LaTeX file
2689 users->owner()->message(_("Running chktex..."));
2691 // Remove all error insets
2692 bool const removedErrorInsets = users->removeAutoInsets();
2694 // Generate the LaTeX file if neccessary
2695 makeLaTeXFile(name, org_path, false);
2698 Chktex chktex(lyxrc.chktex_command, name, filePath());
2699 int res = chktex.run(terr); // run chktex
2702 Alert::alert(_("chktex did not work!"),
2703 _("Could not run with file:"), name);
2704 } else if (res > 0) {
2705 // Insert all errors as errors boxes
2706 users->insertErrors(terr);
2709 // if we removed error insets before we ran chktex or if we inserted
2710 // error insets after we ran chktex, this must be run:
2711 if (removedErrorInsets || res) {
2712 #warning repaint needed here, or do you mean update() ?
2716 users->owner()->busy(false);
2722 void Buffer::validate(LaTeXFeatures & features) const
2724 LyXTextClass const & tclass = params.getLyXTextClass();
2726 if (params.tracking_changes) {
2727 features.require("dvipost");
2728 features.require("color");
2731 // AMS Style is at document level
2732 if (params.use_amsmath == BufferParams::AMS_ON
2733 || tclass.provides(LyXTextClass::amsmath))
2734 features.require("amsmath");
2736 for_each(paragraphs.begin(), paragraphs.end(),
2737 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2739 // the bullet shapes are buffer level not paragraph level
2740 // so they are tested here
2741 for (int i = 0; i < 4; ++i) {
2742 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2743 int const font = params.user_defined_bullets[i].getFont();
2745 int const c = params
2746 .user_defined_bullets[i]
2753 features.require("latexsym");
2755 } else if (font == 1) {
2756 features.require("amssymb");
2757 } else if ((font >= 2 && font <= 5)) {
2758 features.require("pifont");
2763 if (lyxerr.debugging(Debug::LATEX)) {
2764 features.showStruct();
2769 vector<string> const Buffer::getLabelList() const
2771 /// if this is a child document and the parent is already loaded
2772 /// Use the parent's list instead [ale990407]
2773 if (!params.parentname.empty()
2774 && bufferlist.exists(params.parentname)) {
2775 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2777 return tmp->getLabelList();
2780 vector<string> label_list;
2781 for (inset_iterator it = inset_const_iterator_begin();
2782 it != inset_const_iterator_end(); ++it) {
2783 vector<string> const l = it->getLabelList();
2784 label_list.insert(label_list.end(), l.begin(), l.end());
2790 // This is also a buffer property (ale)
2791 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2793 /// if this is a child document and the parent is already loaded
2794 /// use the parent's list instead [ale990412]
2795 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2796 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2798 tmp->fillWithBibKeys(keys);
2803 for (inset_iterator it = inset_const_iterator_begin();
2804 it != inset_const_iterator_end(); ++it) {
2805 if (it->lyxCode() == Inset::BIBTEX_CODE)
2806 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2807 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2808 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2809 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2810 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2811 string const key = bib.getContents();
2812 string const opt = bib.getOptions();
2813 string const ref; // = pit->asString(this, false);
2814 string const info = opt + "TheBibliographyRef" + ref;
2815 keys.push_back(pair<string, string>(key, info));
2821 bool Buffer::isDepClean(string const & name) const
2823 DepClean::const_iterator it = dep_clean_.find(name);
2824 if (it == dep_clean_.end())
2830 void Buffer::markDepClean(string const & name)
2832 dep_clean_[name] = true;
2836 bool Buffer::dispatch(string const & command, bool * result)
2838 // Split command string into command and argument
2840 string line = ltrim(command);
2841 string const arg = trim(split(line, cmd, ' '));
2843 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2847 bool Buffer::dispatch(int action, string const & argument, bool * result)
2849 bool dispatched = true;
2853 bool const tmp = Exporter::Export(this, argument, false);
2866 void Buffer::resizeInsets(BufferView * bv)
2868 /// then remove all LyXText in text-insets
2869 for_each(paragraphs.begin(), paragraphs.end(),
2870 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2874 void Buffer::redraw()
2876 #warning repaint needed here, or do you mean update() ?
2882 void Buffer::changeLanguage(Language const * from, Language const * to)
2885 ParIterator end = par_iterator_end();
2886 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2887 (*it)->changeLanguage(params, from, to);
2891 bool Buffer::isMultiLingual()
2893 ParIterator end = par_iterator_end();
2894 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2895 if ((*it)->isMultiLingual(params))
2902 void Buffer::inset_iterator::setParagraph()
2904 while (pit != pend) {
2905 it = pit->insetlist.begin();
2906 if (it != pit->insetlist.end())
2913 Inset * Buffer::getInsetFromID(int id_arg) const
2915 for (inset_iterator it = inset_const_iterator_begin();
2916 it != inset_const_iterator_end(); ++it)
2918 if (it->id() == id_arg)
2920 Inset * in = it->getInsetFromID(id_arg);
2928 Paragraph * Buffer::getParFromID(int id) const
2933 // why should we allow < 0 ??
2934 //lyx::Assert(id >= 0);
2936 ParConstIterator it(par_iterator_begin());
2937 ParConstIterator end(par_iterator_end());
2939 for (; it != end; ++it) {
2940 // go on then, show me how to remove
2942 if ((*it)->id() == id) {
2943 return const_cast<Paragraph*>(*it);
2951 ParIterator Buffer::par_iterator_begin()
2953 return ParIterator(&*(paragraphs.begin()));
2957 ParIterator Buffer::par_iterator_end()
2959 return ParIterator();
2962 ParConstIterator Buffer::par_iterator_begin() const
2964 return ParConstIterator(&*(paragraphs.begin()));
2968 ParConstIterator Buffer::par_iterator_end() const
2970 return ParConstIterator();
2975 void Buffer::addUser(BufferView * u)
2981 void Buffer::delUser(BufferView *)
2987 Language const * Buffer::getLanguage() const
2989 return params.language;
2993 bool Buffer::isClean() const
2999 bool Buffer::isBakClean() const
3005 void Buffer::markClean() const
3011 // if the .lyx file has been saved, we don't need an
3017 void Buffer::markBakClean()
3023 void Buffer::setUnnamed(bool flag)
3029 bool Buffer::isUnnamed()
3035 void Buffer::markDirty()
3043 DepClean::iterator it = dep_clean_.begin();
3044 DepClean::const_iterator const end = dep_clean_.end();
3046 for (; it != end; ++it) {
3052 string const & Buffer::fileName() const
3058 string const & Buffer::filePath() const
3064 bool Buffer::isReadonly() const
3070 BufferView * Buffer::getUser() const
3076 void Buffer::setParentName(string const & name)
3078 params.parentname = name;
3082 Buffer::inset_iterator::inset_iterator()
3087 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
3094 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
3098 if (it == pit->insetlist.end()) {
3107 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
3109 inset_iterator tmp = *this;
3115 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
3117 return *it.getInset();
3121 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
3123 return it.getInset();
3127 Paragraph * Buffer::inset_iterator::getPar()
3133 lyx::pos_type Buffer::inset_iterator::getPos() const
3139 bool operator==(Buffer::inset_iterator const & iter1,
3140 Buffer::inset_iterator const & iter2)
3142 return iter1.pit == iter2.pit
3143 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
3147 bool operator!=(Buffer::inset_iterator const & iter1,
3148 Buffer::inset_iterator const & iter2)
3150 return !(iter1 == iter2);