]> git.lyx.org Git - lyx.git/blob - src/converter.h
Dekel's import/export patch
[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-2000 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 <map>
20 #include <vector>
21 #include "LString.h"
22
23 class Buffer;
24
25 ///
26 class Format {
27 public:
28         ///
29         Format() {}
30         ///
31         Format(string const & n, string const & e, string const & p,
32                string const & s) :
33                 name(n), extension(e), prettyname(p), shortcut(s) {};
34         ///
35         string name;
36         ///
37         string extension;
38         ///
39         string prettyname;
40         ///
41         string shortcut;
42         ///
43         string viewer;
44 };
45
46 ///
47 struct Command {
48         ///
49         Command(Format const * f, Format const * t, string const & c)
50                 : from(f), to(t), command(c),
51                   latex(false), original_dir(false), need_aux(false) {}
52         ///
53         Format const * from;
54         ///
55         Format const * to;
56         ///
57         string command;
58         /// The converter is latex or its derivatives
59         bool latex;
60         /// Do we need to run the converter in the original directory?
61         bool original_dir;
62         /// This converter needs the .aux files
63         bool need_aux;
64         /// If the converter put the result in a directory, then result_dir
65         /// is the name of the directory
66         string result_dir;
67         /// If the converter put the result in a directory, then result_file
68         /// is the name of the main file in that directory
69         string result_file;
70         /// Command to convert the program output to a LaTeX log file format
71         string parselog;
72         /// Backends in which the converter is not used
73         std::vector<string> disable;
74
75         /// Used by the BFS algorithm
76         bool visited;
77         /// Used by the BFS algorithm
78         std::vector<Command>::iterator previous;
79 };
80
81 class FormatPair {
82 public:
83         ///
84         Format const * format;
85         ///
86         Format const * from;
87         ///
88         string command;
89         ///
90         FormatPair(Format const * f1, Format const * f2, string c)
91                 : format(f1), from(f2), command(c) {}
92 };
93
94 ///
95 class Formats {
96 public:
97         ///
98         static
99         void Add(string const & name);
100         ///
101         static
102         void Add(string const & name, string const & extension, 
103                  string const & prettyname, string const & shortcut);
104         ///
105         static
106         void SetViewer(string const & name, string const & command);
107         ///
108         static
109         bool View(Buffer const * buffer, string const & filename,
110                   string const & format_name);
111         ///
112         static
113         Format * GetFormat(string const & name);
114         ///
115         static
116         string const PrettyName(string const & name);
117         ///
118         static
119         string const Extension(string const & name);
120 private:
121         ///
122         static
123         std::map<string, Format> formats;
124 };
125
126 ///
127 class Converter {
128 public:
129         ///
130         static
131         void Add(string const & from, string const & to,
132                  string const & command, string const & flags);
133         ///
134         
135         ///
136         static
137         std::vector<FormatPair> const
138         GetReachable(string const & from, string const & stop_format,
139                      bool only_viewable);
140         ///
141         static
142         bool IsReachable(string const & from, string const & to);
143         ///
144         static
145         bool Convert(Buffer const * buffer,
146                      string const & from_file, string const & to_file_base,
147                      string const & from_format, string const & to_format,
148                      string const & using_format, string & to_file);
149         ///
150         static
151         bool Convert(Buffer const * buffer,
152                      string const & from_file, string const & to_file_base,
153                      string const & from_format, string const & to_format,
154                      string const & using_format = string());
155         ///
156         static
157         string const SplitFormat(string const & str, string & format);
158         ///
159         static
160         string const dvi_papersize(Buffer const * buffer);
161         ///
162         static
163         string const dvips_options(Buffer const * buffer);
164         ///
165         static
166         void init();
167 private:
168         ///
169         static
170         bool scanLog(Buffer const * buffer, string const & command, 
171                      string const & filename);
172         ///
173         static
174         bool runLaTeX(Buffer const * buffer, string const & command);
175         ///
176         static
177         std::vector<Command> commands;
178         ///
179         static
180         string latex_command;
181 };
182
183 #endif