4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
16 #include "OutputParams.h"
17 #include "support/trivstring.h"
26 namespace support { class FileName; }
33 class ConversionException : public std::exception {
35 ConversionException() {}
36 virtual ~ConversionException() throw() {}
37 virtual const char * what() const throw()
38 { return "Exception caught in conversion routine!"; }
42 typedef std::vector<Format const *> FormatList;
48 Converter(std::string const & f, std::string const & t, std::string const & c,
49 std::string const & l);
53 std::string const from() const { return from_; }
55 std::string const to() const { return to_; }
57 std::string const command() const { return command_; }
59 void setCommand(std::string const & command) { command_ = command; }
61 std::string const flags() const { return flags_; }
63 void setFlags(std::string const & flags) { flags_ = flags; }
65 Format const * From() const { return From_; }
67 void setFrom(Format const * From) { From_ = From; }
69 void setTo(Format const * To) { To_ = To; }
71 Format const * To() const { return To_; }
73 bool latex() const { return latex_; }
75 std::string const latex_flavor() const { return latex_flavor_; }
77 bool docbook() const { return docbook_; }
79 bool need_aux() const { return need_aux_; }
80 /// Return whether or not the needauth option is set for this converter
81 bool need_auth() const { return need_auth_; }
83 bool nice() const { return nice_; }
85 std::string const result_dir() const { return result_dir_; }
87 std::string const result_file() const { return result_file_; }
89 std::string const parselog() const { return parselog_; }
91 std::string const hyperref_driver() const { return href_driver_; }
103 Format const * From_;
107 /// The converter is latex or its derivatives
109 /// The latex derivate
110 trivstring latex_flavor_;
111 /// The converter is DocBook
113 /// This converter needs the .aux files
115 /// we need a "nice" file from the backend, c.f. OutputParams.nice.
117 /// Use of this converter needs explicit user authorization
119 /// If the converter put the result in a directory, then result_dir
120 /// is the name of the directory
121 trivstring result_dir_;
122 /// If the converter put the result in a directory, then result_file
123 /// is the name of the main file in that directory
124 trivstring result_file_;
125 /// Command to convert the program output to a LaTeX log file format
126 trivstring parselog_;
127 /// The hyperref driver
128 trivstring href_driver_;
136 typedef std::vector<Converter> ConverterList;
138 typedef ConverterList::const_iterator const_iterator;
139 /// Return values for converter runs
147 Converter const & get(int i) const { return converterlist_[i]; }
149 Converter const * getConverter(std::string const & from,
150 std::string const & to) const;
152 int getNumber(std::string const & from, std::string const & to) const;
154 void add(std::string const & from, std::string const & to,
155 std::string const & command, std::string const & flags);
157 void erase(std::string const & from, std::string const & to);
160 getReachableTo(std::string const & target, bool clear_visited);
163 getReachable(std::string const & from, bool only_viewable,
165 std::set<std::string> const & excludes = std::set<std::string>());
167 FormatList importableFormats();
168 FormatList exportableFormats(bool only_viewable);
170 std::vector<std::string> loaders() const;
171 std::vector<std::string> savers() const;
173 /// Does a conversion path from format \p from to format \p to exist?
174 bool isReachable(std::string const & from, std::string const & to);
176 Graph::EdgePath getPath(std::string const & from, std::string const & to);
178 OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path,
179 Buffer const * buffer = nullptr);
181 std::string getHyperrefDriver(Graph::EdgePath const & path);
182 /// Flags for converting files
183 enum ConversionFlags {
186 /// Use the default converter if no converter is defined
187 try_default = 1 << 0,
188 /// Get the converted file from cache if possible
192 RetVal convert(Buffer const * buffer,
193 support::FileName const & from_file, support::FileName const & to_file,
194 support::FileName const & orig_from,
195 std::string const & from_format, std::string const & to_format,
196 ErrorList & errorList, int conversionflags = none, bool includeall = false);
198 void update(Formats const & formats);
200 void updateLast(Formats const & formats);
202 bool formatIsUsed(std::string const & format);
204 const_iterator begin() const { return converterlist_.begin(); }
206 const_iterator end() const { return converterlist_.end(); }
210 /// Check whether converter conv is authorized to be run for elements
211 /// within document doc_fname.
212 /// The check succeeds for safe converters, whilst for those potentially
213 /// able to execute arbitrary code, tagged with the 'needauth' option,
214 /// authorization is: always denied if lyxrc.use_converter_needauth_forbidden
215 /// is enabled; always allowed if the lyxrc.use_converter_needauth
216 /// is disabled; user is prompted otherwise.
217 /// However, if use_shell_escape is true and a LaTeX backend is
218 /// going to be executed, both lyxrc.use_converter_needauth and
219 /// lyxrc.use_converter_needauth_forbidden are ignored, because in
220 /// this case the backend has to be executed and LyX will add the
221 /// -shell-escape option, so that user consent is always needed.
222 bool checkAuth(Converter const & conv, std::string const & doc_fname,
223 bool use_shell_escape = false);
228 intToFormat(std::vector<int> const & input);
230 bool scanLog(Buffer const & buffer, std::string const & command,
231 support::FileName const & filename, ErrorList & errorList);
233 RetVal runLaTeX(Buffer const & buffer, std::string const & command,
234 OutputParams const &, ErrorList & errorList);
236 ConverterList converterlist_;
238 trivstring latex_command_;
240 trivstring dvilualatex_command_;
242 trivstring lualatex_command_;
244 trivstring pdflatex_command_;
246 trivstring xelatex_command_;
247 /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
248 /// this method moves each /path/file*.ext file to /path2/file2*.ext2
249 bool move(std::string const & fmt,
250 support::FileName const & from, support::FileName const & to,
256 /// The global instance.
257 /// Implementation is in LyX.cpp.
258 extern Converters & theConverters();
260 /// The global copy after reading lyxrc.defaults.
261 /// Implementation is in LyX.cpp.
262 extern Converters & theSystemConverters();