3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
16 #include "buffer_funcs.h"
17 #include "bufferlist.h"
18 #include "bufferparams.h"
22 #include "errorlist.h"
25 #include "funcrequest.h"
27 #include "iterators.h"
30 #include "LaTeXFeatures.h"
31 #include "LyXAction.h"
36 #include "paragraph.h"
37 #include "paragraph_funcs.h"
38 #include "ParagraphParameters.h"
44 #include "insets/insetbibitem.h"
45 #include "insets/insetbibtex.h"
46 #include "insets/insetinclude.h"
47 #include "insets/insettext.h"
49 #include "frontends/Alert.h"
51 #include "graphics/Previews.h"
53 #include "support/FileInfo.h"
54 #include "support/filetools.h"
55 #include "support/gzstream.h"
56 #include "support/lyxlib.h"
57 #include "support/os.h"
58 #include "support/path.h"
59 #include "support/textutils.h"
60 #include "support/tostr.h"
62 #include <boost/bind.hpp>
63 #include <boost/tuple/tuple.hpp>
65 #include "support/std_sstream.h"
77 using lyx::support::AddName;
78 using lyx::support::ascii_lowercase;
79 using lyx::support::atoi;
80 using lyx::support::bformat;
81 using lyx::support::ChangeExtension;
82 using lyx::support::cmd_ret;
83 using lyx::support::compare_ascii_no_case;
84 using lyx::support::compare_no_case;
85 using lyx::support::contains;
86 using lyx::support::CreateBufferTmpDir;
87 using lyx::support::destroyDir;
88 using lyx::support::FileInfo;
89 using lyx::support::FileInfo;
90 using lyx::support::getExtFromContents;
91 using lyx::support::IsDirWriteable;
92 using lyx::support::IsFileWriteable;
93 using lyx::support::LibFileSearch;
94 using lyx::support::ltrim;
95 using lyx::support::MakeAbsPath;
96 using lyx::support::MakeDisplayPath;
97 using lyx::support::MakeLatexName;
98 using lyx::support::OnlyFilename;
99 using lyx::support::OnlyPath;
100 using lyx::support::Path;
101 using lyx::support::QuoteName;
102 using lyx::support::removeAutosaveFile;
103 using lyx::support::rename;
104 using lyx::support::RunCommand;
105 using lyx::support::split;
106 using lyx::support::strToInt;
107 using lyx::support::subst;
108 using lyx::support::tempName;
109 using lyx::support::trim;
111 namespace os = lyx::support::os;
115 using std::make_pair;
121 using std::ostringstream;
129 // all these externs should eventually be removed.
130 extern BufferList bufferlist;
134 const int LYX_FORMAT = 225;
136 bool openFileWrite(ofstream & ofs, string const & fname)
138 ofs.open(fname.c_str());
140 string const file = MakeDisplayPath(fname, 50);
141 string text = bformat(_("Could not open the specified "
142 "document\n%1$s."), file);
143 Alert::error(_("Could not open file"), text);
152 typedef std::map<string, bool> DepClean;
156 Impl(Buffer & parent, string const & file, bool readonly);
158 limited_stack<Undo> undostack;
159 limited_stack<Undo> redostack;
161 ParagraphList paragraphs;
167 /// need to regenerate .tex ?
171 mutable bool lyx_clean;
173 /// is autosave needed
174 mutable bool bak_clean;
176 /// is this a unnamed file (New...)
182 /// name of the file the buffer is associated with.
185 /// The path to the document file.
188 boost::scoped_ptr<Messages> messages;
190 /** set to true only when the file is fully loaded.
191 * Used to prevent the premature generation of previews
192 * and by the citation inset.
194 bool file_fully_loaded;
198 Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
200 lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
201 filename(file), filepath(OnlyPath(file)), file_fully_loaded(false)
203 lyxvc.buffer(&parent);
204 if (readonly_ || lyxrc.use_tempdir)
205 temppath = CreateBufferTmpDir();
209 Buffer::Buffer(string const & file, bool ronly)
210 : pimpl_(new Impl(*this, file, ronly))
212 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
218 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
219 // here the buffer should take care that it is
220 // saved properly, before it goes into the void.
224 if (!temppath().empty() && destroyDir(temppath()) != 0) {
225 Alert::warning(_("Could not remove temporary directory"),
226 bformat(_("Could not remove the temporary directory %1$s"), temppath()));
229 paragraphs().clear();
231 // Remove any previewed LaTeX snippets associated with this buffer.
232 lyx::graphics::Previews::get().removeLoader(*this);
236 limited_stack<Undo> & Buffer::undostack()
238 return pimpl_->undostack;
242 limited_stack<Undo> const & Buffer::undostack() const
244 return pimpl_->undostack;
248 limited_stack<Undo> & Buffer::redostack()
250 return pimpl_->redostack;
254 limited_stack<Undo> const & Buffer::redostack() const
256 return pimpl_->redostack;
260 BufferParams & Buffer::params()
262 return pimpl_->params;
266 BufferParams const & Buffer::params() const
268 return pimpl_->params;
272 ParagraphList & Buffer::paragraphs()
274 return pimpl_->paragraphs;
278 ParagraphList const & Buffer::paragraphs() const
280 return pimpl_->paragraphs;
284 LyXVC & Buffer::lyxvc()
286 return pimpl_->lyxvc;
290 LyXVC const & Buffer::lyxvc() const
292 return pimpl_->lyxvc;
296 string const & Buffer::temppath() const
298 return pimpl_->temppath;
302 bool & Buffer::niceFile()
304 return pimpl_->nicefile;
308 bool Buffer::niceFile() const
310 return pimpl_->nicefile;
314 TexRow & Buffer::texrow()
316 return pimpl_->texrow;
320 TexRow const & Buffer::texrow() const
322 return pimpl_->texrow;
326 string const Buffer::getLatexName(bool no_path) const
328 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
329 return no_path ? OnlyFilename(name) : name;
333 pair<Buffer::LogType, string> const Buffer::getLogName() const
335 string const filename = getLatexName(false);
337 if (filename.empty())
338 return make_pair(Buffer::latexlog, string());
340 string path = OnlyPath(filename);
342 if (lyxrc.use_tempdir || !IsDirWriteable(path))
345 string const fname = AddName(path,
346 OnlyFilename(ChangeExtension(filename,
349 AddName(path, OnlyFilename(
350 ChangeExtension(filename,
351 formats.extension("literate") + ".out")));
353 // If no Latex log or Build log is newer, show Build log
355 FileInfo const f_fi(fname);
356 FileInfo const b_fi(bname);
359 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
360 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
361 return make_pair(Buffer::buildlog, bname);
363 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
364 return make_pair(Buffer::latexlog, fname);
368 void Buffer::setReadonly(bool flag)
370 if (pimpl_->read_only != flag) {
371 pimpl_->read_only = flag;
377 void Buffer::setFileName(string const & newfile)
379 pimpl_->filename = MakeAbsPath(newfile);
380 pimpl_->filepath = OnlyPath(pimpl_->filename);
381 setReadonly(IsFileWriteable(pimpl_->filename) == 0);
386 // We'll remove this later. (Lgb)
389 void unknownClass(string const & unknown)
391 Alert::warning(_("Unknown document class"),
392 bformat(_("Using the default document class, because the "
393 "class %1$s is unknown."), unknown));
398 int Buffer::readHeader(LyXLex & lex)
400 int unknown_tokens = 0;
404 string const token = lex.getString();
409 if (token == "\\end_header")
412 lyxerr[Debug::PARSER] << "Handling header token: `"
413 << token << '\'' << endl;
416 string unknown = params().readToken(lex, token);
417 if (!unknown.empty()) {
418 if (unknown[0] != '\\') {
419 unknownClass(unknown);
422 string const s = bformat(_("Unknown token: "
426 error(ErrorItem(_("Header error"), s,
431 return unknown_tokens;
435 // candidate for move to BufferView
436 // (at least some parts in the beginning of the func)
439 // changed to be public and have one parameter
440 // if par = 0 normal behavior
441 // else insert behavior
442 // Returns false if "\end_document" is not read (Asger)
443 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
445 Paragraph::depth_type depth = 0;
446 bool the_end_read = false;
448 if (paragraphs().empty()) {
450 if (!params().getLyXTextClass().load()) {
451 string theclass = params().getLyXTextClass().name();
452 Alert::error(_("Can't load document class"), bformat(
453 "Using the default document class, because the "
454 " class %1$s could not be loaded.", theclass));
455 params().textclass = 0;
458 // We don't want to adopt the parameters from the
459 // document we insert, so read them into a temporary buffer
460 // and then discard it
462 Buffer tmpbuf("", false);
463 tmpbuf.readHeader(lex);
468 string const token = lex.getString();
473 lyxerr[Debug::PARSER] << "Handling token: `"
474 << token << '\'' << endl;
476 if (token == "\\end_document") {
481 readParagraph(lex, token, paragraphs(), pit, depth);
488 int Buffer::readParagraph(LyXLex & lex, string const & token,
489 ParagraphList & pars, ParagraphList::iterator & pit,
490 lyx::depth_type & depth)
492 static Change current_change;
495 if (token == "\\begin_layout") {
496 lex.pushToken(token);
499 par.params().depth(depth);
500 if (params().tracking_changes)
502 LyXFont f(LyXFont::ALL_INHERIT, params().language);
506 if (pit != pars.end())
509 pit = pars.insert(pit, par);
511 // FIXME: goddamn InsetTabular makes us pass a Buffer
513 ::readParagraph(*this, *pit, lex);
515 } else if (token == "\\begin_deeper") {
517 } else if (token == "\\end_deeper") {
519 lex.printError("\\end_deeper: " "depth is already null");
530 // needed to insert the selection
531 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
532 LyXFont const & fn,string const & str)
534 LyXLayout_ptr const & layout = par->layout();
538 par->checkInsertChar(font);
539 // insert the string, don't insert doublespace
540 bool space_inserted = true;
541 bool autobreakrows = !par->inInset() ||
542 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
543 for(string::const_iterator cit = str.begin();
544 cit != str.end(); ++cit) {
546 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
547 breakParagraph(params(), paragraphs(), par, pos,
548 layout->isEnvironment());
551 space_inserted = true;
555 // do not insert consecutive spaces if !free_spacing
556 } else if ((*cit == ' ' || *cit == '\t') &&
557 space_inserted && !par->isFreeSpacing()) {
559 } else if (*cit == '\t') {
560 if (!par->isFreeSpacing()) {
561 // tabs are like spaces here
562 par->insertChar(pos, ' ', font);
564 space_inserted = true;
566 const pos_type nb = 8 - pos % 8;
567 for (pos_type a = 0; a < nb ; ++a) {
568 par->insertChar(pos, ' ', font);
571 space_inserted = true;
573 } else if (!IsPrintable(*cit)) {
574 // Ignore unprintables
577 // just insert the character
578 par->insertChar(pos, *cit, font);
580 space_inserted = (*cit == ' ');
587 bool Buffer::readFile(string const & filename)
589 // Check if the file is compressed.
590 string const format = getExtFromContents(filename);
591 if (format == "gzip" || format == "zip" || format == "compress") {
592 params().compressed = true;
595 bool ret = readFile(filename, paragraphs().begin());
597 // After we have read a file, we must ensure that the buffer
598 // language is set and used in the gui.
599 // If you know of a better place to put this, please tell me. (Lgb)
600 updateDocLang(params().language);
606 bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
609 lex.setFile(filename);
611 return readFile(lex, filename, pit);
615 bool Buffer::fully_loaded() const
617 return pimpl_->file_fully_loaded;
621 void Buffer::fully_loaded(bool value)
623 pimpl_->file_fully_loaded = value;
627 bool Buffer::readFile(LyXLex & lex, string const & filename,
628 ParagraphList::iterator pit)
630 BOOST_ASSERT(!filename.empty());
633 Alert::error(_("Document could not be read"),
634 bformat(_("%1$s could not be read."), filename));
639 string const token(lex.getString());
642 Alert::error(_("Document could not be read"),
643 bformat(_("%1$s could not be read."), filename));
647 // the first token _must_ be...
648 if (token != "\\lyxformat") {
649 lyxerr << "Token: " << token << endl;
651 Alert::error(_("Document format failure"),
652 bformat(_("%1$s is not a LyX document."),
658 string tmp_format = lex.getString();
659 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
660 // if present remove ".," from string.
661 string::size_type dot = tmp_format.find_first_of(".,");
662 //lyxerr << " dot found at " << dot << endl;
663 if (dot != string::npos)
664 tmp_format.erase(dot, 1);
665 int file_format = strToInt(tmp_format);
666 //lyxerr << "format: " << file_format << endl;
668 if (file_format > LYX_FORMAT) {
669 Alert::warning(_("Document format failure"),
670 bformat(_("%1$s was created with a newer"
671 " version of LyX. This is likely to"
674 } else if (file_format < LYX_FORMAT) {
675 string const tmpfile = tempName();
676 string command = LibFileSearch("lyx2lyx", "lyx2lyx");
677 if (command.empty()) {
678 Alert::error(_("Conversion script not found"),
679 bformat(_("%1$s is from an earlier"
680 " version of LyX, but the"
681 " conversion script lyx2lyx"
682 " could not be found."),
688 + " -o " + tmpfile + ' '
689 + QuoteName(filename);
690 lyxerr[Debug::INFO] << "Running '"
693 cmd_ret const ret = RunCommand(command);
694 if (ret.first != 0) {
695 Alert::error(_("Conversion script failed"),
696 bformat(_("%1$s is from an earlier version"
697 " of LyX, but the lyx2lyx script"
698 " failed to convert it."),
702 bool ret = readFile(tmpfile, pit);
703 // Do stuff with tmpfile name and buffer name here.
709 bool the_end = readBody(lex, pit);
710 params().setPaperStuff();
713 Alert::error(_("Document format failure"),
714 bformat(_("%1$s ended unexpectedly, which means"
715 " that it is probably corrupted."),
718 pimpl_->file_fully_loaded = true;
723 // Should probably be moved to somewhere else: BufferView? LyXView?
724 bool Buffer::save() const
726 // We don't need autosaves in the immediate future. (Asger)
727 resetAutosaveTimers();
731 if (lyxrc.make_backup) {
732 s = fileName() + '~';
733 if (!lyxrc.backupdir_path.empty())
734 s = AddName(lyxrc.backupdir_path,
735 subst(os::slashify_path(s),'/','!'));
737 // Rename is the wrong way of making a backup,
738 // this is the correct way.
739 /* truss cp fil fil2:
740 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
741 stat("LyXVC.lyx", 0xEFFFF688) = 0
742 open("LyXVC.lyx", O_RDONLY) = 3
743 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
744 fstat(4, 0xEFFFF508) = 0
745 fstat(3, 0xEFFFF508) = 0
746 read(3, " # T h i s f i l e w".., 8192) = 5579
747 write(4, " # T h i s f i l e w".., 5579) = 5579
748 read(3, 0xEFFFD4A0, 8192) = 0
751 chmod("LyXVC3.lyx", 0100644) = 0
752 lseek(0, 0, SEEK_CUR) = 46440
756 // Should probably have some more error checking here.
757 // Doing it this way, also makes the inodes stay the same.
758 // This is still not a very good solution, in particular we
759 // might loose the owner of the backup.
760 FileInfo finfo(fileName());
762 mode_t fmode = finfo.getMode();
763 struct utimbuf times = {
764 finfo.getAccessTime(),
765 finfo.getModificationTime() };
767 ifstream ifs(fileName().c_str());
768 ofstream ofs(s.c_str(), ios::out|ios::trunc);
773 ::chmod(s.c_str(), fmode);
775 if (::utime(s.c_str(), ×)) {
776 lyxerr << "utime error." << endl;
779 lyxerr << "LyX was not able to make "
780 "backup copy. Beware." << endl;
785 if (writeFile(fileName())) {
787 removeAutosaveFile(fileName());
789 // Saving failed, so backup is not backup
790 if (lyxrc.make_backup) {
791 rename(s, fileName());
799 bool Buffer::writeFile(string const & fname) const
801 if (pimpl_->read_only && (fname == fileName())) {
805 FileInfo finfo(fname);
806 if (finfo.exist() && !finfo.writable()) {
812 if (params().compressed) {
813 gz::ogzstream ofs(fname.c_str());
818 retval = do_writeFile(ofs);
821 ofstream ofs(fname.c_str());
825 retval = do_writeFile(ofs);
832 bool Buffer::do_writeFile(ostream & ofs) const
836 // Use the standard "C" locale for file output.
837 ofs.imbue(std::locale::classic());
840 // The top of the file should not be written by params().
842 // write out a comment in the top of the file
843 ofs << "#LyX " << lyx_version
844 << " created this file. For more info see http://www.lyx.org/\n"
845 << "\\lyxformat " << LYX_FORMAT << "\n";
847 // now write out the buffer paramters.
848 params().writeFile(ofs);
850 ofs << "\\end_header\n";
852 Paragraph::depth_type depth = 0;
854 // this will write out all the paragraphs
855 // using recursive descent.
856 ParagraphList::const_iterator pit = paragraphs().begin();
857 ParagraphList::const_iterator pend = paragraphs().end();
858 for (; pit != pend; ++pit)
859 pit->write(*this, ofs, params(), depth);
861 // Write marker that shows file is complete
862 ofs << "\n\\end_document" << endl;
864 // Shouldn't really be needed....
867 // how to check if close went ok?
868 // Following is an attempt... (BE 20001011)
870 // good() returns false if any error occured, including some
872 // bad() returns true if something bad happened in the buffer,
873 // which should include file system full errors.
880 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
882 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
894 pair<int, string> const addDepth(int depth, int ldepth)
898 d += (ldepth - depth) * 2;
899 return make_pair(d, string(d, ' '));
905 string const Buffer::asciiParagraph(Paragraph const & par,
906 unsigned int linelen,
907 bool noparbreak) const
909 ostringstream buffer;
911 Paragraph::depth_type ltype_depth = 0;
912 bool ref_printed = false;
913 Paragraph::depth_type depth = par.params().depth();
915 // First write the layout
916 string const & tmp = par.layout()->name();
917 if (compare_no_case(tmp, "itemize") == 0) {
919 ltype_depth = depth + 1;
920 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
922 ltype_depth = depth + 1;
923 } else if (contains(ascii_lowercase(tmp), "ection")) {
925 ltype_depth = depth + 1;
926 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
928 ltype_depth = depth + 1;
929 } else if (compare_ascii_no_case(tmp, "description") == 0) {
931 ltype_depth = depth + 1;
932 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
935 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
943 /* maybe some vertical spaces */
945 /* the labelwidthstring used in lists */
949 /* some pagebreaks? */
953 /* what about the alignment */
955 // linelen <= 0 is special and means we don't have paragraph breaks
957 string::size_type currlinelen = 0;
963 buffer << string(depth * 2, ' ');
964 currlinelen += depth * 2;
967 // we should probably change to the paragraph language in the
968 // gettext here (if possible) so that strings are outputted in
969 // the correct language! (20012712 Jug)
973 case 4: // (Sub)Paragraph
974 case 5: // Description
978 buffer << _("Abstract") << "\n\n";
981 string const abst = _("Abstract: ");
983 currlinelen += abst.length();
986 case 7: // Bibliography
989 buffer << _("References") << "\n\n";
992 string const refs = _("References: ");
994 currlinelen += refs.length();
1002 string const parlab = par.params().labelString();
1003 buffer << parlab << ' ';
1004 currlinelen += parlab.length() + 1;
1012 pair<int, string> p = addDepth(depth, ltype_depth);
1014 currlinelen += p.first;
1017 // this is to change the linebreak to do it by word a bit more
1018 // intelligent hopefully! (only in the case where we have a
1019 // max linelength!) (Jug)
1023 for (pos_type i = 0; i < par.size(); ++i) {
1024 char c = par.getUChar(params(), i);
1026 case Paragraph::META_INSET:
1028 InsetOld const * inset = par.getInset(i);
1032 currlinelen += word.length();
1035 if (inset->ascii(*this, buffer, linelen)) {
1036 // to be sure it breaks paragraph
1037 currlinelen += linelen;
1046 currlinelen + word.length() > linelen - 10) {
1048 pair<int, string> p = addDepth(depth, ltype_depth);
1050 currlinelen = p.first;
1053 buffer << word << ' ';
1054 currlinelen += word.length() + 1;
1061 lyxerr[Debug::INFO] <<
1062 "writeAsciiFile: NULL char in structure." << endl;
1064 if ((linelen > 0) &&
1065 (currlinelen + word.length()) > linelen)
1069 pair<int, string> p =
1070 addDepth(depth, ltype_depth);
1072 currlinelen = p.first;
1079 return buffer.str();
1083 void Buffer::writeFileAscii(string const & fname, int linelen)
1086 if (!::openFileWrite(ofs, fname))
1088 writeFileAscii(ofs, linelen);
1092 void Buffer::writeFileAscii(ostream & os, int linelen)
1094 ParagraphList::iterator beg = paragraphs().begin();
1095 ParagraphList::iterator end = paragraphs().end();
1096 ParagraphList::iterator it = beg;
1097 for (; it != end; ++it) {
1098 os << asciiParagraph(*it, linelen, it == beg);
1104 void Buffer::makeLaTeXFile(string const & fname,
1105 string const & original_path,
1106 LatexRunParams const & runparams,
1107 bool output_preamble, bool output_body)
1109 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1112 if (!::openFileWrite(ofs, fname))
1115 makeLaTeXFile(ofs, original_path,
1116 runparams, output_preamble, output_body);
1120 lyxerr << "File was not closed properly." << endl;
1125 void Buffer::makeLaTeXFile(ostream & os,
1126 string const & original_path,
1127 LatexRunParams const & runparams_in,
1128 bool output_preamble, bool output_body)
1130 LatexRunParams runparams = runparams_in;
1131 niceFile() = runparams.nice; // this will be used by Insetincludes.
1133 // validate the buffer.
1134 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1135 LaTeXFeatures features(*this, params());
1137 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1140 // The starting paragraph of the coming rows is the
1141 // first paragraph of the document. (Asger)
1142 texrow().start(paragraphs().begin()->id(), 0);
1144 if (output_preamble && runparams.nice) {
1145 os << "%% LyX " << lyx_version << " created this file. "
1146 "For more info, see http://www.lyx.org/.\n"
1147 "%% Do not edit unless you really know what "
1152 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1153 // There are a few differences between nice LaTeX and usual files:
1154 // usual is \batchmode and has a
1155 // special input@path to allow the including of figures
1156 // with either \input or \includegraphics (what figinsets do).
1157 // input@path is set when the actual parameter
1158 // original_path is set. This is done for usual tex-file, but not
1159 // for nice-latex-file. (Matthias 250696)
1160 if (output_preamble) {
1161 if (!runparams.nice) {
1162 // code for usual, NOT nice-latex-file
1163 os << "\\batchmode\n"; // changed
1164 // from \nonstopmode
1167 if (!original_path.empty()) {
1168 string inputpath = os::external_path(original_path);
1169 subst(inputpath, "~", "\\string~");
1170 os << "\\makeatletter\n"
1171 << "\\def\\input@path{{"
1172 << inputpath << "/}}\n"
1173 << "\\makeatother\n";
1179 // Write the preamble
1180 runparams.use_babel = params().writeLaTeX(os, features, texrow());
1186 os << "\\begin{document}\n";
1188 } // output_preamble
1189 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1191 if (!lyxrc.language_auto_begin) {
1192 os << subst(lyxrc.language_command_begin, "$$lang",
1193 params().language->babel())
1198 latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
1200 // add this just in case after all the paragraphs
1204 if (!lyxrc.language_auto_end) {
1205 os << subst(lyxrc.language_command_end, "$$lang",
1206 params().language->babel())
1211 if (output_preamble) {
1212 os << "\\end{document}\n";
1215 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1217 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1221 // Just to be sure. (Asger)
1224 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1225 lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
1228 // we want this to be true outside previews (for insetexternal)
1233 bool Buffer::isLatex() const
1235 return params().getLyXTextClass().outputType() == LATEX;
1239 bool Buffer::isLinuxDoc() const
1241 return params().getLyXTextClass().outputType() == LINUXDOC;
1245 bool Buffer::isLiterate() const
1247 return params().getLyXTextClass().outputType() == LITERATE;
1251 bool Buffer::isDocBook() const
1253 return params().getLyXTextClass().outputType() == DOCBOOK;
1257 bool Buffer::isSGML() const
1259 LyXTextClass const & tclass = params().getLyXTextClass();
1261 return tclass.outputType() == LINUXDOC ||
1262 tclass.outputType() == DOCBOOK;
1266 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1269 if (!::openFileWrite(ofs, fname))
1272 niceFile() = nice; // this will be used by included files.
1274 LaTeXFeatures features(*this, params());
1280 LyXTextClass const & tclass = params().getLyXTextClass();
1282 string top_element = tclass.latexname();
1285 ofs << "<!doctype linuxdoc system";
1287 string preamble = params().preamble;
1288 string const name = nice ? ChangeExtension(pimpl_->filename, ".sgml")
1290 preamble += features.getIncludedFiles(name);
1291 preamble += features.getLyXSGMLEntities();
1293 if (!preamble.empty()) {
1294 ofs << " [ " << preamble << " ]";
1298 if (params().options.empty())
1299 sgml::openTag(ofs, 0, false, top_element);
1301 string top = top_element;
1303 top += params().options;
1304 sgml::openTag(ofs, 0, false, top);
1308 ofs << "<!-- LyX " << lyx_version
1309 << " created this file. For more info see http://www.lyx.org/"
1312 Paragraph::depth_type depth = 0; // paragraph depth
1314 vector<string> environment_stack(5);
1316 ParagraphList::iterator pit = paragraphs().begin();
1317 ParagraphList::iterator pend = paragraphs().end();
1318 for (; pit != pend; ++pit) {
1319 LyXLayout_ptr const & style = pit->layout();
1320 // treat <toc> as a special case for compatibility with old code
1321 if (pit->isInset(0)) {
1322 InsetOld * inset = pit->getInset(0);
1323 InsetOld::Code lyx_code = inset->lyxCode();
1324 if (lyx_code == InsetOld::TOC_CODE) {
1325 string const temp = "toc";
1326 sgml::openTag(ofs, depth, false, temp);
1331 // environment tag closing
1332 for (; depth > pit->params().depth(); --depth) {
1333 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1334 environment_stack[depth].erase();
1337 // write opening SGML tags
1338 switch (style->latextype) {
1339 case LATEX_PARAGRAPH:
1340 if (depth == pit->params().depth()
1341 && !environment_stack[depth].empty()) {
1342 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1343 environment_stack[depth].erase();
1349 sgml::openTag(ofs, depth, false, style->latexname());
1354 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1356 if (!environment_stack[depth].empty()) {
1357 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1361 environment_stack[depth].erase();
1362 sgml::openTag(ofs, depth, false, style->latexname());
1365 case LATEX_ENVIRONMENT:
1366 case LATEX_ITEM_ENVIRONMENT:
1367 case LATEX_BIB_ENVIRONMENT:
1369 string const & latexname = style->latexname();
1371 if (depth == pit->params().depth()
1372 && environment_stack[depth] != latexname) {
1373 sgml::closeTag(ofs, depth, false,
1374 environment_stack[depth]);
1375 environment_stack[depth].erase();
1377 if (depth < pit->params().depth()) {
1378 depth = pit->params().depth();
1379 environment_stack[depth].erase();
1381 if (environment_stack[depth] != latexname) {
1383 sgml::openTag(ofs, depth, false, "p");
1385 sgml::openTag(ofs, depth, false, latexname);
1387 if (environment_stack.size() == depth + 1)
1388 environment_stack.push_back("!-- --");
1389 environment_stack[depth] = latexname;
1392 if (style->latexparam() == "CDATA")
1395 if (style->latextype == LATEX_ENVIRONMENT) break;
1397 if (style->labeltype == LABEL_MANUAL)
1402 sgml::openTag(ofs, depth + 1, false, item_name);
1407 sgml::openTag(ofs, depth, false, style->latexname());
1411 simpleLinuxDocOnePar(ofs, pit, depth);
1414 // write closing SGML tags
1415 switch (style->latextype) {
1418 case LATEX_ENVIRONMENT:
1419 case LATEX_ITEM_ENVIRONMENT:
1420 case LATEX_BIB_ENVIRONMENT:
1421 if (style->latexparam() == "CDATA")
1425 sgml::closeTag(ofs, depth, false, style->latexname());
1431 for (int i = depth; i >= 0; --i)
1432 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1436 sgml::closeTag(ofs, 0, false, top_element);
1440 // How to check for successful close
1442 // we want this to be true outside previews (for insetexternal)
1447 // checks, if newcol chars should be put into this line
1448 // writes newline, if necessary.
1451 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1452 string::size_type newcol)
1455 if (colcount > lyxrc.ascii_linelen) {
1457 colcount = newcol; // assume write after this call
1472 string tag_name(PAR_TAG const & pt) {
1474 case NONE: return "!-- --";
1475 case TT: return "tt";
1476 case SF: return "sf";
1477 case BF: return "bf";
1478 case IT: return "it";
1479 case SL: return "sl";
1480 case EM: return "em";
1487 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1489 p1 = static_cast<PAR_TAG>(p1 | p2);
1494 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1496 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1502 // Handle internal paragraph parsing -- layout already processed.
1503 void Buffer::simpleLinuxDocOnePar(ostream & os,
1504 ParagraphList::iterator par,
1505 lyx::depth_type /*depth*/) const
1507 LyXLayout_ptr const & style = par->layout();
1509 string::size_type char_line_count = 5; // Heuristic choice ;-)
1511 // gets paragraph main font
1514 if (style->labeltype == LABEL_MANUAL) {
1515 font_old = style->labelfont;
1518 font_old = style->font;
1522 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1523 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1524 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1527 stack<PAR_TAG> tag_state;
1528 // parsing main loop
1529 for (pos_type i = 0; i < par->size(); ++i) {
1531 PAR_TAG tag_close = NONE;
1532 list < PAR_TAG > tag_open;
1534 LyXFont const font = par->getFont(params(), i, outerFont(par, paragraphs()));
1536 if (font_old.family() != font.family()) {
1537 switch (family_type) {
1538 case LyXFont::SANS_FAMILY:
1541 case LyXFont::TYPEWRITER_FAMILY:
1548 family_type = font.family();
1550 switch (family_type) {
1551 case LyXFont::SANS_FAMILY:
1552 tag_open.push_back(SF);
1554 case LyXFont::TYPEWRITER_FAMILY:
1555 tag_open.push_back(TT);
1562 if (font_old.series() != font.series()) {
1563 switch (series_type) {
1564 case LyXFont::BOLD_SERIES:
1571 series_type = font.series();
1573 switch (series_type) {
1574 case LyXFont::BOLD_SERIES:
1575 tag_open.push_back(BF);
1583 if (font_old.shape() != font.shape()) {
1584 switch (shape_type) {
1585 case LyXFont::ITALIC_SHAPE:
1588 case LyXFont::SLANTED_SHAPE:
1595 shape_type = font.shape();
1597 switch (shape_type) {
1598 case LyXFont::ITALIC_SHAPE:
1599 tag_open.push_back(IT);
1601 case LyXFont::SLANTED_SHAPE:
1602 tag_open.push_back(SL);
1609 if (font_old.emph() != font.emph()) {
1610 if (font.emph() == LyXFont::ON) {
1611 tag_open.push_back(EM);
1620 list < PAR_TAG > temp;
1621 while (!tag_state.empty() && tag_close) {
1622 PAR_TAG k = tag_state.top();
1624 os << "</" << tag_name(k) << '>';
1631 for(list< PAR_TAG >::const_iterator j = temp.begin();
1632 j != temp.end(); ++j) {
1634 os << '<' << tag_name(*j) << '>';
1637 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1638 j != tag_open.end(); ++j) {
1640 os << '<' << tag_name(*j) << '>';
1643 char c = par->getChar(i);
1645 if (c == Paragraph::META_INSET) {
1646 InsetOld * inset = par->getInset(i);
1647 inset->linuxdoc(*this, os);
1652 if (style->latexparam() == "CDATA") {
1653 // "TeX"-Mode on == > SGML-Mode on.
1660 boost::tie(ws, str) = sgml::escapeChar(c);
1661 if (ws && !par->isFreeSpacing()) {
1662 // in freespacing mode, spaces are
1663 // non-breaking characters
1664 if (desc_on) {// if char is ' ' then...
1667 sgmlLineBreak(os, char_line_count, 6);
1671 sgmlLineBreak(os, char_line_count, 1);
1676 char_line_count += str.length();
1682 while (!tag_state.empty()) {
1683 os << "</" << tag_name(tag_state.top()) << '>';
1687 // resets description flag correctly
1689 // <tag> not closed...
1690 sgmlLineBreak(os, char_line_count, 6);
1696 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1699 if (!::openFileWrite(ofs, fname))
1702 niceFile() = nice; // this will be used by Insetincludes.
1704 LaTeXFeatures features(*this, params());
1709 LyXTextClass const & tclass = params().getLyXTextClass();
1710 string top_element = tclass.latexname();
1713 ofs << "<!DOCTYPE " << top_element
1714 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1716 string preamble = params().preamble;
1717 string const name = nice ? ChangeExtension(pimpl_->filename, ".sgml")
1719 preamble += features.getIncludedFiles(name);
1720 preamble += features.getLyXSGMLEntities();
1722 if (!preamble.empty()) {
1723 ofs << "\n [ " << preamble << " ]";
1728 string top = top_element;
1730 top += params().language->code();
1733 if (!params().options.empty()) {
1735 top += params().options;
1737 sgml::openTag(ofs, 0, false, top);
1739 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1740 << "\n See http://www.lyx.org/ for more information -->\n";
1742 vector<string> environment_stack(10);
1743 vector<string> environment_inner(10);
1744 vector<string> command_stack(10);
1746 bool command_flag = false;
1747 Paragraph::depth_type command_depth = 0;
1748 Paragraph::depth_type command_base = 0;
1749 Paragraph::depth_type cmd_depth = 0;
1750 Paragraph::depth_type depth = 0; // paragraph depth
1753 string command_name;
1755 ParagraphList::iterator par = paragraphs().begin();
1756 ParagraphList::iterator pend = paragraphs().end();
1758 for (; par != pend; ++par) {
1762 int desc_on = 0; // description mode
1764 LyXLayout_ptr const & style = par->layout();
1766 // environment tag closing
1767 for (; depth > par->params().depth(); --depth) {
1768 if (!environment_inner[depth].empty())
1769 sgml::closeEnvTags(ofs, false, environment_inner[depth],
1770 command_depth + depth);
1771 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1772 environment_stack[depth].erase();
1773 environment_inner[depth].erase();
1776 if (depth == par->params().depth()
1777 && environment_stack[depth] != style->latexname()
1778 && !environment_stack[depth].empty()) {
1779 sgml::closeEnvTags(ofs, false, environment_inner[depth],
1780 command_depth + depth);
1781 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1783 environment_stack[depth].erase();
1784 environment_inner[depth].erase();
1787 // Write opening SGML tags.
1788 switch (style->latextype) {
1789 case LATEX_PARAGRAPH:
1790 sgml::openTag(ofs, depth + command_depth,
1791 false, style->latexname());
1796 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1798 command_name = style->latexname();
1800 sgmlparam = style->latexparam();
1801 c_params = split(sgmlparam, c_depth,'|');
1803 cmd_depth = atoi(c_depth);
1806 if (cmd_depth < command_base) {
1807 for (Paragraph::depth_type j = command_depth;
1808 j >= command_base; --j) {
1809 sgml::closeTag(ofs, j, false, command_stack[j]);
1812 command_depth = command_base = cmd_depth;
1813 } else if (cmd_depth <= command_depth) {
1814 for (int j = command_depth;
1815 j >= int(cmd_depth); --j) {
1816 sgml::closeTag(ofs, j, false, command_stack[j]);
1819 command_depth = cmd_depth;
1821 command_depth = cmd_depth;
1823 command_depth = command_base = cmd_depth;
1824 command_flag = true;
1826 if (command_stack.size() == command_depth + 1)
1827 command_stack.push_back(string());
1828 command_stack[command_depth] = command_name;
1830 // treat label as a special case for
1831 // more WYSIWYM handling.
1832 // This is a hack while paragraphs can't have
1833 // attributes, like id in this case.
1834 if (par->isInset(0)) {
1835 InsetOld * inset = par->getInset(0);
1836 InsetOld::Code lyx_code = inset->lyxCode();
1837 if (lyx_code == InsetOld::LABEL_CODE) {
1838 command_name += " id=\"";
1839 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1840 command_name += '"';
1845 sgml::openTag(ofs, depth + command_depth, false, command_name);
1847 item_name = c_params.empty() ? "title" : c_params;
1848 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1851 case LATEX_ENVIRONMENT:
1852 case LATEX_ITEM_ENVIRONMENT:
1853 if (depth < par->params().depth()) {
1854 depth = par->params().depth();
1855 environment_stack[depth].erase();
1858 if (environment_stack[depth] != style->latexname()) {
1859 if (environment_stack.size() == depth + 1) {
1860 environment_stack.push_back("!-- --");
1861 environment_inner.push_back("!-- --");
1863 environment_stack[depth] = style->latexname();
1864 environment_inner[depth] = "!-- --";
1865 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1867 sgml::closeEnvTags(ofs, false, environment_inner[depth],
1868 command_depth + depth);
1871 if (style->latextype == LATEX_ENVIRONMENT) {
1872 if (!style->latexparam().empty()) {
1873 if (style->latexparam() == "CDATA")
1876 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1881 desc_on = (style->labeltype == LABEL_MANUAL);
1883 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1884 sgml::openTag(ofs, depth + 1 + command_depth,
1885 false, environment_inner[depth]);
1887 item_name = desc_on ? "term" : "para";
1888 sgml::openTag(ofs, depth + 1 + command_depth,
1892 sgml::openTag(ofs, depth + command_depth,
1893 false, style->latexname());
1897 simpleDocBookOnePar(ofs, par, desc_on,
1898 depth + 1 + command_depth);
1901 // write closing SGML tags
1902 switch (style->latextype) {
1904 end_tag = c_params.empty() ? "title" : c_params;
1905 sgml::closeTag(ofs, depth + command_depth,
1908 case LATEX_ENVIRONMENT:
1909 if (!style->latexparam().empty()) {
1910 if (style->latexparam() == "CDATA")
1913 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1916 case LATEX_ITEM_ENVIRONMENT:
1917 if (desc_on == 1) break;
1919 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1921 case LATEX_PARAGRAPH:
1922 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1925 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1931 for (int d = depth; d >= 0; --d) {
1932 if (!environment_stack[depth].empty()) {
1933 sgml::closeEnvTags(ofs, false, environment_inner[depth],
1934 command_depth + depth);
1938 for (int j = command_depth; j >= 0 ; --j)
1939 if (!command_stack[j].empty()) {
1940 sgml::closeTag(ofs, j, false, command_stack[j]);
1945 sgml::closeTag(ofs, 0, false, top_element);
1948 // How to check for successful close
1950 // we want this to be true outside previews (for insetexternal)
1955 void Buffer::simpleDocBookOnePar(ostream & os,
1956 ParagraphList::iterator par, int & desc_on,
1957 lyx::depth_type depth) const
1959 bool emph_flag = false;
1961 LyXLayout_ptr const & style = par->layout();
1963 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1965 int char_line_count = depth;
1966 //if (!style.free_spacing)
1967 // os << string(depth,' ');
1969 // parsing main loop
1970 for (pos_type i = 0; i < par->size(); ++i) {
1971 LyXFont font = par->getFont(params(), i, outerFont(par, paragraphs()));
1973 // handle <emphasis> tag
1974 if (font_old.emph() != font.emph()) {
1975 if (font.emph() == LyXFont::ON) {
1976 if (style->latexparam() == "CDATA")
1979 if (style->latexparam() == "CDATA")
1983 if (style->latexparam() == "CDATA")
1985 os << "</emphasis>";
1986 if (style->latexparam() == "CDATA")
1993 if (par->isInset(i)) {
1994 InsetOld * inset = par->getInset(i);
1995 // don't print the inset in position 0 if desc_on == 3 (label)
1996 if (i || desc_on != 3) {
1997 if (style->latexparam() == "CDATA")
1999 inset->docbook(*this, os, false);
2000 if (style->latexparam() == "CDATA")
2004 char c = par->getChar(i);
2007 boost::tie(ws, str) = sgml::escapeChar(c);
2009 if (style->pass_thru) {
2011 } else if (par->isFreeSpacing() || c != ' ') {
2013 } else if (desc_on == 1) {
2015 os << "\n</term><listitem><para>";
2025 if (style->latexparam() == "CDATA")
2027 os << "</emphasis>";
2028 if (style->latexparam() == "CDATA")
2032 // resets description flag correctly
2034 // <term> not closed...
2035 os << "</term>\n<listitem><para> </para>";
2037 if (style->free_spacing)
2042 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2043 // Other flags: -wall -v0 -x
2044 int Buffer::runChktex()
2048 // get LaTeX-Filename
2049 string const name = getLatexName();
2050 string path = filePath();
2052 string const org_path = path;
2053 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2057 Path p(path); // path to LaTeX file
2058 message(_("Running chktex..."));
2060 // Generate the LaTeX file if neccessary
2061 LatexRunParams runparams;
2062 runparams.flavor = LatexRunParams::LATEX;
2063 runparams.nice = false;
2064 makeLaTeXFile(name, org_path, runparams);
2067 Chktex chktex(lyxrc.chktex_command, name, filePath());
2068 int res = chktex.run(terr); // run chktex
2071 Alert::error(_("chktex failure"),
2072 _("Could not run chktex successfully."));
2073 } else if (res > 0) {
2074 // Insert all errors as errors boxes
2075 bufferErrors(*this, terr);
2084 void Buffer::validate(LaTeXFeatures & features) const
2086 LyXTextClass const & tclass = params().getLyXTextClass();
2088 if (params().tracking_changes) {
2089 features.require("dvipost");
2090 features.require("color");
2093 // AMS Style is at document level
2094 if (params().use_amsmath == BufferParams::AMS_ON
2095 || tclass.provides(LyXTextClass::amsmath))
2096 features.require("amsmath");
2098 for_each(paragraphs().begin(), paragraphs().end(),
2099 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2101 // the bullet shapes are buffer level not paragraph level
2102 // so they are tested here
2103 for (int i = 0; i < 4; ++i) {
2104 if (params().user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
2105 int const font = params().user_defined_bullet(i).getFont();
2107 int const c = params()
2108 .user_defined_bullet(i)
2115 features.require("latexsym");
2117 } else if (font == 1) {
2118 features.require("amssymb");
2119 } else if ((font >= 2 && font <= 5)) {
2120 features.require("pifont");
2125 if (lyxerr.debugging(Debug::LATEX)) {
2126 features.showStruct();
2131 void Buffer::getLabelList(std::vector<string> & list) const
2133 /// if this is a child document and the parent is already loaded
2134 /// Use the parent's list instead [ale990407]
2135 if (!params().parentname.empty()
2136 && bufferlist.exists(params().parentname)) {
2137 Buffer const * tmp = bufferlist.getBuffer(params().parentname);
2139 tmp->getLabelList(list);
2144 for (inset_iterator it = inset_const_iterator_begin();
2145 it != inset_const_iterator_end(); ++it) {
2146 it->getLabelList(*this, list);
2151 // This is also a buffer property (ale)
2152 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
2154 /// if this is a child document and the parent is already loaded
2155 /// use the parent's list instead [ale990412]
2156 if (!params().parentname.empty() &&
2157 bufferlist.exists(params().parentname)) {
2158 Buffer const * tmp = bufferlist.getBuffer(params().parentname);
2160 tmp->fillWithBibKeys(keys);
2165 for (inset_iterator it = inset_const_iterator_begin();
2166 it != inset_const_iterator_end(); ++it) {
2167 if (it->lyxCode() == InsetOld::BIBTEX_CODE) {
2168 InsetBibtex const & inset =
2169 dynamic_cast<InsetBibtex const &>(*it);
2170 inset.fillWithBibKeys(*this, keys);
2171 } else if (it->lyxCode() == InsetOld::INCLUDE_CODE) {
2172 InsetInclude const & inset =
2173 dynamic_cast<InsetInclude const &>(*it);
2174 inset.fillWithBibKeys(*this, keys);
2175 } else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2176 InsetBibitem const & inset =
2177 dynamic_cast<InsetBibitem const &>(*it);
2178 string const key = inset.getContents();
2179 string const opt = inset.getOptions();
2180 string const ref; // = pit->asString(this, false);
2181 string const info = opt + "TheBibliographyRef" + ref;
2182 keys.push_back(pair<string, string>(key, info));
2188 bool Buffer::isDepClean(string const & name) const
2190 DepClean::const_iterator it = pimpl_->dep_clean.find(name);
2191 if (it == pimpl_->dep_clean.end())
2197 void Buffer::markDepClean(string const & name)
2199 pimpl_->dep_clean[name] = true;
2203 bool Buffer::dispatch(string const & command, bool * result)
2205 return dispatch(lyxaction.lookupFunc(command), result);
2209 bool Buffer::dispatch(FuncRequest const & func, bool * result)
2211 bool dispatched = true;
2213 switch (func.action) {
2215 bool const tmp = Exporter::Export(this, func.argument, false);
2228 void Buffer::changeLanguage(Language const * from, Language const * to)
2230 lyxerr << "Changing Language!" << endl;
2232 // Take care of l10n/i18n
2235 ParIterator end = par_iterator_end();
2236 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2237 it->changeLanguage(params(), from, to);
2241 void Buffer::updateDocLang(Language const * nlang)
2243 pimpl_->messages.reset(new Messages(nlang->code()));
2247 bool Buffer::isMultiLingual()
2249 ParIterator end = par_iterator_end();
2250 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2251 if (it->isMultiLingual(params()))
2258 void Buffer::inset_iterator::setParagraph()
2260 while (pit != pend) {
2261 it = pit->insetlist.begin();
2262 if (it != pit->insetlist.end())
2269 InsetOld * Buffer::getInsetFromID(int id_arg) const
2271 for (inset_iterator it = inset_const_iterator_begin();
2272 it != inset_const_iterator_end(); ++it)
2274 if (it->id() == id_arg)
2276 InsetOld * in = it->getInsetFromID(id_arg);
2284 ParIterator Buffer::getParFromID(int id) const
2286 #warning FIXME: const correctness! (Andre)
2287 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2288 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2290 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2292 // John says this is called with id == -1 from undo
2293 lyxerr << "getParFromID(), id: " << id << endl;
2297 for (; it != end; ++it)
2305 bool Buffer::hasParWithID(int id) const
2307 ParConstIterator it = par_iterator_begin();
2308 ParConstIterator end = par_iterator_end();
2311 // John says this is called with id == -1 from undo
2312 lyxerr << "hasParWithID(), id: " << id << endl;
2316 for (; it != end; ++it)
2324 ParIterator Buffer::par_iterator_begin()
2326 return ParIterator(paragraphs().begin(), paragraphs());
2330 ParIterator Buffer::par_iterator_end()
2332 return ParIterator(paragraphs().end(), paragraphs());
2336 ParConstIterator Buffer::par_iterator_begin() const
2338 ParagraphList const & pars = paragraphs();
2339 return ParConstIterator(const_cast<ParagraphList&>(pars).begin(), pars);
2343 ParConstIterator Buffer::par_iterator_end() const
2345 ParagraphList const & pars = paragraphs();
2346 return ParConstIterator(const_cast<ParagraphList&>(pars).end(), pars);
2350 Language const * Buffer::getLanguage() const
2352 return params().language;
2356 string const Buffer::B_(string const & l10n) const
2358 if (pimpl_->messages.get()) {
2359 return pimpl_->messages->get(l10n);
2366 bool Buffer::isClean() const
2368 return pimpl_->lyx_clean;
2372 bool Buffer::isBakClean() const
2374 return pimpl_->bak_clean;
2378 void Buffer::markClean() const
2380 if (!pimpl_->lyx_clean) {
2381 pimpl_->lyx_clean = true;
2384 // if the .lyx file has been saved, we don't need an
2386 pimpl_->bak_clean = true;
2390 void Buffer::markBakClean()
2392 pimpl_->bak_clean = true;
2396 void Buffer::setUnnamed(bool flag)
2398 pimpl_->unnamed = flag;
2402 bool Buffer::isUnnamed()
2404 return pimpl_->unnamed;
2408 void Buffer::markDirty()
2410 if (pimpl_->lyx_clean) {
2411 pimpl_->lyx_clean = false;
2414 pimpl_->bak_clean = false;
2416 DepClean::iterator it = pimpl_->dep_clean.begin();
2417 DepClean::const_iterator const end = pimpl_->dep_clean.end();
2419 for (; it != end; ++it) {
2425 string const & Buffer::fileName() const
2427 return pimpl_->filename;
2431 string const & Buffer::filePath() const
2433 return pimpl_->filepath;
2437 bool Buffer::isReadonly() const
2439 return pimpl_->read_only;
2443 void Buffer::setParentName(string const & name)
2445 params().parentname = name;
2449 Buffer::inset_iterator::inset_iterator()
2454 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2461 Buffer::inset_iterator Buffer::inset_iterator_begin()
2463 return inset_iterator(paragraphs().begin(), paragraphs().end());
2467 Buffer::inset_iterator Buffer::inset_iterator_end()
2469 return inset_iterator(paragraphs().end(), paragraphs().end());
2473 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2475 ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
2476 return inset_iterator(pars.begin(), pars.end());
2480 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2482 ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
2483 return inset_iterator(pars.end(), pars.end());
2487 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2491 if (it == pit->insetlist.end()) {
2500 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2502 inset_iterator tmp = *this;
2508 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2514 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2520 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2526 lyx::pos_type Buffer::inset_iterator::getPos() const
2532 bool operator==(Buffer::inset_iterator const & iter1,
2533 Buffer::inset_iterator const & iter2)
2535 return iter1.pit == iter2.pit
2536 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2540 bool operator!=(Buffer::inset_iterator const & iter1,
2541 Buffer::inset_iterator const & iter2)
2543 return !(iter1 == iter2);