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 #pragma implementation
22 #include "bufferlist.h"
24 #include "LyXAction.h"
27 #include "tex-strings.h"
29 #include "bufferview_funcs.h"
34 #include "frontends/LyXView.h"
36 #include "LaTeXFeatures.h"
43 #include "converter.h"
44 #include "BufferView.h"
45 #include "ParagraphParameters.h"
46 #include "iterators.h"
47 #include "lyxtextclasslist.h"
50 #include "mathed/formulamacro.h"
51 #include "mathed/formula.h"
53 #include "insets/inset.h"
54 #include "insets/inseterror.h"
55 #include "insets/insetlabel.h"
56 #include "insets/insetref.h"
57 #include "insets/inseturl.h"
58 #include "insets/insetnote.h"
59 #include "insets/insetquotes.h"
60 #include "insets/insetlatexaccent.h"
61 #include "insets/insetbib.h"
62 #include "insets/insetcite.h"
63 #include "insets/insetexternal.h"
64 #include "insets/insetindex.h"
65 #include "insets/insetinclude.h"
66 #include "insets/insettoc.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/insettext.h"
70 #include "insets/insetert.h"
71 #include "insets/insetgraphics.h"
72 #include "insets/insetfoot.h"
73 #include "insets/insetmarginal.h"
74 #include "insets/insetminipage.h"
75 #include "insets/insetfloat.h"
76 #include "insets/insettabular.h"
78 #include "insets/insettheorem.h"
79 #include "insets/insetlist.h"
81 #include "insets/insetcaption.h"
82 #include "insets/insetfloatlist.h"
84 #include "frontends/Dialogs.h"
85 #include "frontends/Alert.h"
87 #include "graphics/Previews.h"
89 #include "support/textutils.h"
90 #include "support/filetools.h"
91 #include "support/path.h"
92 #include "support/os.h"
93 #include "support/lyxlib.h"
94 #include "support/FileInfo.h"
95 #include "support/lyxmanip.h"
96 #include "support/lyxalgo.h" // for lyx::count
98 #include <boost/bind.hpp>
99 #include <boost/tuple/tuple.hpp>
111 #include <sys/types.h>
118 #ifndef CXX_GLOBAL_CSTD
130 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 = 220;
151 Buffer::Buffer(string const & file, bool ronly)
152 : niceFile(true), lyx_clean(true), bak_clean(true),
153 unnamed(false), dep_clean(0), read_only(ronly),
154 filename_(file), users(0), ctrs(new Counters)
156 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
158 filepath_ = OnlyPath(file);
162 // read_only = ronly;
166 if (read_only || lyxrc.use_tempdir) {
167 tmppath = CreateBufferTmpDir();
176 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
177 // here the buffer should take care that it is
178 // saved properly, before it goes into the void.
180 // make sure that views using this buffer
185 if (!tmppath.empty()) {
186 DestroyBufferTmpDir(tmppath);
191 // Remove any previewed LaTeX snippets assocoated with this buffer.
192 grfx::Previews::get().removeLoader(this);
196 string const Buffer::getLatexName(bool no_path) const
198 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
200 return OnlyFilename(name);
206 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
208 string const filename = getLatexName(false);
210 if (filename.empty())
211 return make_pair(Buffer::latexlog, string());
213 string path = OnlyPath(filename);
215 if (lyxrc.use_tempdir || !IsDirWriteable(path))
218 string const fname = AddName(path,
219 OnlyFilename(ChangeExtension(filename,
222 AddName(path, OnlyFilename(
223 ChangeExtension(filename,
224 formats.extension("literate") + ".out")));
226 // If no Latex log or Build log is newer, show Build log
228 FileInfo const f_fi(fname);
229 FileInfo const b_fi(bname);
232 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
233 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
234 return make_pair(Buffer::buildlog, bname);
236 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
237 return make_pair(Buffer::latexlog, fname);
241 void Buffer::setReadonly(bool flag)
243 if (read_only != flag) {
246 users->owner()->getDialogs().updateBufferDependent(false);
251 /// Update window titles of all users
252 // Should work on a list
253 void Buffer::updateTitles() const
256 users->owner()->updateWindowTitle();
260 /// Reset autosave timer of all users
261 // Should work on a list
262 void Buffer::resetAutosaveTimers() const
265 users->owner()->resetAutosaveTimer();
269 void Buffer::setFileName(string const & newfile)
271 filename_ = MakeAbsPath(newfile);
272 filepath_ = OnlyPath(filename_);
273 setReadonly(IsFileWriteable(filename_) == 0);
278 // We'll remove this later. (Lgb)
281 string last_inset_read;
283 #ifndef NO_COMPABILITY
286 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
295 std::stack<ErtComp> ert_stack;
300 #warning And _why_ is this here? (Lgb)
308 // candidate for move to BufferView
309 // (at least some parts in the beginning of the func)
312 // changed to be public and have one parameter
313 // if par = 0 normal behavior
314 // else insert behavior
315 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
316 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
320 #ifndef NO_COMPABILITY
321 ert_comp.contents.erase();
322 ert_comp.active = false;
323 ert_comp.fromlayout = false;
324 ert_comp.in_tabular = false;
327 Paragraph::depth_type depth = 0;
328 bool the_end_read = false;
330 Paragraph * first_par = 0;
331 LyXFont font(LyXFont::ALL_INHERIT, params.language);
334 if (file_format < 216 && params.language->lang() == "hebrew")
335 font.setLanguage(default_language);
340 par->layout(params.getLyXTextClass().defaultLayout());
342 // We are inserting into an existing document
343 users->text->breakParagraph(users);
344 first_par = users->text->ownerParagraph();
347 // We don't want to adopt the parameters from the
348 // document we insert, so we skip until the text begins:
351 string const pretoken = lex.getString();
352 if (pretoken == "\\layout") {
353 lex.pushToken(pretoken);
361 string const token = lex.getString();
363 if (token.empty()) continue;
365 lyxerr[Debug::PARSER] << "Handling token: `"
366 << token << "'" << endl;
369 parseSingleLyXformat2Token(lex, par, first_par,
377 paragraphs.set(first_par);
379 if (unknown_layouts > 0) {
380 string s = _("Couldn't set the layout for ");
381 if (unknown_layouts == 1) {
382 s += _("one paragraph");
384 s += tostr(unknown_layouts);
385 s += _(" paragraphs");
387 Alert::alert(_("Textclass Loading Error!"), s,
388 _("When reading " + fileName()));
391 if (unknown_tokens > 0) {
392 string s = _("Encountered ");
393 if (unknown_tokens == 1) {
394 s += _("one unknown token");
396 s += tostr(unknown_tokens);
397 s += _(" unknown tokens");
399 Alert::alert(_("Textclass Loading Error!"), s,
400 _("When reading " + fileName()));
407 #ifndef NO_COMPABILITY
409 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
412 if ((par->getChar(pos) == Paragraph::META_INSET) &&
413 (inset = par->getInset(pos)) &&
414 (inset->lyxCode() == Inset::ERT_CODE))
421 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
423 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
424 // we only skip completely empty ERT (only spaces) otherwise
425 // we have to insert it as is.
426 string str(ert_comp.contents);
427 lyxerr[Debug::INSETS] << "ERT contents:\n'"
428 << str << "'" << endl;
429 // check if we have already an ert inset a position earlier
430 // if this is the case then we should insert the contents
431 // inside the other ertinset as it is stupid to have various
434 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
435 // get the last paragraph from the inset before
436 Paragraph * last = inset->firstParagraph();
439 // create the new paragraph after the last one
440 Paragraph * par = new Paragraph(last);
441 par->layout(params.getLyXTextClass().defaultLayoutName());
442 par->setInsetOwner(last->inInset());
444 LyXFont font(LyXFont::ALL_INHERIT, params.language);
445 string::const_iterator cit = str.begin();
446 string::const_iterator end = str.end();
448 for (; cit != end; ++cit) {
449 par->insertChar(pos++, *cit, font);
453 new InsetERT(params, params.language, str, true);
454 par->insertInset(pos++, inset, ert_comp.font);
457 ert_comp.contents.erase();
458 ert_comp.fromlayout = false;
460 ert_comp.active = false;
467 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
468 Paragraph *& first_par,
469 string const & token, int & pos,
470 Paragraph::depth_type & depth,
474 bool the_end_read = false;
475 #ifndef NO_COMPABILITY
476 #ifndef NO_PEXTRA_REALLY
477 // This is super temporary but is needed to get the compability
478 // mode for minipages work correctly together with new tabulars.
479 static int call_depth;
481 bool checkminipage = false;
482 static Paragraph * minipar = 0;
483 static Paragraph * parBeforeMinipage;
487 // The order of the tags tested may seem unnatural, but this
488 // has been done in order to reduce the number of string
489 // comparisons needed to recognize a given token. This leads
490 // on large documents like UserGuide to a reduction of a
492 if (token[0] != '\\') {
493 #ifndef NO_COMPABILITY
494 if (ert_comp.active) {
495 ert_comp.contents += token;
498 for (string::const_iterator cit = token.begin();
499 cit != token.end(); ++cit) {
500 par->insertChar(pos, (*cit), font);
503 #ifndef NO_COMPABILITY
506 } else if (token == "\\layout") {
507 #ifndef NO_COMPABILITY
508 bool old_fromlayout = ert_comp.fromlayout;
509 bool create_new_par = true;
510 ert_comp.in_tabular = false;
512 if (!par->size() && par->previous() &&
513 (par->previous()->size() == 1) &&
514 isErtInset(par->previous(), par->previous()->size()-1))
516 int p = par->previous()->size();
517 insertErtContents(par->previous(), p);
518 create_new_par = false;
520 insertErtContents(par, pos);
523 // reset the font as we start a new layout and if the font is
524 // not ALL_INHERIT,document_language then it will be set to the
525 // right values after this tag (Jug 20020420)
526 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
529 if (file_format < 216 && params.language->lang() == "hebrew")
530 font.setLanguage(default_language);
534 string layoutname = lex.getString();
536 LyXTextClass const & tclass = params.getLyXTextClass();
538 if (layoutname.empty()) {
539 layoutname = tclass.defaultLayoutName();
541 #ifndef NO_COMPABILITY
542 if (compare_ascii_no_case(layoutname, "latex") == 0) {
543 ert_comp.active = true;
544 ert_comp.fromlayout = true;
545 ert_comp.font = font;
547 create_new_par = false;
550 bool hasLayout = tclass.hasLayout(layoutname);
552 lyxerr << "Layout '" << layoutname << "' does not"
553 << " exist in textclass '" << tclass.name()
555 lyxerr << "Trying to use default layout instead."
557 layoutname = tclass.defaultLayoutName();
561 // The is the compability reading of layout caption.
562 // It can be removed in LyX version 1.3.0. (Lgb)
563 if (compare_ascii_no_case(layoutname, "caption") == 0) {
564 // We expect that the par we are now working on is
565 // really inside a InsetText inside a InsetFloat.
566 // We also know that captions can only be
567 // one paragraph. (Lgb)
569 // We should now read until the next "\layout"
571 // This is probably not good enough, what if the
572 // caption is the last par in the document (Lgb)
573 istream & ist = lex.getStream();
579 if (prefixIs(line, "\\layout")) {
583 if (prefixIs(line, "\\begin_inset"))
585 if (prefixIs(line, "\\end_inset")) {
596 // Now we should have the whole layout in ss
597 // we should now be able to give this to the
599 ss << "\\end_inset\n";
601 // This seems like a bug in stringstream.
602 // We really should be able to use ss
604 istringstream is(ss.str());
606 tmplex.setStream(is);
607 Inset * inset = new InsetCaption;
608 inset->Read(this, tmplex);
609 par->InsertInset(pos, inset, font);
613 #ifndef NO_COMPABILITY
614 if (create_new_par) {
619 par = new Paragraph(par);
620 par->layout(params.getLyXTextClass().defaultLayout());
623 par->layout(params.getLyXTextClass()[layoutname]);
624 // Test whether the layout is obsolete.
625 LyXLayout_ptr const & layout = par->layout();
626 if (!layout->obsoleted_by().empty())
627 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
628 par->params().depth(depth);
629 #ifndef NO_COMPABILITY
631 // we duplicate code here because it's easier to remove
632 // the code then of NO_COMPATIBILITY
633 par->layout(layoutname);
634 // Test whether the layout is obsolete.
635 LyXLayout_ptr const & layout =
636 params.getLyXTextClass()[par->layout()];
637 if (!layout->obsoleted_by().empty())
638 par->layout(layout->obsoleted_by());
639 par->params().depth(depth);
646 } else if (token == "\\end_inset") {
647 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
648 << "Last inset read was: " << last_inset_read
650 // Simply ignore this. The insets do not have
652 // But insets should read it, it is a part of
653 // the inset isn't it? Lgb.
654 } else if (token == "\\begin_inset") {
655 #ifndef NO_COMPABILITY
656 insertErtContents(par, pos, false);
657 ert_stack.push(ert_comp);
658 ert_comp = ErtComp();
660 readInset(lex, par, pos, font);
661 #ifndef NO_COMPABILITY
662 ert_comp = ert_stack.top();
664 insertErtContents(par, pos);
666 } else if (token == "\\family") {
668 font.setLyXFamily(lex.getString());
669 } else if (token == "\\series") {
671 font.setLyXSeries(lex.getString());
672 } else if (token == "\\shape") {
674 font.setLyXShape(lex.getString());
675 } else if (token == "\\size") {
677 font.setLyXSize(lex.getString());
678 #ifndef NO_COMPABILITY
679 } else if (token == "\\latex") {
681 string const tok = lex.getString();
682 if (tok == "no_latex") {
684 insertErtContents(par, pos);
685 } else if (tok == "latex") {
686 ert_comp.active = true;
687 ert_comp.font = font;
688 } else if (tok == "default") {
690 insertErtContents(par, pos);
692 lex.printError("Unknown LaTeX font flag "
696 } else if (token == "\\lang") {
698 string const tok = lex.getString();
699 Language const * lang = languages.getLanguage(tok);
701 font.setLanguage(lang);
703 font.setLanguage(params.language);
704 lex.printError("Unknown language `$$Token'");
706 } else if (token == "\\numeric") {
708 font.setNumber(font.setLyXMisc(lex.getString()));
709 } else if (token == "\\emph") {
711 font.setEmph(font.setLyXMisc(lex.getString()));
712 } else if (token == "\\bar") {
714 string const tok = lex.getString();
715 // This is dirty, but gone with LyX3. (Asger)
717 font.setUnderbar(LyXFont::ON);
718 else if (tok == "no")
719 font.setUnderbar(LyXFont::OFF);
720 else if (tok == "default")
721 font.setUnderbar(LyXFont::INHERIT);
723 lex.printError("Unknown bar font flag "
725 } else if (token == "\\noun") {
727 font.setNoun(font.setLyXMisc(lex.getString()));
728 } else if (token == "\\color") {
730 font.setLyXColor(lex.getString());
731 } else if (token == "\\SpecialChar") {
732 LyXLayout_ptr const & layout = par->layout();
734 // Insets don't make sense in a free-spacing context! ---Kayvan
735 if (layout->free_spacing || par->isFreeSpacing()) {
738 string next_token = lex.getString();
739 if (next_token == "\\-") {
740 par->insertChar(pos, '-', font);
741 } else if (next_token == "\\protected_separator"
742 || next_token == "~") {
743 par->insertChar(pos, ' ', font);
745 lex.printError("Token `$$Token' "
747 "paragraph layout!");
752 Inset * inset = new InsetSpecialChar;
753 inset->read(this, lex);
754 par->insertInset(pos, inset, font);
757 } else if (token == "\\i") {
758 Inset * inset = new InsetLatexAccent;
759 inset->read(this, lex);
760 par->insertInset(pos, inset, font);
762 } else if (token == "\\backslash") {
763 #ifndef NO_COMPABILITY
764 if (ert_comp.active) {
765 ert_comp.contents += "\\";
768 par->insertChar(pos, '\\', font);
770 #ifndef NO_COMPABILITY
773 #ifndef NO_COMPABILITY
774 } else if (token == "\\begin_float") {
775 insertErtContents(par, pos);
776 //insertErtContents(par, pos, false);
777 //ert_stack.push(ert_comp);
778 //ert_comp = ErtComp();
780 // This is the compability reader. It can be removed in
781 // LyX version 1.3.0. (Lgb)
783 string const tmptok = lex.getString();
784 //lyxerr << "old float: " << tmptok << endl;
787 stringstream old_float;
789 if (tmptok == "footnote") {
790 inset = new InsetFoot(params);
791 old_float << "collapsed true\n";
792 } else if (tmptok == "margin") {
793 inset = new InsetMarginal(params);
794 old_float << "collapsed true\n";
795 } else if (tmptok == "fig") {
796 inset = new InsetFloat(params, "figure");
797 old_float << "wide false\n"
798 << "collapsed false\n";
799 } else if (tmptok == "tab") {
800 inset = new InsetFloat(params, "table");
801 old_float << "wide false\n"
802 << "collapsed false\n";
803 } else if (tmptok == "alg") {
804 inset = new InsetFloat(params, "algorithm");
805 old_float << "wide false\n"
806 << "collapsed false\n";
807 } else if (tmptok == "wide-fig") {
808 inset = new InsetFloat(params, "figure");
809 //InsetFloat * tmp = new InsetFloat("figure");
812 old_float << "wide true\n"
813 << "collapsed false\n";
814 } else if (tmptok == "wide-tab") {
815 inset = new InsetFloat(params, "table");
816 //InsetFloat * tmp = new InsetFloat("table");
819 old_float << "wide true\n"
820 << "collapsed false\n";
824 #ifndef NO_PEXTRA_REALLY
827 return false; // no end read yet
830 // Here we need to check for \end_deeper and handle that
831 // before we do the footnote parsing.
832 // This _is_ a hack! (Lgb)
835 string const tmp = lex.getString();
836 if (tmp == "\\end_deeper") {
837 //lyxerr << "\\end_deeper caught!" << endl;
839 lex.printError("\\end_deeper: "
840 "depth is already null");
845 old_float << tmp << ' ';
850 old_float << lex.getLongString("\\end_float")
851 << "\n\\end_inset\n";
852 //lyxerr << "Float Body:\n" << old_float.str() << endl;
853 // That this does not work seems like a bug
854 // in stringstream. (Lgb)
855 istringstream istr(old_float.str());
857 nylex.setStream(istr);
858 inset->read(this, nylex);
859 par->insertInset(pos, inset, font);
861 insertErtContents(par, pos);
863 // we have to reset the font as in the old format after a float
864 // the font was automatically reset!
865 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
867 } else if (token == "\\begin_deeper") {
869 } else if (token == "\\end_deeper") {
871 lex.printError("\\end_deeper: "
872 "depth is already null");
876 } else if (token == "\\begin_preamble") {
877 params.readPreamble(lex);
878 } else if (token == "\\textclass") {
880 pair<bool, textclass_type> pp =
881 textclasslist.NumberOfClass(lex.getString());
883 params.textclass = pp.second;
885 Alert::alert(string(_("Textclass error")),
886 string(_("The document uses an unknown textclass \"")) +
887 lex.getString() + string("\"."),
888 string(_("LyX will not be able to produce output correctly.")));
889 params.textclass = 0;
891 if (!params.getLyXTextClass().load()) {
892 // if the textclass wasn't loaded properly
893 // we need to either substitute another
894 // or stop loading the file.
895 // I can substitute but I don't see how I can
896 // stop loading... ideas?? ARRae980418
897 Alert::alert(_("Textclass Loading Error!"),
898 string(_("Can't load textclass ")) +
899 params.getLyXTextClass().name(),
900 _("-- substituting default"));
901 params.textclass = 0;
903 } else if (token == "\\options") {
905 params.options = lex.getString();
906 } else if (token == "\\language") {
907 params.readLanguage(lex);
908 } else if (token == "\\fontencoding") {
910 } else if (token == "\\inputencoding") {
912 params.inputenc = lex.getString();
913 } else if (token == "\\graphics") {
914 params.readGraphicsDriver(lex);
915 } else if (token == "\\fontscheme") {
917 params.fonts = lex.getString();
918 } else if (token == "\\noindent") {
919 par->params().noindent(true);
920 } else if (token == "\\leftindent") {
922 LyXLength value(lex.getString());
923 par->params().leftIndent(value);
924 } else if (token == "\\fill_top") {
925 par->params().spaceTop(VSpace(VSpace::VFILL));
926 } else if (token == "\\fill_bottom") {
927 par->params().spaceBottom(VSpace(VSpace::VFILL));
928 } else if (token == "\\line_top") {
929 par->params().lineTop(true);
930 } else if (token == "\\line_bottom") {
931 par->params().lineBottom(true);
932 } else if (token == "\\pagebreak_top") {
933 par->params().pagebreakTop(true);
934 } else if (token == "\\pagebreak_bottom") {
935 par->params().pagebreakBottom(true);
936 } else if (token == "\\start_of_appendix") {
937 par->params().startOfAppendix(true);
938 } else if (token == "\\paragraph_separation") {
939 int tmpret = lex.findToken(string_paragraph_separation);
942 params.paragraph_separation =
943 static_cast<BufferParams::PARSEP>(tmpret);
944 } else if (token == "\\defskip") {
946 params.defskip = VSpace(lex.getString());
947 #ifndef NO_COMPABILITY
948 } else if (token == "\\epsfig") { // obsolete
949 // Indeed it is obsolete, but we HAVE to be backwards
950 // compatible until 0.14, because otherwise all figures
951 // in existing documents are irretrivably lost. (Asger)
952 params.readGraphicsDriver(lex);
954 } else if (token == "\\quotes_language") {
955 int tmpret = lex.findToken(string_quotes_language);
958 InsetQuotes::quote_language tmpl =
959 InsetQuotes::EnglishQ;
962 tmpl = InsetQuotes::EnglishQ;
965 tmpl = InsetQuotes::SwedishQ;
968 tmpl = InsetQuotes::GermanQ;
971 tmpl = InsetQuotes::PolishQ;
974 tmpl = InsetQuotes::FrenchQ;
977 tmpl = InsetQuotes::DanishQ;
980 params.quotes_language = tmpl;
981 } else if (token == "\\quotes_times") {
983 switch (lex.getInteger()) {
985 params.quotes_times = InsetQuotes::SingleQ;
988 params.quotes_times = InsetQuotes::DoubleQ;
991 } else if (token == "\\papersize") {
992 int tmpret = lex.findToken(string_papersize);
996 params.papersize2 = tmpret;
997 } else if (token == "\\paperpackage") {
998 int tmpret = lex.findToken(string_paperpackages);
1001 params.paperpackage = BufferParams::PACKAGE_NONE;
1003 params.paperpackage = tmpret;
1004 } else if (token == "\\use_geometry") {
1006 params.use_geometry = lex.getInteger();
1007 } else if (token == "\\use_amsmath") {
1009 params.use_amsmath = lex.getInteger();
1010 } else if (token == "\\use_natbib") {
1012 params.use_natbib = lex.getInteger();
1013 } else if (token == "\\use_numerical_citations") {
1015 params.use_numerical_citations = lex.getInteger();
1016 } else if (token == "\\paperorientation") {
1017 int tmpret = lex.findToken(string_orientation);
1020 params.orientation =
1021 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1022 } else if (token == "\\paperwidth") {
1024 params.paperwidth = lex.getString();
1025 } else if (token == "\\paperheight") {
1027 params.paperheight = lex.getString();
1028 } else if (token == "\\leftmargin") {
1030 params.leftmargin = lex.getString();
1031 } else if (token == "\\topmargin") {
1033 params.topmargin = lex.getString();
1034 } else if (token == "\\rightmargin") {
1036 params.rightmargin = lex.getString();
1037 } else if (token == "\\bottommargin") {
1039 params.bottommargin = lex.getString();
1040 } else if (token == "\\headheight") {
1042 params.headheight = lex.getString();
1043 } else if (token == "\\headsep") {
1045 params.headsep = lex.getString();
1046 } else if (token == "\\footskip") {
1048 params.footskip = lex.getString();
1049 } else if (token == "\\paperfontsize") {
1051 params.fontsize = rtrim(lex.getString());
1052 } else if (token == "\\papercolumns") {
1054 params.columns = lex.getInteger();
1055 } else if (token == "\\papersides") {
1057 switch (lex.getInteger()) {
1059 case 1: params.sides = LyXTextClass::OneSide; break;
1060 case 2: params.sides = LyXTextClass::TwoSides; break;
1062 } else if (token == "\\paperpagestyle") {
1064 params.pagestyle = rtrim(lex.getString());
1065 } else if (token == "\\bullet") {
1067 int const index = lex.getInteger();
1069 int temp_int = lex.getInteger();
1070 params.user_defined_bullets[index].setFont(temp_int);
1071 params.temp_bullets[index].setFont(temp_int);
1073 temp_int = lex.getInteger();
1074 params.user_defined_bullets[index].setCharacter(temp_int);
1075 params.temp_bullets[index].setCharacter(temp_int);
1077 temp_int = lex.getInteger();
1078 params.user_defined_bullets[index].setSize(temp_int);
1079 params.temp_bullets[index].setSize(temp_int);
1081 string const temp_str = lex.getString();
1082 if (temp_str != "\\end_bullet") {
1083 // this element isn't really necessary for
1084 // parsing but is easier for humans
1085 // to understand bullets. Put it back and
1086 // set a debug message?
1087 lex.printError("\\end_bullet expected, got" + temp_str);
1088 //how can I put it back?
1090 } else if (token == "\\bulletLaTeX") {
1091 // The bullet class should be able to read this.
1093 int const index = lex.getInteger();
1095 string temp_str = lex.getString();
1097 while (temp_str != "\\end_bullet") {
1098 // this loop structure is needed when user
1099 // enters an empty string since the first
1100 // thing returned will be the \\end_bullet
1102 // if the LaTeX entry has spaces. Each element
1103 // therefore needs to be read in turn
1104 sum_str += temp_str;
1106 temp_str = lex.getString();
1109 params.user_defined_bullets[index].setText(sum_str);
1110 params.temp_bullets[index].setText(sum_str);
1111 } else if (token == "\\secnumdepth") {
1113 params.secnumdepth = lex.getInteger();
1114 } else if (token == "\\tocdepth") {
1116 params.tocdepth = lex.getInteger();
1117 } else if (token == "\\spacing") {
1119 string const tmp = rtrim(lex.getString());
1120 Spacing::Space tmp_space = Spacing::Default;
1121 float tmp_val = 0.0;
1122 if (tmp == "single") {
1123 tmp_space = Spacing::Single;
1124 } else if (tmp == "onehalf") {
1125 tmp_space = Spacing::Onehalf;
1126 } else if (tmp == "double") {
1127 tmp_space = Spacing::Double;
1128 } else if (tmp == "other") {
1130 tmp_space = Spacing::Other;
1131 tmp_val = lex.getFloat();
1133 lex.printError("Unknown spacing token: '$$Token'");
1135 // Small hack so that files written with klyx will be
1136 // parsed correctly.
1138 par->params().spacing(Spacing(tmp_space, tmp_val));
1140 params.spacing.set(tmp_space, tmp_val);
1142 } else if (token == "\\paragraph_spacing") {
1144 string const tmp = rtrim(lex.getString());
1145 if (tmp == "single") {
1146 par->params().spacing(Spacing(Spacing::Single));
1147 } else if (tmp == "onehalf") {
1148 par->params().spacing(Spacing(Spacing::Onehalf));
1149 } else if (tmp == "double") {
1150 par->params().spacing(Spacing(Spacing::Double));
1151 } else if (tmp == "other") {
1153 par->params().spacing(Spacing(Spacing::Other,
1156 lex.printError("Unknown spacing token: '$$Token'");
1158 } else if (token == "\\float_placement") {
1160 params.float_placement = lex.getString();
1161 } else if (token == "\\align") {
1162 int tmpret = lex.findToken(string_align);
1163 if (tmpret == -1) ++tmpret;
1164 int const tmpret2 = int(pow(2.0, tmpret));
1165 par->params().align(LyXAlignment(tmpret2));
1166 } else if (token == "\\added_space_top") {
1168 VSpace value = VSpace(lex.getString());
1169 // only add the length when value > 0 or
1171 if ((value.length().len().value() != 0) ||
1173 (value.kind() != VSpace::LENGTH))
1174 par->params().spaceTop(value);
1175 } else if (token == "\\added_space_bottom") {
1177 VSpace value = VSpace(lex.getString());
1178 // only add the length when value > 0 or
1180 if ((value.length().len().value() != 0) ||
1182 (value.kind() != VSpace::LENGTH))
1183 par->params().spaceBottom(value);
1184 #ifndef NO_COMPABILITY
1185 #ifndef NO_PEXTRA_REALLY
1186 } else if (token == "\\pextra_type") {
1188 par->params().pextraType(lex.getInteger());
1189 } else if (token == "\\pextra_width") {
1191 par->params().pextraWidth(lex.getString());
1192 } else if (token == "\\pextra_widthp") {
1194 par->params().pextraWidthp(lex.getString());
1195 } else if (token == "\\pextra_alignment") {
1197 par->params().pextraAlignment(lex.getInteger());
1198 } else if (token == "\\pextra_hfill") {
1200 par->params().pextraHfill(lex.getInteger());
1201 } else if (token == "\\pextra_start_minipage") {
1203 par->params().pextraStartMinipage(lex.getInteger());
1206 } else if (token == "\\labelwidthstring") {
1208 par->params().labelWidthString(lex.getString());
1209 // do not delete this token, it is still needed!
1210 } else if (token == "\\newline") {
1211 #ifndef NO_COMPABILITY
1212 if (!ert_comp.in_tabular && ert_comp.active) {
1213 ert_comp.contents += char(Paragraph::META_NEWLINE);
1215 // Since we cannot know it this is only a regular
1216 // newline or a tabular cell delimter we have to
1217 // handle the ERT here.
1218 insertErtContents(par, pos, false);
1220 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1224 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1227 } else if (token == "\\LyXTable") {
1228 #ifndef NO_COMPABILITY
1229 ert_comp.in_tabular = true;
1231 Inset * inset = new InsetTabular(*this);
1232 inset->read(this, lex);
1233 par->insertInset(pos, inset, font);
1235 } else if (token == "\\hfill") {
1236 par->insertChar(pos, Paragraph::META_HFILL, font);
1238 } else if (token == "\\protected_separator") { // obsolete
1239 // This is a backward compability thingie. (Lgb)
1240 // Remove it later some time...introduced with fileformat
1242 LyXLayout_ptr const & layout = par->layout();
1244 if (layout->free_spacing || par->isFreeSpacing()) {
1245 par->insertChar(pos, ' ', font);
1247 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1248 par->insertInset(pos, inset, font);
1251 } else if (token == "\\bibitem") { // ale970302
1253 InsetCommandParams p("bibitem", "dummy");
1254 par->bibkey = new InsetBibKey(p);
1256 par->bibkey->read(this, lex);
1257 } else if (token == "\\the_end") {
1258 #ifndef NO_COMPABILITY
1259 // If we still have some ert active here we have to insert
1260 // it so we don't loose it. (Lgb)
1261 insertErtContents(par, pos);
1263 the_end_read = true;
1264 #ifndef NO_COMPABILITY
1265 #ifndef NO_PEXTRA_REALLY
1268 minipar = parBeforeMinipage = 0;
1272 #ifndef NO_COMPABILITY
1273 if (ert_comp.active) {
1274 ert_comp.contents += token;
1277 // This should be insurance for the future: (Asger)
1280 string const s = _("Unknown token: ") + token
1281 + " " + lex.text() + "\n";
1282 // we can do this here this way because we're actually reading
1283 // the buffer and don't care about LyXText right now.
1284 InsetError * new_inset = new InsetError(s);
1285 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1288 #ifndef NO_COMPABILITY
1293 #ifndef NO_COMPABILITY
1294 #ifndef NO_PEXTRA_REALLY
1295 // I wonder if we could use this blanket fix for all the
1296 // checkminipage cases...
1297 // don't forget about ert paragraphs and compatibility read for'em
1298 if (par && (par->size() || !ert_comp.contents.empty())) {
1299 // It is possible that this will check to often,
1300 // but that should not be an correctness issue.
1301 // Only a speed issue.
1302 checkminipage = true;
1305 // now check if we have a minipage paragraph as at this
1306 // point we already read all the necessary data!
1307 // this cannot be done in layout because there we did
1308 // not read yet the paragraph PEXTRA-params (Jug)
1310 // BEGIN pextra_minipage compability
1311 // This should be removed in 1.3.x (Lgb)
1312 // I don't think we should remove this so fast (Jug)
1314 // This compability code is not perfect. In a couple
1315 // of rand cases it fails. When the minipage par is
1316 // the first par in the document, and when there are
1317 // none or only one regular paragraphs after the
1318 // minipage. Currently I am not investing any effort
1319 // in fixing those cases.
1321 // lyxerr << "Call depth: " << call_depth << endl;
1322 // lyxerr << "Checkminipage: " << checkminipage << endl;
1324 if (checkminipage && (call_depth == 1)) {
1325 checkminipage = false;
1326 if (minipar && (minipar != par) &&
1327 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1328 lyxerr << "minipages in a row" << endl;
1329 if (par->params().pextraStartMinipage()) {
1330 lyxerr << "start new minipage" << endl;
1331 // minipages in a row
1332 par->previous()->next(0);
1335 Paragraph * tmp = minipar;
1337 tmp->params().pextraType(0);
1338 tmp->params().pextraWidth(string());
1339 tmp->params().pextraWidthp(string());
1340 tmp->params().pextraAlignment(0);
1341 tmp->params().pextraHfill(false);
1342 tmp->params().pextraStartMinipage(false);
1345 // create a new paragraph to insert the
1346 // minipages in the following case
1347 if (par->params().pextraStartMinipage() &&
1348 !par->params().pextraHfill()) {
1349 Paragraph * p = new Paragraph;
1350 p->layout(params.getLyXTextClass().defaultLayoutName());
1352 p->previous(parBeforeMinipage);
1353 parBeforeMinipage->next(p);
1355 p->params().depth(parBeforeMinipage->params().depth());
1356 parBeforeMinipage = p;
1358 InsetMinipage * mini = new InsetMinipage(params);
1359 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1360 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1361 if (!par->params().pextraWidthp().empty()) {
1362 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1363 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1365 Paragraph * op = mini->firstParagraph();
1366 mini->inset.paragraph(par);
1368 // and free the old ones!
1371 Paragraph * pp = op->next();
1375 // Insert the minipage last in the
1376 // previous paragraph.
1377 if (par->params().pextraHfill()) {
1378 parBeforeMinipage->insertChar
1379 (parBeforeMinipage->size(),
1380 Paragraph::META_HFILL, font);
1382 parBeforeMinipage->insertInset
1383 (parBeforeMinipage->size(), mini, font);
1387 lyxerr << "new minipage par" << endl;
1388 //nothing to do just continue reading
1391 } else if (minipar && (minipar != par)) {
1392 lyxerr << "last minipage par read" << endl;
1393 // The last paragraph read was not part of a
1394 // minipage but the par linked list is...
1395 // So we need to remove the last par from the
1397 if (par->previous())
1398 par->previous()->next(0);
1399 par->previous(parBeforeMinipage);
1400 parBeforeMinipage->next(par);
1401 Paragraph * tmp = minipar;
1403 tmp->params().pextraType(0);
1404 tmp->params().pextraWidth(string());
1405 tmp->params().pextraWidthp(string());
1406 tmp->params().pextraAlignment(0);
1407 tmp->params().pextraHfill(false);
1408 tmp->params().pextraStartMinipage(false);
1411 depth = parBeforeMinipage->params().depth();
1412 // and set this depth on the par as it has not been set already
1413 par->params().depth(depth);
1414 minipar = parBeforeMinipage = 0;
1415 } else if (!minipar &&
1416 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1417 // par is the first paragraph in a minipage
1418 lyxerr << "begin minipage" << endl;
1419 // To minimize problems for
1420 // the users we will insert
1421 // the first minipage in
1422 // a sequence of minipages
1423 // in its own paragraph.
1424 Paragraph * p = new Paragraph;
1425 p->layout(params.getLyXTextClass().defaultLayoutName());
1426 p->previous(par->previous());
1428 p->params().depth(depth);
1429 par->params().depth(0);
1431 if (par->previous())
1432 par->previous()->next(p);
1434 parBeforeMinipage = p;
1436 if (!first_par || (first_par == par))
1439 InsetMinipage * mini = new InsetMinipage(params);
1440 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1441 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1442 if (!par->params().pextraWidthp().empty()) {
1443 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1444 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1447 Paragraph * op = mini->firstParagraph();
1448 mini->inset.paragraph(minipar);
1450 // and free the old ones!
1453 Paragraph * pp = op->next();
1458 // Insert the minipage last in the
1459 // previous paragraph.
1460 if (minipar->params().pextraHfill()) {
1461 parBeforeMinipage->insertChar
1462 (parBeforeMinipage->size(),
1463 Paragraph::META_HFILL, font);
1465 parBeforeMinipage->insertInset
1466 (parBeforeMinipage->size(), mini, font);
1467 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1468 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1469 if (!par->params().pextraWidthp().empty()) {
1470 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1474 // End of pextra_minipage compability
1478 return the_end_read;
1481 // needed to insert the selection
1482 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1483 LyXFont const & fn,string const & str) const
1485 LyXLayout_ptr const & layout = par->layout();
1489 par->checkInsertChar(font);
1490 // insert the string, don't insert doublespace
1491 bool space_inserted = true;
1492 bool autobreakrows = !par->inInset() ||
1493 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1494 for(string::const_iterator cit = str.begin();
1495 cit != str.end(); ++cit) {
1497 if (autobreakrows && (!par->empty() || layout->keepempty)) {
1498 par->breakParagraph(params, pos,
1499 layout->isEnvironment());
1502 space_inserted = true;
1506 // do not insert consecutive spaces if !free_spacing
1507 } else if ((*cit == ' ' || *cit == '\t') &&
1508 space_inserted && !layout->free_spacing &&
1509 !par->isFreeSpacing())
1512 } else if (*cit == '\t') {
1513 if (!layout->free_spacing && !par->isFreeSpacing()) {
1514 // tabs are like spaces here
1515 par->insertChar(pos, ' ', font);
1517 space_inserted = true;
1519 const pos_type nb = 8 - pos % 8;
1520 for (pos_type a = 0; a < nb ; ++a) {
1521 par->insertChar(pos, ' ', font);
1524 space_inserted = true;
1526 } else if (!IsPrintable(*cit)) {
1527 // Ignore unprintables
1530 // just insert the character
1531 par->insertChar(pos, *cit, font);
1533 space_inserted = (*cit == ' ');
1540 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1541 int & pos, LyXFont & font)
1543 // consistency check
1544 if (lex.getString() != "\\begin_inset") {
1545 lyxerr << "Buffer::readInset: Consistency check failed."
1552 string const tmptok = lex.getString();
1553 last_inset_read = tmptok;
1555 // test the different insets
1556 if (tmptok == "LatexCommand") {
1557 InsetCommandParams inscmd;
1560 string const cmdName = inscmd.getCmdName();
1562 // This strange command allows LyX to recognize "natbib" style
1563 // citations: citet, citep, Citet etc.
1564 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1565 inset = new InsetCitation(inscmd);
1566 } else if (cmdName == "bibitem") {
1567 lex.printError("Wrong place for bibitem");
1568 inset = new InsetBibKey(inscmd);
1569 } else if (cmdName == "BibTeX") {
1570 inset = new InsetBibtex(inscmd);
1571 } else if (cmdName == "index") {
1572 inset = new InsetIndex(inscmd);
1573 } else if (cmdName == "include") {
1574 inset = new InsetInclude(inscmd, *this);
1575 } else if (cmdName == "label") {
1576 inset = new InsetLabel(inscmd);
1577 } else if (cmdName == "url"
1578 || cmdName == "htmlurl") {
1579 inset = new InsetUrl(inscmd);
1580 } else if (cmdName == "ref"
1581 || cmdName == "pageref"
1582 || cmdName == "vref"
1583 || cmdName == "vpageref"
1584 || cmdName == "prettyref") {
1585 if (!inscmd.getOptions().empty()
1586 || !inscmd.getContents().empty()) {
1587 inset = new InsetRef(inscmd, *this);
1589 } else if (cmdName == "tableofcontents") {
1590 inset = new InsetTOC(inscmd);
1591 } else if (cmdName == "listofalgorithms") {
1592 inset = new InsetFloatList("algorithm");
1593 } else if (cmdName == "listoffigures") {
1594 inset = new InsetFloatList("figure");
1595 } else if (cmdName == "listoftables") {
1596 inset = new InsetFloatList("table");
1597 } else if (cmdName == "printindex") {
1598 inset = new InsetPrintIndex(inscmd);
1599 } else if (cmdName == "lyxparent") {
1600 inset = new InsetParent(inscmd, *this);
1603 bool alreadyread = false;
1604 if (tmptok == "Quotes") {
1605 inset = new InsetQuotes;
1606 } else if (tmptok == "External") {
1607 inset = new InsetExternal;
1608 } else if (tmptok == "FormulaMacro") {
1609 inset = new InsetFormulaMacro;
1610 } else if (tmptok == "Formula") {
1611 inset = new InsetFormula;
1612 } else if (tmptok == "Figure") { // Backward compatibility
1613 // inset = new InsetFig(100, 100, *this);
1614 inset = new InsetGraphics;
1615 } else if (tmptok == "Graphics") {
1616 inset = new InsetGraphics;
1617 } else if (tmptok == "Info") {// backwards compatibility
1618 inset = new InsetNote(this,
1619 lex.getLongString("\\end_inset"),
1622 } else if (tmptok == "Note") {
1623 inset = new InsetNote(params);
1624 } else if (tmptok == "Include") {
1625 InsetCommandParams p("Include");
1626 inset = new InsetInclude(p, *this);
1627 } else if (tmptok == "ERT") {
1628 inset = new InsetERT(params);
1629 } else if (tmptok == "Tabular") {
1630 inset = new InsetTabular(*this);
1631 } else if (tmptok == "Text") {
1632 inset = new InsetText(params);
1633 } else if (tmptok == "Foot") {
1634 inset = new InsetFoot(params);
1635 } else if (tmptok == "Marginal") {
1636 inset = new InsetMarginal(params);
1637 } else if (tmptok == "Minipage") {
1638 inset = new InsetMinipage(params);
1639 } else if (tmptok == "Float") {
1641 string tmptok = lex.getString();
1642 inset = new InsetFloat(params, tmptok);
1644 } else if (tmptok == "List") {
1645 inset = new InsetList;
1646 } else if (tmptok == "Theorem") {
1647 inset = new InsetList;
1649 } else if (tmptok == "Caption") {
1650 inset = new InsetCaption(params);
1651 } else if (tmptok == "FloatList") {
1652 inset = new InsetFloatList;
1655 if (inset && !alreadyread) inset->read(this, lex);
1659 par->insertInset(pos, inset, font);
1665 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1669 string const token(lex.getString());
1670 if (token == "\\lyxformat") { // the first token _must_ be...
1672 string tmp_format = lex.getString();
1673 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1674 // if present remove ".," from string.
1675 string::size_type dot = tmp_format.find_first_of(".,");
1676 //lyxerr << " dot found at " << dot << endl;
1677 if (dot != string::npos)
1678 tmp_format.erase(dot, 1);
1679 file_format = strToInt(tmp_format);
1680 if (file_format == LYX_FORMAT) {
1682 } else if (file_format > LYX_FORMAT) {
1684 Alert::alert(_("Warning!"),
1685 _("LyX file format is newer that what"),
1686 _("is supported in this LyX version. Expect some problems."));
1688 } else if (file_format < LYX_FORMAT) {
1690 if (file_format < 200) {
1691 Alert::alert(_("ERROR!"),
1692 _("Old LyX file format found. "
1693 "Use LyX 0.10.x to read this!"));
1695 } else if (file_format < 220) {
1696 string const command = "lyx2lyx "
1697 + QuoteName(filename_);
1698 cmd_ret const ret = RunCommand(command);
1700 Alert::alert(_("ERROR!"),
1701 _("An error occured while "
1702 "running the conversion script."));
1705 istringstream is(ret.second);
1706 LyXLex tmplex(0, 0);
1707 tmplex.setStream(is);
1708 return readFile(tmplex);
1711 bool the_end = readLyXformat2(lex, par);
1712 params.setPaperStuff();
1715 // the_end was added in 213
1716 if (file_format < 213)
1721 Alert::alert(_("Warning!"),
1722 _("Reading of document is not complete"),
1723 _("Maybe the document is truncated"));
1726 } else { // "\\lyxformat" not found
1727 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1730 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1735 // Should probably be moved to somewhere else: BufferView? LyXView?
1736 bool Buffer::save() const
1738 // We don't need autosaves in the immediate future. (Asger)
1739 resetAutosaveTimers();
1743 if (lyxrc.make_backup) {
1744 s = fileName() + '~';
1745 if (!lyxrc.backupdir_path.empty())
1746 s = AddName(lyxrc.backupdir_path,
1747 subst(os::slashify_path(s),'/','!'));
1749 // Rename is the wrong way of making a backup,
1750 // this is the correct way.
1751 /* truss cp fil fil2:
1752 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1753 stat("LyXVC.lyx", 0xEFFFF688) = 0
1754 open("LyXVC.lyx", O_RDONLY) = 3
1755 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1756 fstat(4, 0xEFFFF508) = 0
1757 fstat(3, 0xEFFFF508) = 0
1758 read(3, " # T h i s f i l e w".., 8192) = 5579
1759 write(4, " # T h i s f i l e w".., 5579) = 5579
1760 read(3, 0xEFFFD4A0, 8192) = 0
1763 chmod("LyXVC3.lyx", 0100644) = 0
1764 lseek(0, 0, SEEK_CUR) = 46440
1768 // Should probably have some more error checking here.
1769 // Doing it this way, also makes the inodes stay the same.
1770 // This is still not a very good solution, in particular we
1771 // might loose the owner of the backup.
1772 FileInfo finfo(fileName());
1773 if (finfo.exist()) {
1774 mode_t fmode = finfo.getMode();
1775 struct utimbuf times = {
1776 finfo.getAccessTime(),
1777 finfo.getModificationTime() };
1779 ifstream ifs(fileName().c_str());
1780 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1785 ::chmod(s.c_str(), fmode);
1787 if (::utime(s.c_str(), ×)) {
1788 lyxerr << "utime error." << endl;
1791 lyxerr << "LyX was not able to make "
1792 "backup copy. Beware." << endl;
1797 if (writeFile(fileName())) {
1799 removeAutosaveFile(fileName());
1801 // Saving failed, so backup is not backup
1802 if (lyxrc.make_backup) {
1803 lyx::rename(s, fileName());
1811 bool Buffer::writeFile(string const & fname) const
1813 if (read_only && (fname == fileName())) {
1817 FileInfo finfo(fname);
1818 if (finfo.exist() && !finfo.writable()) {
1822 ofstream ofs(fname.c_str());
1828 // Use the standard "C" locale for file output.
1829 ofs.imbue(std::locale::classic());
1832 // The top of the file should not be written by params.
1834 // write out a comment in the top of the file
1835 ofs << '#' << lyx_docversion
1836 << " created this file. For more info see http://www.lyx.org/\n"
1837 << "\\lyxformat " << LYX_FORMAT << "\n";
1839 // now write out the buffer paramters.
1840 params.writeFile(ofs);
1842 Paragraph::depth_type depth = 0;
1844 // this will write out all the paragraphs
1845 // using recursive descent.
1846 ParagraphList::iterator pit = paragraphs.begin();
1847 ParagraphList::iterator pend = paragraphs.end();
1848 for (; pit != pend; ++pit)
1849 pit->write(this, ofs, params, depth);
1851 // Write marker that shows file is complete
1852 ofs << "\n\\the_end" << endl;
1856 // how to check if close went ok?
1857 // Following is an attempt... (BE 20001011)
1859 // good() returns false if any error occured, including some
1860 // formatting error.
1861 // bad() returns true if something bad happened in the buffer,
1862 // which should include file system full errors.
1869 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1871 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1883 pair<int, string> const addDepth(int depth, int ldepth)
1887 d += (ldepth - depth) * 2;
1888 return make_pair(d, string(d, ' '));
1894 string const Buffer::asciiParagraph(Paragraph const & par,
1895 unsigned int linelen,
1896 bool noparbreak) const
1898 ostringstream buffer;
1899 Paragraph::depth_type depth = 0;
1901 Paragraph::depth_type ltype_depth = 0;
1902 bool ref_printed = false;
1903 // if (!par->previous()) {
1905 // begins or ends a deeper area ?
1906 if (depth != par->params().depth()) {
1907 if (par->params().depth() > depth) {
1908 while (par->params().depth() > depth) {
1912 while (par->params().depth() < depth) {
1918 depth = par.params().depth();
1921 // First write the layout
1922 string const & tmp = par.layout()->name();
1923 if (compare_no_case(tmp, "itemize") == 0) {
1925 ltype_depth = depth + 1;
1926 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1928 ltype_depth = depth + 1;
1929 } else if (contains(ascii_lowercase(tmp), "ection")) {
1931 ltype_depth = depth + 1;
1932 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1934 ltype_depth = depth + 1;
1935 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1937 ltype_depth = depth + 1;
1938 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1941 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1949 /* maybe some vertical spaces */
1951 /* the labelwidthstring used in lists */
1955 /* some pagebreaks? */
1959 /* what about the alignment */
1961 // lyxerr << "Should this ever happen?" << endl;
1964 // linelen <= 0 is special and means we don't have paragraph breaks
1966 string::size_type currlinelen = 0;
1972 buffer << string(depth * 2, ' ');
1973 currlinelen += depth * 2;
1976 // we should probably change to the paragraph language in the
1977 // gettext here (if possible) so that strings are outputted in
1978 // the correct language! (20012712 Jug)
1982 case 4: // (Sub)Paragraph
1983 case 5: // Description
1987 buffer << _("Abstract") << "\n\n";
1990 string const abst = _("Abstract: ");
1992 currlinelen += abst.length();
1995 case 7: // Bibliography
1998 buffer << _("References") << "\n\n";
2001 string const refs = _("References: ");
2003 currlinelen += refs.length();
2011 string const parlab = par.params().labelString();
2012 buffer << parlab << " ";
2013 currlinelen += parlab.length() + 1;
2021 pair<int, string> p = addDepth(depth, ltype_depth);
2023 currlinelen += p.first;
2026 // this is to change the linebreak to do it by word a bit more
2027 // intelligent hopefully! (only in the case where we have a
2028 // max linelenght!) (Jug)
2032 for (pos_type i = 0; i < par.size(); ++i) {
2033 char c = par.getUChar(params, i);
2035 case Paragraph::META_INSET:
2037 Inset const * inset = par.getInset(i);
2041 currlinelen += word.length();
2044 if (inset->ascii(this, buffer, linelen)) {
2045 // to be sure it breaks paragraph
2046 currlinelen += linelen;
2052 case Paragraph::META_NEWLINE:
2054 buffer << word << "\n";
2057 pair<int, string> p = addDepth(depth,
2060 currlinelen = p.first;
2064 case Paragraph::META_HFILL:
2065 buffer << word << "\t";
2066 currlinelen += word.length() + 1;
2073 currlinelen + word.length() > linelen - 10) {
2075 pair<int, string> p =
2076 addDepth(depth, ltype_depth);
2078 currlinelen = p.first;
2081 buffer << word << ' ';
2082 currlinelen += word.length() + 1;
2089 lyxerr[Debug::INFO] <<
2090 "writeAsciiFile: NULL char in structure." << endl;
2092 if ((linelen > 0) &&
2093 (currlinelen + word.length()) > linelen)
2097 pair<int, string> p =
2098 addDepth(depth, ltype_depth);
2100 currlinelen = p.first;
2107 return buffer.str().c_str();
2111 void Buffer::writeFileAscii(string const & fname, int linelen)
2113 ofstream ofs(fname.c_str());
2115 Alert::err_alert(_("Error: Cannot write file:"), fname);
2118 writeFileAscii(ofs, linelen);
2122 void Buffer::writeFileAscii(ostream & os, int linelen)
2124 ParagraphList::iterator beg = paragraphs.begin();
2125 ParagraphList::iterator end = paragraphs.end();
2126 ParagraphList::iterator it = beg;
2127 for (; it != end; ++it) {
2128 os << asciiParagraph(*it, linelen, it == beg);
2137 void Buffer::makeLaTeXFile(string const & fname,
2138 string const & original_path,
2139 bool nice, bool only_body, bool only_preamble)
2141 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2143 ofstream ofs(fname.c_str());
2145 Alert::err_alert(_("Error: Cannot open file: "), fname);
2149 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
2153 lyxerr << "File was not closed properly." << endl;
2158 void Buffer::makeLaTeXFile(ostream & os,
2159 string const & original_path,
2160 bool nice, bool only_body, bool only_preamble)
2162 niceFile = nice; // this will be used by Insetincludes.
2164 // validate the buffer.
2165 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2166 LaTeXFeatures features(params);
2168 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2171 // The starting paragraph of the coming rows is the
2172 // first paragraph of the document. (Asger)
2173 texrow.start(&*(paragraphs.begin()), 0);
2175 if (!only_body && nice) {
2176 os << "%% " << lyx_docversion << " created this file. "
2177 "For more info, see http://www.lyx.org/.\n"
2178 "%% Do not edit unless you really know what "
2183 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2184 // There are a few differences between nice LaTeX and usual files:
2185 // usual is \batchmode and has a
2186 // special input@path to allow the including of figures
2187 // with either \input or \includegraphics (what figinsets do).
2188 // input@path is set when the actual parameter
2189 // original_path is set. This is done for usual tex-file, but not
2190 // for nice-latex-file. (Matthias 250696)
2193 // code for usual, NOT nice-latex-file
2194 os << "\\batchmode\n"; // changed
2195 // from \nonstopmode
2198 if (!original_path.empty()) {
2199 string inputpath = os::external_path(original_path);
2200 subst(inputpath, "~", "\\string~");
2201 os << "\\makeatletter\n"
2202 << "\\def\\input@path{{"
2203 << inputpath << "/}}\n"
2204 << "\\makeatother\n";
2210 os << "\\documentclass";
2212 LyXTextClass const & tclass = params.getLyXTextClass();
2214 ostringstream options; // the document class options.
2216 if (tokenPos(tclass.opt_fontsize(),
2217 '|', params.fontsize) >= 0) {
2218 // only write if existing in list (and not default)
2219 options << params.fontsize << "pt,";
2223 if (!params.use_geometry &&
2224 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2225 switch (params.papersize) {
2226 case BufferParams::PAPER_A4PAPER:
2227 options << "a4paper,";
2229 case BufferParams::PAPER_USLETTER:
2230 options << "letterpaper,";
2232 case BufferParams::PAPER_A5PAPER:
2233 options << "a5paper,";
2235 case BufferParams::PAPER_B5PAPER:
2236 options << "b5paper,";
2238 case BufferParams::PAPER_EXECUTIVEPAPER:
2239 options << "executivepaper,";
2241 case BufferParams::PAPER_LEGALPAPER:
2242 options << "legalpaper,";
2248 if (params.sides != tclass.sides()) {
2249 switch (params.sides) {
2250 case LyXTextClass::OneSide:
2251 options << "oneside,";
2253 case LyXTextClass::TwoSides:
2254 options << "twoside,";
2260 if (params.columns != tclass.columns()) {
2261 if (params.columns == 2)
2262 options << "twocolumn,";
2264 options << "onecolumn,";
2267 if (!params.use_geometry
2268 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2269 options << "landscape,";
2271 // language should be a parameter to \documentclass
2273 ostringstream language_options;
2274 if (params.language->babel() == "hebrew"
2275 && default_language->babel() != "hebrew")
2276 // This seems necessary
2277 features.useLanguage(default_language);
2279 if (lyxrc.language_use_babel ||
2280 params.language->lang() != lyxrc.default_language ||
2281 features.hasLanguages()) {
2283 language_options << features.getLanguages();
2284 language_options << params.language->babel();
2285 if (lyxrc.language_global_options)
2286 options << language_options.str() << ',';
2289 // the user-defined options
2290 if (!params.options.empty()) {
2291 options << params.options << ',';
2294 string strOptions(options.str().c_str());
2295 if (!strOptions.empty()) {
2296 strOptions = rtrim(strOptions, ",");
2297 os << '[' << strOptions << ']';
2300 os << '{' << tclass.latexname() << "}\n";
2302 // end of \documentclass defs
2304 // font selection must be done before loading fontenc.sty
2305 // The ae package is not needed when using OT1 font encoding.
2306 if (params.fonts != "default" &&
2307 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2308 os << "\\usepackage{" << params.fonts << "}\n";
2310 if (params.fonts == "ae") {
2311 os << "\\usepackage{aecompl}\n";
2315 // this one is not per buffer
2316 if (lyxrc.fontenc != "default") {
2317 os << "\\usepackage[" << lyxrc.fontenc
2322 if (params.inputenc == "auto") {
2323 string const doc_encoding =
2324 params.language->encoding()->LatexName();
2326 // Create a list with all the input encodings used
2328 set<string> encodings = features.getEncodingSet(doc_encoding);
2330 os << "\\usepackage[";
2331 std::copy(encodings.begin(), encodings.end(),
2332 std::ostream_iterator<string>(os, ","));
2333 os << doc_encoding << "]{inputenc}\n";
2335 } else if (params.inputenc != "default") {
2336 os << "\\usepackage[" << params.inputenc
2341 // At the very beginning the text parameters.
2342 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2343 switch (params.paperpackage) {
2344 case BufferParams::PACKAGE_A4:
2345 os << "\\usepackage{a4}\n";
2348 case BufferParams::PACKAGE_A4WIDE:
2349 os << "\\usepackage{a4wide}\n";
2352 case BufferParams::PACKAGE_WIDEMARGINSA4:
2353 os << "\\usepackage[widemargins]{a4}\n";
2358 if (params.use_geometry) {
2359 os << "\\usepackage{geometry}\n";
2361 os << "\\geometry{verbose";
2362 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2364 switch (params.papersize2) {
2365 case BufferParams::VM_PAPER_CUSTOM:
2366 if (!params.paperwidth.empty())
2367 os << ",paperwidth="
2368 << params.paperwidth;
2369 if (!params.paperheight.empty())
2370 os << ",paperheight="
2371 << params.paperheight;
2373 case BufferParams::VM_PAPER_USLETTER:
2374 os << ",letterpaper";
2376 case BufferParams::VM_PAPER_USLEGAL:
2377 os << ",legalpaper";
2379 case BufferParams::VM_PAPER_USEXECUTIVE:
2380 os << ",executivepaper";
2382 case BufferParams::VM_PAPER_A3:
2385 case BufferParams::VM_PAPER_A4:
2388 case BufferParams::VM_PAPER_A5:
2391 case BufferParams::VM_PAPER_B3:
2394 case BufferParams::VM_PAPER_B4:
2397 case BufferParams::VM_PAPER_B5:
2401 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2402 switch (lyxrc.default_papersize) {
2403 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2404 case BufferParams::PAPER_USLETTER:
2405 os << ",letterpaper";
2407 case BufferParams::PAPER_LEGALPAPER:
2408 os << ",legalpaper";
2410 case BufferParams::PAPER_EXECUTIVEPAPER:
2411 os << ",executivepaper";
2413 case BufferParams::PAPER_A3PAPER:
2416 case BufferParams::PAPER_A4PAPER:
2419 case BufferParams::PAPER_A5PAPER:
2422 case BufferParams::PAPER_B5PAPER:
2427 if (!params.topmargin.empty())
2428 os << ",tmargin=" << params.topmargin;
2429 if (!params.bottommargin.empty())
2430 os << ",bmargin=" << params.bottommargin;
2431 if (!params.leftmargin.empty())
2432 os << ",lmargin=" << params.leftmargin;
2433 if (!params.rightmargin.empty())
2434 os << ",rmargin=" << params.rightmargin;
2435 if (!params.headheight.empty())
2436 os << ",headheight=" << params.headheight;
2437 if (!params.headsep.empty())
2438 os << ",headsep=" << params.headsep;
2439 if (!params.footskip.empty())
2440 os << ",footskip=" << params.footskip;
2445 if (tokenPos(tclass.opt_pagestyle(),
2446 '|', params.pagestyle) >= 0) {
2447 if (params.pagestyle == "fancy") {
2448 os << "\\usepackage{fancyhdr}\n";
2451 os << "\\pagestyle{" << params.pagestyle << "}\n";
2455 if (params.secnumdepth != tclass.secnumdepth()) {
2456 os << "\\setcounter{secnumdepth}{"
2457 << params.secnumdepth
2461 if (params.tocdepth != tclass.tocdepth()) {
2462 os << "\\setcounter{tocdepth}{"
2468 if (params.paragraph_separation) {
2469 switch (params.defskip.kind()) {
2470 case VSpace::SMALLSKIP:
2471 os << "\\setlength\\parskip{\\smallskipamount}\n";
2473 case VSpace::MEDSKIP:
2474 os << "\\setlength\\parskip{\\medskipamount}\n";
2476 case VSpace::BIGSKIP:
2477 os << "\\setlength\\parskip{\\bigskipamount}\n";
2479 case VSpace::LENGTH:
2480 os << "\\setlength\\parskip{"
2481 << params.defskip.length().asLatexString()
2484 default: // should never happen // Then delete it.
2485 os << "\\setlength\\parskip{\\medskipamount}\n";
2490 os << "\\setlength\\parindent{0pt}\n";
2494 // Now insert the LyX specific LaTeX commands...
2496 // The optional packages;
2497 string preamble(features.getPackages());
2499 // this might be useful...
2500 preamble += "\n\\makeatletter\n";
2502 // Some macros LyX will need
2503 string tmppreamble(features.getMacros());
2505 if (!tmppreamble.empty()) {
2506 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2507 "LyX specific LaTeX commands.\n"
2508 + tmppreamble + '\n';
2511 // the text class specific preamble
2512 tmppreamble = features.getTClassPreamble();
2513 if (!tmppreamble.empty()) {
2514 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2515 "Textclass specific LaTeX commands.\n"
2516 + tmppreamble + '\n';
2519 /* the user-defined preamble */
2520 if (!params.preamble.empty()) {
2521 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2522 "User specified LaTeX commands.\n"
2523 + params.preamble + '\n';
2526 // Itemize bullet settings need to be last in case the user
2527 // defines their own bullets that use a package included
2528 // in the user-defined preamble -- ARRae
2529 // Actually it has to be done much later than that
2530 // since some packages like frenchb make modifications
2531 // at \begin{document} time -- JMarc
2533 for (int i = 0; i < 4; ++i) {
2534 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2535 if (bullets_def.empty())
2536 bullets_def="\\AtBeginDocument{\n";
2537 bullets_def += " \\renewcommand{\\labelitemi";
2539 // `i' is one less than the item to modify
2546 bullets_def += "ii";
2552 bullets_def += "}{" +
2553 params.user_defined_bullets[i].getText()
2558 if (!bullets_def.empty())
2559 preamble += bullets_def + "}\n\n";
2562 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2563 for (int j = 0; j != nlines; ++j) {
2567 // We try to load babel late, in case it interferes
2568 // with other packages.
2570 string tmp = lyxrc.language_package;
2571 if (!lyxrc.language_global_options
2572 && tmp == "\\usepackage{babel}")
2573 tmp = string("\\usepackage[") +
2574 language_options.str().c_str() +
2576 preamble += tmp + "\n";
2577 preamble += features.getBabelOptions();
2580 preamble += "\\makeatother\n";
2588 os << "\\begin{document}\n";
2591 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2593 if (!lyxrc.language_auto_begin) {
2594 os << subst(lyxrc.language_command_begin, "$$lang",
2595 params.language->babel())
2600 latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
2602 // add this just in case after all the paragraphs
2606 if (!lyxrc.language_auto_end) {
2607 os << subst(lyxrc.language_command_end, "$$lang",
2608 params.language->babel())
2614 os << "\\end{document}\n";
2617 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2619 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2623 // Just to be sure. (Asger)
2626 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2627 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2629 // we want this to be true outside previews (for insetexternal)
2635 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2637 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2638 Paragraph * endpar, TexRow & texrow,
2639 bool moving_arg) const
2641 bool was_title = false;
2642 bool already_title = false;
2645 while (par != endpar) {
2646 Inset * in = par->inInset();
2647 // well we have to check if we are in an inset with unlimited
2648 // length (all in one row) if that is true then we don't allow
2649 // any special options in the paragraph and also we don't allow
2650 // any environment other then "Standard" to be valid!
2651 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2652 LyXLayout_ptr const & layout = par->layout();
2654 if (layout->intitle) {
2655 if (already_title) {
2656 lyxerr <<"Error in latexParagraphs: You"
2657 " should not mix title layouts"
2658 " with normal ones." << endl;
2661 } else if (was_title && !already_title) {
2662 ofs << "\\maketitle\n";
2664 already_title = true;
2668 if (layout->isEnvironment() ||
2669 !par->params().leftIndent().zero())
2671 par = par->TeXEnvironment(this, params, ofs, texrow);
2673 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2676 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2679 // It might be that we only have a title in this document
2680 if (was_title && !already_title) {
2681 ofs << "\\maketitle\n";
2687 bool Buffer::isLatex() const
2689 return params.getLyXTextClass().outputType() == LATEX;
2693 bool Buffer::isLinuxDoc() const
2695 return params.getLyXTextClass().outputType() == LINUXDOC;
2699 bool Buffer::isLiterate() const
2701 return params.getLyXTextClass().outputType() == LITERATE;
2705 bool Buffer::isDocBook() const
2707 return params.getLyXTextClass().outputType() == DOCBOOK;
2711 bool Buffer::isSGML() const
2713 LyXTextClass const & tclass = params.getLyXTextClass();
2715 return tclass.outputType() == LINUXDOC ||
2716 tclass.outputType() == DOCBOOK;
2720 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2721 string const & latexname) const
2723 if (!latexname.empty() && latexname != "!-- --") {
2725 os << string(" ",depth);
2726 os << "<" << latexname << ">";
2736 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2737 string const & latexname) const
2739 if (!latexname.empty() && latexname != "!-- --") {
2741 os << endl << string(" ",depth);
2742 os << "</" << latexname << ">";
2752 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2754 ofstream ofs(fname.c_str());
2757 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2761 niceFile = nice; // this will be used by included files.
2763 LaTeXFeatures features(params);
2769 LyXTextClass const & tclass = params.getLyXTextClass();
2771 string top_element = tclass.latexname();
2774 ofs << "<!doctype linuxdoc system";
2776 string preamble = params.preamble;
2777 const string name = nice ? ChangeExtension(filename_, ".sgml")
2779 preamble += features.getIncludedFiles(name);
2780 preamble += features.getLyXSGMLEntities();
2782 if (!preamble.empty()) {
2783 ofs << " [ " << preamble << " ]";
2787 if (params.options.empty())
2788 sgmlOpenTag(ofs, 0, false, top_element);
2790 string top = top_element;
2792 top += params.options;
2793 sgmlOpenTag(ofs, 0, false, top);
2797 ofs << "<!-- " << lyx_docversion
2798 << " created this file. For more info see http://www.lyx.org/"
2801 Paragraph::depth_type depth = 0; // paragraph depth
2802 Paragraph * par = &*(paragraphs.begin());
2804 vector<string> environment_stack(5);
2807 LyXLayout_ptr const & style = par->layout();
2808 // treat <toc> as a special case for compatibility with old code
2809 if (par->isInset(0)) {
2810 Inset * inset = par->getInset(0);
2811 Inset::Code lyx_code = inset->lyxCode();
2812 if (lyx_code == Inset::TOC_CODE) {
2813 string const temp = "toc";
2814 sgmlOpenTag(ofs, depth, false, temp);
2821 // environment tag closing
2822 for (; depth > par->params().depth(); --depth) {
2823 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2824 environment_stack[depth].erase();
2827 // write opening SGML tags
2828 switch (style->latextype) {
2829 case LATEX_PARAGRAPH:
2830 if (depth == par->params().depth()
2831 && !environment_stack[depth].empty()) {
2832 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2833 environment_stack[depth].erase();
2839 sgmlOpenTag(ofs, depth, false, style->latexname());
2845 _("Error : Wrong depth for"
2846 " LatexType Command.\n"));
2848 if (!environment_stack[depth].empty()) {
2849 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2853 environment_stack[depth].erase();
2854 sgmlOpenTag(ofs, depth, false, style->latexname());
2857 case LATEX_ENVIRONMENT:
2858 case LATEX_ITEM_ENVIRONMENT:
2860 string const & latexname = style->latexname();
2862 if (depth == par->params().depth()
2863 && environment_stack[depth] != latexname) {
2864 sgmlCloseTag(ofs, depth, false,
2865 environment_stack[depth]);
2866 environment_stack[depth].erase();
2868 if (depth < par->params().depth()) {
2869 depth = par->params().depth();
2870 environment_stack[depth].erase();
2872 if (environment_stack[depth] != latexname) {
2874 sgmlOpenTag(ofs, depth, false, "p");
2876 sgmlOpenTag(ofs, depth, false, latexname);
2878 if (environment_stack.size() == depth + 1)
2879 environment_stack.push_back("!-- --");
2880 environment_stack[depth] = latexname;
2883 if (style->latexparam() == "CDATA")
2886 if (style->latextype == LATEX_ENVIRONMENT) break;
2888 if (style->labeltype == LABEL_MANUAL)
2893 sgmlOpenTag(ofs, depth + 1, false, item_name);
2898 sgmlOpenTag(ofs, depth, false, style->latexname());
2902 simpleLinuxDocOnePar(ofs, par, depth);
2907 // write closing SGML tags
2908 switch (style->latextype) {
2911 case LATEX_ENVIRONMENT:
2912 case LATEX_ITEM_ENVIRONMENT:
2913 if (style->latexparam() == "CDATA")
2917 sgmlCloseTag(ofs, depth, false, style->latexname());
2923 for (int i = depth; i >= 0; --i)
2924 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2928 sgmlCloseTag(ofs, 0, false, top_element);
2932 // How to check for successful close
2934 // we want this to be true outside previews (for insetexternal)
2939 // checks, if newcol chars should be put into this line
2940 // writes newline, if necessary.
2943 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2944 string::size_type newcol)
2947 if (colcount > lyxrc.ascii_linelen) {
2949 colcount = newcol; // assume write after this call
2964 string tag_name(PAR_TAG const & pt) {
2966 case NONE: return "!-- --";
2967 case TT: return "tt";
2968 case SF: return "sf";
2969 case BF: return "bf";
2970 case IT: return "it";
2971 case SL: return "sl";
2972 case EM: return "em";
2979 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2981 p1 = static_cast<PAR_TAG>(p1 | p2);
2986 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2988 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2994 // Handle internal paragraph parsing -- layout already processed.
2995 void Buffer::simpleLinuxDocOnePar(ostream & os,
2997 Paragraph::depth_type /*depth*/)
2999 LyXLayout_ptr const & style = par->layout();
3001 string::size_type char_line_count = 5; // Heuristic choice ;-)
3003 // gets paragraph main font
3006 if (style->labeltype == LABEL_MANUAL) {
3007 font_old = style->labelfont;
3010 font_old = style->font;
3014 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3015 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3016 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3019 stack<PAR_TAG> tag_state;
3020 // parsing main loop
3021 for (pos_type i = 0; i < par->size(); ++i) {
3023 PAR_TAG tag_close = NONE;
3024 list < PAR_TAG > tag_open;
3026 LyXFont const font = par->getFont(params, i);
3028 if (font_old.family() != font.family()) {
3029 switch (family_type) {
3030 case LyXFont::SANS_FAMILY:
3033 case LyXFont::TYPEWRITER_FAMILY:
3040 family_type = font.family();
3042 switch (family_type) {
3043 case LyXFont::SANS_FAMILY:
3044 tag_open.push_back(SF);
3046 case LyXFont::TYPEWRITER_FAMILY:
3047 tag_open.push_back(TT);
3054 if (font_old.series() != font.series()) {
3055 switch (series_type) {
3056 case LyXFont::BOLD_SERIES:
3063 series_type = font.series();
3065 switch (series_type) {
3066 case LyXFont::BOLD_SERIES:
3067 tag_open.push_back(BF);
3075 if (font_old.shape() != font.shape()) {
3076 switch (shape_type) {
3077 case LyXFont::ITALIC_SHAPE:
3080 case LyXFont::SLANTED_SHAPE:
3087 shape_type = font.shape();
3089 switch (shape_type) {
3090 case LyXFont::ITALIC_SHAPE:
3091 tag_open.push_back(IT);
3093 case LyXFont::SLANTED_SHAPE:
3094 tag_open.push_back(SL);
3101 if (font_old.emph() != font.emph()) {
3102 if (font.emph() == LyXFont::ON) {
3103 tag_open.push_back(EM);
3112 list < PAR_TAG > temp;
3113 while (!tag_state.empty() && tag_close) {
3114 PAR_TAG k = tag_state.top();
3116 os << "</" << tag_name(k) << ">";
3123 for(list< PAR_TAG >::const_iterator j = temp.begin();
3124 j != temp.end(); ++j) {
3126 os << "<" << tag_name(*j) << ">";
3129 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3130 j != tag_open.end(); ++j) {
3132 os << "<" << tag_name(*j) << ">";
3135 char c = par->getChar(i);
3137 if (c == Paragraph::META_INSET) {
3138 Inset * inset = par->getInset(i);
3139 inset->linuxdoc(this, os);
3144 if (style->latexparam() == "CDATA") {
3145 // "TeX"-Mode on == > SGML-Mode on.
3152 boost::tie(ws, str) = sgml::escapeChar(c);
3153 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
3154 // in freespacing mode, spaces are
3155 // non-breaking characters
3156 if (desc_on) {// if char is ' ' then...
3159 sgmlLineBreak(os, char_line_count, 6);
3163 sgmlLineBreak(os, char_line_count, 1);
3168 char_line_count += str.length();
3174 while (!tag_state.empty()) {
3175 os << "</" << tag_name(tag_state.top()) << ">";
3179 // resets description flag correctly
3181 // <tag> not closed...
3182 sgmlLineBreak(os, char_line_count, 6);
3188 // Print an error message.
3189 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3190 string const & /*message*/) const
3192 #ifdef WITH_WARNINGS
3193 #warning This is wrong we cannot insert an inset like this!!!
3194 // I guess this was Jose' so I explain you more or less why this
3195 // is wrong. This way you insert something in the paragraph and
3196 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3197 // I deactivate this code, have a look at BufferView::insertErrors
3198 // how you should do this correctly! (Jug 20020315)
3201 // insert an error marker in text
3202 InsetError * new_inset = new InsetError(message);
3203 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3209 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3211 ofstream ofs(fname.c_str());
3213 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3217 Paragraph * par = &*(paragraphs.begin());
3219 niceFile = nice; // this will be used by Insetincludes.
3221 LaTeXFeatures features(params);
3226 LyXTextClass const & tclass = params.getLyXTextClass();
3227 string top_element = tclass.latexname();
3230 ofs << "<!DOCTYPE " << top_element
3231 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3233 string preamble = params.preamble;
3234 const string name = nice ? ChangeExtension(filename_, ".sgml")
3236 preamble += features.getIncludedFiles(name);
3237 preamble += features.getLyXSGMLEntities();
3239 if (!preamble.empty()) {
3240 ofs << "\n [ " << preamble << " ]";
3245 string top = top_element;
3247 top += params.language->code();
3250 if (!params.options.empty()) {
3252 top += params.options;
3254 sgmlOpenTag(ofs, 0, false, top);
3256 ofs << "<!-- DocBook file was created by " << lyx_docversion
3257 << "\n See http://www.lyx.org/ for more information -->\n";
3259 vector<string> environment_stack(10);
3260 vector<string> environment_inner(10);
3261 vector<string> command_stack(10);
3263 bool command_flag = false;
3264 Paragraph::depth_type command_depth = 0;
3265 Paragraph::depth_type command_base = 0;
3266 Paragraph::depth_type cmd_depth = 0;
3267 Paragraph::depth_type depth = 0; // paragraph depth
3270 string command_name;
3276 int desc_on = 0; // description mode
3278 LyXLayout_ptr const & style = par->layout();
3280 // environment tag closing
3281 for (; depth > par->params().depth(); --depth) {
3282 if (environment_inner[depth] != "!-- --") {
3283 item_name = "listitem";
3284 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3285 if (environment_inner[depth] == "varlistentry")
3286 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3288 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3289 environment_stack[depth].erase();
3290 environment_inner[depth].erase();
3293 if (depth == par->params().depth()
3294 && environment_stack[depth] != style->latexname()
3295 && !environment_stack[depth].empty()) {
3296 if (environment_inner[depth] != "!-- --") {
3297 item_name= "listitem";
3298 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3299 if (environment_inner[depth] == "varlistentry")
3300 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3303 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3305 environment_stack[depth].erase();
3306 environment_inner[depth].erase();
3309 // Write opening SGML tags.
3310 switch (style->latextype) {
3311 case LATEX_PARAGRAPH:
3312 sgmlOpenTag(ofs, depth + command_depth,
3313 false, style->latexname());
3319 _("Error : Wrong depth for "
3320 "LatexType Command.\n"));
3322 command_name = style->latexname();
3324 sgmlparam = style->latexparam();
3325 c_params = split(sgmlparam, c_depth,'|');
3327 cmd_depth = lyx::atoi(c_depth);
3330 if (cmd_depth < command_base) {
3331 for (Paragraph::depth_type j = command_depth;
3332 j >= command_base; --j) {
3333 sgmlCloseTag(ofs, j, false, command_stack[j]);
3336 command_depth = command_base = cmd_depth;
3337 } else if (cmd_depth <= command_depth) {
3338 for (int j = command_depth;
3339 j >= int(cmd_depth); --j) {
3340 sgmlCloseTag(ofs, j, false, command_stack[j]);
3343 command_depth = cmd_depth;
3345 command_depth = cmd_depth;
3347 command_depth = command_base = cmd_depth;
3348 command_flag = true;
3350 if (command_stack.size() == command_depth + 1)
3351 command_stack.push_back(string());
3352 command_stack[command_depth] = command_name;
3354 // treat label as a special case for
3355 // more WYSIWYM handling.
3356 // This is a hack while paragraphs can't have
3357 // attributes, like id in this case.
3358 if (par->isInset(0)) {
3359 Inset * inset = par->getInset(0);
3360 Inset::Code lyx_code = inset->lyxCode();
3361 if (lyx_code == Inset::LABEL_CODE) {
3362 command_name += " id=\"";
3363 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3364 command_name += "\"";
3369 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3371 item_name = c_params.empty()?"title":c_params;
3372 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3375 case LATEX_ENVIRONMENT:
3376 case LATEX_ITEM_ENVIRONMENT:
3377 if (depth < par->params().depth()) {
3378 depth = par->params().depth();
3379 environment_stack[depth].erase();
3382 if (environment_stack[depth] != style->latexname()) {
3383 if (environment_stack.size() == depth + 1) {
3384 environment_stack.push_back("!-- --");
3385 environment_inner.push_back("!-- --");
3387 environment_stack[depth] = style->latexname();
3388 environment_inner[depth] = "!-- --";
3389 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3391 if (environment_inner[depth] != "!-- --") {
3392 item_name= "listitem";
3393 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3394 if (environment_inner[depth] == "varlistentry")
3395 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3399 if (style->latextype == LATEX_ENVIRONMENT) {
3400 if (!style->latexparam().empty()) {
3401 if (style->latexparam() == "CDATA")
3404 sgmlOpenTag(ofs, depth + command_depth, false, style->latexparam());
3409 desc_on = (style->labeltype == LABEL_MANUAL);
3411 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
3412 sgmlOpenTag(ofs, depth + 1 + command_depth,
3413 false, environment_inner[depth]);
3415 item_name = desc_on ? "term" : "para";
3416 sgmlOpenTag(ofs, depth + 1 + command_depth,
3420 sgmlOpenTag(ofs, depth + command_depth,
3421 false, style->latexname());
3425 simpleDocBookOnePar(ofs, par, desc_on,
3426 depth + 1 + command_depth);
3430 // write closing SGML tags
3431 switch (style->latextype) {
3433 end_tag = c_params.empty() ? "title" : c_params;
3434 sgmlCloseTag(ofs, depth + command_depth,
3437 case LATEX_ENVIRONMENT:
3438 if (!style->latexparam().empty()) {
3439 if (style->latexparam() == "CDATA")
3442 sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
3445 case LATEX_ITEM_ENVIRONMENT:
3446 if (desc_on == 1) break;
3448 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3450 case LATEX_PARAGRAPH:
3451 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3454 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3460 for (int d = depth; d >= 0; --d) {
3461 if (!environment_stack[depth].empty()) {
3462 if (environment_inner[depth] != "!-- --") {
3463 item_name = "listitem";
3464 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3465 if (environment_inner[depth] == "varlistentry")
3466 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3469 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3473 for (int j = command_depth; j >= 0 ; --j)
3474 if (!command_stack[j].empty()) {
3475 sgmlCloseTag(ofs, j, false, command_stack[j]);
3480 sgmlCloseTag(ofs, 0, false, top_element);
3483 // How to check for successful close
3485 // we want this to be true outside previews (for insetexternal)
3490 void Buffer::simpleDocBookOnePar(ostream & os,
3491 Paragraph * par, int & desc_on,
3492 Paragraph::depth_type depth) const
3494 bool emph_flag = false;
3496 LyXLayout_ptr const & style = par->layout();
3498 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
3500 int char_line_count = depth;
3501 //if (!style.free_spacing)
3502 // os << string(depth,' ');
3504 // parsing main loop
3505 for (pos_type i = 0; i < par->size(); ++i) {
3506 LyXFont font = par->getFont(params, i);
3508 // handle <emphasis> tag
3509 if (font_old.emph() != font.emph()) {
3510 if (font.emph() == LyXFont::ON) {
3511 if (style->latexparam() == "CDATA")
3514 if (style->latexparam() == "CDATA")
3518 if (style->latexparam() == "CDATA")
3520 os << "</emphasis>";
3521 if (style->latexparam() == "CDATA")
3528 if (par->isInset(i)) {
3529 Inset * inset = par->getInset(i);
3530 // don't print the inset in position 0 if desc_on == 3 (label)
3531 if (i || desc_on != 3) {
3532 if (style->latexparam() == "CDATA")
3534 inset->docbook(this, os, false);
3535 if (style->latexparam() == "CDATA")
3539 char c = par->getChar(i);
3542 boost::tie(ws, str) = sgml::escapeChar(c);
3544 if (style->pass_thru) {
3546 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
3548 } else if (desc_on ==1) {
3550 os << "\n</term><listitem><para>";
3560 if (style->latexparam() == "CDATA")
3562 os << "</emphasis>";
3563 if (style->latexparam() == "CDATA")
3567 // resets description flag correctly
3569 // <term> not closed...
3570 os << "</term>\n<listitem><para> </para>";
3572 if (style->free_spacing)
3577 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3578 // Other flags: -wall -v0 -x
3579 int Buffer::runChktex()
3581 if (!users->text) return 0;
3583 users->owner()->prohibitInput();
3585 // get LaTeX-Filename
3586 string const name = getLatexName();
3587 string path = filePath();
3589 string const org_path = path;
3590 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3594 Path p(path); // path to LaTeX file
3595 users->owner()->message(_("Running chktex..."));
3597 // Remove all error insets
3598 bool const removedErrorInsets = users->removeAutoInsets();
3600 // Generate the LaTeX file if neccessary
3601 makeLaTeXFile(name, org_path, false);
3604 Chktex chktex(lyxrc.chktex_command, name, filePath());
3605 int res = chktex.run(terr); // run chktex
3608 Alert::alert(_("chktex did not work!"),
3609 _("Could not run with file:"), name);
3610 } else if (res > 0) {
3611 // Insert all errors as errors boxes
3612 users->insertErrors(terr);
3615 // if we removed error insets before we ran chktex or if we inserted
3616 // error insets after we ran chktex, this must be run:
3617 if (removedErrorInsets || res) {
3618 #warning repaint needed here, or do you mean update() ?
3622 users->owner()->allowInput();
3628 void Buffer::validate(LaTeXFeatures & features) const
3630 LyXTextClass const & tclass = params.getLyXTextClass();
3632 // AMS Style is at document level
3633 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3634 features.require("amsmath");
3636 for_each(paragraphs.begin(), paragraphs.end(),
3637 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
3639 // the bullet shapes are buffer level not paragraph level
3640 // so they are tested here
3641 for (int i = 0; i < 4; ++i) {
3642 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3643 int const font = params.user_defined_bullets[i].getFont();
3645 int const c = params
3646 .user_defined_bullets[i]
3653 features.require("latexsym");
3655 } else if (font == 1) {
3656 features.require("amssymb");
3657 } else if ((font >= 2 && font <= 5)) {
3658 features.require("pifont");
3663 if (lyxerr.debugging(Debug::LATEX)) {
3664 features.showStruct();
3669 // This function should be in Buffer because it's a buffer's property (ale)
3670 string const Buffer::getIncludeonlyList(char delim)
3673 for (inset_iterator it = inset_iterator_begin();
3674 it != inset_iterator_end(); ++it) {
3675 if (it->lyxCode() == Inset::INCLUDE_CODE) {
3676 InsetInclude & inc = static_cast<InsetInclude &>(*it);
3677 if (inc.isIncludeOnly()) {
3680 lst += inc.getRelFileBaseName();
3684 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3689 vector<string> const Buffer::getLabelList() const
3691 /// if this is a child document and the parent is already loaded
3692 /// Use the parent's list instead [ale990407]
3693 if (!params.parentname.empty()
3694 && bufferlist.exists(params.parentname)) {
3695 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3697 return tmp->getLabelList();
3700 vector<string> label_list;
3701 for (inset_iterator it = inset_const_iterator_begin();
3702 it != inset_const_iterator_end(); ++it) {
3703 vector<string> const l = it->getLabelList();
3704 label_list.insert(label_list.end(), l.begin(), l.end());
3710 // This is also a buffer property (ale)
3711 vector<pair<string, string> > const Buffer::getBibkeyList() const
3713 typedef pair<string, string> StringPair;
3714 /// if this is a child document and the parent is already loaded
3715 /// Use the parent's list instead [ale990412]
3716 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3717 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3719 return tmp->getBibkeyList();
3722 vector<StringPair> keys;
3723 ParagraphList::iterator pit = paragraphs.begin();
3724 ParagraphList::iterator pend = paragraphs.end();
3725 for (; pit != pend; ++pit) {
3727 string const key = pit->bibkey->getContents();
3728 string const opt = pit->bibkey->getOptions();
3729 string const ref = pit->asString(this, false);
3730 string const info = opt + "TheBibliographyRef" + ref;
3732 keys.push_back(StringPair(key, info));
3736 // Might be either using bibtex or a child has bibliography
3738 for (inset_iterator it = inset_const_iterator_begin();
3739 it != inset_const_iterator_end(); ++it) {
3740 // Search for Bibtex or Include inset
3741 if (it->lyxCode() == Inset::BIBTEX_CODE) {
3742 vector<StringPair> tmp =
3743 static_cast<InsetBibtex &>(*it).getKeys(this);
3744 keys.insert(keys.end(), tmp.begin(), tmp.end());
3745 } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
3746 vector<StringPair> const tmp =
3747 static_cast<InsetInclude &>(*it).getKeys();
3748 keys.insert(keys.end(), tmp.begin(), tmp.end());
3757 bool Buffer::isDepClean(string const & name) const
3759 DEPCLEAN * item = dep_clean;
3760 while (item && item->master != name)
3762 if (!item) return true;
3767 void Buffer::markDepClean(string const & name)
3770 dep_clean = new DEPCLEAN;
3771 dep_clean->clean = true;
3772 dep_clean->master = name;
3773 dep_clean->next = 0;
3775 DEPCLEAN * item = dep_clean;
3776 while (item && item->master != name)
3781 item = new DEPCLEAN;
3783 item->master = name;
3790 bool Buffer::dispatch(string const & command, bool * result)
3792 // Split command string into command and argument
3794 string line = ltrim(command);
3795 string const arg = trim(split(line, cmd, ' '));
3797 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3801 bool Buffer::dispatch(int action, string const & argument, bool * result)
3803 bool dispatched = true;
3807 bool const tmp = Exporter::Export(this, argument, false);
3820 void Buffer::resizeInsets(BufferView * bv)
3822 /// then remove all LyXText in text-insets
3823 for_each(paragraphs.begin(), paragraphs.end(),
3824 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
3828 void Buffer::redraw()
3830 #warning repaint needed here, or do you mean update() ?
3836 void Buffer::changeLanguage(Language const * from, Language const * to)
3839 ParIterator end = par_iterator_end();
3840 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3841 (*it)->changeLanguage(params, from, to);
3845 bool Buffer::isMultiLingual()
3847 ParIterator end = par_iterator_end();
3848 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3849 if ((*it)->isMultiLingual(params))
3856 Counters & Buffer::counters() const
3862 void Buffer::inset_iterator::setParagraph()
3864 while (pit != pend) {
3865 it = pit->insetlist.begin();
3866 if (it != pit->insetlist.end())
3873 Inset * Buffer::getInsetFromID(int id_arg) const
3875 for (inset_iterator it = inset_const_iterator_begin();
3876 it != inset_const_iterator_end(); ++it)
3878 if (it->id() == id_arg)
3880 Inset * in = it->getInsetFromID(id_arg);
3888 Paragraph * Buffer::getParFromID(int id) const
3893 ParagraphList::iterator it = paragraphs.begin();
3894 ParagraphList::iterator end = paragraphs.end();
3895 for (; it != end; ++it) {
3896 if (it->id() == id) {
3899 Paragraph * tmp = it->getParFromID(id);
3908 ParIterator Buffer::par_iterator_begin()
3910 return ParIterator(&*(paragraphs.begin()));
3914 ParIterator Buffer::par_iterator_end()
3916 return ParIterator();
3920 void Buffer::addUser(BufferView * u)
3926 void Buffer::delUser(BufferView *)
3932 Language const * Buffer::getLanguage() const
3934 return params.language;
3938 bool Buffer::isClean() const
3944 bool Buffer::isBakClean() const
3950 void Buffer::markClean() const
3956 // if the .lyx file has been saved, we don't need an
3962 void Buffer::markBakClean()
3968 void Buffer::setUnnamed(bool flag)
3974 bool Buffer::isUnnamed()
3980 void Buffer::markDirty()
3987 DEPCLEAN * tmp = dep_clean;
3995 string const & Buffer::fileName() const
4001 string const & Buffer::filePath() const
4007 bool Buffer::isReadonly() const
4013 BufferView * Buffer::getUser() const
4019 void Buffer::setParentName(string const & name)
4021 params.parentname = name;
4025 Buffer::inset_iterator::inset_iterator()
4030 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
4037 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
4041 if (it == pit->insetlist.end()) {
4050 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
4052 inset_iterator tmp = *this;
4058 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
4060 return *it.getInset();
4064 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
4066 return it.getInset();
4070 Paragraph * Buffer::inset_iterator::getPar()
4076 lyx::pos_type Buffer::inset_iterator::getPos() const
4082 bool operator==(Buffer::inset_iterator const & iter1,
4083 Buffer::inset_iterator const & iter2)
4085 return iter1.pit == iter2.pit
4086 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
4090 bool operator!=(Buffer::inset_iterator const & iter1,
4091 Buffer::inset_iterator const & iter2)
4093 return !(iter1 == iter2);