]> git.lyx.org Git - lyx.git/blob - src/converter.h
hopefully fix tex2lyx linking.
[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 <string>
20
21
22 namespace lyx {
23
24
25 class Buffer;
26 class ErrorList;
27 class Format;
28 class Formats;
29 class OutputParams;
30
31
32 ///
33 class Converter {
34 public:
35         ///
36         Converter(std::string const & f, std::string const & t, std::string const & c,
37                   std::string const & l);
38         ///
39         void readFlags();
40         ///
41         std::string from;
42         ///
43         std::string to;
44         ///
45         std::string command;
46         ///
47         std::string flags;
48         ///
49         Format const * From;
50         ///
51         Format const * To;
52
53         /// The converter is latex or its derivatives
54         bool latex;
55         /// The converter is xml
56         bool xml;
57         /// Do we need to run the converter in the original directory?
58         bool original_dir;
59         /// This converter needs the .aux files
60         bool need_aux;
61         /// If the converter put the result in a directory, then result_dir
62         /// is the name of the directory
63         std::string result_dir;
64         /// If the converter put the result in a directory, then result_file
65         /// is the name of the main file in that directory
66         std::string result_file;
67         /// Command to convert the program output to a LaTeX log file format
68         std::string parselog;
69 };
70
71
72 ///
73 class Converters {
74 public:
75         ///
76         typedef std::vector<int> EdgePath; // to be removed SOON
77         ///
78         typedef std::vector<Converter> ConverterList;
79         ///
80         typedef ConverterList::const_iterator const_iterator;
81         ///
82         Converter const & get(int i) const {
83                 return converterlist_[i];
84         }
85         ///
86         Converter const * getConverter(std::string const & from,
87                                        std::string const & to) const;
88         ///
89         int getNumber(std::string const & from, std::string const & to) const;
90         ///
91         void add(std::string const & from, std::string const & to,
92                  std::string const & command, std::string const & flags);
93         //
94         void erase(std::string const & from, std::string const & to);
95         ///
96         void sort();
97         ///
98         std::vector<Format const *> const
99         getReachableTo(std::string const & target, bool clear_visited);
100         ///
101         std::vector<Format const *> const
102         getReachable(std::string const & from, bool only_viewable,
103                      bool clear_visited);
104         /// Does a conversion path from format \p from to format \p to exist?
105         bool isReachable(std::string const & from, std::string const & to);
106         ///
107         Graph::EdgePath const getPath(std::string const & from, std::string const & to);
108         ///
109         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
110         /// Flags for converting files
111         enum ConversionFlags {
112                 /// No special flags
113                 none = 0,
114                 /// Use the default converter if no converter is defined
115                 try_default = 1 << 0,
116                 /// Get the converted file from cache if possible
117                 try_cache = 1 << 1
118         };
119         ///
120         bool convert(Buffer const * buffer,
121                      std::string const & from_file, std::string const & to_file,
122                      std::string const & orig_from,
123                      std::string const & from_format, std::string const & to_format,
124                      ErrorList & errorList, int conversionflags = none);
125         ///
126         void update(Formats const & formats);
127         ///
128         void updateLast(Formats const & formats);
129         ///
130         bool formatIsUsed(std::string const & format);
131         ///
132         const_iterator begin() const {
133                 return converterlist_.begin();
134         }
135         const_iterator end() const {
136                 return converterlist_.end();
137         }
138         ///
139         void buildGraph();
140 private:
141         ///
142         std::vector<Format const *> const
143         intToFormat(std::vector<int> const & input);
144         ///
145         bool scanLog(Buffer const & buffer, std::string const & command,
146                      std::string const & filename, ErrorList & errorList);
147         ///
148         bool runLaTeX(Buffer const & buffer, std::string const & command,
149                       OutputParams const &, ErrorList & errorList);
150         ///
151         ConverterList converterlist_;
152         ///
153         std::string latex_command_;
154         /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
155         /// this method moves each /path/file*.ext file to /path2/file2*.ext2
156         bool move(std::string const & fmt,
157                   std::string const & from, std::string const & to,
158                   bool copy);
159         ///
160         Graph G_;
161 };
162
163 extern Converters converters;
164
165 extern Converters system_converters;
166
167
168 } // namespace lyx
169
170 #endif //CONVERTER_H