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