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