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"
49 #include "mathed/formulamacro.h"
50 #include "mathed/formula.h"
52 #include "insets/inset.h"
53 #include "insets/inseterror.h"
54 #include "insets/insetlabel.h"
55 #include "insets/insetref.h"
56 #include "insets/inseturl.h"
57 #include "insets/insetnote.h"
58 #include "insets/insetquotes.h"
59 #include "insets/insetlatexaccent.h"
60 #include "insets/insetbib.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/insetminipage.h"
74 #include "insets/insetfloat.h"
75 #include "insets/insettabular.h"
77 #include "insets/insettheorem.h"
78 #include "insets/insetlist.h"
80 #include "insets/insetcaption.h"
81 #include "insets/insetfloatlist.h"
83 #include "frontends/Dialogs.h"
84 #include "frontends/Alert.h"
86 #include "graphics/Previews.h"
88 #include "support/textutils.h"
89 #include "support/filetools.h"
90 #include "support/path.h"
91 #include "support/os.h"
92 #include "support/lyxlib.h"
93 #include "support/FileInfo.h"
94 #include "support/lyxmanip.h"
95 #include "support/lyxalgo.h" // for lyx::count
107 #include <sys/types.h>
115 #ifndef CXX_GLOBAL_CSTD
127 using std::make_pair;
136 using lyx::textclass_type;
138 // all these externs should eventually be removed.
139 extern BufferList bufferlist;
141 extern LyXAction lyxaction;
145 const int LYX_FORMAT = 220;
149 extern int tex_code_break_column;
152 Buffer::Buffer(string const & file, bool ronly)
153 : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
154 unnamed(false), dep_clean(0), read_only(ronly),
155 filename_(file), users(0)
157 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
159 filepath_ = OnlyPath(file);
164 // read_only = ronly;
168 if (read_only || lyxrc.use_tempdir) {
169 tmppath = CreateBufferTmpDir();
178 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
179 // here the buffer should take care that it is
180 // saved properly, before it goes into the void.
182 // make sure that views using this buffer
187 if (!tmppath.empty()) {
188 DestroyBufferTmpDir(tmppath);
191 Paragraph * par = paragraph;
194 tmppar = par->next();
200 // Remove any previewed LaTeX snippets assocoated with this buffer.
201 grfx::Previews::get().removeLoader(this);
205 string const Buffer::getLatexName(bool no_path) const
207 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
209 return OnlyFilename(name);
215 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
217 string const filename = getLatexName(false);
219 if (filename.empty())
220 return make_pair(Buffer::latexlog, string());
222 string path = OnlyPath(filename);
224 if (lyxrc.use_tempdir || !IsDirWriteable(path))
227 string const fname = AddName(path,
228 OnlyFilename(ChangeExtension(filename,
231 AddName(path, OnlyFilename(
232 ChangeExtension(filename,
233 formats.extension("literate") + ".out")));
235 // If no Latex log or Build log is newer, show Build log
237 FileInfo const f_fi(fname);
238 FileInfo const b_fi(bname);
241 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
242 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
243 return make_pair(Buffer::buildlog, bname);
245 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
246 return make_pair(Buffer::latexlog, fname);
250 void Buffer::setReadonly(bool flag)
252 if (read_only != flag) {
255 users->owner()->getDialogs()->updateBufferDependent(false);
260 /// Update window titles of all users
261 // Should work on a list
262 void Buffer::updateTitles() const
265 users->owner()->updateWindowTitle();
269 /// Reset autosave timer of all users
270 // Should work on a list
271 void Buffer::resetAutosaveTimers() const
274 users->owner()->resetAutosaveTimer();
278 void Buffer::setFileName(string const & newfile)
280 filename_ = MakeAbsPath(newfile);
281 filepath_ = OnlyPath(filename_);
282 setReadonly(IsFileWriteable(filename_) == 0);
287 // We'll remove this later. (Lgb)
290 string last_inset_read;
292 #ifndef NO_COMPABILITY
295 ErtComp() : active(false), fromlayout(false), in_tabular(false) {
304 std::stack<ErtComp> ert_stack;
309 #warning And _why_ is this here? (Lgb)
317 // candidate for move to BufferView
318 // (at least some parts in the beginning of the func)
321 // changed to be public and have one parameter
322 // if par = 0 normal behavior
323 // else insert behavior
324 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
325 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
329 #ifndef NO_COMPABILITY
330 ert_comp.contents.erase();
331 ert_comp.active = false;
332 ert_comp.fromlayout = false;
333 ert_comp.in_tabular = false;
336 Paragraph::depth_type depth = 0;
337 bool the_end_read = false;
339 Paragraph * first_par = 0;
340 LyXFont font(LyXFont::ALL_INHERIT, params.language);
343 if (file_format < 216 && params.language->lang() == "hebrew")
344 font.setLanguage(default_language);
349 par->layout(params.getLyXTextClass().defaultLayout());
351 // We are inserting into an existing document
352 users->text->breakParagraph(users);
353 first_par = users->text->ownerParagraph();
356 // We don't want to adopt the parameters from the
357 // document we insert, so we skip until the text begins:
360 string const pretoken = lex.getString();
361 if (pretoken == "\\layout") {
362 lex.pushToken(pretoken);
370 string const token = lex.getString();
372 if (token.empty()) continue;
374 lyxerr[Debug::PARSER] << "Handling token: `"
375 << token << "'" << endl;
378 parseSingleLyXformat2Token(lex, par, first_par,
386 paragraph = first_par;
388 if (unknown_layouts > 0) {
389 string s = _("Couldn't set the layout for ");
390 if (unknown_layouts == 1) {
391 s += _("one paragraph");
393 s += tostr(unknown_layouts);
394 s += _(" paragraphs");
396 Alert::alert(_("Textclass Loading Error!"), s,
397 _("When reading " + fileName()));
400 if (unknown_tokens > 0) {
401 string s = _("Encountered ");
402 if (unknown_tokens == 1) {
403 s += _("one unknown token");
405 s += tostr(unknown_tokens);
406 s += _(" unknown tokens");
408 Alert::alert(_("Textclass Loading Error!"), s,
409 _("When reading " + fileName()));
416 #ifndef NO_COMPABILITY
418 Inset * Buffer::isErtInset(Paragraph * par, int pos) const
421 if ((par->getChar(pos) == Paragraph::META_INSET) &&
422 (inset = par->getInset(pos)) &&
423 (inset->lyxCode() == Inset::ERT_CODE))
430 void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
432 if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
433 // we only skip completely empty ERT (only spaces) otherwise
434 // we have to insert it as is.
435 string str(ert_comp.contents);
436 lyxerr[Debug::INSETS] << "ERT contents:\n'"
437 << str << "'" << endl;
438 // check if we have already an ert inset a position earlier
439 // if this is the case then we should insert the contents
440 // inside the other ertinset as it is stupid to have various
443 if ((pos > 0) && (inset=isErtInset(par, pos-1))) {
444 // get the last paragraph from the inset before
445 Paragraph * last = inset->firstParagraph();
448 // create the new paragraph after the last one
449 Paragraph * par = new Paragraph(last);
450 par->layout(params.getLyXTextClass().defaultLayoutName());
451 par->setInsetOwner(last->inInset());
453 LyXFont font(LyXFont::ALL_INHERIT, params.language);
454 string::const_iterator cit = str.begin();
455 string::const_iterator end = str.end();
457 for (; cit != end; ++cit) {
458 par->insertChar(pos++, *cit, font);
462 new InsetERT(params, params.language, str, true);
463 par->insertInset(pos++, inset, ert_comp.font);
466 ert_comp.contents.erase();
467 ert_comp.fromlayout = false;
469 ert_comp.active = false;
476 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
477 Paragraph *& first_par,
478 string const & token, int & pos,
479 Paragraph::depth_type & depth,
483 bool the_end_read = false;
484 #ifndef NO_COMPABILITY
485 #ifndef NO_PEXTRA_REALLY
486 // This is super temporary but is needed to get the compability
487 // mode for minipages work correctly together with new tabulars.
488 static int call_depth;
490 bool checkminipage = false;
491 static Paragraph * minipar = 0;
492 static Paragraph * parBeforeMinipage;
496 // The order of the tags tested may seem unnatural, but this
497 // has been done in order to reduce the number of string
498 // comparisons needed to recognize a given token. This leads
499 // on large documents like UserGuide to a reduction of a
501 if (token[0] != '\\') {
502 #ifndef NO_COMPABILITY
503 if (ert_comp.active) {
504 ert_comp.contents += token;
507 for (string::const_iterator cit = token.begin();
508 cit != token.end(); ++cit) {
509 par->insertChar(pos, (*cit), font);
512 #ifndef NO_COMPABILITY
515 } else if (token == "\\layout") {
516 #ifndef NO_COMPABILITY
517 bool old_fromlayout = ert_comp.fromlayout;
518 bool create_new_par = true;
519 ert_comp.in_tabular = false;
521 if (!par->size() && par->previous() &&
522 (par->previous()->size() == 1) &&
523 isErtInset(par->previous(), par->previous()->size()-1))
525 int p = par->previous()->size();
526 insertErtContents(par->previous(), p);
527 create_new_par = false;
529 insertErtContents(par, pos);
532 // reset the font as we start a new layout and if the font is
533 // not ALL_INHERIT,document_language then it will be set to the
534 // right values after this tag (Jug 20020420)
535 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
538 if (file_format < 216 && params.language->lang() == "hebrew")
539 font.setLanguage(default_language);
543 string layoutname = lex.getString();
545 LyXTextClass const & tclass = params.getLyXTextClass();
547 if (layoutname.empty()) {
548 layoutname = tclass.defaultLayoutName();
550 #ifndef NO_COMPABILITY
551 if (compare_ascii_no_case(layoutname, "latex") == 0) {
552 ert_comp.active = true;
553 ert_comp.fromlayout = true;
554 ert_comp.font = font;
556 create_new_par = false;
559 bool hasLayout = tclass.hasLayout(layoutname);
561 lyxerr << "Layout '" << layoutname << "' does not"
562 << " exist in textclass '" << tclass.name()
564 lyxerr << "Trying to use default layout instead."
566 layoutname = tclass.defaultLayoutName();
570 // The is the compability reading of layout caption.
571 // It can be removed in LyX version 1.3.0. (Lgb)
572 if (compare_ascii_no_case(layoutname, "caption") == 0) {
573 // We expect that the par we are now working on is
574 // really inside a InsetText inside a InsetFloat.
575 // We also know that captions can only be
576 // one paragraph. (Lgb)
578 // We should now read until the next "\layout"
580 // This is probably not good enough, what if the
581 // caption is the last par in the document (Lgb)
582 istream & ist = lex.getStream();
588 if (prefixIs(line, "\\layout")) {
592 if (prefixIs(line, "\\begin_inset"))
594 if (prefixIs(line, "\\end_inset")) {
605 // Now we should have the whole layout in ss
606 // we should now be able to give this to the
608 ss << "\\end_inset\n";
610 // This seems like a bug in stringstream.
611 // We really should be able to use ss
613 istringstream is(ss.str());
615 tmplex.setStream(is);
616 Inset * inset = new InsetCaption;
617 inset->Read(this, tmplex);
618 par->InsertInset(pos, inset, font);
622 #ifndef NO_COMPABILITY
623 if (create_new_par) {
628 par = new Paragraph(par);
629 par->layout(params.getLyXTextClass().defaultLayout());
632 par->layout(params.getLyXTextClass()[layoutname]);
633 // Test whether the layout is obsolete.
634 LyXLayout_ptr const & layout = par->layout();
635 if (!layout->obsoleted_by().empty())
636 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
637 par->params().depth(depth);
638 #ifndef NO_COMPABILITY
640 // we duplicate code here because it's easier to remove
641 // the code then of NO_COMPATIBILITY
642 par->layout(layoutname);
643 // Test whether the layout is obsolete.
644 LyXLayout_ptr const & layout =
645 params.getLyXTextClass()[par->layout()];
646 if (!layout->obsoleted_by().empty())
647 par->layout(layout->obsoleted_by());
648 par->params().depth(depth);
655 } else if (token == "\\end_inset") {
656 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
657 << "Last inset read was: " << last_inset_read
659 // Simply ignore this. The insets do not have
661 // But insets should read it, it is a part of
662 // the inset isn't it? Lgb.
663 } else if (token == "\\begin_inset") {
664 #ifndef NO_COMPABILITY
665 insertErtContents(par, pos, false);
666 ert_stack.push(ert_comp);
667 ert_comp = ErtComp();
669 readInset(lex, par, pos, font);
670 #ifndef NO_COMPABILITY
671 ert_comp = ert_stack.top();
673 insertErtContents(par, pos);
675 } else if (token == "\\family") {
677 font.setLyXFamily(lex.getString());
678 } else if (token == "\\series") {
680 font.setLyXSeries(lex.getString());
681 } else if (token == "\\shape") {
683 font.setLyXShape(lex.getString());
684 } else if (token == "\\size") {
686 font.setLyXSize(lex.getString());
687 #ifndef NO_COMPABILITY
688 } else if (token == "\\latex") {
690 string const tok = lex.getString();
691 if (tok == "no_latex") {
693 insertErtContents(par, pos);
694 } else if (tok == "latex") {
695 ert_comp.active = true;
696 ert_comp.font = font;
697 } else if (tok == "default") {
699 insertErtContents(par, pos);
701 lex.printError("Unknown LaTeX font flag "
705 } else if (token == "\\lang") {
707 string const tok = lex.getString();
708 Language const * lang = languages.getLanguage(tok);
710 font.setLanguage(lang);
712 font.setLanguage(params.language);
713 lex.printError("Unknown language `$$Token'");
715 } else if (token == "\\numeric") {
717 font.setNumber(font.setLyXMisc(lex.getString()));
718 } else if (token == "\\emph") {
720 font.setEmph(font.setLyXMisc(lex.getString()));
721 } else if (token == "\\bar") {
723 string const tok = lex.getString();
724 // This is dirty, but gone with LyX3. (Asger)
726 font.setUnderbar(LyXFont::ON);
727 else if (tok == "no")
728 font.setUnderbar(LyXFont::OFF);
729 else if (tok == "default")
730 font.setUnderbar(LyXFont::INHERIT);
732 lex.printError("Unknown bar font flag "
734 } else if (token == "\\noun") {
736 font.setNoun(font.setLyXMisc(lex.getString()));
737 } else if (token == "\\color") {
739 font.setLyXColor(lex.getString());
740 } else if (token == "\\SpecialChar") {
741 LyXLayout_ptr const & layout = par->layout();
743 // Insets don't make sense in a free-spacing context! ---Kayvan
744 if (layout->free_spacing || par->isFreeSpacing()) {
747 string next_token = lex.getString();
748 if (next_token == "\\-") {
749 par->insertChar(pos, '-', font);
750 } else if (next_token == "\\protected_separator"
751 || next_token == "~") {
752 par->insertChar(pos, ' ', font);
754 lex.printError("Token `$$Token' "
756 "paragraph layout!");
761 Inset * inset = new InsetSpecialChar;
762 inset->read(this, lex);
763 par->insertInset(pos, inset, font);
766 } else if (token == "\\i") {
767 Inset * inset = new InsetLatexAccent;
768 inset->read(this, lex);
769 par->insertInset(pos, inset, font);
771 } else if (token == "\\backslash") {
772 #ifndef NO_COMPABILITY
773 if (ert_comp.active) {
774 ert_comp.contents += "\\";
777 par->insertChar(pos, '\\', font);
779 #ifndef NO_COMPABILITY
782 #ifndef NO_COMPABILITY
783 } else if (token == "\\begin_float") {
784 insertErtContents(par, pos);
785 //insertErtContents(par, pos, false);
786 //ert_stack.push(ert_comp);
787 //ert_comp = ErtComp();
789 // This is the compability reader. It can be removed in
790 // LyX version 1.3.0. (Lgb)
792 string const tmptok = lex.getString();
793 //lyxerr << "old float: " << tmptok << endl;
796 stringstream old_float;
798 if (tmptok == "footnote") {
799 inset = new InsetFoot(params);
800 old_float << "collapsed true\n";
801 } else if (tmptok == "margin") {
802 inset = new InsetMarginal(params);
803 old_float << "collapsed true\n";
804 } else if (tmptok == "fig") {
805 inset = new InsetFloat(params, "figure");
806 old_float << "wide false\n"
807 << "collapsed false\n";
808 } else if (tmptok == "tab") {
809 inset = new InsetFloat(params, "table");
810 old_float << "wide false\n"
811 << "collapsed false\n";
812 } else if (tmptok == "alg") {
813 inset = new InsetFloat(params, "algorithm");
814 old_float << "wide false\n"
815 << "collapsed false\n";
816 } else if (tmptok == "wide-fig") {
817 inset = new InsetFloat(params, "figure");
818 //InsetFloat * tmp = new InsetFloat("figure");
821 old_float << "wide true\n"
822 << "collapsed false\n";
823 } else if (tmptok == "wide-tab") {
824 inset = new InsetFloat(params, "table");
825 //InsetFloat * tmp = new InsetFloat("table");
828 old_float << "wide true\n"
829 << "collapsed false\n";
833 #ifndef NO_PEXTRA_REALLY
836 return false; // no end read yet
839 // Here we need to check for \end_deeper and handle that
840 // before we do the footnote parsing.
841 // This _is_ a hack! (Lgb)
844 string const tmp = lex.getString();
845 if (tmp == "\\end_deeper") {
846 //lyxerr << "\\end_deeper caught!" << endl;
848 lex.printError("\\end_deeper: "
849 "depth is already null");
854 old_float << tmp << ' ';
859 old_float << lex.getLongString("\\end_float")
860 << "\n\\end_inset\n";
861 //lyxerr << "Float Body:\n" << old_float.str() << endl;
862 // That this does not work seems like a bug
863 // in stringstream. (Lgb)
864 istringstream istr(old_float.str());
866 nylex.setStream(istr);
867 inset->read(this, nylex);
868 par->insertInset(pos, inset, font);
870 insertErtContents(par, pos);
872 // we have to reset the font as in the old format after a float
873 // the font was automatically reset!
874 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
876 } else if (token == "\\begin_deeper") {
878 } else if (token == "\\end_deeper") {
880 lex.printError("\\end_deeper: "
881 "depth is already null");
885 } else if (token == "\\begin_preamble") {
886 params.readPreamble(lex);
887 } else if (token == "\\textclass") {
889 pair<bool, textclass_type> pp =
890 textclasslist.NumberOfClass(lex.getString());
892 params.textclass = pp.second;
894 Alert::alert(string(_("Textclass error")),
895 string(_("The document uses an unknown textclass \"")) +
896 lex.getString() + string("\"."),
897 string(_("LyX will not be able to produce output correctly.")));
898 params.textclass = 0;
900 if (!params.getLyXTextClass().load()) {
901 // if the textclass wasn't loaded properly
902 // we need to either substitute another
903 // or stop loading the file.
904 // I can substitute but I don't see how I can
905 // stop loading... ideas?? ARRae980418
906 Alert::alert(_("Textclass Loading Error!"),
907 string(_("Can't load textclass ")) +
908 params.getLyXTextClass().name(),
909 _("-- substituting default"));
910 params.textclass = 0;
912 } else if (token == "\\options") {
914 params.options = lex.getString();
915 } else if (token == "\\language") {
916 params.readLanguage(lex);
917 } else if (token == "\\fontencoding") {
919 } else if (token == "\\inputencoding") {
921 params.inputenc = lex.getString();
922 } else if (token == "\\graphics") {
923 params.readGraphicsDriver(lex);
924 } else if (token == "\\fontscheme") {
926 params.fonts = lex.getString();
927 } else if (token == "\\noindent") {
928 par->params().noindent(true);
929 } else if (token == "\\leftindent") {
931 LyXLength value(lex.getString());
932 par->params().leftIndent(value);
933 } else if (token == "\\fill_top") {
934 par->params().spaceTop(VSpace(VSpace::VFILL));
935 } else if (token == "\\fill_bottom") {
936 par->params().spaceBottom(VSpace(VSpace::VFILL));
937 } else if (token == "\\line_top") {
938 par->params().lineTop(true);
939 } else if (token == "\\line_bottom") {
940 par->params().lineBottom(true);
941 } else if (token == "\\pagebreak_top") {
942 par->params().pagebreakTop(true);
943 } else if (token == "\\pagebreak_bottom") {
944 par->params().pagebreakBottom(true);
945 } else if (token == "\\start_of_appendix") {
946 par->params().startOfAppendix(true);
947 } else if (token == "\\paragraph_separation") {
948 int tmpret = lex.findToken(string_paragraph_separation);
951 params.paragraph_separation =
952 static_cast<BufferParams::PARSEP>(tmpret);
953 } else if (token == "\\defskip") {
955 params.defskip = VSpace(lex.getString());
956 #ifndef NO_COMPABILITY
957 } else if (token == "\\epsfig") { // obsolete
958 // Indeed it is obsolete, but we HAVE to be backwards
959 // compatible until 0.14, because otherwise all figures
960 // in existing documents are irretrivably lost. (Asger)
961 params.readGraphicsDriver(lex);
963 } else if (token == "\\quotes_language") {
964 int tmpret = lex.findToken(string_quotes_language);
967 InsetQuotes::quote_language tmpl =
968 InsetQuotes::EnglishQ;
971 tmpl = InsetQuotes::EnglishQ;
974 tmpl = InsetQuotes::SwedishQ;
977 tmpl = InsetQuotes::GermanQ;
980 tmpl = InsetQuotes::PolishQ;
983 tmpl = InsetQuotes::FrenchQ;
986 tmpl = InsetQuotes::DanishQ;
989 params.quotes_language = tmpl;
990 } else if (token == "\\quotes_times") {
992 switch (lex.getInteger()) {
994 params.quotes_times = InsetQuotes::SingleQ;
997 params.quotes_times = InsetQuotes::DoubleQ;
1000 } else if (token == "\\papersize") {
1001 int tmpret = lex.findToken(string_papersize);
1005 params.papersize2 = tmpret;
1006 } else if (token == "\\paperpackage") {
1007 int tmpret = lex.findToken(string_paperpackages);
1010 params.paperpackage = BufferParams::PACKAGE_NONE;
1012 params.paperpackage = tmpret;
1013 } else if (token == "\\use_geometry") {
1015 params.use_geometry = lex.getInteger();
1016 } else if (token == "\\use_amsmath") {
1018 params.use_amsmath = lex.getInteger();
1019 } else if (token == "\\use_natbib") {
1021 params.use_natbib = lex.getInteger();
1022 } else if (token == "\\use_numerical_citations") {
1024 params.use_numerical_citations = lex.getInteger();
1025 } else if (token == "\\paperorientation") {
1026 int tmpret = lex.findToken(string_orientation);
1029 params.orientation =
1030 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
1031 } else if (token == "\\paperwidth") {
1033 params.paperwidth = lex.getString();
1034 } else if (token == "\\paperheight") {
1036 params.paperheight = lex.getString();
1037 } else if (token == "\\leftmargin") {
1039 params.leftmargin = lex.getString();
1040 } else if (token == "\\topmargin") {
1042 params.topmargin = lex.getString();
1043 } else if (token == "\\rightmargin") {
1045 params.rightmargin = lex.getString();
1046 } else if (token == "\\bottommargin") {
1048 params.bottommargin = lex.getString();
1049 } else if (token == "\\headheight") {
1051 params.headheight = lex.getString();
1052 } else if (token == "\\headsep") {
1054 params.headsep = lex.getString();
1055 } else if (token == "\\footskip") {
1057 params.footskip = lex.getString();
1058 } else if (token == "\\paperfontsize") {
1060 params.fontsize = rtrim(lex.getString());
1061 } else if (token == "\\papercolumns") {
1063 params.columns = lex.getInteger();
1064 } else if (token == "\\papersides") {
1066 switch (lex.getInteger()) {
1068 case 1: params.sides = LyXTextClass::OneSide; break;
1069 case 2: params.sides = LyXTextClass::TwoSides; break;
1071 } else if (token == "\\paperpagestyle") {
1073 params.pagestyle = rtrim(lex.getString());
1074 } else if (token == "\\bullet") {
1076 int const index = lex.getInteger();
1078 int temp_int = lex.getInteger();
1079 params.user_defined_bullets[index].setFont(temp_int);
1080 params.temp_bullets[index].setFont(temp_int);
1082 temp_int = lex.getInteger();
1083 params.user_defined_bullets[index].setCharacter(temp_int);
1084 params.temp_bullets[index].setCharacter(temp_int);
1086 temp_int = lex.getInteger();
1087 params.user_defined_bullets[index].setSize(temp_int);
1088 params.temp_bullets[index].setSize(temp_int);
1090 string const temp_str = lex.getString();
1091 if (temp_str != "\\end_bullet") {
1092 // this element isn't really necessary for
1093 // parsing but is easier for humans
1094 // to understand bullets. Put it back and
1095 // set a debug message?
1096 lex.printError("\\end_bullet expected, got" + temp_str);
1097 //how can I put it back?
1099 } else if (token == "\\bulletLaTeX") {
1100 // The bullet class should be able to read this.
1102 int const index = lex.getInteger();
1104 string temp_str = lex.getString();
1106 while (temp_str != "\\end_bullet") {
1107 // this loop structure is needed when user
1108 // enters an empty string since the first
1109 // thing returned will be the \\end_bullet
1111 // if the LaTeX entry has spaces. Each element
1112 // therefore needs to be read in turn
1113 sum_str += temp_str;
1115 temp_str = lex.getString();
1118 params.user_defined_bullets[index].setText(sum_str);
1119 params.temp_bullets[index].setText(sum_str);
1120 } else if (token == "\\secnumdepth") {
1122 params.secnumdepth = lex.getInteger();
1123 } else if (token == "\\tocdepth") {
1125 params.tocdepth = lex.getInteger();
1126 } else if (token == "\\spacing") {
1128 string const tmp = rtrim(lex.getString());
1129 Spacing::Space tmp_space = Spacing::Default;
1130 float tmp_val = 0.0;
1131 if (tmp == "single") {
1132 tmp_space = Spacing::Single;
1133 } else if (tmp == "onehalf") {
1134 tmp_space = Spacing::Onehalf;
1135 } else if (tmp == "double") {
1136 tmp_space = Spacing::Double;
1137 } else if (tmp == "other") {
1139 tmp_space = Spacing::Other;
1140 tmp_val = lex.getFloat();
1142 lex.printError("Unknown spacing token: '$$Token'");
1144 // Small hack so that files written with klyx will be
1145 // parsed correctly.
1147 par->params().spacing(Spacing(tmp_space, tmp_val));
1149 params.spacing.set(tmp_space, tmp_val);
1151 } else if (token == "\\paragraph_spacing") {
1153 string const tmp = rtrim(lex.getString());
1154 if (tmp == "single") {
1155 par->params().spacing(Spacing(Spacing::Single));
1156 } else if (tmp == "onehalf") {
1157 par->params().spacing(Spacing(Spacing::Onehalf));
1158 } else if (tmp == "double") {
1159 par->params().spacing(Spacing(Spacing::Double));
1160 } else if (tmp == "other") {
1162 par->params().spacing(Spacing(Spacing::Other,
1165 lex.printError("Unknown spacing token: '$$Token'");
1167 } else if (token == "\\float_placement") {
1169 params.float_placement = lex.getString();
1170 } else if (token == "\\align") {
1171 int tmpret = lex.findToken(string_align);
1172 if (tmpret == -1) ++tmpret;
1173 int const tmpret2 = int(pow(2.0, tmpret));
1174 par->params().align(LyXAlignment(tmpret2));
1175 } else if (token == "\\added_space_top") {
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().spaceTop(value);
1184 } else if (token == "\\added_space_bottom") {
1186 VSpace value = VSpace(lex.getString());
1187 // only add the length when value > 0 or
1189 if ((value.length().len().value() != 0) ||
1191 (value.kind() != VSpace::LENGTH))
1192 par->params().spaceBottom(value);
1193 #ifndef NO_COMPABILITY
1194 #ifndef NO_PEXTRA_REALLY
1195 } else if (token == "\\pextra_type") {
1197 par->params().pextraType(lex.getInteger());
1198 } else if (token == "\\pextra_width") {
1200 par->params().pextraWidth(lex.getString());
1201 } else if (token == "\\pextra_widthp") {
1203 par->params().pextraWidthp(lex.getString());
1204 } else if (token == "\\pextra_alignment") {
1206 par->params().pextraAlignment(lex.getInteger());
1207 } else if (token == "\\pextra_hfill") {
1209 par->params().pextraHfill(lex.getInteger());
1210 } else if (token == "\\pextra_start_minipage") {
1212 par->params().pextraStartMinipage(lex.getInteger());
1215 } else if (token == "\\labelwidthstring") {
1217 par->params().labelWidthString(lex.getString());
1218 // do not delete this token, it is still needed!
1219 } else if (token == "\\newline") {
1220 #ifndef NO_COMPABILITY
1221 if (!ert_comp.in_tabular && ert_comp.active) {
1222 ert_comp.contents += char(Paragraph::META_NEWLINE);
1224 // Since we cannot know it this is only a regular
1225 // newline or a tabular cell delimter we have to
1226 // handle the ERT here.
1227 insertErtContents(par, pos, false);
1229 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1233 par->insertChar(pos, Paragraph::META_NEWLINE, font);
1236 } else if (token == "\\LyXTable") {
1237 #ifndef NO_COMPABILITY
1238 ert_comp.in_tabular = true;
1240 Inset * inset = new InsetTabular(*this);
1241 inset->read(this, lex);
1242 par->insertInset(pos, inset, font);
1244 } else if (token == "\\hfill") {
1245 par->insertChar(pos, Paragraph::META_HFILL, font);
1247 } else if (token == "\\protected_separator") { // obsolete
1248 // This is a backward compability thingie. (Lgb)
1249 // Remove it later some time...introduced with fileformat
1251 LyXLayout_ptr const & layout = par->layout();
1253 if (layout->free_spacing || par->isFreeSpacing()) {
1254 par->insertChar(pos, ' ', font);
1256 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1257 par->insertInset(pos, inset, font);
1260 } else if (token == "\\bibitem") { // ale970302
1262 InsetCommandParams p("bibitem", "dummy");
1263 par->bibkey = new InsetBibKey(p);
1265 par->bibkey->read(this, lex);
1266 } else if (token == "\\the_end") {
1267 #ifndef NO_COMPABILITY
1268 // If we still have some ert active here we have to insert
1269 // it so we don't loose it. (Lgb)
1270 insertErtContents(par, pos);
1272 the_end_read = true;
1273 #ifndef NO_COMPABILITY
1274 #ifndef NO_PEXTRA_REALLY
1277 minipar = parBeforeMinipage = 0;
1281 #ifndef NO_COMPABILITY
1282 if (ert_comp.active) {
1283 ert_comp.contents += token;
1286 // This should be insurance for the future: (Asger)
1289 string const s = _("Unknown token: ") + token
1290 + " " + lex.text() + "\n";
1291 // we can do this here this way because we're actually reading
1292 // the buffer and don't care about LyXText right now.
1293 InsetError * new_inset = new InsetError(s);
1294 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1297 #ifndef NO_COMPABILITY
1302 #ifndef NO_COMPABILITY
1303 #ifndef NO_PEXTRA_REALLY
1304 // I wonder if we could use this blanket fix for all the
1305 // checkminipage cases...
1306 // don't forget about ert paragraphs and compatibility read for'em
1307 if (par && (par->size() || !ert_comp.contents.empty())) {
1308 // It is possible that this will check to often,
1309 // but that should not be an correctness issue.
1310 // Only a speed issue.
1311 checkminipage = true;
1314 // now check if we have a minipage paragraph as at this
1315 // point we already read all the necessary data!
1316 // this cannot be done in layout because there we did
1317 // not read yet the paragraph PEXTRA-params (Jug)
1319 // BEGIN pextra_minipage compability
1320 // This should be removed in 1.3.x (Lgb)
1321 // I don't think we should remove this so fast (Jug)
1323 // This compability code is not perfect. In a couple
1324 // of rand cases it fails. When the minipage par is
1325 // the first par in the document, and when there are
1326 // none or only one regular paragraphs after the
1327 // minipage. Currently I am not investing any effort
1328 // in fixing those cases.
1330 // lyxerr << "Call depth: " << call_depth << endl;
1331 // lyxerr << "Checkminipage: " << checkminipage << endl;
1333 if (checkminipage && (call_depth == 1)) {
1334 checkminipage = false;
1335 if (minipar && (minipar != par) &&
1336 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1337 lyxerr << "minipages in a row" << endl;
1338 if (par->params().pextraStartMinipage()) {
1339 lyxerr << "start new minipage" << endl;
1340 // minipages in a row
1341 par->previous()->next(0);
1344 Paragraph * tmp = minipar;
1346 tmp->params().pextraType(0);
1347 tmp->params().pextraWidth(string());
1348 tmp->params().pextraWidthp(string());
1349 tmp->params().pextraAlignment(0);
1350 tmp->params().pextraHfill(false);
1351 tmp->params().pextraStartMinipage(false);
1354 // create a new paragraph to insert the
1355 // minipages in the following case
1356 if (par->params().pextraStartMinipage() &&
1357 !par->params().pextraHfill()) {
1358 Paragraph * p = new Paragraph;
1359 p->layout(params.getLyXTextClass().defaultLayoutName());
1361 p->previous(parBeforeMinipage);
1362 parBeforeMinipage->next(p);
1364 p->params().depth(parBeforeMinipage->params().depth());
1365 parBeforeMinipage = p;
1367 InsetMinipage * mini = new InsetMinipage(params);
1368 mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
1369 mini->pageWidth(LyXLength(par->params().pextraWidth()));
1370 if (!par->params().pextraWidthp().empty()) {
1371 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1372 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1374 Paragraph * op = mini->firstParagraph();
1375 mini->inset.paragraph(par);
1377 // and free the old ones!
1380 Paragraph * pp = op->next();
1384 // Insert the minipage last in the
1385 // previous paragraph.
1386 if (par->params().pextraHfill()) {
1387 parBeforeMinipage->insertChar
1388 (parBeforeMinipage->size(),
1389 Paragraph::META_HFILL, font);
1391 parBeforeMinipage->insertInset
1392 (parBeforeMinipage->size(), mini, font);
1396 lyxerr << "new minipage par" << endl;
1397 //nothing to do just continue reading
1400 } else if (minipar && (minipar != par)) {
1401 lyxerr << "last minipage par read" << endl;
1402 // The last paragraph read was not part of a
1403 // minipage but the par linked list is...
1404 // So we need to remove the last par from the
1406 if (par->previous())
1407 par->previous()->next(0);
1408 par->previous(parBeforeMinipage);
1409 parBeforeMinipage->next(par);
1410 Paragraph * tmp = minipar;
1412 tmp->params().pextraType(0);
1413 tmp->params().pextraWidth(string());
1414 tmp->params().pextraWidthp(string());
1415 tmp->params().pextraAlignment(0);
1416 tmp->params().pextraHfill(false);
1417 tmp->params().pextraStartMinipage(false);
1420 depth = parBeforeMinipage->params().depth();
1421 // and set this depth on the par as it has not been set already
1422 par->params().depth(depth);
1423 minipar = parBeforeMinipage = 0;
1424 } else if (!minipar &&
1425 (par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE)) {
1426 // par is the first paragraph in a minipage
1427 lyxerr << "begin minipage" << endl;
1428 // To minimize problems for
1429 // the users we will insert
1430 // the first minipage in
1431 // a sequence of minipages
1432 // in its own paragraph.
1433 Paragraph * p = new Paragraph;
1434 p->layout(params.getLyXTextClass().defaultLayoutName());
1435 p->previous(par->previous());
1437 p->params().depth(depth);
1438 par->params().depth(0);
1440 if (par->previous())
1441 par->previous()->next(p);
1443 parBeforeMinipage = p;
1445 if (!first_par || (first_par == par))
1448 InsetMinipage * mini = new InsetMinipage(params);
1449 mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
1450 mini->pageWidth(LyXLength(minipar->params().pextraWidth()));
1451 if (!par->params().pextraWidthp().empty()) {
1452 lyxerr << "WP:" << mini->pageWidth().asString() << endl;
1453 mini->pageWidth(LyXLength((par->params().pextraWidthp())+"col%"));
1456 Paragraph * op = mini->firstParagraph();
1457 mini->inset.paragraph(minipar);
1459 // and free the old ones!
1462 Paragraph * pp = op->next();
1467 // Insert the minipage last in the
1468 // previous paragraph.
1469 if (minipar->params().pextraHfill()) {
1470 parBeforeMinipage->insertChar
1471 (parBeforeMinipage->size(),
1472 Paragraph::META_HFILL, font);
1474 parBeforeMinipage->insertInset
1475 (parBeforeMinipage->size(), mini, font);
1476 } else if (par->params().pextraType() == Paragraph::PEXTRA_INDENT) {
1477 par->params().leftIndent(LyXLength(par->params().pextraWidth()));
1478 if (!par->params().pextraWidthp().empty()) {
1479 par->params().leftIndent(LyXLength((par->params().pextraWidthp())+"col%"));
1483 // End of pextra_minipage compability
1487 return the_end_read;
1490 // needed to insert the selection
1491 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1492 LyXFont const & fn,string const & str) const
1494 LyXLayout_ptr const & layout = par->layout();
1498 par->checkInsertChar(font);
1499 // insert the string, don't insert doublespace
1500 bool space_inserted = true;
1501 bool autobreakrows = !par->inInset() ||
1502 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1503 for(string::const_iterator cit = str.begin();
1504 cit != str.end(); ++cit) {
1506 if (autobreakrows && (par->size() || layout->keepempty)) {
1507 par->breakParagraph(params, pos,
1508 layout->isEnvironment());
1511 space_inserted = true;
1515 // do not insert consecutive spaces if !free_spacing
1516 } else if ((*cit == ' ' || *cit == '\t') &&
1517 space_inserted && !layout->free_spacing &&
1518 !par->isFreeSpacing())
1521 } else if (*cit == '\t') {
1522 if (!layout->free_spacing && !par->isFreeSpacing()) {
1523 // tabs are like spaces here
1524 par->insertChar(pos, ' ', font);
1526 space_inserted = true;
1528 const pos_type nb = 8 - pos % 8;
1529 for (pos_type a = 0; a < nb ; ++a) {
1530 par->insertChar(pos, ' ', font);
1533 space_inserted = true;
1535 } else if (!IsPrintable(*cit)) {
1536 // Ignore unprintables
1539 // just insert the character
1540 par->insertChar(pos, *cit, font);
1542 space_inserted = (*cit == ' ');
1549 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1550 int & pos, LyXFont & font)
1552 // consistency check
1553 if (lex.getString() != "\\begin_inset") {
1554 lyxerr << "Buffer::readInset: Consistency check failed."
1561 string const tmptok = lex.getString();
1562 last_inset_read = tmptok;
1564 // test the different insets
1565 if (tmptok == "LatexCommand") {
1566 InsetCommandParams inscmd;
1569 string const cmdName = inscmd.getCmdName();
1571 // This strange command allows LyX to recognize "natbib" style
1572 // citations: citet, citep, Citet etc.
1573 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1574 inset = new InsetCitation(inscmd);
1575 } else if (cmdName == "bibitem") {
1576 lex.printError("Wrong place for bibitem");
1577 inset = new InsetBibKey(inscmd);
1578 } else if (cmdName == "BibTeX") {
1579 inset = new InsetBibtex(inscmd);
1580 } else if (cmdName == "index") {
1581 inset = new InsetIndex(inscmd);
1582 } else if (cmdName == "include") {
1583 inset = new InsetInclude(inscmd, *this);
1584 } else if (cmdName == "label") {
1585 inset = new InsetLabel(inscmd);
1586 } else if (cmdName == "url"
1587 || cmdName == "htmlurl") {
1588 inset = new InsetUrl(inscmd);
1589 } else if (cmdName == "ref"
1590 || cmdName == "pageref"
1591 || cmdName == "vref"
1592 || cmdName == "vpageref"
1593 || cmdName == "prettyref") {
1594 if (!inscmd.getOptions().empty()
1595 || !inscmd.getContents().empty()) {
1596 inset = new InsetRef(inscmd, *this);
1598 } else if (cmdName == "tableofcontents") {
1599 inset = new InsetTOC(inscmd);
1600 } else if (cmdName == "listofalgorithms") {
1601 inset = new InsetFloatList("algorithm");
1602 } else if (cmdName == "listoffigures") {
1603 inset = new InsetFloatList("figure");
1604 } else if (cmdName == "listoftables") {
1605 inset = new InsetFloatList("table");
1606 } else if (cmdName == "printindex") {
1607 inset = new InsetPrintIndex(inscmd);
1608 } else if (cmdName == "lyxparent") {
1609 inset = new InsetParent(inscmd, *this);
1612 bool alreadyread = false;
1613 if (tmptok == "Quotes") {
1614 inset = new InsetQuotes;
1615 } else if (tmptok == "External") {
1616 inset = new InsetExternal;
1617 } else if (tmptok == "FormulaMacro") {
1618 inset = new InsetFormulaMacro;
1619 } else if (tmptok == "Formula") {
1620 inset = new InsetFormula;
1621 } else if (tmptok == "Figure") { // Backward compatibility
1622 // inset = new InsetFig(100, 100, *this);
1623 inset = new InsetGraphics;
1624 } else if (tmptok == "Graphics") {
1625 inset = new InsetGraphics;
1626 } else if (tmptok == "Info") {// backwards compatibility
1627 inset = new InsetNote(this,
1628 lex.getLongString("\\end_inset"),
1631 } else if (tmptok == "Note") {
1632 inset = new InsetNote(params);
1633 } else if (tmptok == "Include") {
1634 InsetCommandParams p("Include");
1635 inset = new InsetInclude(p, *this);
1636 } else if (tmptok == "ERT") {
1637 inset = new InsetERT(params);
1638 } else if (tmptok == "Tabular") {
1639 inset = new InsetTabular(*this);
1640 } else if (tmptok == "Text") {
1641 inset = new InsetText(params);
1642 } else if (tmptok == "Foot") {
1643 inset = new InsetFoot(params);
1644 } else if (tmptok == "Marginal") {
1645 inset = new InsetMarginal(params);
1646 } else if (tmptok == "Minipage") {
1647 inset = new InsetMinipage(params);
1648 } else if (tmptok == "Float") {
1650 string tmptok = lex.getString();
1651 inset = new InsetFloat(params, tmptok);
1653 } else if (tmptok == "List") {
1654 inset = new InsetList;
1655 } else if (tmptok == "Theorem") {
1656 inset = new InsetList;
1658 } else if (tmptok == "Caption") {
1659 inset = new InsetCaption(params);
1660 } else if (tmptok == "FloatList") {
1661 inset = new InsetFloatList;
1664 if (inset && !alreadyread) inset->read(this, lex);
1668 par->insertInset(pos, inset, font);
1674 bool Buffer::readFile(LyXLex & lex, Paragraph * par)
1678 string const token(lex.getString());
1679 if (token == "\\lyxformat") { // the first token _must_ be...
1681 string tmp_format = lex.getString();
1682 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1683 // if present remove ".," from string.
1684 string::size_type dot = tmp_format.find_first_of(".,");
1685 //lyxerr << " dot found at " << dot << endl;
1686 if (dot != string::npos)
1687 tmp_format.erase(dot, 1);
1688 file_format = strToInt(tmp_format);
1689 if (file_format == LYX_FORMAT) {
1691 } else if (file_format > LYX_FORMAT) {
1693 Alert::alert(_("Warning!"),
1694 _("LyX file format is newer that what"),
1695 _("is supported in this LyX version. Expect some problems."));
1697 } else if (file_format < LYX_FORMAT) {
1699 if (file_format < 200) {
1700 Alert::alert(_("ERROR!"),
1701 _("Old LyX file format found. "
1702 "Use LyX 0.10.x to read this!"));
1704 } else if (file_format < 220) {
1705 string const command = "lyx2lyx "
1706 + QuoteName(filename_);
1707 cmd_ret const ret = RunCommand(command);
1709 Alert::alert(_("ERROR!"),
1710 _("An error occured while "
1711 "running the conversion script."));
1714 istringstream is(ret.second);
1715 LyXLex tmplex(0, 0);
1716 tmplex.setStream(is);
1717 return readFile(tmplex);
1720 bool the_end = readLyXformat2(lex, par);
1721 params.setPaperStuff();
1724 // the_end was added in 213
1725 if (file_format < 213)
1730 Alert::alert(_("Warning!"),
1731 _("Reading of document is not complete"),
1732 _("Maybe the document is truncated"));
1735 } else { // "\\lyxformat" not found
1736 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1739 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1744 // Should probably be moved to somewhere else: BufferView? LyXView?
1745 bool Buffer::save() const
1747 // We don't need autosaves in the immediate future. (Asger)
1748 resetAutosaveTimers();
1752 if (lyxrc.make_backup) {
1753 s = fileName() + '~';
1754 if (!lyxrc.backupdir_path.empty())
1755 s = AddName(lyxrc.backupdir_path,
1756 subst(os::slashify_path(s),'/','!'));
1758 // Rename is the wrong way of making a backup,
1759 // this is the correct way.
1760 /* truss cp fil fil2:
1761 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1762 stat("LyXVC.lyx", 0xEFFFF688) = 0
1763 open("LyXVC.lyx", O_RDONLY) = 3
1764 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1765 fstat(4, 0xEFFFF508) = 0
1766 fstat(3, 0xEFFFF508) = 0
1767 read(3, " # T h i s f i l e w".., 8192) = 5579
1768 write(4, " # T h i s f i l e w".., 5579) = 5579
1769 read(3, 0xEFFFD4A0, 8192) = 0
1772 chmod("LyXVC3.lyx", 0100644) = 0
1773 lseek(0, 0, SEEK_CUR) = 46440
1777 // Should probably have some more error checking here.
1778 // Doing it this way, also makes the inodes stay the same.
1779 // This is still not a very good solution, in particular we
1780 // might loose the owner of the backup.
1781 FileInfo finfo(fileName());
1782 if (finfo.exist()) {
1783 mode_t fmode = finfo.getMode();
1784 struct utimbuf times = {
1785 finfo.getAccessTime(),
1786 finfo.getModificationTime() };
1788 ifstream ifs(fileName().c_str());
1789 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1794 ::chmod(s.c_str(), fmode);
1796 if (::utime(s.c_str(), ×)) {
1797 lyxerr << "utime error." << endl;
1800 lyxerr << "LyX was not able to make "
1801 "backup copy. Beware." << endl;
1806 if (writeFile(fileName())) {
1808 removeAutosaveFile(fileName());
1810 // Saving failed, so backup is not backup
1811 if (lyxrc.make_backup) {
1812 lyx::rename(s, fileName());
1820 bool Buffer::writeFile(string const & fname) const
1822 if (read_only && (fname == fileName())) {
1826 FileInfo finfo(fname);
1827 if (finfo.exist() && !finfo.writable()) {
1831 ofstream ofs(fname.c_str());
1837 // Use the standard "C" locale for file output.
1838 ofs.imbue(std::locale::classic());
1841 // The top of the file should not be written by params.
1843 // write out a comment in the top of the file
1844 ofs << '#' << lyx_docversion
1845 << " created this file. For more info see http://www.lyx.org/\n"
1846 << "\\lyxformat " << LYX_FORMAT << "\n";
1848 // now write out the buffer paramters.
1849 params.writeFile(ofs);
1851 Paragraph::depth_type depth = 0;
1853 // this will write out all the paragraphs
1854 // using recursive descent.
1855 paragraph->writeFile(this, ofs, params, depth);
1857 // Write marker that shows file is complete
1858 ofs << "\n\\the_end" << endl;
1862 // how to check if close went ok?
1863 // Following is an attempt... (BE 20001011)
1865 // good() returns false if any error occured, including some
1866 // formatting error.
1867 // bad() returns true if something bad happened in the buffer,
1868 // which should include file system full errors.
1875 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1877 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1889 pair<int, string> const addDepth(int depth, int ldepth)
1893 d += (ldepth - depth) * 2;
1894 return make_pair(d, string(d, ' '));
1900 string const Buffer::asciiParagraph(Paragraph const * par,
1901 unsigned int linelen,
1902 bool noparbreak) const
1904 ostringstream buffer;
1905 Paragraph::depth_type depth = 0;
1907 Paragraph::depth_type ltype_depth = 0;
1908 bool ref_printed = false;
1909 // if (!par->previous()) {
1911 // begins or ends a deeper area ?
1912 if (depth != par->params().depth()) {
1913 if (par->params().depth() > depth) {
1914 while (par->params().depth() > depth) {
1918 while (par->params().depth() < depth) {
1924 depth = par->params().depth();
1927 // First write the layout
1928 string const & tmp = par->layout()->name();
1929 if (compare_no_case(tmp, "itemize") == 0) {
1931 ltype_depth = depth + 1;
1932 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1934 ltype_depth = depth + 1;
1935 } else if (contains(ascii_lowercase(tmp), "ection")) {
1937 ltype_depth = depth + 1;
1938 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1940 ltype_depth = depth + 1;
1941 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1943 ltype_depth = depth + 1;
1944 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1947 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1955 /* maybe some vertical spaces */
1957 /* the labelwidthstring used in lists */
1961 /* some pagebreaks? */
1965 /* what about the alignment */
1967 // lyxerr << "Should this ever happen?" << endl;
1970 // linelen <= 0 is special and means we don't have pargraph breaks
1972 string::size_type currlinelen = 0;
1978 buffer << string(depth * 2, ' ');
1979 currlinelen += depth * 2;
1982 // we should probably change to the paragraph language in the
1983 // gettext here (if possible) so that strings are outputted in
1984 // the correct language! (20012712 Jug)
1988 case 4: // (Sub)Paragraph
1989 case 5: // Description
1993 buffer << _("Abstract") << "\n\n";
1996 string const abst = _("Abstract: ");
1998 currlinelen += abst.length();
2001 case 7: // Bibliography
2004 buffer << _("References") << "\n\n";
2007 string const refs = _("References: ");
2009 currlinelen += refs.length();
2017 string const parlab = par->params().labelString();
2018 buffer << parlab << " ";
2019 currlinelen += parlab.length() + 1;
2027 pair<int, string> p = addDepth(depth, ltype_depth);
2029 currlinelen += p.first;
2032 // this is to change the linebreak to do it by word a bit more
2033 // intelligent hopefully! (only in the case where we have a
2034 // max linelenght!) (Jug)
2038 for (pos_type i = 0; i < par->size(); ++i) {
2039 char c = par->getUChar(params, i);
2041 case Paragraph::META_INSET:
2043 Inset const * inset = par->getInset(i);
2047 currlinelen += word.length();
2050 if (inset->ascii(this, buffer, linelen)) {
2051 // to be sure it breaks paragraph
2052 currlinelen += linelen;
2058 case Paragraph::META_NEWLINE:
2060 buffer << word << "\n";
2063 pair<int, string> p = addDepth(depth,
2066 currlinelen = p.first;
2070 case Paragraph::META_HFILL:
2071 buffer << word << "\t";
2072 currlinelen += word.length() + 1;
2079 currlinelen + word.length() > linelen - 10) {
2081 pair<int, string> p =
2082 addDepth(depth, ltype_depth);
2084 currlinelen = p.first;
2087 buffer << word << ' ';
2088 currlinelen += word.length() + 1;
2095 lyxerr[Debug::INFO] <<
2096 "writeAsciiFile: NULL char in structure." << endl;
2098 if ((linelen > 0) &&
2099 (currlinelen + word.length()) > linelen)
2103 pair<int, string> p =
2104 addDepth(depth, ltype_depth);
2106 currlinelen = p.first;
2113 return buffer.str().c_str();
2117 void Buffer::writeFileAscii(string const & fname, int linelen)
2119 ofstream ofs(fname.c_str());
2121 Alert::err_alert(_("Error: Cannot write file:"), fname);
2124 writeFileAscii(ofs, linelen);
2128 void Buffer::writeFileAscii(ostream & ofs, int linelen)
2130 Paragraph * par = paragraph;
2132 ofs << asciiParagraph(par, linelen, par->previous() == 0);
2142 void Buffer::makeLaTeXFile(string const & fname,
2143 string const & original_path,
2144 bool nice, bool only_body, bool only_preamble)
2146 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
2148 ofstream ofs(fname.c_str());
2150 Alert::err_alert(_("Error: Cannot open file: "), fname);
2154 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
2158 lyxerr << "File was not closed properly." << endl;
2163 void Buffer::makeLaTeXFile(ostream & os,
2164 string const & original_path,
2165 bool nice, bool only_body, bool only_preamble)
2167 niceFile = nice; // this will be used by Insetincludes.
2169 tex_code_break_column = lyxrc.ascii_linelen;
2171 // validate the buffer.
2172 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
2173 LaTeXFeatures features(params);
2175 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
2178 // The starting paragraph of the coming rows is the
2179 // first paragraph of the document. (Asger)
2180 texrow.start(paragraph, 0);
2182 if (!only_body && nice) {
2183 os << "%% " << lyx_docversion << " created this file. "
2184 "For more info, see http://www.lyx.org/.\n"
2185 "%% Do not edit unless you really know what "
2190 lyxerr[Debug::INFO] << "lyx header finished" << endl;
2191 // There are a few differences between nice LaTeX and usual files:
2192 // usual is \batchmode and has a
2193 // special input@path to allow the including of figures
2194 // with either \input or \includegraphics (what figinsets do).
2195 // batchmode is not set if there is a tex_code_break_column.
2196 // In this case somebody is interested in the generated LaTeX,
2197 // so this is OK. input@path is set when the actual parameter
2198 // original_path is set. This is done for usual tex-file, but not
2199 // for nice-latex-file. (Matthias 250696)
2202 // code for usual, NOT nice-latex-file
2203 os << "\\batchmode\n"; // changed
2204 // from \nonstopmode
2207 if (!original_path.empty()) {
2208 string inputpath = os::external_path(original_path);
2209 subst(inputpath, "~", "\\string~");
2210 os << "\\makeatletter\n"
2211 << "\\def\\input@path{{"
2212 << inputpath << "/}}\n"
2213 << "\\makeatother\n";
2219 os << "\\documentclass";
2221 LyXTextClass const & tclass = params.getLyXTextClass();
2223 ostringstream options; // the document class options.
2225 if (tokenPos(tclass.opt_fontsize(),
2226 '|', params.fontsize) >= 0) {
2227 // only write if existing in list (and not default)
2228 options << params.fontsize << "pt,";
2232 if (!params.use_geometry &&
2233 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
2234 switch (params.papersize) {
2235 case BufferParams::PAPER_A4PAPER:
2236 options << "a4paper,";
2238 case BufferParams::PAPER_USLETTER:
2239 options << "letterpaper,";
2241 case BufferParams::PAPER_A5PAPER:
2242 options << "a5paper,";
2244 case BufferParams::PAPER_B5PAPER:
2245 options << "b5paper,";
2247 case BufferParams::PAPER_EXECUTIVEPAPER:
2248 options << "executivepaper,";
2250 case BufferParams::PAPER_LEGALPAPER:
2251 options << "legalpaper,";
2257 if (params.sides != tclass.sides()) {
2258 switch (params.sides) {
2259 case LyXTextClass::OneSide:
2260 options << "oneside,";
2262 case LyXTextClass::TwoSides:
2263 options << "twoside,";
2269 if (params.columns != tclass.columns()) {
2270 if (params.columns == 2)
2271 options << "twocolumn,";
2273 options << "onecolumn,";
2276 if (!params.use_geometry
2277 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2278 options << "landscape,";
2280 // language should be a parameter to \documentclass
2282 ostringstream language_options;
2283 if (params.language->babel() == "hebrew"
2284 && default_language->babel() != "hebrew")
2285 // This seems necessary
2286 features.useLanguage(default_language);
2288 if (lyxrc.language_use_babel ||
2289 params.language->lang() != lyxrc.default_language ||
2290 features.hasLanguages()) {
2292 language_options << features.getLanguages();
2293 language_options << params.language->babel();
2294 if (lyxrc.language_global_options)
2295 options << language_options.str() << ',';
2298 // the user-defined options
2299 if (!params.options.empty()) {
2300 options << params.options << ',';
2303 string strOptions(options.str().c_str());
2304 if (!strOptions.empty()) {
2305 strOptions = rtrim(strOptions, ",");
2306 os << '[' << strOptions << ']';
2309 os << '{' << tclass.latexname() << "}\n";
2311 // end of \documentclass defs
2313 // font selection must be done before loading fontenc.sty
2314 // The ae package is not needed when using OT1 font encoding.
2315 if (params.fonts != "default" &&
2316 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
2317 os << "\\usepackage{" << params.fonts << "}\n";
2319 if (params.fonts == "ae") {
2320 os << "\\usepackage{aecompl}\n";
2324 // this one is not per buffer
2325 if (lyxrc.fontenc != "default") {
2326 os << "\\usepackage[" << lyxrc.fontenc
2331 if (params.inputenc == "auto") {
2332 string const doc_encoding =
2333 params.language->encoding()->LatexName();
2335 // Create a list with all the input encodings used
2337 set<string> encodings = features.getEncodingSet(doc_encoding);
2339 os << "\\usepackage[";
2340 std::copy(encodings.begin(), encodings.end(),
2341 std::ostream_iterator<string>(os, ","));
2342 os << doc_encoding << "]{inputenc}\n";
2344 } else if (params.inputenc != "default") {
2345 os << "\\usepackage[" << params.inputenc
2350 // At the very beginning the text parameters.
2351 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2352 switch (params.paperpackage) {
2353 case BufferParams::PACKAGE_A4:
2354 os << "\\usepackage{a4}\n";
2357 case BufferParams::PACKAGE_A4WIDE:
2358 os << "\\usepackage{a4wide}\n";
2361 case BufferParams::PACKAGE_WIDEMARGINSA4:
2362 os << "\\usepackage[widemargins]{a4}\n";
2367 if (params.use_geometry) {
2368 os << "\\usepackage{geometry}\n";
2370 os << "\\geometry{verbose";
2371 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2373 switch (params.papersize2) {
2374 case BufferParams::VM_PAPER_CUSTOM:
2375 if (!params.paperwidth.empty())
2376 os << ",paperwidth="
2377 << params.paperwidth;
2378 if (!params.paperheight.empty())
2379 os << ",paperheight="
2380 << params.paperheight;
2382 case BufferParams::VM_PAPER_USLETTER:
2383 os << ",letterpaper";
2385 case BufferParams::VM_PAPER_USLEGAL:
2386 os << ",legalpaper";
2388 case BufferParams::VM_PAPER_USEXECUTIVE:
2389 os << ",executivepaper";
2391 case BufferParams::VM_PAPER_A3:
2394 case BufferParams::VM_PAPER_A4:
2397 case BufferParams::VM_PAPER_A5:
2400 case BufferParams::VM_PAPER_B3:
2403 case BufferParams::VM_PAPER_B4:
2406 case BufferParams::VM_PAPER_B5:
2410 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2411 switch (lyxrc.default_papersize) {
2412 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2413 case BufferParams::PAPER_USLETTER:
2414 os << ",letterpaper";
2416 case BufferParams::PAPER_LEGALPAPER:
2417 os << ",legalpaper";
2419 case BufferParams::PAPER_EXECUTIVEPAPER:
2420 os << ",executivepaper";
2422 case BufferParams::PAPER_A3PAPER:
2425 case BufferParams::PAPER_A4PAPER:
2428 case BufferParams::PAPER_A5PAPER:
2431 case BufferParams::PAPER_B5PAPER:
2436 if (!params.topmargin.empty())
2437 os << ",tmargin=" << params.topmargin;
2438 if (!params.bottommargin.empty())
2439 os << ",bmargin=" << params.bottommargin;
2440 if (!params.leftmargin.empty())
2441 os << ",lmargin=" << params.leftmargin;
2442 if (!params.rightmargin.empty())
2443 os << ",rmargin=" << params.rightmargin;
2444 if (!params.headheight.empty())
2445 os << ",headheight=" << params.headheight;
2446 if (!params.headsep.empty())
2447 os << ",headsep=" << params.headsep;
2448 if (!params.footskip.empty())
2449 os << ",footskip=" << params.footskip;
2454 if (tokenPos(tclass.opt_pagestyle(),
2455 '|', params.pagestyle) >= 0) {
2456 if (params.pagestyle == "fancy") {
2457 os << "\\usepackage{fancyhdr}\n";
2460 os << "\\pagestyle{" << params.pagestyle << "}\n";
2464 if (params.secnumdepth != tclass.secnumdepth()) {
2465 os << "\\setcounter{secnumdepth}{"
2466 << params.secnumdepth
2470 if (params.tocdepth != tclass.tocdepth()) {
2471 os << "\\setcounter{tocdepth}{"
2477 if (params.paragraph_separation) {
2478 switch (params.defskip.kind()) {
2479 case VSpace::SMALLSKIP:
2480 os << "\\setlength\\parskip{\\smallskipamount}\n";
2482 case VSpace::MEDSKIP:
2483 os << "\\setlength\\parskip{\\medskipamount}\n";
2485 case VSpace::BIGSKIP:
2486 os << "\\setlength\\parskip{\\bigskipamount}\n";
2488 case VSpace::LENGTH:
2489 os << "\\setlength\\parskip{"
2490 << params.defskip.length().asLatexString()
2493 default: // should never happen // Then delete it.
2494 os << "\\setlength\\parskip{\\medskipamount}\n";
2499 os << "\\setlength\\parindent{0pt}\n";
2503 // Now insert the LyX specific LaTeX commands...
2505 // The optional packages;
2506 string preamble(features.getPackages());
2508 // this might be useful...
2509 preamble += "\n\\makeatletter\n";
2511 // Some macros LyX will need
2512 string tmppreamble(features.getMacros());
2514 if (!tmppreamble.empty()) {
2515 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2516 "LyX specific LaTeX commands.\n"
2517 + tmppreamble + '\n';
2520 // the text class specific preamble
2521 tmppreamble = features.getTClassPreamble();
2522 if (!tmppreamble.empty()) {
2523 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2524 "Textclass specific LaTeX commands.\n"
2525 + tmppreamble + '\n';
2528 /* the user-defined preamble */
2529 if (!params.preamble.empty()) {
2530 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2531 "User specified LaTeX commands.\n"
2532 + params.preamble + '\n';
2535 // Itemize bullet settings need to be last in case the user
2536 // defines their own bullets that use a package included
2537 // in the user-defined preamble -- ARRae
2538 // Actually it has to be done much later than that
2539 // since some packages like frenchb make modifications
2540 // at \begin{document} time -- JMarc
2542 for (int i = 0; i < 4; ++i) {
2543 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2544 if (bullets_def.empty())
2545 bullets_def="\\AtBeginDocument{\n";
2546 bullets_def += " \\renewcommand{\\labelitemi";
2548 // `i' is one less than the item to modify
2555 bullets_def += "ii";
2561 bullets_def += "}{" +
2562 params.user_defined_bullets[i].getText()
2567 if (!bullets_def.empty())
2568 preamble += bullets_def + "}\n\n";
2571 int(lyx::count(preamble.begin(), preamble.end(), '\n'));
2572 for (int j = 0; j != nlines; ++j) {
2576 // We try to load babel late, in case it interferes
2577 // with other packages.
2579 string tmp = lyxrc.language_package;
2580 if (!lyxrc.language_global_options
2581 && tmp == "\\usepackage{babel}")
2582 tmp = string("\\usepackage[") +
2583 language_options.str().c_str() +
2585 preamble += tmp + "\n";
2586 preamble += features.getBabelOptions();
2589 preamble += "\\makeatother\n";
2597 os << "\\begin{document}\n";
2600 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
2602 if (!lyxrc.language_auto_begin) {
2603 os << subst(lyxrc.language_command_begin, "$$lang",
2604 params.language->babel())
2609 latexParagraphs(os, paragraph, 0, texrow);
2611 // add this just in case after all the paragraphs
2615 if (!lyxrc.language_auto_end) {
2616 os << subst(lyxrc.language_command_end, "$$lang",
2617 params.language->babel())
2623 os << "\\end{document}\n";
2626 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2628 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2632 // Just to be sure. (Asger)
2635 // tex_code_break_column's value is used to decide
2636 // if we are in batchmode or not (within mathed_write()
2637 // in math_write.C) so we must set it to a non-zero
2638 // value when we leave otherwise we save incorrect .lyx files.
2639 tex_code_break_column = lyxrc.ascii_linelen;
2641 lyxerr[Debug::INFO] << "Finished making latex file." << endl;
2642 lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
2644 // we want this to be true outside previews (for insetexternal)
2650 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2652 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
2653 Paragraph * endpar, TexRow & texrow,
2654 bool moving_arg) const
2656 bool was_title = false;
2657 bool already_title = false;
2660 while (par != endpar) {
2661 Inset * in = par->inInset();
2662 // well we have to check if we are in an inset with unlimited
2663 // lenght (all in one row) if that is true then we don't allow
2664 // any special options in the paragraph and also we don't allow
2665 // any environment other then "Standard" to be valid!
2666 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
2667 LyXLayout_ptr const & layout = par->layout();
2669 if (layout->intitle) {
2670 if (already_title) {
2671 lyxerr <<"Error in latexParagraphs: You"
2672 " should not mix title layouts"
2673 " with normal ones." << endl;
2676 } else if (was_title && !already_title) {
2677 ofs << "\\maketitle\n";
2679 already_title = true;
2683 if (layout->isEnvironment() ||
2684 !par->params().leftIndent().zero())
2686 par = par->TeXEnvironment(this, params, ofs, texrow);
2688 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2691 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
2694 // It might be that we only have a title in this document
2695 if (was_title && !already_title) {
2696 ofs << "\\maketitle\n";
2702 bool Buffer::isLatex() const
2704 return params.getLyXTextClass().outputType() == LATEX;
2708 bool Buffer::isLinuxDoc() const
2710 return params.getLyXTextClass().outputType() == LINUXDOC;
2714 bool Buffer::isLiterate() const
2716 return params.getLyXTextClass().outputType() == LITERATE;
2720 bool Buffer::isDocBook() const
2722 return params.getLyXTextClass().outputType() == DOCBOOK;
2726 bool Buffer::isSGML() const
2728 LyXTextClass const & tclass = params.getLyXTextClass();
2730 return tclass.outputType() == LINUXDOC ||
2731 tclass.outputType() == DOCBOOK;
2735 int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2736 string const & latexname) const
2738 if (!latexname.empty() && latexname != "!-- --") {
2740 os << string(" ",depth);
2741 os << "<" << latexname << ">";
2751 int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont,
2752 string const & latexname) const
2754 if (!latexname.empty() && latexname != "!-- --") {
2756 os << endl << string(" ",depth);
2757 os << "</" << latexname << ">";
2767 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2769 ofstream ofs(fname.c_str());
2772 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2776 niceFile = nice; // this will be used by included files.
2778 LaTeXFeatures features(params);
2784 LyXTextClass const & tclass = params.getLyXTextClass();
2786 string top_element = tclass.latexname();
2789 ofs << "<!doctype linuxdoc system";
2791 string preamble = params.preamble;
2792 const string name = nice ? ChangeExtension(filename_, ".sgml")
2794 preamble += features.getIncludedFiles(name);
2795 preamble += features.getLyXSGMLEntities();
2797 if (!preamble.empty()) {
2798 ofs << " [ " << preamble << " ]";
2802 if (params.options.empty())
2803 sgmlOpenTag(ofs, 0, false, top_element);
2805 string top = top_element;
2807 top += params.options;
2808 sgmlOpenTag(ofs, 0, false, top);
2812 ofs << "<!-- " << lyx_docversion
2813 << " created this file. For more info see http://www.lyx.org/"
2816 Paragraph::depth_type depth = 0; // paragraph depth
2817 Paragraph * par = paragraph;
2819 vector<string> environment_stack(5);
2822 LyXLayout_ptr const & style = par->layout();
2823 // treat <toc> as a special case for compatibility with old code
2824 if (par->isInset(0)) {
2825 Inset * inset = par->getInset(0);
2826 Inset::Code lyx_code = inset->lyxCode();
2827 if (lyx_code == Inset::TOC_CODE) {
2828 string const temp = "toc";
2829 sgmlOpenTag(ofs, depth, false, temp);
2836 // environment tag closing
2837 for (; depth > par->params().depth(); --depth) {
2838 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2839 environment_stack[depth].erase();
2842 // write opening SGML tags
2843 switch (style->latextype) {
2844 case LATEX_PARAGRAPH:
2845 if (depth == par->params().depth()
2846 && !environment_stack[depth].empty()) {
2847 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2848 environment_stack[depth].erase();
2854 sgmlOpenTag(ofs, depth, false, style->latexname());
2860 _("Error : Wrong depth for"
2861 " LatexType Command.\n"));
2863 if (!environment_stack[depth].empty()) {
2864 sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
2868 environment_stack[depth].erase();
2869 sgmlOpenTag(ofs, depth, false, style->latexname());
2872 case LATEX_ENVIRONMENT:
2873 case LATEX_ITEM_ENVIRONMENT:
2875 string const & latexname = style->latexname();
2877 if (depth == par->params().depth()
2878 && environment_stack[depth] != latexname) {
2879 sgmlCloseTag(ofs, depth, false,
2880 environment_stack[depth]);
2881 environment_stack[depth].erase();
2883 if (depth < par->params().depth()) {
2884 depth = par->params().depth();
2885 environment_stack[depth].erase();
2887 if (environment_stack[depth] != latexname) {
2889 sgmlOpenTag(ofs, depth, false, "p");
2891 sgmlOpenTag(ofs, depth, false, latexname);
2893 if (environment_stack.size() == depth + 1)
2894 environment_stack.push_back("!-- --");
2895 environment_stack[depth] = latexname;
2898 if (style->latexparam() == "CDATA")
2901 if (style->latextype == LATEX_ENVIRONMENT) break;
2903 if (style->labeltype == LABEL_MANUAL)
2908 sgmlOpenTag(ofs, depth + 1, false, item_name);
2913 sgmlOpenTag(ofs, depth, false, style->latexname());
2917 simpleLinuxDocOnePar(ofs, par, depth);
2922 // write closing SGML tags
2923 switch (style->latextype) {
2926 case LATEX_ENVIRONMENT:
2927 case LATEX_ITEM_ENVIRONMENT:
2928 if (style->latexparam() == "CDATA")
2932 sgmlCloseTag(ofs, depth, false, style->latexname());
2938 for (int i = depth; i >= 0; --i)
2939 sgmlCloseTag(ofs, depth, false, environment_stack[i]);
2943 sgmlCloseTag(ofs, 0, false, top_element);
2947 // How to check for successful close
2949 // we want this to be true outside previews (for insetexternal)
2954 // checks, if newcol chars should be put into this line
2955 // writes newline, if necessary.
2958 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2959 string::size_type newcol)
2962 if (colcount > lyxrc.ascii_linelen) {
2964 colcount = newcol; // assume write after this call
2979 string tag_name(PAR_TAG const & pt) {
2981 case NONE: return "!-- --";
2982 case TT: return "tt";
2983 case SF: return "sf";
2984 case BF: return "bf";
2985 case IT: return "it";
2986 case SL: return "sl";
2987 case EM: return "em";
2994 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2996 p1 = static_cast<PAR_TAG>(p1 | p2);
3001 void reset(PAR_TAG & p1, PAR_TAG const & p2)
3003 p1 = static_cast<PAR_TAG>(p1 & ~p2);
3009 // Handle internal paragraph parsing -- layout already processed.
3010 void Buffer::simpleLinuxDocOnePar(ostream & os,
3012 Paragraph::depth_type /*depth*/)
3014 LyXLayout_ptr const & style = par->layout();
3016 string::size_type char_line_count = 5; // Heuristic choice ;-)
3018 // gets paragraph main font
3021 if (style->labeltype == LABEL_MANUAL) {
3022 font_old = style->labelfont;
3025 font_old = style->font;
3029 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
3030 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
3031 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
3034 stack<PAR_TAG> tag_state;
3035 // parsing main loop
3036 for (pos_type i = 0; i < par->size(); ++i) {
3038 PAR_TAG tag_close = NONE;
3039 list < PAR_TAG > tag_open;
3041 LyXFont const font = par->getFont(params, i);
3043 if (font_old.family() != font.family()) {
3044 switch (family_type) {
3045 case LyXFont::SANS_FAMILY:
3048 case LyXFont::TYPEWRITER_FAMILY:
3055 family_type = font.family();
3057 switch (family_type) {
3058 case LyXFont::SANS_FAMILY:
3059 tag_open.push_back(SF);
3061 case LyXFont::TYPEWRITER_FAMILY:
3062 tag_open.push_back(TT);
3069 if (font_old.series() != font.series()) {
3070 switch (series_type) {
3071 case LyXFont::BOLD_SERIES:
3078 series_type = font.series();
3080 switch (series_type) {
3081 case LyXFont::BOLD_SERIES:
3082 tag_open.push_back(BF);
3090 if (font_old.shape() != font.shape()) {
3091 switch (shape_type) {
3092 case LyXFont::ITALIC_SHAPE:
3095 case LyXFont::SLANTED_SHAPE:
3102 shape_type = font.shape();
3104 switch (shape_type) {
3105 case LyXFont::ITALIC_SHAPE:
3106 tag_open.push_back(IT);
3108 case LyXFont::SLANTED_SHAPE:
3109 tag_open.push_back(SL);
3116 if (font_old.emph() != font.emph()) {
3117 if (font.emph() == LyXFont::ON) {
3118 tag_open.push_back(EM);
3127 list < PAR_TAG > temp;
3128 while (!tag_state.empty() && tag_close) {
3129 PAR_TAG k = tag_state.top();
3131 os << "</" << tag_name(k) << ">";
3138 for(list< PAR_TAG >::const_iterator j = temp.begin();
3139 j != temp.end(); ++j) {
3141 os << "<" << tag_name(*j) << ">";
3144 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
3145 j != tag_open.end(); ++j) {
3147 os << "<" << tag_name(*j) << ">";
3150 char c = par->getChar(i);
3152 if (c == Paragraph::META_INSET) {
3153 Inset * inset = par->getInset(i);
3154 inset->linuxdoc(this, os);
3159 if (style->latexparam() == "CDATA") {
3160 // "TeX"-Mode on == > SGML-Mode on.
3166 if (par->sgmlConvertChar(c, sgml_string)
3167 && !style->free_spacing && !par->isFreeSpacing())
3169 // in freespacing mode, spaces are
3170 // non-breaking characters
3171 if (desc_on) {// if char is ' ' then...
3174 sgmlLineBreak(os, char_line_count, 6);
3178 sgmlLineBreak(os, char_line_count, 1);
3183 char_line_count += sgml_string.length();
3189 while (!tag_state.empty()) {
3190 os << "</" << tag_name(tag_state.top()) << ">";
3194 // resets description flag correctly
3196 // <tag> not closed...
3197 sgmlLineBreak(os, char_line_count, 6);
3203 // Print an error message.
3204 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
3205 string const & /*message*/) const
3207 #ifdef WITH_WARNINGS
3208 #warning This is wrong we cannot insert an inset like this!!!
3209 // I guess this was Jose' so I explain you more or less why this
3210 // is wrong. This way you insert something in the paragraph and
3211 // don't tell it to LyXText (row rebreaking and undo handling!!!)
3212 // I deactivate this code, have a look at BufferView::insertErrors
3213 // how you should do this correctly! (Jug 20020315)
3216 // insert an error marker in text
3217 InsetError * new_inset = new InsetError(message);
3218 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
3224 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3226 ofstream ofs(fname.c_str());
3228 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3232 Paragraph * par = paragraph;
3234 niceFile = nice; // this will be used by Insetincludes.
3236 LaTeXFeatures features(params);
3241 LyXTextClass const & tclass = params.getLyXTextClass();
3242 string top_element = tclass.latexname();
3245 ofs << "<!DOCTYPE " << top_element
3246 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
3248 string preamble = params.preamble;
3249 const string name = nice ? ChangeExtension(filename_, ".sgml")
3251 preamble += features.getIncludedFiles(name);
3252 preamble += features.getLyXSGMLEntities();
3254 if (!preamble.empty()) {
3255 ofs << "\n [ " << preamble << " ]";
3260 string top = top_element;
3262 top += params.language->code();
3265 if (!params.options.empty()) {
3267 top += params.options;
3269 sgmlOpenTag(ofs, 0, false, top);
3271 ofs << "<!-- DocBook file was created by " << lyx_docversion
3272 << "\n See http://www.lyx.org/ for more information -->\n";
3274 vector<string> environment_stack(10);
3275 vector<string> environment_inner(10);
3276 vector<string> command_stack(10);
3278 bool command_flag = false;
3279 Paragraph::depth_type command_depth = 0;
3280 Paragraph::depth_type command_base = 0;
3281 Paragraph::depth_type cmd_depth = 0;
3282 Paragraph::depth_type depth = 0; // paragraph depth
3285 string command_name;
3291 int desc_on = 0; // description mode
3293 LyXLayout_ptr const & style = par->layout();
3295 // environment tag closing
3296 for (; depth > par->params().depth(); --depth) {
3297 if (environment_inner[depth] != "!-- --") {
3298 item_name = "listitem";
3299 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3300 if (environment_inner[depth] == "varlistentry")
3301 sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
3303 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3304 environment_stack[depth].erase();
3305 environment_inner[depth].erase();
3308 if (depth == par->params().depth()
3309 && environment_stack[depth] != style->latexname()
3310 && !environment_stack[depth].empty()) {
3311 if (environment_inner[depth] != "!-- --") {
3312 item_name= "listitem";
3313 sgmlCloseTag(ofs, command_depth+depth, false, item_name);
3314 if (environment_inner[depth] == "varlistentry")
3315 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3318 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3320 environment_stack[depth].erase();
3321 environment_inner[depth].erase();
3324 // Write opening SGML tags.
3325 switch (style->latextype) {
3326 case LATEX_PARAGRAPH:
3327 sgmlOpenTag(ofs, depth + command_depth,
3328 false, style->latexname());
3334 _("Error : Wrong depth for "
3335 "LatexType Command.\n"));
3337 command_name = style->latexname();
3339 sgmlparam = style->latexparam();
3340 c_params = split(sgmlparam, c_depth,'|');
3342 cmd_depth = lyx::atoi(c_depth);
3345 if (cmd_depth < command_base) {
3346 for (Paragraph::depth_type j = command_depth;
3347 j >= command_base; --j) {
3348 sgmlCloseTag(ofs, j, false, command_stack[j]);
3351 command_depth = command_base = cmd_depth;
3352 } else if (cmd_depth <= command_depth) {
3353 for (int j = command_depth;
3354 j >= int(cmd_depth); --j) {
3355 sgmlCloseTag(ofs, j, false, command_stack[j]);
3358 command_depth = cmd_depth;
3360 command_depth = cmd_depth;
3362 command_depth = command_base = cmd_depth;
3363 command_flag = true;
3365 if (command_stack.size() == command_depth + 1)
3366 command_stack.push_back(string());
3367 command_stack[command_depth] = command_name;
3369 // treat label as a special case for
3370 // more WYSIWYM handling.
3371 // This is a hack while paragraphs can't have
3372 // attributes, like id in this case.
3373 if (par->isInset(0)) {
3374 Inset * inset = par->getInset(0);
3375 Inset::Code lyx_code = inset->lyxCode();
3376 if (lyx_code == Inset::LABEL_CODE) {
3377 command_name += " id=\"";
3378 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3379 command_name += "\"";
3384 sgmlOpenTag(ofs, depth + command_depth, false, command_name);
3386 item_name = c_params.empty()?"title":c_params;
3387 sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
3390 case LATEX_ENVIRONMENT:
3391 case LATEX_ITEM_ENVIRONMENT:
3392 if (depth < par->params().depth()) {
3393 depth = par->params().depth();
3394 environment_stack[depth].erase();
3397 if (environment_stack[depth] != style->latexname()) {
3398 if (environment_stack.size() == depth + 1) {
3399 environment_stack.push_back("!-- --");
3400 environment_inner.push_back("!-- --");
3402 environment_stack[depth] = style->latexname();
3403 environment_inner[depth] = "!-- --";
3404 sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
3406 if (environment_inner[depth] != "!-- --") {
3407 item_name= "listitem";
3408 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3409 if (environment_inner[depth] == "varlistentry")
3410 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3414 if (style->latextype == LATEX_ENVIRONMENT) {
3415 if (!style->latexparam().empty()) {
3416 if (style->latexparam() == "CDATA")
3419 sgmlOpenTag(ofs, depth + command_depth, false, style->latexparam());
3424 desc_on = (style->labeltype == LABEL_MANUAL);
3426 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
3427 sgmlOpenTag(ofs, depth + 1 + command_depth,
3428 false, environment_inner[depth]);
3430 item_name = desc_on ? "term" : "para";
3431 sgmlOpenTag(ofs, depth + 1 + command_depth,
3435 sgmlOpenTag(ofs, depth + command_depth,
3436 false, style->latexname());
3440 simpleDocBookOnePar(ofs, par, desc_on,
3441 depth + 1 + command_depth);
3445 // write closing SGML tags
3446 switch (style->latextype) {
3448 end_tag = c_params.empty() ? "title" : c_params;
3449 sgmlCloseTag(ofs, depth + command_depth,
3452 case LATEX_ENVIRONMENT:
3453 if (!style->latexparam().empty()) {
3454 if (style->latexparam() == "CDATA")
3457 sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
3460 case LATEX_ITEM_ENVIRONMENT:
3461 if (desc_on == 1) break;
3463 sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
3465 case LATEX_PARAGRAPH:
3466 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3469 sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
3475 for (int d = depth; d >= 0; --d) {
3476 if (!environment_stack[depth].empty()) {
3477 if (environment_inner[depth] != "!-- --") {
3478 item_name = "listitem";
3479 sgmlCloseTag(ofs, command_depth + depth, false, item_name);
3480 if (environment_inner[depth] == "varlistentry")
3481 sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
3484 sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
3488 for (int j = command_depth; j >= 0 ; --j)
3489 if (!command_stack[j].empty()) {
3490 sgmlCloseTag(ofs, j, false, command_stack[j]);
3495 sgmlCloseTag(ofs, 0, false, top_element);
3498 // How to check for successful close
3500 // we want this to be true outside previews (for insetexternal)
3505 void Buffer::simpleDocBookOnePar(ostream & os,
3506 Paragraph * par, int & desc_on,
3507 Paragraph::depth_type depth) const
3509 bool emph_flag = false;
3511 LyXLayout_ptr const & style = par->layout();
3513 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
3515 int char_line_count = depth;
3516 //if (!style.free_spacing)
3517 // os << string(depth,' ');
3519 // parsing main loop
3520 for (pos_type i = 0; i < par->size(); ++i) {
3521 LyXFont font = par->getFont(params, i);
3523 // handle <emphasis> tag
3524 if (font_old.emph() != font.emph()) {
3525 if (font.emph() == LyXFont::ON) {
3526 if (style->latexparam() == "CDATA")
3529 if (style->latexparam() == "CDATA")
3533 if (style->latexparam() == "CDATA")
3535 os << "</emphasis>";
3536 if (style->latexparam() == "CDATA")
3543 if (par->isInset(i)) {
3544 Inset * inset = par->getInset(i);
3545 // don't print the inset in position 0 if desc_on == 3 (label)
3546 if (i || desc_on != 3) {
3547 if (style->latexparam() == "CDATA")
3549 inset->docbook(this, os, false);
3550 if (style->latexparam() == "CDATA")
3554 char c = par->getChar(i);
3556 par->sgmlConvertChar(c, sgml_string);
3558 if (style->pass_thru) {
3560 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
3562 } else if (desc_on ==1) {
3564 os << "\n</term><listitem><para>";
3574 if (style->latexparam() == "CDATA")
3576 os << "</emphasis>";
3577 if (style->latexparam() == "CDATA")
3581 // resets description flag correctly
3583 // <term> not closed...
3584 os << "</term>\n<listitem><para> </para>";
3586 if (style->free_spacing)
3591 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3592 // Other flags: -wall -v0 -x
3593 int Buffer::runChktex()
3595 if (!users->text) return 0;
3597 users->owner()->prohibitInput();
3599 // get LaTeX-Filename
3600 string const name = getLatexName();
3601 string path = filePath();
3603 string const org_path = path;
3604 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
3608 Path p(path); // path to LaTeX file
3609 users->owner()->message(_("Running chktex..."));
3611 // Remove all error insets
3612 bool const removedErrorInsets = users->removeAutoInsets();
3614 // Generate the LaTeX file if neccessary
3615 makeLaTeXFile(name, org_path, false);
3618 Chktex chktex(lyxrc.chktex_command, name, filePath());
3619 int res = chktex.run(terr); // run chktex
3622 Alert::alert(_("chktex did not work!"),
3623 _("Could not run with file:"), name);
3624 } else if (res > 0) {
3625 // Insert all errors as errors boxes
3626 users->insertErrors(terr);
3629 // if we removed error insets before we ran chktex or if we inserted
3630 // error insets after we ran chktex, this must be run:
3631 if (removedErrorInsets || res) {
3632 #warning repaint needed here, or do you mean update() ?
3636 users->owner()->allowInput();
3642 void Buffer::validate(LaTeXFeatures & features) const
3644 Paragraph * par = paragraph;
3645 LyXTextClass const & tclass = params.getLyXTextClass();
3647 // AMS Style is at document level
3648 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
3649 features.require("amsmath");
3652 // We don't use "lyxerr.debug" because of speed. (Asger)
3653 if (lyxerr.debugging(Debug::LATEX))
3654 lyxerr << "Paragraph: " << par << endl;
3656 // Now just follow the list of paragraphs and run
3657 // validate on each of them.
3658 par->validate(features);
3660 // and then the next paragraph
3664 // the bullet shapes are buffer level not paragraph level
3665 // so they are tested here
3666 for (int i = 0; i < 4; ++i) {
3667 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3668 int const font = params.user_defined_bullets[i].getFont();
3670 int const c = params
3671 .user_defined_bullets[i]
3678 features.require("latexsym");
3680 } else if (font == 1) {
3681 features.require("amssymb");
3682 } else if ((font >= 2 && font <= 5)) {
3683 features.require("pifont");
3688 if (lyxerr.debugging(Debug::LATEX)) {
3689 features.showStruct();
3694 // This function should be in Buffer because it's a buffer's property (ale)
3695 string const Buffer::getIncludeonlyList(char delim)
3698 for (inset_iterator it = inset_iterator_begin();
3699 it != inset_iterator_end(); ++it) {
3700 if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3701 InsetInclude * insetinc =
3702 static_cast<InsetInclude *>(*it);
3703 if (insetinc->isIncludeOnly()) {
3706 lst += insetinc->getRelFileBaseName();
3710 lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
3715 vector<string> const Buffer::getLabelList()
3717 /// if this is a child document and the parent is already loaded
3718 /// Use the parent's list instead [ale990407]
3719 if (!params.parentname.empty()
3720 && bufferlist.exists(params.parentname)) {
3721 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3723 return tmp->getLabelList();
3726 vector<string> label_list;
3727 for (inset_iterator it = inset_iterator_begin();
3728 it != inset_iterator_end(); ++it) {
3729 vector<string> const l = (*it)->getLabelList();
3730 label_list.insert(label_list.end(), l.begin(), l.end());
3736 // This is also a buffer property (ale)
3737 vector<pair<string, string> > const Buffer::getBibkeyList() const
3739 typedef pair<string, string> StringPair;
3740 /// if this is a child document and the parent is already loaded
3741 /// Use the parent's list instead [ale990412]
3742 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3743 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
3745 return tmp->getBibkeyList();
3748 vector<StringPair> keys;
3749 Paragraph * par = paragraph;
3752 string const key = par->bibkey->getContents();
3753 string const opt = par->bibkey->getOptions();
3754 string const ref = par->asString(this, false);
3755 string const info = opt + "TheBibliographyRef" + ref;
3757 keys.push_back(StringPair(key, info));
3762 // Might be either using bibtex or a child has bibliography
3764 for (inset_iterator it = inset_const_iterator_begin();
3765 it != inset_const_iterator_end(); ++it) {
3766 // Search for Bibtex or Include inset
3767 if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
3768 vector<StringPair> tmp =
3769 static_cast<InsetBibtex*>(*it)->getKeys(this);
3770 keys.insert(keys.end(), tmp.begin(), tmp.end());
3771 } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
3772 vector<StringPair> const tmp =
3773 static_cast<InsetInclude*>(*it)->getKeys();
3774 keys.insert(keys.end(), tmp.begin(), tmp.end());
3783 bool Buffer::isDepClean(string const & name) const
3785 DEPCLEAN * item = dep_clean;
3786 while (item && item->master != name)
3788 if (!item) return true;
3793 void Buffer::markDepClean(string const & name)
3796 dep_clean = new DEPCLEAN;
3797 dep_clean->clean = true;
3798 dep_clean->master = name;
3799 dep_clean->next = 0;
3801 DEPCLEAN * item = dep_clean;
3802 while (item && item->master != name)
3807 item = new DEPCLEAN;
3809 item->master = name;
3816 bool Buffer::dispatch(string const & command, bool * result)
3818 // Split command string into command and argument
3820 string line = ltrim(command);
3821 string const arg = trim(split(line, cmd, ' '));
3823 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
3827 bool Buffer::dispatch(int action, string const & argument, bool * result)
3829 bool dispatched = true;
3833 bool const tmp = Exporter::Export(this, argument, false);
3846 void Buffer::resizeInsets(BufferView * bv)
3848 /// then remove all LyXText in text-insets
3849 Paragraph * par = paragraph;
3850 for (; par; par = par->next()) {
3851 par->resizeInsetsLyXText(bv);
3856 void Buffer::redraw()
3858 #warning repaint needed here, or do you mean update() ?
3864 void Buffer::changeLanguage(Language const * from, Language const * to)
3867 ParIterator end = par_iterator_end();
3868 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3869 (*it)->changeLanguage(params, from, to);
3873 bool Buffer::isMultiLingual()
3875 ParIterator end = par_iterator_end();
3876 for (ParIterator it = par_iterator_begin(); it != end; ++it)
3877 if ((*it)->isMultiLingual(params))
3884 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
3887 it = par->InsetIterator(pos);
3888 if (it == par->inset_iterator_end()) {
3895 void Buffer::inset_iterator::setParagraph()
3898 it = par->inset_iterator_begin();
3899 if (it != par->inset_iterator_end())
3904 // We maintain an invariant that whenever par = 0 then it = 0
3908 Inset * Buffer::getInsetFromID(int id_arg) const
3910 for (inset_iterator it = inset_const_iterator_begin();
3911 it != inset_const_iterator_end(); ++it)
3913 if ((*it)->id() == id_arg)
3915 Inset * in = (*it)->getInsetFromID(id_arg);
3923 Paragraph * Buffer::getParFromID(int id) const
3925 if (id < 0) return 0;
3926 Paragraph * par = paragraph;
3928 if (par->id() == id) {
3931 Paragraph * tmp = par->getParFromID(id);
3941 ParIterator Buffer::par_iterator_begin()
3943 return ParIterator(paragraph);
3947 ParIterator Buffer::par_iterator_end()
3949 return ParIterator();