]> git.lyx.org Git - lyx.git/blob - src/converter.h
fix typo that put too many include paths for most people
[lyx.git] / src / converter.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef CONVERTER_H
13 #define CONVERTER_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <vector>
20 #include <queue>
21 #include "LString.h"
22 #include "support/lstrings.h"
23
24 class Buffer;
25
26 ///
27 class Format {
28 public:
29         ///
30         Format(string const & n, string const & e, string const & p,
31                string const & s, string const & v) :
32                 name_(n), extension_(e), prettyname_(p), shortcut_(s),
33                 viewer_(v) {};
34         ///
35         bool dummy() const;
36         ///
37         bool isChildFormat() const;
38         ///
39         string const parentFormat() const;
40         ///
41         string const & name() const {
42                 return name_;
43         }
44         ///
45         string const & extension() const {
46                 return extension_;
47         }
48         ///
49         string const & prettyname() const {
50                 return prettyname_;
51         }
52         ///
53         string const & shortcut() const {
54                 return shortcut_;
55         }
56         ///
57         string const & viewer() const {
58                 return viewer_;
59         }
60         ///
61         void setViewer(string const & v) {
62                 viewer_ = v;
63         }
64 private:
65         string name_;
66         ///
67         string extension_;
68         ///
69         string prettyname_;
70         ///
71         string shortcut_;
72         ///
73         string viewer_;
74 };
75
76
77 inline
78 bool operator<(Format const & a, Format const & b)
79 {
80         return compare_no_case(a.prettyname(), b.prettyname()) < 0;
81 }
82
83
84 ///
85 class Formats {
86 public:
87         ///
88         typedef std::vector<Format> FormatList;
89         ///
90         typedef FormatList::const_iterator const_iterator;
91         ///
92         Format const & get(FormatList::size_type i) const {
93                 return formatlist[i];
94         }
95         ///
96         Format const * getFormat(string const & name) const;
97         ///
98         int getNumber(string const & name) const;
99         ///
100         void add(string const & name);
101         ///
102         void add(string const & name, string const & extension,
103                  string const & prettyname, string const & shortcut);
104         ///
105         void erase(string const & name);
106         ///
107         void sort();
108         ///
109         void setViewer(string const & name, string const & command);
110         ///
111         bool view(Buffer const * buffer, string const & filename,
112                   string const & format_name) const;
113         ///
114         string const prettyName(string const & name) const;
115         ///
116         string const extension(string const & name) const;
117         ///
118         const_iterator begin() const {
119                 return formatlist.begin();
120         }
121         ///
122         const_iterator end() const {
123                 return formatlist.end();
124         }
125         ///
126         FormatList::size_type size() const {
127                 return formatlist.size();
128         }
129 private:
130         ///
131         FormatList formatlist;
132 };
133
134 ///////////////////////////////////////////////////////////////////////
135
136 ///
137 class Converter {
138 public:
139         ///
140         Converter(string const & f, string const & t, string const & c,
141                   string const & l)
142                 : from(f), to(t), command(c), flags(l), From(0), To(0),
143                   latex(false), original_dir(false), need_aux(false) {}
144         ///
145         void readFlags();
146         ///
147         string from;
148         ///
149         string to;
150         ///
151         string command;
152         ///
153         string flags;
154         ///
155         Format const * From;
156         ///
157         Format const * To;
158
159         /// The converter is latex or its derivatives
160         bool latex;
161         /// Do we need to run the converter in the original directory?
162         bool original_dir;
163         /// This converter needs the .aux files
164         bool need_aux;
165         /// If the converter put the result in a directory, then result_dir
166         /// is the name of the directory
167         string result_dir;
168         /// If the converter put the result in a directory, then result_file
169         /// is the name of the main file in that directory
170         string result_file;
171         /// Command to convert the program output to a LaTeX log file format
172         string parselog;
173 };
174
175
176 ///
177 class Converters {
178 public:
179         typedef std::vector<Converter> ConverterList;
180         ///
181         typedef ConverterList::const_iterator const_iterator;
182         ///
183         typedef std::vector<int> EdgePath;
184         ///
185         Converter const & get(int i) const {
186                 return converterlist_[i];
187         }
188         ///
189         Converter const * getConverter(string const & from, string const & to);
190         ///
191         int getNumber(string const & from, string const & to);
192         ///
193         void add(string const & from, string const & to,
194                  string const & command, string const & flags);
195         //
196         void erase(string const & from, string const & to);
197         ///
198         void sort();
199         ///
200         std::vector<Format const *> const
201         getReachableTo(string const & target, bool clear_visited);
202         ///
203         std::vector<Format const *> const
204         getReachable(string const & from, bool only_viewable,
205                      bool clear_visited);
206         ///
207         bool isReachable(string const & from, string const & to);
208         ///
209         EdgePath const getPath(string const & from, string const & to);
210         ///
211         bool usePdflatex(EdgePath const & path);
212         ///
213         bool convert(Buffer const * buffer,
214                      string const & from_file, string const & to_file_base,
215                      string const & from_format, string const & to_format,
216                      string & to_file);
217         ///
218         bool convert(Buffer const * buffer,
219                      string const & from_file, string const & to_file_base,
220                      string const & from_format, string const & to_format);
221         ///
222         string const papersize(Buffer const * buffer);
223         ///
224         string const dvips_options(Buffer const * buffer);
225         ///
226         string const dvipdfm_options(Buffer const * buffer);
227         ///
228         void update(Formats const & formats);
229         ///
230         void updateLast(Formats const & formats);
231         ///
232         void buildGraph();
233         ///
234         bool formatIsUsed(string const & format);
235         ///
236         const_iterator begin() const {
237                 return converterlist_.begin();
238         }
239         const_iterator end() const {
240                 return converterlist_.end();
241         }
242 private:
243         ///
244         bool scanLog(Buffer const * buffer, string const & command,
245                      string const & filename);
246         ///
247         bool runLaTeX(Buffer const * buffer, string const & command);
248         ///
249         ConverterList converterlist_;
250         ///
251         string latex_command_;
252         ///
253         struct Vertex {
254                 std::vector<int> in_vertices;
255                 std::vector<int> out_vertices;
256                 std::vector<int> out_edges;
257         };
258         ///
259         static
260         std::vector<Vertex> vertices_;
261         ///
262         std::vector<bool> visited_;
263         ///
264         std::queue<int> Q_;
265         ///
266         int bfs_init(string const & start, bool clear_visited = true);
267         ///
268         bool move(string const & from, string const & to, bool copy);
269 };
270
271 extern Formats formats;
272 extern Converters converters;
273
274 extern Formats system_formats;
275 extern Converters system_converters;
276
277 #endif