]> git.lyx.org Git - lyx.git/blob - src/Converter.h
tex2lyx: roundtrip support for the suppress_date option, for the remaining part I...
[lyx.git] / src / Converter.h
1 // -*- C++ -*-
2 /**
3  * \file Converter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CONVERTER_H
13 #define CONVERTER_H
14
15 #include "Graph.h"
16 #include "OutputParams.h"
17
18 #include <vector>
19 #include <set>
20 #include <string>
21
22
23 namespace lyx {
24
25 namespace support { class FileName; }
26
27 class Buffer;
28 class ErrorList;
29 class Format;
30 class Formats;
31 class OutputParams;
32
33
34 ///
35 class Converter {
36 public:
37         ///
38         Converter(std::string const & f, std::string const & t, std::string const & c,
39                   std::string const & l);
40         ///
41         void readFlags();
42         ///
43         std::string from;
44         ///
45         std::string to;
46         ///
47         std::string command;
48         ///
49         std::string flags;
50         ///
51         Format const * From;
52         ///
53         Format const * To;
54
55         /// The converter is latex or its derivatives
56         bool latex;
57         /// The latex derivate
58         std::string latex_flavor;
59         /// The converter is xml
60         bool xml;
61         /// This converter needs the .aux files
62         bool need_aux;
63         /// If the converter put the result in a directory, then result_dir
64         /// is the name of the directory
65         std::string result_dir;
66         /// If the converter put the result in a directory, then result_file
67         /// is the name of the main file in that directory
68         std::string result_file;
69         /// Command to convert the program output to a LaTeX log file format
70         std::string parselog;
71 };
72
73
74 ///
75 class Converters {
76 public:
77         ///
78         typedef std::vector<Converter> ConverterList;
79         ///
80         typedef ConverterList::const_iterator const_iterator;
81         ///
82         typedef std::vector<std::string> FormatList;
83
84         ///
85         Converter const & get(int i) const { return converterlist_[i]; }
86         ///
87         Converter const * getConverter(std::string const & from,
88                                        std::string const & to) const;
89         ///
90         int getNumber(std::string const & from, std::string const & to) const;
91         ///
92         void add(std::string const & from, std::string const & to,
93                  std::string const & command, std::string const & flags);
94         //
95         void erase(std::string const & from, std::string const & to);
96         ///
97         std::vector<Format const *> const
98         getReachableTo(std::string const & target, bool clear_visited);
99         ///
100         std::vector<Format const *> const
101         getReachable(std::string const & from, bool only_viewable,
102                bool clear_visited,
103                std::set<std::string> const & excludes = std::set<std::string>());
104
105         std::vector<Format const *> importableFormats();
106         std::vector<Format const *> exportableFormats(bool only_viewable);
107
108         std::vector<std::string> loaders() const;
109         std::vector<std::string> savers() const;
110
111         /// Does a conversion path from format \p from to format \p to exist?
112         bool isReachable(std::string const & from, std::string const & to);
113         ///
114         Graph::EdgePath getPath(std::string const & from, std::string const & to);
115         ///
116         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
117         /// Flags for converting files
118         enum ConversionFlags {
119                 /// No special flags
120                 none = 0,
121                 /// Use the default converter if no converter is defined
122                 try_default = 1 << 0,
123                 /// Get the converted file from cache if possible
124                 try_cache = 1 << 1
125         };
126         ///
127         bool convert(Buffer const * buffer,
128                      support::FileName const & from_file, support::FileName const & to_file,
129                      support::FileName const & orig_from,
130                      std::string const & from_format, std::string const & to_format,
131                      ErrorList & errorList, int conversionflags = none);
132         ///
133         void update(Formats const & formats);
134         ///
135         void updateLast(Formats const & formats);
136         ///
137         bool formatIsUsed(std::string const & format);
138         ///
139         const_iterator begin() const { return converterlist_.begin(); }
140         ///
141         const_iterator end() const { return converterlist_.end(); }
142         ///
143         void buildGraph();
144 private:
145         ///
146         std::vector<Format const *> const
147         intToFormat(std::vector<int> const & input);
148         ///
149         bool scanLog(Buffer const & buffer, std::string const & command,
150                      support::FileName const & filename, ErrorList & errorList);
151         ///
152         bool runLaTeX(Buffer const & buffer, std::string const & command,
153                       OutputParams const &, ErrorList & errorList);
154         ///
155         ConverterList converterlist_;
156         ///
157         std::string latex_command_;
158         ///
159         std::string xelatex_command_;
160         /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
161         /// this method moves each /path/file*.ext file to /path2/file2*.ext2
162         bool move(std::string const & fmt,
163                   support::FileName const & from, support::FileName const & to,
164                   bool copy);
165         ///
166         Graph G_;
167 };
168
169 /// The global instance.
170 /// Implementation is in LyX.cpp.
171 extern Converters & theConverters();
172
173 /// The global copy after reading lyxrc.defaults.
174 /// Implementation is in LyX.cpp.
175 extern Converters & theSystemConverters();
176
177 } // namespace lyx
178
179 #endif //CONVERTER_H