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