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