]> git.lyx.org Git - lyx.git/blob - src/converter.h
Alfredo's second patch
[lyx.git] / src / converter.h
1 // -*- C++ -*-
2
3 #ifndef CONVERTER_H
4 #define CONVERTER_H
5
6 /**
7  * \file converter.h
8  * This file is part of LyX, the document processor.
9  * Licence details can be found in the file COPYING.
10  *
11  * \author Dekel Tsur
12  *
13  * Full author contact details are available in file CREDITS
14  */
15
16 #include "graph.h"
17
18 #include <vector>
19
20 class Format;
21 class Formats;
22
23 class Buffer;
24
25 ///
26 class Converter {
27 public:
28         ///
29         Converter(string const & f, string const & t, string const & c,
30                   string const & l);
31         ///
32         void readFlags();
33         ///
34         string from;
35         ///
36         string to;
37         ///
38         string command;
39         ///
40         string flags;
41         ///
42         Format const * From;
43         ///
44         Format const * To;
45
46         /// The converter is latex or its derivatives
47         bool latex;
48         /// Do we need to run the converter in the original directory?
49         bool original_dir;
50         /// This converter needs the .aux files
51         bool need_aux;
52         /// If the converter put the result in a directory, then result_dir
53         /// is the name of the directory
54         string result_dir;
55         /// If the converter put the result in a directory, then result_file
56         /// is the name of the main file in that directory
57         string result_file;
58         /// Command to convert the program output to a LaTeX log file format
59         string parselog;
60 };
61
62
63 ///
64 class Converters {
65 public:
66         ///
67         typedef std::vector<int> EdgePath; // to be removed SOON
68         ///
69         typedef std::vector<Converter> ConverterList;
70         ///
71         typedef ConverterList::const_iterator const_iterator;
72         ///
73         Converter const & get(int i) const {
74                 return converterlist_[i];
75         }
76         ///
77         Converter const * getConverter(string const & from, string const & to);
78         ///
79         int getNumber(string const & from, string const & to);
80         ///
81         void add(string const & from, string const & to,
82                  string const & command, string const & flags);
83         //
84         void erase(string const & from, string const & to);
85         ///
86         void sort();
87         ///
88         std::vector<Format const *> const
89         getReachableTo(string const & target, bool clear_visited);
90         ///
91         std::vector<Format const *> const
92         getReachable(string const & from, bool only_viewable,
93                      bool clear_visited);
94         ///
95         bool isReachable(string const & from, string const & to);
96         ///
97         Graph::EdgePath const getPath(string const & from, string const & to);
98         ///
99         bool usePdflatex(Graph::EdgePath const & path);
100         ///
101         bool convert(Buffer const * buffer,
102                      string const & from_file, string const & to_file_base,
103                      string const & from_format, string const & to_format,
104                      string & to_file);
105         ///
106         bool convert(Buffer const * buffer,
107                      string const & from_file, string const & to_file_base,
108                      string const & from_format, string const & to_format);
109         ///
110         string const dvips_options(Buffer const * buffer);
111         ///
112         string const dvipdfm_options(Buffer const * buffer);
113         ///
114         void update(Formats const & formats);
115         ///
116         void updateLast(Formats const & formats);
117         ///
118         bool formatIsUsed(string const & format);
119         ///
120         const_iterator begin() const {
121                 return converterlist_.begin();
122         }
123         const_iterator end() const {
124                 return converterlist_.end();
125         }
126         ///
127         void buildGraph();
128 private:
129         ///
130         std::vector<Format const *> const
131         Converters::intToFormat(std::vector<int> const & input);
132         ///
133         bool scanLog(Buffer const * buffer, string const & command,
134                      string const & filename);
135         ///
136         bool runLaTeX(Buffer const * buffer, string const & command);
137         ///
138         ConverterList converterlist_;
139         ///
140         string latex_command_;
141         ///
142         bool move(string const & from, string const & to, bool copy);
143         ///
144         Graph G_;
145 };
146
147 extern Converters converters;
148
149 extern Converters system_converters;
150
151 #endif //CONVERTER_H