]> git.lyx.org Git - lyx.git/blob - src/converter.h
757fe944d90cd326876e338849d9c751a4d15e58
[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() : in_degree(0) {}
61         ///
62         Format(string const & n);
63         ///
64         string name;
65         ///
66         string prettyname;
67         ///
68         string viewer;
69         ///
70         int in_degree;
71 };
72
73 ///
74 class Formats {
75 public:
76         ///
77         static
78         void Add(string const & name);
79         ///
80         static
81         void SetViewer(string const & name, string const & command);
82         ///
83         static
84         bool View(Buffer * buffer, string const & filename);
85         ///
86         static
87         Format * GetFormat(string const & name);
88         ///
89         static
90         string const PrettyName(string const & name);
91 private:
92         ///
93         static
94         std::map<string, Format> formats;
95 };
96
97 ///
98 class Converter {
99 public:
100         ///
101         static
102         void Add(string const & from, string const & to,
103                  string const & command, string const & flags);
104         ///
105         static
106         std::vector<std::pair<string, string> > const
107         GetReachable(string const & from,
108                      bool only_viewable = false);
109         ///
110         static
111         bool Convert(Buffer * buffer, string const & from_file,
112                      string const & to_file, string const & using_format,
113                      string * view_file = 0);
114         ///
115         static
116         string const SplitFormat(string const & str, string & format);
117         ///
118         static
119         string const dvi_papersize(Buffer const * buffer);
120         ///
121         static
122         string const dvips_options(Buffer const * buffer);
123 private:
124         ///
125         static
126         bool scanLog(Buffer * buffer, string const & command, 
127                      string const & filename);
128         ///
129         static
130         bool runLaTeX(Buffer * buffer, string const & command);
131         ///
132         static
133         std::vector<Command> commands;
134         ///
135         static
136         string latex_command;
137 };
138
139 #endif