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 typedef std::vector<Format const *> FormatList;
40 Converter(std::string const & f, std::string const & t, std::string const & c,
41 std::string const & l);
45 std::string const from() const { return from_; }
47 std::string const to() const { return to_; }
49 std::string const command() const { return command_; }
51 void setCommand(std::string const & command) { command_ = command; }
53 std::string const flags() const { return flags_; }
55 void setFlags(std::string const & flags) { flags_ = flags; }
57 Format const * From() const { return From_; }
59 void setFrom(Format const * From) { From_ = From; }
61 void setTo(Format const * To) { To_ = To; }
63 Format const * To() const { return To_; }
65 bool latex() const { return latex_; }
67 std::string const latex_flavor() const { return latex_flavor_; }
69 bool xml() const { return xml_; }
71 bool need_aux() const { return need_aux_; }
72 /// Return whether or not the needauth option is set for this converter
73 bool need_auth() const { return need_auth_; }
75 bool nice() const { return nice_; }
77 std::string const result_dir() const { return result_dir_; }
79 std::string const result_file() const { return result_file_; }
81 std::string const parselog() const { return parselog_; }
97 /// The converter is latex or its derivatives
99 /// The latex derivate
100 trivstring latex_flavor_;
101 /// The converter is xml
103 /// This converter needs the .aux files
105 /// we need a "nice" file from the backend, c.f. OutputParams.nice.
107 /// Use of this converter needs explicit user authorization
109 /// If the converter put the result in a directory, then result_dir
110 /// is the name of the directory
111 trivstring result_dir_;
112 /// If the converter put the result in a directory, then result_file
113 /// is the name of the main file in that directory
114 trivstring result_file_;
115 /// Command to convert the program output to a LaTeX log file format
116 trivstring parselog_;
124 typedef std::vector<Converter> ConverterList;
126 typedef ConverterList::const_iterator const_iterator;
129 Converter const & get(int i) const { return converterlist_[i]; }
131 Converter const * getConverter(std::string const & from,
132 std::string const & to) const;
134 int getNumber(std::string const & from, std::string const & to) const;
136 void add(std::string const & from, std::string const & to,
137 std::string const & command, std::string const & flags);
139 void erase(std::string const & from, std::string const & to);
142 getReachableTo(std::string const & target, bool clear_visited);
145 getReachable(std::string const & from, bool only_viewable,
147 std::set<std::string> const & excludes = std::set<std::string>());
149 FormatList importableFormats();
150 FormatList exportableFormats(bool only_viewable);
152 std::vector<std::string> loaders() const;
153 std::vector<std::string> savers() const;
155 /// Does a conversion path from format \p from to format \p to exist?
156 bool isReachable(std::string const & from, std::string const & to);
158 Graph::EdgePath getPath(std::string const & from, std::string const & to);
160 OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path,
161 Buffer const * buffer = 0);
162 /// Flags for converting files
163 enum ConversionFlags {
166 /// Use the default converter if no converter is defined
167 try_default = 1 << 0,
168 /// Get the converted file from cache if possible
172 bool convert(Buffer const * buffer,
173 support::FileName const & from_file, support::FileName const & to_file,
174 support::FileName const & orig_from,
175 std::string const & from_format, std::string const & to_format,
176 ErrorList & errorList, int conversionflags = none);
178 void update(Formats const & formats);
180 void updateLast(Formats const & formats);
182 bool formatIsUsed(std::string const & format);
184 const_iterator begin() const { return converterlist_.begin(); }
186 const_iterator end() const { return converterlist_.end(); }
190 /// Check whether converter conv is authorized to be run for elements
191 /// within document doc_fname.
192 /// The check succeeds for safe converters, whilst for those potentially
193 /// able to execute arbitrary code, tagged with the 'needauth' option,
194 /// authorization is: always denied if lyxrc.use_converter_needauth_forbidden
195 /// is enabled; always allowed if the lyxrc.use_converter_needauth
196 /// is disabled; user is prompted otherwise
197 bool checkAuth(Converter const & conv, std::string const & doc_fname);
202 intToFormat(std::vector<int> const & input);
204 bool scanLog(Buffer const & buffer, std::string const & command,
205 support::FileName const & filename, ErrorList & errorList);
207 bool runLaTeX(Buffer const & buffer, std::string const & command,
208 OutputParams const &, ErrorList & errorList);
210 ConverterList converterlist_;
212 trivstring latex_command_;
214 trivstring dvilualatex_command_;
216 trivstring lualatex_command_;
218 trivstring pdflatex_command_;
220 trivstring xelatex_command_;
221 /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
222 /// this method moves each /path/file*.ext file to /path2/file2*.ext2
223 bool move(std::string const & fmt,
224 support::FileName const & from, support::FileName const & to,
230 /// The global instance.
231 /// Implementation is in LyX.cpp.
232 extern Converters & theConverters();
234 /// The global copy after reading lyxrc.defaults.
235 /// Implementation is in LyX.cpp.
236 extern Converters & theSystemConverters();