]> git.lyx.org Git - lyx.git/blob - src/Format.cpp
add the background image to distribution tarball
[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 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
481 static std::map<std::string, ZippedInfo> zipped_;
482
483
484 bool Formats::isZippedFile(support::FileName const & filename) const {
485         string const & fname = filename.absFileName();
486         time_t timestamp = filename.lastModified();
487         map<string, ZippedInfo>::iterator it = zipped_.find(fname);
488         if (it != zipped_.end() && it->second.timestamp == timestamp)
489                 return it->second.zipped;
490         string const & format = getFormatFromFile(filename);
491         bool zipped = (format == "gzip" || format == "zip");
492         zipped_.insert(make_pair(fname, ZippedInfo(zipped, timestamp)));
493         return zipped;
494 }
495
496
497 bool Formats::isZippedFileFormat(string const & format)
498 {
499         return contains("gzip zip compress", format) && !format.empty();
500 }
501
502
503 bool Formats::isPostScriptFileFormat(string const & format)
504 {
505         return format == "ps" || format == "eps";
506 }
507
508 static string fixCommand(string const & cmd, string const & ext,
509                   os::auto_open_mode mode)
510 {
511         // configure.py says we do not want a viewer/editor
512         if (cmd.empty())
513                 return cmd;
514
515         // Does the OS manage this format?
516         if (os::canAutoOpenFile(ext, mode))
517                 return "auto";
518
519         // if configure.py found nothing, clear the command
520         if (token(cmd, ' ', 0) == "auto")
521                 return string();
522
523         // use the command found by configure.py
524         return cmd;
525 }
526
527
528 void Formats::setAutoOpen()
529 {
530         FormatList::iterator fit = formatlist.begin();
531         FormatList::iterator const fend = formatlist.end();
532         for ( ; fit != fend ; ++fit) {
533                 fit->setViewer(fixCommand(fit->viewer(), fit->extension(), os::VIEW));
534                 fit->setEditor(fixCommand(fit->editor(), fit->extension(), os::EDIT));
535         }
536 }
537
538
539 int Formats::getNumber(string const & name) const
540 {
541         FormatList::const_iterator cit =
542                 find_if(formatlist.begin(), formatlist.end(),
543                         FormatNamesEqual(name));
544         if (cit != formatlist.end())
545                 return distance(formatlist.begin(), cit);
546         else
547                 return -1;
548 }
549
550
551 void Formats::add(string const & name)
552 {
553         if (!getFormat(name))
554                 add(name, name, name, string(), string(), string(),
555                     string(), Format::document);
556 }
557
558
559 void Formats::add(string const & name, string const & extensions,
560                   string const & prettyname, string const & shortcut,
561                   string const & viewer, string const & editor,
562                   string const & mime, int flags)
563 {
564         FormatList::iterator it =
565                 find_if(formatlist.begin(), formatlist.end(),
566                         FormatNamesEqual(name));
567         if (it == formatlist.end())
568                 formatlist.push_back(Format(name, extensions, prettyname,
569                                             shortcut, viewer, editor, mime, flags));
570         else
571                 *it = Format(name, extensions, prettyname, shortcut, viewer,
572                              editor, mime, flags);
573 }
574
575
576 void Formats::erase(string const & name)
577 {
578         FormatList::iterator it =
579                 find_if(formatlist.begin(), formatlist.end(),
580                         FormatNamesEqual(name));
581         if (it != formatlist.end())
582                 formatlist.erase(it);
583 }
584
585
586 void Formats::sort()
587 {
588         std::sort(formatlist.begin(), formatlist.end());
589 }
590
591
592 void Formats::setViewer(string const & name, string const & command)
593 {
594         add(name);
595         FormatList::iterator it =
596                 find_if(formatlist.begin(), formatlist.end(),
597                         FormatNamesEqual(name));
598         if (it != formatlist.end())
599                 it->setViewer(command);
600 }
601
602
603 void Formats::setEditor(string const & name, string const & command)
604 {
605         add(name);
606         FormatList::iterator it =
607                 find_if(formatlist.begin(), formatlist.end(),
608                         FormatNamesEqual(name));
609         if (it != formatlist.end())
610                 it->setEditor(command);
611 }
612
613
614 bool Formats::view(Buffer const & buffer, FileName const & filename,
615                    string const & format_name) const
616 {
617         if (filename.empty() || !filename.exists()) {
618                 Alert::error(_("Cannot view file"),
619                         bformat(_("File does not exist: %1$s"),
620                                 from_utf8(filename.absFileName())));
621                 return false;
622         }
623
624         Format const * format = getFormat(format_name);
625         if (format && format->viewer().empty() &&
626             format->isChildFormat())
627                 format = getFormat(format->parentFormat());
628         if (!format || format->viewer().empty()) {
629 // FIXME: I believe this is the wrong place to show alerts, it should be done
630 // by the caller (this should be "utility" code)
631                 Alert::error(_("Cannot view file"),
632                         bformat(_("No information for viewing %1$s"),
633                                 prettyName(format_name)));
634                 return false;
635         }
636         // viewer is 'auto'
637         if (format->viewer() == "auto") {
638                 if (os::autoOpenFile(filename.absFileName(), os::VIEW, buffer.filePath()))
639                         return true;
640                 else {
641                         Alert::error(_("Cannot view file"),
642                                 bformat(_("Auto-view file %1$s failed"),
643                                         from_utf8(filename.absFileName())));
644                         return false;
645                 }
646         }
647
648         string command = libScriptSearch(format->viewer());
649
650         if (format_name == "dvi" &&
651             !lyxrc.view_dvi_paper_option.empty()) {
652                 string paper_size = buffer.params().paperSizeName(BufferParams::XDVI);
653                 if (!paper_size.empty()) {
654                         command += ' ' + lyxrc.view_dvi_paper_option;
655                         command += ' ' + paper_size;
656                         if (buffer.params().orientation == ORIENTATION_LANDSCAPE &&
657                             buffer.params().papersize != PAPER_CUSTOM)
658                                 command += 'r';
659                 }
660         }
661
662         if (!contains(command, token_from_format))
663                 command += ' ' + token_from_format;
664
665         command = subst(command, token_from_format, quoteName(onlyFileName(filename.toFilesystemEncoding())));
666         command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
667         command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
668         LYXERR(Debug::FILES, "Executing command: " << command);
669         // FIXME UNICODE utf8 can be wrong for files
670         buffer.message(_("Executing command: ") + from_utf8(command));
671
672         PathChanger p(filename.onlyPath());
673         Systemcall one;
674         one.startscript(Systemcall::DontWait, command, buffer.filePath());
675
676         // we can't report any sort of error, since we aren't waiting
677         return true;
678 }
679
680
681 bool Formats::edit(Buffer const & buffer, FileName const & filename,
682                          string const & format_name) const
683 {
684         if (filename.empty() || !filename.exists()) {
685                 Alert::error(_("Cannot edit file"),
686                         bformat(_("File does not exist: %1$s"),
687                                 from_utf8(filename.absFileName())));
688                 return false;
689         }
690
691         // LinkBack files look like PDF, but have the .linkback extension
692         string const ext = getExtension(filename.absFileName());
693         if (format_name == "pdf6" && ext == "linkback") {
694 #ifdef USE_MACOSX_PACKAGING
695                 return editLinkBackFile(filename.absFileName().c_str());
696 #else
697                 Alert::error(_("Cannot edit file"),
698                              _("LinkBack files can only be edited on Apple Mac OSX."));
699                 return false;
700 #endif // USE_MACOSX_PACKAGING
701         }
702
703         Format const * format = getFormat(format_name);
704         if (format && format->editor().empty() &&
705             format->isChildFormat())
706                 format = getFormat(format->parentFormat());
707         if (!format || format->editor().empty()) {
708 // FIXME: I believe this is the wrong place to show alerts, it should
709 // be done by the caller (this should be "utility" code)
710                 Alert::error(_("Cannot edit file"),
711                         bformat(_("No information for editing %1$s"),
712                                 prettyName(format_name)));
713                 return false;
714         }
715
716         // editor is 'auto'
717         if (format->editor() == "auto") {
718                 if (os::autoOpenFile(filename.absFileName(), os::EDIT, buffer.filePath()))
719                         return true;
720                 else {
721                         Alert::error(_("Cannot edit file"),
722                                 bformat(_("Auto-edit file %1$s failed"),
723                                         from_utf8(filename.absFileName())));
724                         return false;
725                 }
726         }
727
728         string command = format->editor();
729
730         if (!contains(command, token_from_format))
731                 command += ' ' + token_from_format;
732
733         command = subst(command, token_from_format, quoteName(filename.toFilesystemEncoding()));
734         command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
735         command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
736         LYXERR(Debug::FILES, "Executing command: " << command);
737         // FIXME UNICODE utf8 can be wrong for files
738         buffer.message(_("Executing command: ") + from_utf8(command));
739
740         Systemcall one;
741         one.startscript(Systemcall::DontWait, command, buffer.filePath());
742
743         // we can't report any sort of error, since we aren't waiting
744         return true;
745 }
746
747
748 docstring const Formats::prettyName(string const & name) const
749 {
750         Format const * format = getFormat(name);
751         if (format)
752                 return from_utf8(format->prettyname());
753         else
754                 return from_utf8(name);
755 }
756
757
758 string const Formats::extension(string const & name) const
759 {
760         Format const * format = getFormat(name);
761         if (format)
762                 return format->extension();
763         else
764                 return name;
765 }
766
767
768 string const Formats::extensions(string const & name) const
769 {
770         Format const * format = getFormat(name);
771         if (format)
772                 return format->extensions();
773         else
774                 return name;
775 }
776
777
778 namespace {
779
780 typedef Translator<OutputParams::FLAVOR, string> FlavorTranslator;
781
782
783 FlavorTranslator initFlavorTranslator()
784 {
785         FlavorTranslator f(OutputParams::LATEX, "latex");
786         f.addPair(OutputParams::DVILUATEX, "dviluatex");
787         f.addPair(OutputParams::LUATEX, "luatex");
788         f.addPair(OutputParams::PDFLATEX, "pdflatex");
789         f.addPair(OutputParams::XETEX, "xetex");
790         f.addPair(OutputParams::XML, "docbook-xml");
791         f.addPair(OutputParams::HTML, "xhtml");
792         f.addPair(OutputParams::TEXT, "text");
793         return f;
794 }
795
796
797 FlavorTranslator const & flavorTranslator()
798 {
799         static FlavorTranslator translator = initFlavorTranslator();
800         return translator;
801 }
802
803 }
804
805
806 std::string flavor2format(OutputParams::FLAVOR flavor)
807 {
808         return flavorTranslator().find(flavor);
809 }
810
811
812 /* Not currently needed, but I'll leave the code in case it is.
813 OutputParams::FLAVOR format2flavor(std::string fmt)
814 {
815         return flavorTranslator().find(fmt);
816 } */
817
818 Formats formats;
819
820 Formats system_formats;
821
822
823 } // namespace lyx