]> git.lyx.org Git - lyx.git/blob - src/Format.cpp
Natbib authoryear uses (Ref1; Ref2) by default.
[lyx.git] / src / Format.cpp
1 /**
2  * \file Format.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Dekel Tsur
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Format.h"
14 #include "Buffer.h"
15 #include "BufferParams.h"
16 #include "LyXRC.h"
17 #include "ServerSocket.h"
18
19 #include "frontends/alert.h" //to be removed?
20
21 #include "support/debug.h"
22 #include "support/filetools.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
25 #include "support/os.h"
26 #include "support/PathChanger.h"
27 #include "support/Systemcall.h"
28 #include "support/textutils.h"
29 #include "support/Translator.h"
30
31 #include <algorithm>
32 #include <map>
33 #include <ctime>
34
35 // FIXME: Q_WS_MACX is not available, it's in Qt
36 #ifdef USE_MACOSX_PACKAGING
37 #include "support/linkback/LinkBackProxy.h"
38 #endif
39
40 #ifdef HAVE_MAGIC_H
41 #include <magic.h>
42 #endif
43
44 using namespace std;
45 using namespace lyx::support;
46
47 namespace lyx {
48
49 namespace Alert = frontend::Alert;
50 namespace os = support::os;
51
52 namespace {
53
54 string const token_from_format("$$i");
55 string const token_path_format("$$p");
56 string const token_socket_format("$$a");
57
58
59 class FormatNamesEqual : public unary_function<Format, bool> {
60 public:
61         FormatNamesEqual(string const & name)
62                 : name_(name)
63         {}
64         bool operator()(Format const & f) const
65         {
66                 return f.name() == name_;
67         }
68 private:
69         string name_;
70 };
71
72
73 class FormatExtensionsEqual : public unary_function<Format, bool> {
74 public:
75         FormatExtensionsEqual(string const & extension)
76                 : extension_(extension)
77         {}
78         bool operator()(Format const & f) const
79         {
80                 return f.hasExtension(extension_);
81         }
82 private:
83         string extension_;
84 };
85
86
87 class FormatMimeEqual : public unary_function<Format, bool> {
88 public:
89         FormatMimeEqual(string const & mime)
90                 : mime_(mime)
91         {}
92         bool operator()(Format const & f) const
93         {
94                 // The test for empty mime strings is needed since we allow
95                 // formats with empty mime types.
96                 return f.mime() == mime_ && !mime_.empty();
97         }
98 private:
99         string mime_;
100 };
101
102
103 class FormatPrettyNameEqual : public unary_function<Format, bool> {
104 public:
105         FormatPrettyNameEqual(string const & prettyname)
106                 : prettyname_(prettyname)
107         {}
108         bool operator()(Format const & f) const
109         {
110                 return f.prettyname() == prettyname_;
111         }
112 private:
113         string prettyname_;
114 };
115
116 } //namespace anon
117
118 bool Format::formatSorter(Format const * lhs, Format const * rhs)
119 {
120         return _(lhs->prettyname()) < _(rhs->prettyname());
121 }
122
123 bool operator<(Format const & a, Format const & b)
124 {
125         return _(a.prettyname()) < _(b.prettyname());
126 }
127
128
129 Format::Format(string const & n, string const & e, string const & p,
130                string const & s, string const & v, string const & ed,
131                string const & m, int flags)
132         : name_(n), prettyname_(p), shortcut_(s), viewer_(v),
133           editor_(ed), mime_(m), flags_(flags)
134 {
135         extension_list_ = getVectorFromString(e, ",");
136         LYXERR(Debug::GRAPHICS, "New Format: n=" << n << ", flags=" << flags);
137 }
138
139
140 bool Format::dummy() const
141 {
142         return extension().empty();
143 }
144
145
146 string const Format::extensions() const
147 {
148         return getStringFromVector(extension_list_, ", ");
149 }
150
151
152 bool Format::hasExtension(string const & e) const
153 {
154         return (find(extension_list_.begin(), extension_list_.end(), e)
155                 != extension_list_.end());
156 }
157
158
159 bool Format::isChildFormat() const
160 {
161         if (name_.empty())
162                 return false;
163         return isDigitASCII(name_[name_.length() - 1]);
164 }
165
166
167 string const Format::parentFormat() const
168 {
169         return name_.substr(0, name_.length() - 1);
170 }
171
172
173 void Format::setExtensions(string const & e)
174 {
175         extension_list_ = getVectorFromString(e, ",");
176 }
177
178
179 // This method should return a reference, and throw an exception
180 // if the format named name cannot be found (Lgb)
181 Format const * Formats::getFormat(string const & name) const
182 {
183         FormatList::const_iterator cit =
184                 find_if(formatlist.begin(), formatlist.end(),
185                         FormatNamesEqual(name));
186         if (cit != formatlist.end())
187                 return &(*cit);
188         else
189                 return 0;
190 }
191
192
193 namespace {
194
195 /** Guess the file format name (as in Format::name()) from contents.
196  *  Normally you don't want to use this directly, but rather
197  *  Formats::getFormatFromFile().
198  */
199 string guessFormatFromContents(FileName const & fn)
200 {
201         // the different filetypes and what they contain in one of the first lines
202         // (dots are any characters).           (Herbert 20020131)
203         // AGR  Grace...
204         // BMP  BM...
205         // EPS  %!PS-Adobe-3.0 EPSF...
206         // FIG  #FIG...
207         // FITS ...BITPIX...
208         // GIF  GIF...
209         // JPG  JFIF
210         // PDF  %PDF-...
211         // PNG  .PNG...
212         // PBM  P1... or P4     (B/W)
213         // PGM  P2... or P5     (Grayscale)
214         // PPM  P3... or P6     (color)
215         // PS   %!PS-Adobe-2.0 or 1.0,  no "EPSF"!
216         // SGI  \001\332...     (decimal 474)
217         // TGIF %TGIF...
218         // TIFF II... or MM...
219         // XBM  ..._bits[]...
220         // XPM  /* XPM */    sometimes missing (f.ex. tgif-export)
221         //      ...static char *...
222         // XWD  \000\000\000\151        (0x00006900) decimal 105
223         //
224         // GZIP \037\213        http://www.ietf.org/rfc/rfc1952.txt
225         // ZIP  PK...                   http://www.halyava.ru/document/ind_arch.htm
226         // Z    \037\235                UNIX compress
227
228         // paranoia check
229         if (fn.empty() || !fn.isReadableFile())
230                 return string();
231
232         ifstream ifs(fn.toFilesystemEncoding().c_str());
233         if (!ifs)
234                 // Couldn't open file...
235                 return string();
236
237         // gnuzip
238         static string const gzipStamp = "\037\213";
239
240         // PKZIP
241         static string const zipStamp = "PK";
242
243         // ZIP containers (koffice, openoffice.org etc).
244         static string const nonzipStamp = "\008\0\0\0mimetypeapplication/";
245
246         // compress
247         static string const compressStamp = "\037\235";
248
249         // Maximum strings to read
250         int const max_count = 50;
251         int count = 0;
252
253         string str;
254         string format;
255         bool firstLine = true;
256         bool backslash = false;
257         int dollars = 0;
258         while ((count++ < max_count) && format.empty()) {
259                 if (ifs.eof())
260                         break;
261
262                 getline(ifs, str);
263                 string const stamp = str.substr(0, 2);
264                 if (firstLine && str.size() >= 2) {
265                         // at first we check for a zipped file, because this
266                         // information is saved in the first bytes of the file!
267                         // also some graphic formats which save the information
268                         // in the first line, too.
269                         if (prefixIs(str, gzipStamp)) {
270                                 format =  "gzip";
271
272                         } else if (stamp == zipStamp &&
273                                    !contains(str, nonzipStamp)) {
274                                 format =  "zip";
275
276                         } else if (stamp == compressStamp) {
277                                 format =  "compress";
278
279                         // the graphics part
280                         } else if (stamp == "BM") {
281                                 format =  "bmp";
282
283                         } else if (stamp == "\001\332") {
284                                 format =  "sgi";
285
286                         // PBM family
287                         // Don't need to use str.at(0), str.at(1) because
288                         // we already know that str.size() >= 2
289                         } else if (str[0] == 'P') {
290                                 switch (str[1]) {
291                                 case '1':
292                                 case '4':
293                                         format =  "pbm";
294                                     break;
295                                 case '2':
296                                 case '5':
297                                         format =  "pgm";
298                                     break;
299                                 case '3':
300                                 case '6':
301                                         format =  "ppm";
302                                 }
303                                 break;
304
305                         } else if ((stamp == "II") || (stamp == "MM")) {
306                                 format =  "tiff";
307
308                         } else if (prefixIs(str,"%TGIF")) {
309                                 format =  "tgif";
310
311                         } else if (prefixIs(str,"#FIG")) {
312                                 format =  "fig";
313
314                         } else if (prefixIs(str,"GIF")) {
315                                 format =  "gif";
316
317                         } else if (str.size() > 3) {
318                                 int const c = ((str[0] << 24) & (str[1] << 16) &
319                                                (str[2] << 8)  & str[3]);
320                                 if (c == 105) {
321                                         format =  "xwd";
322                                 }
323                         }
324
325                         firstLine = false;
326                 }
327
328                 if (!format.empty())
329                     break;
330                 else if (contains(str,"EPSF"))
331                         // dummy, if we have wrong file description like
332                         // %!PS-Adobe-2.0EPSF"
333                         format = "eps";
334
335                 else if (contains(str, "Grace"))
336                         format = "agr";
337
338                 else if (contains(str, "JFIF"))
339                         format = "jpg";
340
341                 else if (contains(str, "%PDF"))
342                         // autodetect pdf format for graphics inclusion
343                         format = "pdf6";
344
345                 else if (contains(str, "PNG"))
346                         format = "png";
347
348                 else if (contains(str, "%!PS-Adobe")) {
349                         // eps or ps
350                         ifs >> str;
351                         if (contains(str,"EPSF"))
352                                 format = "eps";
353                         else
354                             format = "ps";
355                 }
356
357                 else if (contains(str, "_bits[]"))
358                         format = "xbm";
359
360                 else if (contains(str, "XPM") || contains(str, "static char *"))
361                         format = "xpm";
362
363                 else if (contains(str, "BITPIX"))
364                         format = "fits";
365
366                 else if (contains(str, "\\documentclass") ||
367                          contains(str, "\\chapter") ||
368                          contains(str, "\\section") ||
369                          contains(str, "\\begin") ||
370                          contains(str, "\\end") ||
371                          contains(str, "$$") ||
372                          contains(str, "\\[") ||
373                          contains(str, "\\]"))
374                         format = "latex";
375                 else {
376                         if (contains(str, '\\'))
377                                 backslash = true;
378                         dollars += count_char(str, '$');
379                 }
380         }
381
382         if (format.empty() && backslash && dollars > 1)
383                 // inline equation
384                 format = "latex";
385
386         if (format.empty()) {
387                 if (ifs.eof())
388                         LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
389                                "\tFile type not recognised before EOF!");
390         } else {
391                 LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format);
392                 return format;
393         }
394
395         LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
396                 << "\tCouldn't find a known format!");
397         return string();
398 }
399
400 }
401
402
403 string Formats::getFormatFromFile(FileName const & filename) const
404 {
405         if (filename.empty())
406                 return string();
407
408 #ifdef HAVE_MAGIC_H
409         if (filename.exists()) {
410                 magic_t magic_cookie = magic_open(MAGIC_MIME);
411                 if (magic_cookie) {
412                         string format;
413                         if (magic_load(magic_cookie, NULL) != 0) {
414                                 LYXERR(Debug::GRAPHICS, "Formats::getFormatFromFile\n"
415                                         << "\tCouldn't load magic database - "
416                                         << magic_error(magic_cookie));
417                         } else {
418                                 string mime = magic_file(magic_cookie,
419                                         filename.toFilesystemEncoding().c_str());
420                                 mime = token(mime, ';', 0);
421                                 // we need our own ps/eps detection
422                                 if ((mime != "application/postscript") && (mime != "text/plain")) {
423                                         Formats::const_iterator cit =
424                                                 find_if(formatlist.begin(), formatlist.end(),
425                                                         FormatMimeEqual(mime));
426                                         if (cit != formats.end()) {
427                                                 LYXERR(Debug::GRAPHICS, "\tgot format from MIME type: "
428                                                         << mime << " -> " << cit->name());
429                                                 format = cit->name();
430                                         }
431                                 }
432                         }
433                         magic_close(magic_cookie);
434                         if (!format.empty())
435                                 return format;
436                 }
437         }
438 #endif
439
440         string const format = guessFormatFromContents(filename);
441         string const ext = getExtension(filename.absFileName());
442         if (isZippedFileFormat(format) && !ext.empty()) {
443                 string const & fmt_name = formats.getFormatFromExtension(ext);
444                 if (!fmt_name.empty()) {
445                         Format const * p_format = formats.getFormat(fmt_name);
446                         if (p_format && p_format->zippedNative())
447                                 return p_format->name();
448                 }
449         }
450         if (!format.empty())
451                 return format;
452
453         // try to find a format from the file extension.
454         return getFormatFromExtension(ext);
455 }
456
457
458 string Formats::getFormatFromExtension(string const & ext) const
459 {
460         if (!ext.empty()) {
461                 // this is ambigous if two formats have the same extension,
462                 // but better than nothing
463                 Formats::const_iterator cit =
464                         find_if(formatlist.begin(), formatlist.end(),
465                                 FormatExtensionsEqual(ext));
466                 if (cit != formats.end()) {
467                         LYXERR(Debug::GRAPHICS, "\twill guess format from file extension: "
468                                 << ext << " -> " << cit->name());
469                         return cit->name();
470                 }
471         }
472         return string();
473 }
474
475
476 string Formats::getFormatFromPrettyName(string const & prettyname) const
477 {
478         if (!prettyname.empty()) {
479                 Formats::const_iterator cit =
480                         find_if(formatlist.begin(), formatlist.end(),
481                                 FormatPrettyNameEqual(prettyname));
482                 if (cit != formats.end())
483                         return cit->name();
484         }
485         return string();
486 }
487
488
489 /// Used to store last timestamp of file and whether it is (was) zipped
490 struct ZippedInfo {
491         bool zipped;
492         std::time_t timestamp;
493         ZippedInfo(bool zipped, std::time_t timestamp)
494         : zipped(zipped), timestamp(timestamp) { }
495 };
496
497
498 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
499 static std::map<std::string, ZippedInfo> zipped_;
500
501
502 bool Formats::isZippedFile(support::FileName const & filename) const {
503         string const & fname = filename.absFileName();
504         time_t timestamp = filename.lastModified();
505         map<string, ZippedInfo>::iterator it = zipped_.find(fname);
506         if (it != zipped_.end() && it->second.timestamp == timestamp)
507                 return it->second.zipped;
508         string const & format = getFormatFromFile(filename);
509         bool zipped = (format == "gzip" || format == "zip");
510         zipped_.insert(make_pair(fname, ZippedInfo(zipped, timestamp)));
511         return zipped;
512 }
513
514
515 bool Formats::isZippedFileFormat(string const & format)
516 {
517         return contains("gzip zip compress", format) && !format.empty();
518 }
519
520
521 bool Formats::isPostScriptFileFormat(string const & format)
522 {
523         return format == "ps" || format == "eps";
524 }
525
526 static string fixCommand(string const & cmd, string const & ext,
527                   os::auto_open_mode mode)
528 {
529         // configure.py says we do not want a viewer/editor
530         if (cmd.empty())
531                 return cmd;
532
533         // Does the OS manage this format?
534         if (os::canAutoOpenFile(ext, mode))
535                 return "auto";
536
537         // if configure.py found nothing, clear the command
538         if (token(cmd, ' ', 0) == "auto")
539                 return string();
540
541         // use the command found by configure.py
542         return cmd;
543 }
544
545
546 void Formats::setAutoOpen()
547 {
548         FormatList::iterator fit = formatlist.begin();
549         FormatList::iterator const fend = formatlist.end();
550         for ( ; fit != fend ; ++fit) {
551                 fit->setViewer(fixCommand(fit->viewer(), fit->extension(), os::VIEW));
552                 fit->setEditor(fixCommand(fit->editor(), fit->extension(), os::EDIT));
553         }
554 }
555
556
557 int Formats::getNumber(string const & name) const
558 {
559         FormatList::const_iterator cit =
560                 find_if(formatlist.begin(), formatlist.end(),
561                         FormatNamesEqual(name));
562         if (cit != formatlist.end())
563                 return distance(formatlist.begin(), cit);
564         else
565                 return -1;
566 }
567
568
569 void Formats::add(string const & name)
570 {
571         if (!getFormat(name))
572                 add(name, name, name, string(), string(), string(),
573                     string(), Format::document);
574 }
575
576
577 void Formats::add(string const & name, string const & extensions,
578                   string const & prettyname, string const & shortcut,
579                   string const & viewer, string const & editor,
580                   string const & mime, int flags)
581 {
582         FormatList::iterator it =
583                 find_if(formatlist.begin(), formatlist.end(),
584                         FormatNamesEqual(name));
585         if (it == formatlist.end())
586                 formatlist.push_back(Format(name, extensions, prettyname,
587                                             shortcut, viewer, editor, mime, flags));
588         else
589                 *it = Format(name, extensions, prettyname, shortcut, viewer,
590                              editor, mime, flags);
591 }
592
593
594 void Formats::erase(string const & name)
595 {
596         FormatList::iterator it =
597                 find_if(formatlist.begin(), formatlist.end(),
598                         FormatNamesEqual(name));
599         if (it != formatlist.end())
600                 formatlist.erase(it);
601 }
602
603
604 void Formats::sort()
605 {
606         std::sort(formatlist.begin(), formatlist.end());
607 }
608
609
610 void Formats::setViewer(string const & name, string const & command)
611 {
612         add(name);
613         FormatList::iterator it =
614                 find_if(formatlist.begin(), formatlist.end(),
615                         FormatNamesEqual(name));
616         if (it != formatlist.end())
617                 it->setViewer(command);
618 }
619
620
621 void Formats::setEditor(string const & name, string const & command)
622 {
623         add(name);
624         FormatList::iterator it =
625                 find_if(formatlist.begin(), formatlist.end(),
626                         FormatNamesEqual(name));
627         if (it != formatlist.end())
628                 it->setEditor(command);
629 }
630
631
632 bool Formats::view(Buffer const & buffer, FileName const & filename,
633                    string const & format_name) const
634 {
635         if (filename.empty() || !filename.exists()) {
636                 Alert::error(_("Cannot view file"),
637                         bformat(_("File does not exist: %1$s"),
638                                 from_utf8(filename.absFileName())));
639                 return false;
640         }
641
642         Format const * format = getFormat(format_name);
643         if (format && format->viewer().empty() &&
644             format->isChildFormat())
645                 format = getFormat(format->parentFormat());
646         if (!format || format->viewer().empty()) {
647 // FIXME: I believe this is the wrong place to show alerts, it should be done
648 // by the caller (this should be "utility" code)
649                 Alert::error(_("Cannot view file"),
650                         bformat(_("No information for viewing %1$s"),
651                                 prettyName(format_name)));
652                 return false;
653         }
654         // viewer is 'auto'
655         if (format->viewer() == "auto") {
656                 if (os::autoOpenFile(filename.absFileName(), os::VIEW, buffer.filePath()))
657                         return true;
658                 else {
659                         Alert::error(_("Cannot view file"),
660                                 bformat(_("Auto-view file %1$s failed"),
661                                         from_utf8(filename.absFileName())));
662                         return false;
663                 }
664         }
665
666         string command = libScriptSearch(format->viewer());
667
668         if (format_name == "dvi" &&
669             !lyxrc.view_dvi_paper_option.empty()) {
670                 string paper_size = buffer.params().paperSizeName(BufferParams::XDVI);
671                 if (!paper_size.empty()) {
672                         command += ' ' + lyxrc.view_dvi_paper_option;
673                         command += ' ' + paper_size;
674                         if (buffer.params().orientation == ORIENTATION_LANDSCAPE &&
675                             buffer.params().papersize != PAPER_CUSTOM)
676                                 command += 'r';
677                 }
678         }
679
680         if (!contains(command, token_from_format))
681                 command += ' ' + token_from_format;
682
683         command = subst(command, token_from_format, quoteName(onlyFileName(filename.toFilesystemEncoding())));
684         command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
685         command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
686         LYXERR(Debug::FILES, "Executing command: " << command);
687         // FIXME UNICODE utf8 can be wrong for files
688         buffer.message(_("Executing command: ") + from_utf8(command));
689
690         PathChanger p(filename.onlyPath());
691         Systemcall one;
692         one.startscript(Systemcall::DontWait, command, buffer.filePath());
693
694         // we can't report any sort of error, since we aren't waiting
695         return true;
696 }
697
698
699 bool Formats::edit(Buffer const & buffer, FileName const & filename,
700                          string const & format_name) const
701 {
702         if (filename.empty() || !filename.exists()) {
703                 Alert::error(_("Cannot edit file"),
704                         bformat(_("File does not exist: %1$s"),
705                                 from_utf8(filename.absFileName())));
706                 return false;
707         }
708
709         // LinkBack files look like PDF, but have the .linkback extension
710         string const ext = getExtension(filename.absFileName());
711         if (format_name == "pdf6" && ext == "linkback") {
712 #ifdef USE_MACOSX_PACKAGING
713                 return editLinkBackFile(filename.absFileName().c_str());
714 #else
715                 Alert::error(_("Cannot edit file"),
716                              _("LinkBack files can only be edited on Apple Mac OSX."));
717                 return false;
718 #endif // USE_MACOSX_PACKAGING
719         }
720
721         Format const * format = getFormat(format_name);
722         if (format && format->editor().empty() &&
723             format->isChildFormat())
724                 format = getFormat(format->parentFormat());
725         if (!format || format->editor().empty()) {
726 // FIXME: I believe this is the wrong place to show alerts, it should
727 // be done by the caller (this should be "utility" code)
728                 Alert::error(_("Cannot edit file"),
729                         bformat(_("No information for editing %1$s"),
730                                 prettyName(format_name)));
731                 return false;
732         }
733
734         // editor is 'auto'
735         if (format->editor() == "auto") {
736                 if (os::autoOpenFile(filename.absFileName(), os::EDIT, buffer.filePath()))
737                         return true;
738                 else {
739                         Alert::error(_("Cannot edit file"),
740                                 bformat(_("Auto-edit file %1$s failed"),
741                                         from_utf8(filename.absFileName())));
742                         return false;
743                 }
744         }
745
746         string command = format->editor();
747
748         if (!contains(command, token_from_format))
749                 command += ' ' + token_from_format;
750
751         command = subst(command, token_from_format, quoteName(filename.toFilesystemEncoding()));
752         command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
753         command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
754         LYXERR(Debug::FILES, "Executing command: " << command);
755         // FIXME UNICODE utf8 can be wrong for files
756         buffer.message(_("Executing command: ") + from_utf8(command));
757
758         Systemcall one;
759         one.startscript(Systemcall::DontWait, command, buffer.filePath());
760
761         // we can't report any sort of error, since we aren't waiting
762         return true;
763 }
764
765
766 docstring const Formats::prettyName(string const & name) const
767 {
768         Format const * format = getFormat(name);
769         if (format)
770                 return from_utf8(format->prettyname());
771         else
772                 return from_utf8(name);
773 }
774
775
776 string const Formats::extension(string const & name) const
777 {
778         Format const * format = getFormat(name);
779         if (format)
780                 return format->extension();
781         else
782                 return name;
783 }
784
785
786 string const Formats::extensions(string const & name) const
787 {
788         Format const * format = getFormat(name);
789         if (format)
790                 return format->extensions();
791         else
792                 return name;
793 }
794
795
796 namespace {
797
798 typedef Translator<OutputParams::FLAVOR, string> FlavorTranslator;
799
800
801 FlavorTranslator initFlavorTranslator()
802 {
803         FlavorTranslator f(OutputParams::LATEX, "latex");
804         f.addPair(OutputParams::DVILUATEX, "dviluatex");
805         f.addPair(OutputParams::LUATEX, "luatex");
806         f.addPair(OutputParams::PDFLATEX, "pdflatex");
807         f.addPair(OutputParams::XETEX, "xetex");
808         f.addPair(OutputParams::XML, "docbook-xml");
809         f.addPair(OutputParams::HTML, "xhtml");
810         f.addPair(OutputParams::TEXT, "text");
811         return f;
812 }
813
814
815 FlavorTranslator const & flavorTranslator()
816 {
817         static FlavorTranslator translator = initFlavorTranslator();
818         return translator;
819 }
820
821 }
822
823
824 std::string flavor2format(OutputParams::FLAVOR flavor)
825 {
826         return flavorTranslator().find(flavor);
827 }
828
829
830 /* Not currently needed, but I'll leave the code in case it is.
831 OutputParams::FLAVOR format2flavor(std::string fmt)
832 {
833         return flavorTranslator().find(fmt);
834 } */
835
836 Formats formats;
837
838 Formats system_formats;
839
840
841 } // namespace lyx