]> git.lyx.org Git - lyx.git/blob - src/converter.h
partial framebox support
[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         // use the compare_ascii_no_case instead of compare_no_case,
81         // because in turkish, 'i' is not the lowercase version of 'I',
82         // and thus turkish locale breaks parsing of tags.
83
84         return compare_ascii_no_case(a.prettyname(), b.prettyname()) < 0;
85 }
86
87
88 ///
89 class Formats {
90 public:
91         ///
92         typedef std::vector<Format> FormatList;
93         ///
94         typedef FormatList::const_iterator const_iterator;
95         ///
96         Format const & get(FormatList::size_type i) const {
97                 return formatlist[i];
98         }
99         ///
100         Format const * getFormat(string const & name) const;
101         ///
102         int getNumber(string const & name) const;
103         ///
104         void add(string const & name);
105         ///
106         void add(string const & name, string const & extension,
107                  string const & prettyname, string const & shortcut);
108         ///
109         void erase(string const & name);
110         ///
111         void sort();
112         ///
113         void setViewer(string const & name, string const & command);
114         ///
115         bool view(Buffer const * buffer, string const & filename,
116                   string const & format_name) const;
117         ///
118         string const prettyName(string const & name) const;
119         ///
120         string const extension(string const & name) const;
121         ///
122         const_iterator begin() const {
123                 return formatlist.begin();
124         }
125         ///
126         const_iterator end() const {
127                 return formatlist.end();
128         }
129         ///
130         FormatList::size_type size() const {
131                 return formatlist.size();
132         }
133 private:
134         ///
135         FormatList formatlist;
136 };
137
138 ///////////////////////////////////////////////////////////////////////
139
140 ///
141 class Converter {
142 public:
143         ///
144         Converter(string const & f, string const & t, string const & c,
145                   string const & l)
146                 : from(f), to(t), command(c), flags(l), From(0), To(0),
147                   latex(false), original_dir(false), need_aux(false) {}
148         ///
149         void readFlags();
150         ///
151         string from;
152         ///
153         string to;
154         ///
155         string command;
156         ///
157         string flags;
158         ///
159         Format const * From;
160         ///
161         Format const * To;
162
163         /// The converter is latex or its derivatives
164         bool latex;
165         /// Do we need to run the converter in the original directory?
166         bool original_dir;
167         /// This converter needs the .aux files
168         bool need_aux;
169         /// If the converter put the result in a directory, then result_dir
170         /// is the name of the directory
171         string result_dir;
172         /// If the converter put the result in a directory, then result_file
173         /// is the name of the main file in that directory
174         string result_file;
175         /// Command to convert the program output to a LaTeX log file format
176         string parselog;
177 };
178
179
180 ///
181 class Converters {
182 public:
183         typedef std::vector<Converter> ConverterList;
184         ///
185         typedef ConverterList::const_iterator const_iterator;
186         ///
187         typedef std::vector<int> EdgePath;
188         ///
189         Converter const & get(int i) const {
190                 return converterlist_[i];
191         }
192         ///
193         Converter const * getConverter(string const & from, string const & to);
194         ///
195         int getNumber(string const & from, string const & to);
196         ///
197         void add(string const & from, string const & to,
198                  string const & command, string const & flags);
199         //
200         void erase(string const & from, string const & to);
201         ///
202         void sort();
203         ///
204         std::vector<Format const *> const
205         getReachableTo(string const & target, bool clear_visited);
206         ///
207         std::vector<Format const *> const
208         getReachable(string const & from, bool only_viewable,
209                      bool clear_visited);
210         ///
211         bool isReachable(string const & from, string const & to);
212         ///
213         EdgePath const getPath(string const & from, string const & to);
214         ///
215         bool usePdflatex(EdgePath const & path);
216         ///
217         bool convert(Buffer const * buffer,
218                      string const & from_file, string const & to_file_base,
219                      string const & from_format, string const & to_format,
220                      string & to_file);
221         ///
222         bool convert(Buffer const * buffer,
223                      string const & from_file, string const & to_file_base,
224                      string const & from_format, string const & to_format);
225         ///
226         string const papersize(Buffer const * buffer);
227         ///
228         string const dvips_options(Buffer const * buffer);
229         ///
230         string const dvipdfm_options(Buffer const * buffer);
231         ///
232         void update(Formats const & formats);
233         ///
234         void updateLast(Formats const & formats);
235         ///
236         void buildGraph();
237         ///
238         bool formatIsUsed(string const & format);
239         ///
240         const_iterator begin() const {
241                 return converterlist_.begin();
242         }
243         const_iterator end() const {
244                 return converterlist_.end();
245         }
246 private:
247         ///
248         bool scanLog(Buffer const * buffer, string const & command,
249                      string const & filename);
250         ///
251         bool runLaTeX(Buffer const * buffer, string const & command);
252         ///
253         ConverterList converterlist_;
254         ///
255         string latex_command_;
256         ///
257         struct Vertex {
258                 std::vector<int> in_vertices;
259                 std::vector<int> out_vertices;
260                 std::vector<int> out_edges;
261         };
262         ///
263         static
264         std::vector<Vertex> vertices_;
265         ///
266         std::vector<bool> visited_;
267         ///
268         std::queue<int> Q_;
269         ///
270         int bfs_init(string const & start, bool clear_visited = true);
271         ///
272         bool move(string const & from, string const & to, bool copy);
273 };
274
275 extern Formats formats;
276 extern Converters converters;
277
278 extern Formats system_formats;
279 extern Converters system_converters;
280
281 #endif