]> git.lyx.org Git - lyx.git/blob - src/buffer.C
466da5bc83be1b51b9604aa3db2215b72c2e2a15
[lyx.git] / src / buffer.C
1 /**
2  * \file buffer.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "buffer.h"
14
15 #include "author.h"
16 #include "BranchList.h"
17 #include "buffer_funcs.h"
18 #include "bufferlist.h"
19 #include "bufferparams.h"
20 #include "counters.h"
21 #include "Bullet.h"
22 #include "Chktex.h"
23 #include "debug.h"
24 #include "encoding.h"
25 #include "errorlist.h"
26 #include "exporter.h"
27 #include "format.h"
28 #include "funcrequest.h"
29 #include "gettext.h"
30 #include "insetiterator.h"
31 #include "language.h"
32 #include "LaTeX.h"
33 #include "LaTeXFeatures.h"
34 #include "LyXAction.h"
35 #include "lyxlex.h"
36 #include "lyxtext.h"
37 #include "lyxrc.h"
38 #include "lyxvc.h"
39 #include "lyx_main.h"
40 #include "messages.h"
41 #include "output.h"
42 #include "output_docbook.h"
43 #include "output_latex.h"
44 #include "paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
47 #include "pariterator.h"
48 #include "sgml.h"
49 #include "texrow.h"
50 #include "undo.h"
51 #include "version.h"
52
53 #include "insets/insetbibitem.h"
54 #include "insets/insetbibtex.h"
55 #include "insets/insetinclude.h"
56 #include "insets/insettext.h"
57
58 #include "mathed/math_macrotemplate.h"
59 #include "mathed/math_macrotable.h"
60 #include "mathed/math_support.h"
61
62 #include "frontends/Alert.h"
63
64 #include "graphics/Previews.h"
65
66 #include "support/types.h"
67 #include "support/lyxalgo.h"
68 #include "support/filetools.h"
69 #include "support/fs_extras.h"
70 # include <boost/iostreams/filtering_stream.hpp>
71 # include <boost/iostreams/filter/gzip.hpp>
72 # include <boost/iostreams/device/file.hpp>
73 namespace io = boost::iostreams;
74 #include "support/lyxlib.h"
75 #include "support/os.h"
76 #include "support/path.h"
77 #include "support/textutils.h"
78 #include "support/convert.h"
79
80 #include <boost/bind.hpp>
81 #include <boost/filesystem/operations.hpp>
82
83 #if defined (HAVE_UTIME_H)
84 # include <utime.h>
85 #elif defined (HAVE_SYS_UTIME_H)
86 # include <sys/utime.h>
87 #endif
88
89 #include <iomanip>
90 #include <stack>
91 #include <sstream>
92 #include <fstream>
93
94
95 using lyx::pos_type;
96 using lyx::pit_type;
97
98 using lyx::support::addName;
99 using lyx::support::bformat;
100 using lyx::support::changeExtension;
101 using lyx::support::cmd_ret;
102 using lyx::support::createBufferTmpDir;
103 using lyx::support::destroyDir;
104 using lyx::support::getFormatFromContents;
105 using lyx::support::isDirWriteable;
106 using lyx::support::libFileSearch;
107 using lyx::support::latex_path;
108 using lyx::support::ltrim;
109 using lyx::support::makeAbsPath;
110 using lyx::support::makeDisplayPath;
111 using lyx::support::makeLatexName;
112 using lyx::support::onlyFilename;
113 using lyx::support::onlyPath;
114 using lyx::support::Path;
115 using lyx::support::quoteName;
116 using lyx::support::removeAutosaveFile;
117 using lyx::support::rename;
118 using lyx::support::runCommand;
119 using lyx::support::split;
120 using lyx::support::subst;
121 using lyx::support::tempName;
122 using lyx::support::trim;
123
124 namespace os = lyx::support::os;
125 namespace fs = boost::filesystem;
126
127 using std::endl;
128 using std::for_each;
129 using std::make_pair;
130
131 using std::ifstream;
132 using std::ios;
133 using std::map;
134 using std::ostream;
135 using std::ostringstream;
136 using std::ofstream;
137 using std::pair;
138 using std::stack;
139 using std::vector;
140 using std::string;
141
142
143 // all these externs should eventually be removed.
144 extern BufferList bufferlist;
145
146 namespace {
147
148 int const LYX_FORMAT = 249;
149
150 } // namespace anon
151
152
153 typedef std::map<string, bool> DepClean;
154
155 class Buffer::Impl
156 {
157 public:
158         Impl(Buffer & parent, string const & file, bool readonly);
159
160         limited_stack<Undo> undostack;
161         limited_stack<Undo> redostack;
162         BufferParams params;
163         LyXVC lyxvc;
164         string temppath;
165         TexRow texrow;
166
167         /// need to regenerate .tex?
168         DepClean dep_clean;
169
170         /// is save needed?
171         mutable bool lyx_clean;
172
173         /// is autosave needed?
174         mutable bool bak_clean;
175
176         /// is this a unnamed file (New...)?
177         bool unnamed;
178
179         /// buffer is r/o
180         bool read_only;
181
182         /// name of the file the buffer is associated with.
183         string filename;
184
185         boost::scoped_ptr<Messages> messages;
186
187         /** Set to true only when the file is fully loaded.
188          *  Used to prevent the premature generation of previews
189          *  and by the citation inset.
190          */
191         bool file_fully_loaded;
192
193         /// our LyXText that should be wrapped in an InsetText
194         InsetText inset;
195
196         ///
197         MacroTable macros;
198 };
199
200
201 Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
202         : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
203           filename(file), file_fully_loaded(false),
204                 inset(params)
205 {
206         inset.setAutoBreakRows(true);
207         lyxvc.buffer(&parent);
208         temppath = createBufferTmpDir();
209         params.filepath = onlyPath(file);
210         // FIXME: And now do something if temppath == string(), because we
211         // assume from now on that temppath points to a valid temp dir.
212         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
213 }
214
215
216 Buffer::Buffer(string const & file, bool readonly)
217         : pimpl_(new Impl(*this, file, readonly))
218 {
219         lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
220 }
221
222
223 Buffer::~Buffer()
224 {
225         lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
226         // here the buffer should take care that it is
227         // saved properly, before it goes into the void.
228
229         closing();
230
231         if (!temppath().empty() && !destroyDir(temppath())) {
232                 Alert::warning(_("Could not remove temporary directory"),
233                         bformat(_("Could not remove the temporary directory %1$s"), temppath()));
234         }
235
236         // Remove any previewed LaTeX snippets associated with this buffer.
237         lyx::graphics::Previews::get().removeLoader(*this);
238 }
239
240
241 LyXText & Buffer::text() const
242 {
243         return const_cast<LyXText &>(pimpl_->inset.text_);
244 }
245
246
247 InsetBase & Buffer::inset() const
248 {
249         return const_cast<InsetText &>(pimpl_->inset);
250 }
251
252
253 limited_stack<Undo> & Buffer::undostack()
254 {
255         return pimpl_->undostack;
256 }
257
258
259 limited_stack<Undo> const & Buffer::undostack() const
260 {
261         return pimpl_->undostack;
262 }
263
264
265 limited_stack<Undo> & Buffer::redostack()
266 {
267         return pimpl_->redostack;
268 }
269
270
271 limited_stack<Undo> const & Buffer::redostack() const
272 {
273         return pimpl_->redostack;
274 }
275
276
277 BufferParams & Buffer::params()
278 {
279         return pimpl_->params;
280 }
281
282
283 BufferParams const & Buffer::params() const
284 {
285         return pimpl_->params;
286 }
287
288
289 ParagraphList & Buffer::paragraphs()
290 {
291         return text().paragraphs();
292 }
293
294
295 ParagraphList const & Buffer::paragraphs() const
296 {
297         return text().paragraphs();
298 }
299
300
301 LyXVC & Buffer::lyxvc()
302 {
303         return pimpl_->lyxvc;
304 }
305
306
307 LyXVC const & Buffer::lyxvc() const
308 {
309         return pimpl_->lyxvc;
310 }
311
312
313 string const & Buffer::temppath() const
314 {
315         return pimpl_->temppath;
316 }
317
318
319 TexRow & Buffer::texrow()
320 {
321         return pimpl_->texrow;
322 }
323
324
325 TexRow const & Buffer::texrow() const
326 {
327         return pimpl_->texrow;
328 }
329
330
331 string const Buffer::getLatexName(bool const no_path) const
332 {
333         string const name = changeExtension(makeLatexName(fileName()), ".tex");
334         return no_path ? onlyFilename(name) : name;
335 }
336
337
338 pair<Buffer::LogType, string> const Buffer::getLogName() const
339 {
340         string const filename = getLatexName(false);
341
342         if (filename.empty())
343                 return make_pair(Buffer::latexlog, string());
344
345         string const path = temppath();
346
347         string const fname = addName(path,
348                                      onlyFilename(changeExtension(filename,
349                                                                   ".log")));
350         string const bname =
351                 addName(path, onlyFilename(
352                         changeExtension(filename,
353                                         formats.extension("literate") + ".out")));
354
355         // If no Latex log or Build log is newer, show Build log
356
357         if (fs::exists(bname) &&
358             (!fs::exists(fname) || fs::last_write_time(fname) < fs::last_write_time(bname))) {
359                 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
360                 return make_pair(Buffer::buildlog, bname);
361         }
362         lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
363         return make_pair(Buffer::latexlog, fname);
364 }
365
366
367 void Buffer::setReadonly(bool const flag)
368 {
369         if (pimpl_->read_only != flag) {
370                 pimpl_->read_only = flag;
371                 readonly(flag);
372         }
373 }
374
375
376 void Buffer::setFileName(string const & newfile)
377 {
378         pimpl_->filename = makeAbsPath(newfile);
379         params().filepath = onlyPath(pimpl_->filename);
380         setReadonly(fs::is_readonly(pimpl_->filename));
381         updateTitles();
382 }
383
384
385 // We'll remove this later. (Lgb)
386 namespace {
387
388 void unknownClass(string const & unknown)
389 {
390         Alert::warning(_("Unknown document class"),
391                 bformat(_("Using the default document class, because the "
392                         "class %1$s is unknown."), unknown));
393 }
394
395 } // anon
396
397
398 int Buffer::readHeader(LyXLex & lex)
399 {
400         int unknown_tokens = 0;
401         int line = -1;
402         int begin_header_line = -1;
403
404         // Initialize parameters that may be/go lacking in header:
405         params().branchlist().clear();
406         params().preamble.erase();
407         params().options.erase();
408         params().float_placement.erase();
409         params().paperwidth.erase();
410         params().paperheight.erase();
411         params().leftmargin.erase();
412         params().rightmargin.erase();
413         params().topmargin.erase();
414         params().bottommargin.erase();
415         params().headheight.erase();
416         params().headsep.erase();
417         params().footskip.erase();
418
419         ErrorList & errorList = errorLists_["Parse"];
420
421         while (lex.isOK()) {
422                 lex.next();
423                 string const token = lex.getString();
424
425                 if (token.empty())
426                         continue;
427
428                 if (token == "\\end_header")
429                         break;
430
431                 ++line;
432                 if (token == "\\begin_header") {
433                         begin_header_line = line;
434                         continue;
435                 }
436
437                 lyxerr[Debug::PARSER] << "Handling document header token: `"
438                                       << token << '\'' << endl;
439
440                 string unknown = params().readToken(lex, token);
441                 if (!unknown.empty()) {
442                         if (unknown[0] != '\\' && token == "\\textclass") {
443                                 unknownClass(unknown);
444                         } else {
445                                 ++unknown_tokens;
446                                 string const s = bformat(_("Unknown token: "
447                                                            "%1$s %2$s\n"),
448                                                          token,
449                                                          lex.getString());
450                                 errorList.push_back(ErrorItem(_("Document header error"),
451                                         s, -1, 0, 0));
452                         }
453                 }
454         }
455         if (begin_header_line) {
456                 string const s = _("\\begin_header is missing");
457                 errorList.push_back(ErrorItem(_("Document header error"),
458                         s, -1, 0, 0));
459         }
460
461         return unknown_tokens;
462 }
463
464
465 // Uwe C. Schroeder
466 // changed to be public and have one parameter
467 // Returns false if "\end_document" is not read (Asger)
468 bool Buffer::readDocument(LyXLex & lex)
469 {
470         ErrorList & errorList = errorLists_["Parse"];
471         errorList.clear();
472
473         lex.next();
474         string const token = lex.getString();
475         if (token != "\\begin_document") {
476                 string const s = _("\\begin_document is missing");
477                 errorList.push_back(ErrorItem(_("Document header error"),
478                         s, -1, 0, 0));
479         }
480
481         // we are reading in a brand new document
482         BOOST_ASSERT(paragraphs().empty());
483
484         readHeader(lex);
485         if (!params().getLyXTextClass().load(filePath())) {
486                 string theclass = params().getLyXTextClass().name();
487                 Alert::error(_("Can't load document class"), bformat(
488                                      "Using the default document class, because the "
489                                      " class %1$s could not be loaded.", theclass));
490                 params().textclass = 0;
491         }
492
493         bool const res = text().read(*this, lex, errorList);
494         for_each(text().paragraphs().begin(),
495                  text().paragraphs().end(),
496                  bind(&Paragraph::setInsetOwner, _1, &inset()));
497         updateBibfilesCache();
498
499         return res;
500 }
501
502
503 // needed to insert the selection
504 void Buffer::insertStringAsLines(ParagraphList & pars,
505         pit_type & pit, pos_type & pos,
506         LyXFont const & fn, string const & str, bool autobreakrows)
507 {
508         LyXFont font = fn;
509
510         // insert the string, don't insert doublespace
511         bool space_inserted = true;
512         for (string::const_iterator cit = str.begin();
513             cit != str.end(); ++cit) {
514                 Paragraph & par = pars[pit];
515                 if (*cit == '\n') {
516                         if (autobreakrows && (!par.empty() || par.allowEmpty())) {
517                                 breakParagraph(params(), pars, pit, pos,
518                                                par.layout()->isEnvironment());
519                                 ++pit;
520                                 pos = 0;
521                                 space_inserted = true;
522                         } else {
523                                 continue;
524                         }
525                         // do not insert consecutive spaces if !free_spacing
526                 } else if ((*cit == ' ' || *cit == '\t') &&
527                            space_inserted && !par.isFreeSpacing()) {
528                         continue;
529                 } else if (*cit == '\t') {
530                         if (!par.isFreeSpacing()) {
531                                 // tabs are like spaces here
532                                 par.insertChar(pos, ' ', font);
533                                 ++pos;
534                                 space_inserted = true;
535                         } else {
536                                 const pos_type n = 8 - pos % 8;
537                                 for (pos_type i = 0; i < n; ++i) {
538                                         par.insertChar(pos, ' ', font);
539                                         ++pos;
540                                 }
541                                 space_inserted = true;
542                         }
543                 } else if (!isPrintable(*cit)) {
544                         // Ignore unprintables
545                         continue;
546                 } else {
547                         // just insert the character
548                         par.insertChar(pos, *cit, font);
549                         ++pos;
550                         space_inserted = (*cit == ' ');
551                 }
552
553         }
554 }
555
556
557 bool Buffer::readFile(string const & filename)
558 {
559         // Check if the file is compressed.
560         string const format = getFormatFromContents(filename);
561         if (format == "gzip" || format == "zip" || format == "compress") {
562                 params().compressed = true;
563         }
564
565         // remove dummy empty par
566         paragraphs().clear();
567         LyXLex lex(0, 0);
568         lex.setFile(filename);
569         if (!readFile(lex, filename))
570                 return false;
571
572         // After we have read a file, we must ensure that the buffer
573         // language is set and used in the gui.
574         // If you know of a better place to put this, please tell me. (Lgb)
575         updateDocLang(params().language);
576
577         return true;
578 }
579
580
581 bool Buffer::fully_loaded() const
582 {
583         return pimpl_->file_fully_loaded;
584 }
585
586
587 void Buffer::fully_loaded(bool const value)
588 {
589         pimpl_->file_fully_loaded = value;
590 }
591
592
593 bool Buffer::readFile(LyXLex & lex, string const & filename)
594 {
595         BOOST_ASSERT(!filename.empty());
596
597         if (!lex.isOK()) {
598                 Alert::error(_("Document could not be read"),
599                              bformat(_("%1$s could not be read."), filename));
600                 return false;
601         }
602
603         lex.next();
604         string const token(lex.getString());
605
606         if (!lex.isOK()) {
607                 Alert::error(_("Document could not be read"),
608                              bformat(_("%1$s could not be read."), filename));
609                 return false;
610         }
611
612         // the first token _must_ be...
613         if (token != "\\lyxformat") {
614                 lyxerr << "Token: " << token << endl;
615
616                 Alert::error(_("Document format failure"),
617                              bformat(_("%1$s is not a LyX document."),
618                                        filename));
619                 return false;
620         }
621
622         lex.next();
623         string tmp_format = lex.getString();
624         //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
625         // if present remove ".," from string.
626         string::size_type dot = tmp_format.find_first_of(".,");
627         //lyxerr << "           dot found at " << dot << endl;
628         if (dot != string::npos)
629                         tmp_format.erase(dot, 1);
630         int const file_format = convert<int>(tmp_format);
631         //lyxerr << "format: " << file_format << endl;
632
633         if (file_format != LYX_FORMAT) {
634                 string const tmpfile = tempName();
635                 if (tmpfile.empty()) {
636                         Alert::error(_("Conversion failed"),
637                                      bformat(_("%1$s is from an earlier"
638                                               " version of LyX, but a temporary"
639                                               " file for converting it could"
640                                               " not be created."),
641                                               filename));
642                         return false;
643                 }
644                 string const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
645                 if (lyx2lyx.empty()) {
646                         Alert::error(_("Conversion script not found"),
647                                      bformat(_("%1$s is from an earlier"
648                                                " version of LyX, but the"
649                                                " conversion script lyx2lyx"
650                                                " could not be found."),
651                                                filename));
652                         return false;
653                 }
654                 ostringstream command;
655                 command << os::python() << ' ' << quoteName(lyx2lyx)
656                         << " -t " << convert<string>(LYX_FORMAT)
657                         << " -o " << quoteName(tmpfile) << ' '
658                         << quoteName(filename);
659                 string const command_str = command.str();
660
661                 lyxerr[Debug::INFO] << "Running '"
662                                     << command_str << '\''
663                                     << endl;
664
665                 cmd_ret const ret = runCommand(command_str);
666                 if (ret.first != 0) {
667                         Alert::error(_("Conversion script failed"),
668                                      bformat(_("%1$s is from an earlier version"
669                                               " of LyX, but the lyx2lyx script"
670                                               " failed to convert it."),
671                                               filename));
672                         return false;
673                 } else {
674                         bool const ret = readFile(tmpfile);
675                         // Do stuff with tmpfile name and buffer name here.
676                         return ret;
677                 }
678
679         }
680
681         if (readDocument(lex)) {
682                 Alert::error(_("Document format failure"),
683                              bformat(_("%1$s ended unexpectedly, which means"
684                                        " that it is probably corrupted."),
685                                        filename));
686         }
687
688         //lyxerr << "removing " << MacroTable::localMacros().size()
689         //      << " temporary macro entries" << endl;
690         //MacroTable::localMacros().clear();
691
692         pimpl_->file_fully_loaded = true;
693         return true;
694 }
695
696
697 // Should probably be moved to somewhere else: BufferView? LyXView?
698 bool Buffer::save() const
699 {
700         // We don't need autosaves in the immediate future. (Asger)
701         resetAutosaveTimers();
702
703         // make a backup
704         string s;
705         if (lyxrc.make_backup) {
706                 s = fileName() + '~';
707                 if (!lyxrc.backupdir_path.empty())
708                         s = addName(lyxrc.backupdir_path,
709                                     subst(os::internal_path(s),'/','!'));
710
711                 // It might very well be that this variant is just
712                 // good enough. (Lgb)
713                 // But to use this we need fs::copy_file to actually do a copy,
714                 // even when the target file exists. (Lgb)
715                 if (fs::exists(fileName()) && fs::is_writable(fs::path(fileName()).branch_path())) {
716                   //try {
717                     fs::copy_file(fileName(), s, false);
718                     //}
719                     //catch (fs::filesystem_error const & fe) {
720                     //lyxerr << "LyX was not able to make backup copy. Beware.\n"
721                     //     << fe.what() << endl;
722                     //}
723                 }
724         }
725
726         if (writeFile(fileName())) {
727                 markClean();
728                 removeAutosaveFile(fileName());
729         } else {
730                 // Saving failed, so backup is not backup
731                 if (lyxrc.make_backup)
732                         rename(s, fileName());
733                 return false;
734         }
735         return true;
736 }
737
738
739 bool Buffer::writeFile(string const & fname) const
740 {
741         if (pimpl_->read_only && fname == fileName())
742                 return false;
743
744         bool retval = false;
745
746         if (params().compressed) {
747                 io::filtering_ostream ofs(io::gzip_compressor() | io::file_sink(fname));
748                 if (!ofs)
749                         return false;
750
751                 retval = do_writeFile(ofs);
752         } else {
753                 ofstream ofs(fname.c_str(), ios::out|ios::trunc);
754                 if (!ofs)
755                         return false;
756
757                 retval = do_writeFile(ofs);
758         }
759
760         return retval;
761 }
762
763
764 bool Buffer::do_writeFile(ostream & ofs) const
765 {
766 #ifdef HAVE_LOCALE
767         // Use the standard "C" locale for file output.
768         ofs.imbue(std::locale::classic());
769 #endif
770
771         // The top of the file should not be written by params().
772
773         // write out a comment in the top of the file
774         ofs << "#LyX " << lyx_version
775             << " created this file. For more info see http://www.lyx.org/\n"
776             << "\\lyxformat " << LYX_FORMAT << "\n"
777             << "\\begin_document\n";
778
779         // now write out the buffer parameters.
780         ofs << "\\begin_header\n";
781         params().writeFile(ofs);
782         ofs << "\\end_header\n";
783
784         // write the text
785         ofs << "\n\\begin_body\n";
786         text().write(*this, ofs);
787         ofs << "\n\\end_body\n";
788
789         // Write marker that shows file is complete
790         ofs << "\\end_document" << endl;
791
792         // Shouldn't really be needed....
793         //ofs.close();
794
795         // how to check if close went ok?
796         // Following is an attempt... (BE 20001011)
797
798         // good() returns false if any error occured, including some
799         //        formatting error.
800         // bad()  returns true if something bad happened in the buffer,
801         //        which should include file system full errors.
802
803         bool status = true;
804         if (!ofs) {
805                 status = false;
806                 lyxerr << "File was not closed properly." << endl;
807         }
808
809         return status;
810 }
811
812
813 void Buffer::makeLaTeXFile(string const & fname,
814                            string const & original_path,
815                            OutputParams const & runparams,
816                            bool output_preamble, bool output_body)
817 {
818         lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
819
820         ofstream ofs;
821         if (!openFileWrite(ofs, fname))
822                 return;
823
824         writeLaTeXSource(ofs, original_path,
825                       runparams, output_preamble, output_body);
826
827         ofs.close();
828         if (ofs.fail())
829                 lyxerr << "File '" << fname << "' was not closed properly." << endl;
830 }
831
832
833 void Buffer::writeLaTeXSource(ostream & os,
834                            string const & original_path,
835                            OutputParams const & runparams_in,
836                            bool const output_preamble, bool const output_body)
837 {
838         OutputParams runparams = runparams_in;
839
840         // validate the buffer.
841         lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
842         LaTeXFeatures features(*this, params(), runparams);
843         validate(features);
844         lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
845
846         texrow().reset();
847
848         // The starting paragraph of the coming rows is the
849         // first paragraph of the document. (Asger)
850         texrow().start(paragraphs().begin()->id(), 0);
851
852         if (output_preamble && runparams.nice) {
853                 os << "%% LyX " << lyx_version << " created this file.  "
854                         "For more info, see http://www.lyx.org/.\n"
855                         "%% Do not edit unless you really know what "
856                         "you are doing.\n";
857                 texrow().newline();
858                 texrow().newline();
859         }
860         lyxerr[Debug::INFO] << "lyx document header finished" << endl;
861         // There are a few differences between nice LaTeX and usual files:
862         // usual is \batchmode and has a
863         // special input@path to allow the including of figures
864         // with either \input or \includegraphics (what figinsets do).
865         // input@path is set when the actual parameter
866         // original_path is set. This is done for usual tex-file, but not
867         // for nice-latex-file. (Matthias 250696)
868         // Note that input@path is only needed for something the user does
869         // in the preamble, included .tex files or ERT, files included by
870         // LyX work without it.
871         if (output_preamble) {
872                 if (!runparams.nice) {
873                         // code for usual, NOT nice-latex-file
874                         os << "\\batchmode\n"; // changed
875                         // from \nonstopmode
876                         texrow().newline();
877                 }
878                 if (!original_path.empty()) {
879                         string const inputpath = latex_path(original_path);
880                         os << "\\makeatletter\n"
881                             << "\\def\\input@path{{"
882                             << inputpath << "/}}\n"
883                             << "\\makeatother\n";
884                         texrow().newline();
885                         texrow().newline();
886                         texrow().newline();
887                 }
888
889                 // Write the preamble
890                 runparams.use_babel = params().writeLaTeX(os, features, texrow());
891
892                 if (!output_body)
893                         return;
894
895                 // make the body.
896                 os << "\\begin{document}\n";
897                 texrow().newline();
898         } // output_preamble
899         lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
900
901         if (!lyxrc.language_auto_begin) {
902                 os << subst(lyxrc.language_command_begin, "$$lang",
903                              params().language->babel())
904                     << endl;
905                 texrow().newline();
906         }
907
908         // if we are doing a real file with body, even if this is the
909         // child of some other buffer, let's cut the link here.
910         // This happens for example if only a child document is printed.
911         string save_parentname;
912         if (output_preamble) {
913                 save_parentname = params().parentname;
914                 params().parentname.erase();
915         }
916
917         // the real stuff
918         latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
919
920         // Restore the parenthood if needed
921         if (output_preamble)
922                 params().parentname = save_parentname;
923
924         // add this just in case after all the paragraphs
925         os << endl;
926         texrow().newline();
927
928         if (!lyxrc.language_auto_end) {
929                 os << subst(lyxrc.language_command_end, "$$lang",
930                              params().language->babel())
931                     << endl;
932                 texrow().newline();
933         }
934
935         if (output_preamble) {
936                 os << "\\end{document}\n";
937                 texrow().newline();
938
939                 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
940         } else {
941                 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
942                                      << endl;
943         }
944
945         // Just to be sure. (Asger)
946         texrow().newline();
947
948         lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
949         lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
950                             << '.' << endl;
951 }
952
953
954 bool Buffer::isLatex() const
955 {
956         return params().getLyXTextClass().outputType() == LATEX;
957 }
958
959
960 bool Buffer::isLiterate() const
961 {
962         return params().getLyXTextClass().outputType() == LITERATE;
963 }
964
965
966 bool Buffer::isDocBook() const
967 {
968         return params().getLyXTextClass().outputType() == DOCBOOK;
969 }
970
971
972 void Buffer::makeDocBookFile(string const & fname,
973                               OutputParams const & runparams,
974                               bool const body_only)
975 {
976         lyxerr[Debug::LATEX] << "makeDocBookFile..." << endl;
977
978         ofstream ofs;
979         if (!openFileWrite(ofs, fname))
980                 return;
981
982         writeDocBookSource(ofs, fname, runparams, body_only);
983
984         ofs.close();
985         if (ofs.fail())
986                 lyxerr << "File '" << fname << "' was not closed properly." << endl;
987 }
988
989
990 void Buffer::writeDocBookSource(ostream & os, string const & fname,
991                              OutputParams const & runparams,
992                              bool const only_body)
993 {
994         LaTeXFeatures features(*this, params(), runparams);
995         validate(features);
996
997         texrow().reset();
998
999         LyXTextClass const & tclass = params().getLyXTextClass();
1000         string const & top_element = tclass.latexname();
1001
1002         if (!only_body) {
1003                 if (runparams.flavor == OutputParams::XML)
1004                         os << "<?xml version=\"1.0\" encoding=\""
1005                             << params().language->encoding()->name() << "\"?>\n";
1006
1007                 os << "<!DOCTYPE " << top_element << " ";
1008
1009                 if (! tclass.class_header().empty()) os << tclass.class_header();
1010                 else if (runparams.flavor == OutputParams::XML)
1011                         os << "PUBLIC \"-//OASIS//DTD DocBook XML//EN\" "
1012                             << "\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\"";
1013                 else
1014                         os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\"";
1015
1016                 string preamble = params().preamble;
1017                 if (runparams.flavor != OutputParams::XML ) {
1018                         preamble += "<!ENTITY % output.print.png \"IGNORE\">\n";
1019                         preamble += "<!ENTITY % output.print.pdf \"IGNORE\">\n";
1020                         preamble += "<!ENTITY % output.print.eps \"IGNORE\">\n";
1021                         preamble += "<!ENTITY % output.print.bmp \"IGNORE\">\n";
1022                 }
1023
1024                 string const name = runparams.nice ? changeExtension(pimpl_->filename, ".sgml")
1025                          : fname;
1026                 preamble += features.getIncludedFiles(name);
1027                 preamble += features.getLyXSGMLEntities();
1028
1029                 if (!preamble.empty()) {
1030                         os << "\n [ " << preamble << " ]";
1031                 }
1032                 os << ">\n\n";
1033         }
1034
1035         string top = top_element;
1036         top += " lang=\"";
1037         if (runparams.flavor == OutputParams::XML)
1038                 top += params().language->code();
1039         else
1040                 top += params().language->code().substr(0,2);
1041         top += '"';
1042
1043         if (!params().options.empty()) {
1044                 top += ' ';
1045                 top += params().options;
1046         }
1047
1048         os << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML")
1049             << " file was created by LyX " << lyx_version
1050             << "\n  See http://www.lyx.org/ for more information -->\n";
1051
1052         params().getLyXTextClass().counters().reset();
1053
1054         sgml::openTag(os, top);
1055         os << '\n';
1056         docbookParagraphs(paragraphs(), *this, os, runparams);
1057         sgml::closeTag(os, top_element);
1058 }
1059
1060
1061 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1062 // Other flags: -wall -v0 -x
1063 int Buffer::runChktex()
1064 {
1065         busy(true);
1066
1067         // get LaTeX-Filename
1068         string const name = getLatexName();
1069         string const path = temppath();
1070         string const org_path = filePath();
1071
1072         Path p(path); // path to LaTeX file
1073         message(_("Running chktex..."));
1074
1075         // Generate the LaTeX file if neccessary
1076         OutputParams runparams;
1077         runparams.flavor = OutputParams::LATEX;
1078         runparams.nice = false;
1079         makeLaTeXFile(name, org_path, runparams);
1080
1081         TeXErrors terr;
1082         Chktex chktex(lyxrc.chktex_command, name, filePath());
1083         int const res = chktex.run(terr); // run chktex
1084
1085         if (res == -1) {
1086                 Alert::error(_("chktex failure"),
1087                              _("Could not run chktex successfully."));
1088         } else if (res > 0) {
1089                 // Fill-in the error list with the TeX errors
1090                 bufferErrors(*this, terr, errorLists_["ChkTex"]);
1091         }
1092
1093         busy(false);
1094
1095         errors("ChkTeX");
1096
1097         return res;
1098 }
1099
1100
1101 void Buffer::validate(LaTeXFeatures & features) const
1102 {
1103         LyXTextClass const & tclass = params().getLyXTextClass();
1104
1105         if (features.isAvailable("dvipost") && params().tracking_changes
1106             && params().output_changes)
1107                 features.require("dvipost");
1108
1109         // AMS Style is at document level
1110         if (params().use_amsmath == BufferParams::AMS_ON
1111             || tclass.provides(LyXTextClass::amsmath))
1112                 features.require("amsmath");
1113
1114         for_each(paragraphs().begin(), paragraphs().end(),
1115                  boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1116
1117         // the bullet shapes are buffer level not paragraph level
1118         // so they are tested here
1119         for (int i = 0; i < 4; ++i) {
1120                 if (params().user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1121                         int const font = params().user_defined_bullet(i).getFont();
1122                         if (font == 0) {
1123                                 int const c = params()
1124                                         .user_defined_bullet(i)
1125                                         .getCharacter();
1126                                 if (c == 16
1127                                    || c == 17
1128                                    || c == 25
1129                                    || c == 26
1130                                    || c == 31) {
1131                                         features.require("latexsym");
1132                                 }
1133                         } else if (font == 1) {
1134                                 features.require("amssymb");
1135                         } else if ((font >= 2 && font <= 5)) {
1136                                 features.require("pifont");
1137                         }
1138                 }
1139         }
1140
1141         if (lyxerr.debugging(Debug::LATEX)) {
1142                 features.showStruct();
1143         }
1144 }
1145
1146
1147 void Buffer::getLabelList(vector<string> & list) const
1148 {
1149         /// if this is a child document and the parent is already loaded
1150         /// Use the parent's list instead  [ale990407]
1151         Buffer const * tmp = getMasterBuffer();
1152         if (!tmp) {
1153                 lyxerr << "getMasterBuffer() failed!" << endl;
1154                 BOOST_ASSERT(tmp);
1155         }
1156         if (tmp != this) {
1157                 tmp->getLabelList(list);
1158                 return;
1159         }
1160
1161         for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
1162                 it.nextInset()->getLabelList(*this, list);
1163 }
1164
1165
1166 // This is also a buffer property (ale)
1167 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys)
1168         const
1169 {
1170         /// if this is a child document and the parent is already loaded
1171         /// use the parent's list instead  [ale990412]
1172         Buffer const * tmp = getMasterBuffer();
1173         BOOST_ASSERT(tmp);
1174         if (tmp != this) {
1175                 tmp->fillWithBibKeys(keys);
1176                 return;
1177         }
1178
1179         for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
1180                 if (it->lyxCode() == InsetBase::BIBTEX_CODE) {
1181                         InsetBibtex const & inset =
1182                                 dynamic_cast<InsetBibtex const &>(*it);
1183                         inset.fillWithBibKeys(*this, keys);
1184                 } else if (it->lyxCode() == InsetBase::INCLUDE_CODE) {
1185                         InsetInclude const & inset =
1186                                 dynamic_cast<InsetInclude const &>(*it);
1187                         inset.fillWithBibKeys(*this, keys);
1188                 } else if (it->lyxCode() == InsetBase::BIBITEM_CODE) {
1189                         InsetBibitem const & inset =
1190                                 dynamic_cast<InsetBibitem const &>(*it);
1191                         string const key = inset.getContents();
1192                         string const opt = inset.getOptions();
1193                         string const ref; // = pit->asString(this, false);
1194                         string const info = opt + "TheBibliographyRef" + ref;
1195                         keys.push_back(pair<string, string>(key, info));
1196                 }
1197         }
1198 }
1199
1200
1201 void Buffer::updateBibfilesCache()
1202 {
1203         // if this is a child document and the parent is already loaded
1204         // update the parent's cache instead
1205         Buffer * tmp = getMasterBuffer();
1206         BOOST_ASSERT(tmp);
1207         if (tmp != this) {
1208                 tmp->updateBibfilesCache();
1209                 return;
1210         }
1211
1212         bibfilesCache_.clear();
1213         for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
1214                 if (it->lyxCode() == InsetBase::BIBTEX_CODE) {
1215                         InsetBibtex const & inset =
1216                                 dynamic_cast<InsetBibtex const &>(*it);
1217                         vector<string> const bibfiles = inset.getFiles(*this);
1218                         bibfilesCache_.insert(bibfilesCache_.end(),
1219                                 bibfiles.begin(),
1220                                 bibfiles.end());
1221                 } else if (it->lyxCode() == InsetBase::INCLUDE_CODE) {
1222                         InsetInclude & inset =
1223                                 dynamic_cast<InsetInclude &>(*it);
1224                         inset.updateBibfilesCache(*this);
1225                         vector<string> const & bibfiles =
1226                                         inset.getBibfilesCache(*this);
1227                         bibfilesCache_.insert(bibfilesCache_.end(),
1228                                 bibfiles.begin(),
1229                                 bibfiles.end());
1230                 }
1231         }
1232 }
1233
1234
1235 vector<string> const & Buffer::getBibfilesCache() const
1236 {
1237         // if this is a child document and the parent is already loaded
1238         // use the parent's cache instead
1239         Buffer const * tmp = getMasterBuffer();
1240         BOOST_ASSERT(tmp);
1241         if (tmp != this)
1242                 return tmp->getBibfilesCache();
1243
1244         return bibfilesCache_;
1245 }
1246
1247
1248 bool Buffer::isDepClean(string const & name) const
1249 {
1250         DepClean::const_iterator const it = pimpl_->dep_clean.find(name);
1251         if (it == pimpl_->dep_clean.end())
1252                 return true;
1253         return it->second;
1254 }
1255
1256
1257 void Buffer::markDepClean(string const & name)
1258 {
1259         pimpl_->dep_clean[name] = true;
1260 }
1261
1262
1263 bool Buffer::dispatch(string const & command, bool * result)
1264 {
1265         return dispatch(lyxaction.lookupFunc(command), result);
1266 }
1267
1268
1269 bool Buffer::dispatch(FuncRequest const & func, bool * result)
1270 {
1271         bool dispatched = true;
1272
1273         switch (func.action) {
1274                 case LFUN_BUFFER_EXPORT: {
1275                         bool const tmp = Exporter::Export(this, func.argument, false);
1276                         if (result)
1277                                 *result = tmp;
1278                         break;
1279                 }
1280
1281                 default:
1282                         dispatched = false;
1283         }
1284         return dispatched;
1285 }
1286
1287
1288 void Buffer::changeLanguage(Language const * from, Language const * to)
1289 {
1290         BOOST_ASSERT(from);
1291         BOOST_ASSERT(to);
1292
1293         // Take care of l10n/i18n
1294         updateDocLang(to);
1295
1296         for_each(par_iterator_begin(),
1297                  par_iterator_end(),
1298                  bind(&Paragraph::changeLanguage, _1, params(), from, to));
1299
1300         text().current_font.setLanguage(to);
1301         text().real_current_font.setLanguage(to);
1302 }
1303
1304
1305 void Buffer::updateDocLang(Language const * nlang)
1306 {
1307         BOOST_ASSERT(nlang);
1308
1309         pimpl_->messages.reset(new Messages(nlang->code()));
1310
1311         updateLabels(*this);
1312 }
1313
1314
1315 bool Buffer::isMultiLingual() const
1316 {
1317         ParConstIterator end = par_iterator_end();
1318         for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
1319                 if (it->isMultiLingual(params()))
1320                         return true;
1321
1322         return false;
1323 }
1324
1325
1326 ParIterator Buffer::getParFromID(int const id) const
1327 {
1328         ParConstIterator it = par_iterator_begin();
1329         ParConstIterator const end = par_iterator_end();
1330
1331         if (id < 0) {
1332                 // John says this is called with id == -1 from undo
1333                 lyxerr << "getParFromID(), id: " << id << endl;
1334                 return end;
1335         }
1336
1337         for (; it != end; ++it)
1338                 if (it->id() == id)
1339                         return it;
1340
1341         return end;
1342 }
1343
1344
1345 bool Buffer::hasParWithID(int const id) const
1346 {
1347         ParConstIterator const it = getParFromID(id);
1348         return it != par_iterator_end();
1349 }
1350
1351
1352 ParIterator Buffer::par_iterator_begin()
1353 {
1354         return ::par_iterator_begin(inset());
1355 }
1356
1357
1358 ParIterator Buffer::par_iterator_end()
1359 {
1360         return ::par_iterator_end(inset());
1361 }
1362
1363
1364 ParConstIterator Buffer::par_iterator_begin() const
1365 {
1366         return ::par_const_iterator_begin(inset());
1367 }
1368
1369
1370 ParConstIterator Buffer::par_iterator_end() const
1371 {
1372         return ::par_const_iterator_end(inset());
1373 }
1374
1375
1376 Language const * Buffer::getLanguage() const
1377 {
1378         return params().language;
1379 }
1380
1381
1382 string const Buffer::B_(string const & l10n) const
1383 {
1384         if (pimpl_->messages.get()) {
1385                 return pimpl_->messages->get(l10n);
1386         }
1387
1388         return _(l10n);
1389 }
1390
1391
1392 bool Buffer::isClean() const
1393 {
1394         return pimpl_->lyx_clean;
1395 }
1396
1397
1398 bool Buffer::isBakClean() const
1399 {
1400         return pimpl_->bak_clean;
1401 }
1402
1403
1404 void Buffer::markClean() const
1405 {
1406         if (!pimpl_->lyx_clean) {
1407                 pimpl_->lyx_clean = true;
1408                 updateTitles();
1409         }
1410         // if the .lyx file has been saved, we don't need an
1411         // autosave
1412         pimpl_->bak_clean = true;
1413 }
1414
1415
1416 void Buffer::markBakClean()
1417 {
1418         pimpl_->bak_clean = true;
1419 }
1420
1421
1422 void Buffer::setUnnamed(bool flag)
1423 {
1424         pimpl_->unnamed = flag;
1425 }
1426
1427
1428 bool Buffer::isUnnamed() const
1429 {
1430         return pimpl_->unnamed;
1431 }
1432
1433
1434 #ifdef WITH_WARNINGS
1435 #warning this function should be moved to buffer_pimpl.C
1436 #endif
1437 void Buffer::markDirty()
1438 {
1439         if (pimpl_->lyx_clean) {
1440                 pimpl_->lyx_clean = false;
1441                 updateTitles();
1442         }
1443         pimpl_->bak_clean = false;
1444
1445         DepClean::iterator it = pimpl_->dep_clean.begin();
1446         DepClean::const_iterator const end = pimpl_->dep_clean.end();
1447
1448         for (; it != end; ++it) {
1449                 it->second = false;
1450         }
1451 }
1452
1453
1454 string const & Buffer::fileName() const
1455 {
1456         return pimpl_->filename;
1457 }
1458
1459
1460 string const & Buffer::filePath() const
1461 {
1462         return params().filepath;
1463 }
1464
1465
1466 bool Buffer::isReadonly() const
1467 {
1468         return pimpl_->read_only;
1469 }
1470
1471
1472 void Buffer::setParentName(string const & name)
1473 {
1474         params().parentname = name;
1475 }
1476
1477
1478 Buffer const * Buffer::getMasterBuffer() const
1479 {
1480         if (!params().parentname.empty()
1481             && bufferlist.exists(params().parentname)) {
1482                 Buffer const * buf = bufferlist.getBuffer(params().parentname);
1483                 if (buf)
1484                         return buf->getMasterBuffer();
1485         }
1486
1487         return this;
1488 }
1489
1490
1491 Buffer * Buffer::getMasterBuffer()
1492 {
1493         if (!params().parentname.empty()
1494             && bufferlist.exists(params().parentname)) {
1495                 Buffer * buf = bufferlist.getBuffer(params().parentname);
1496                 if (buf)
1497                         return buf->getMasterBuffer();
1498         }
1499
1500         return this;
1501 }
1502
1503
1504 MacroData const & Buffer::getMacro(std::string const & name) const
1505 {
1506         return pimpl_->macros.get(name);
1507 }
1508
1509
1510 bool Buffer::hasMacro(string const & name) const
1511 {
1512         return pimpl_->macros.has(name);
1513 }
1514
1515
1516 void Buffer::insertMacro(string const & name, MacroData const & data)
1517 {
1518         MacroTable::globalMacros().insert(name, data);
1519         pimpl_->macros.insert(name, data);
1520 }
1521
1522
1523 void Buffer::buildMacros()
1524 {
1525         // Start with global table.
1526         pimpl_->macros = MacroTable::globalMacros();
1527
1528         // Now add our own.
1529         ParagraphList const & pars = text().paragraphs();
1530         for (size_t i = 0, n = pars.size(); i != n; ++i) {
1531                 //lyxerr << "searching main par " << i
1532                 //      << " for macro definitions" << std::endl;
1533                 InsetList const & insets = pars[i].insetlist;
1534                 InsetList::const_iterator it = insets.begin();
1535                 InsetList::const_iterator end = insets.end();
1536                 for ( ; it != end; ++it) {
1537                         //lyxerr << "found inset code " << it->inset->lyxCode() << std::endl;
1538                         if (it->inset->lyxCode() == InsetBase::MATHMACRO_CODE) {
1539                                 MathMacroTemplate const & mac
1540                                         = static_cast<MathMacroTemplate const &>(*it->inset);
1541                                 insertMacro(mac.name(), mac.asMacroData());
1542                         }
1543                 }
1544         }
1545 }
1546
1547
1548 void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc)
1549 {
1550         cursor_ = cur;
1551         anchor_ = anc;
1552 }
1553
1554
1555 void Buffer::changeRefsIfUnique(string const & from, string const & to)
1556 {
1557         // Check if the label 'from' appears more than once
1558         vector<string> labels;
1559         getLabelList(labels);
1560
1561         if (lyx::count(labels.begin(), labels.end(), from) > 1)
1562                 return;
1563
1564         InsetBase::Code code = InsetBase::REF_CODE;
1565
1566         ParIterator it = par_iterator_begin();
1567         ParIterator end = par_iterator_end();
1568         for ( ; it != end; ++it) {
1569                 bool changed_inset = false;
1570                 for (InsetList::iterator it2 = it->insetlist.begin();
1571                      it2 != it->insetlist.end(); ++it2) {
1572                         if (it2->inset->lyxCode() == code) {
1573                                 InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
1574                                 if (inset->getContents() == from) {
1575                                         inset->setContents(to);
1576                                         //inset->setButtonLabel();
1577                                         changed_inset = true;
1578                                 }
1579                         }
1580                 }
1581         }
1582 }
1583
1584
1585 void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source)
1586 {
1587         OutputParams runparams;
1588         runparams.nice = true;
1589         runparams.flavor = OutputParams::LATEX;
1590         runparams.linelen = lyxrc.ascii_linelen;
1591         // No side effect of file copying and image conversion
1592         runparams.dryrun = true;
1593
1594         if (full_source) {
1595                 os << "% Preview source code\n\n";
1596                 if (isLatex()) 
1597                         writeLaTeXSource(os, filePath(), runparams, true, true);
1598                 else 
1599                         writeDocBookSource(os, fileName(), runparams, false);
1600         } else {
1601                 runparams.par_begin = par_begin;
1602                 runparams.par_end = par_end;
1603                 if (par_begin + 1 == par_end)
1604                         os << "% Preview source code for paragraph " << par_begin << "\n\n";
1605                 else
1606                         os << "% Preview source code from paragraph " << par_begin << " to " << par_end - 1 << "\n\n";
1607                 // output paragraphs
1608                 if (isLatex()) {
1609                         texrow().reset();
1610                         latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
1611                 } else // DocBook
1612                         docbookParagraphs(paragraphs(), *this, os, runparams);
1613         }
1614 }
1615
1616
1617 ErrorList const & Buffer::errorList(string const & type) const
1618 {
1619         static ErrorList const emptyErrorList;
1620         std::map<std::string, ErrorList>::const_iterator I = errorLists_.find(type);
1621         if (I == errorLists_.end())
1622                 return emptyErrorList;
1623
1624         return I->second;
1625 }
1626
1627
1628 ErrorList & Buffer::errorList(string const & type)
1629 {
1630         return errorLists_[type];
1631 }