]> git.lyx.org Git - lyx.git/blob - src/converter.h
b23a0ffd62ca884140f8d13781a08b587a4103c4
[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 struct Command {
27         ///
28         Command(string const & f, string const & t, string const & c)
29                 : from(f), to(t), command(c),
30                   original_dir(false), need_aux(false) {}
31         ///
32         string from;
33         ///
34         string to;
35         ///
36         string command;
37         /// Do we need to run the converter in the original directory?
38         bool original_dir;
39         /// This converter needs the .aux files
40         bool need_aux;
41         /// If the converter put the result in a directory, then result_dir
42         /// is the name of the directory
43         string result_dir;
44         /// If the converter put the result in a directory, then result_file
45         /// is the name of the main file in that directory
46         string result_file;
47         /// Command to convert the program output to a LaTeX log file format
48         string parselog;
49
50         /// Used by the BFS algorithm
51         bool visited;
52         /// Used by the BFS algorithm
53         std::vector<Command>::iterator previous;
54 };
55
56 ///
57 class Format {
58 public:
59         ///
60         Format() {}
61         ///
62         Format(string const & n);
63         ///
64         string name;
65         ///
66         string prettyname;
67         ///
68         string viewer;
69 };
70
71 class FormatPair {
72 public:
73         ///
74         Format * format;
75         ///
76         Format * from;
77         ///
78         string command;
79         ///
80         FormatPair(Format * f1, Format * f2, string c)
81                 : format(f1), from(f2), command(c) {}
82 };
83
84 ///
85 class Formats {
86 public:
87         ///
88         static
89         void Add(string const & name);
90         ///
91         static
92         void SetViewer(string const & name, string const & command);
93         ///
94         static
95         bool View(Buffer const * buffer, string const & filename);
96         ///
97         static
98         Format * GetFormat(string const & name);
99         ///
100         static
101         string const PrettyName(string const & name);
102 private:
103         ///
104         static
105         std::map<string, Format> formats;
106 };
107
108 ///
109 class Converter {
110 public:
111         ///
112         static
113         void Add(string const & from, string const & to,
114                  string const & command, string const & flags);
115         ///
116         
117         ///
118         static
119         std::vector<FormatPair> const
120         GetReachable(string const & from,
121                      bool only_viewable = false);
122         ///
123         static
124         bool IsReachable(string const & from, string const & target_format);
125         ///
126         static
127         bool Convert(Buffer const * buffer, string const & from_file,
128                      string const & to_file, string const & using_format,
129                      string * view_file = 0);
130         ///
131         static
132         string const SplitFormat(string const & str, string & format);
133         ///
134         static
135         string const dvi_papersize(Buffer const * buffer);
136         ///
137         static
138         string const dvips_options(Buffer const * buffer);
139         ///
140         static
141         void init();
142 private:
143         ///
144         static
145         bool scanLog(Buffer const * buffer, string const & command, 
146                      string const & filename);
147         ///
148         static
149         bool runLaTeX(Buffer const * buffer, string const & command);
150         ///
151         static
152         std::vector<Command> commands;
153         ///
154         static
155         string latex_command;
156 };
157
158 #endif