2000-08-30 03:40:51 +00:00
|
|
|
// -*- C++ -*-
|
2003-02-28 09:49:49 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Converter.h
|
2003-02-28 09:49:49 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-28 09:49:49 +00:00
|
|
|
*/
|
2000-11-13 10:35:02 +00:00
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#ifndef CONVERTER_H
|
|
|
|
#define CONVERTER_H
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Graph.h"
|
|
|
|
#include "OutputParams.h"
|
2002-07-16 21:17:10 +00:00
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#include <vector>
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2003-09-06 23:36:02 +00:00
|
|
|
class Buffer;
|
2006-08-13 16:16:43 +00:00
|
|
|
class ErrorList;
|
2003-02-28 09:49:49 +00:00
|
|
|
class Format;
|
|
|
|
class Formats;
|
2003-11-05 12:06:20 +00:00
|
|
|
class OutputParams;
|
2001-02-16 09:25:43 +00:00
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2000-11-13 10:35:02 +00:00
|
|
|
class Converter {
|
|
|
|
public:
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
Converter(std::string const & f, std::string const & t, std::string const & c,
|
|
|
|
std::string const & l);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2001-07-30 11:56:00 +00:00
|
|
|
void readFlags();
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string from;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string to;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string command;
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string flags;
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
|
|
|
Format const * From;
|
|
|
|
///
|
|
|
|
Format const * To;
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
/// The converter is latex or its derivatives
|
|
|
|
bool latex;
|
2004-05-13 11:21:58 +00:00
|
|
|
/// The converter is xml
|
|
|
|
bool xml;
|
2000-09-11 15:42:17 +00:00
|
|
|
/// This converter needs the .aux files
|
|
|
|
bool need_aux;
|
|
|
|
/// If the converter put the result in a directory, then result_dir
|
|
|
|
/// is the name of the directory
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string result_dir;
|
2000-09-11 15:42:17 +00:00
|
|
|
/// If the converter put the result in a directory, then result_file
|
|
|
|
/// is the name of the main file in that directory
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string result_file;
|
2000-10-02 16:44:47 +00:00
|
|
|
/// Command to convert the program output to a LaTeX log file format
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string parselog;
|
2000-08-30 03:40:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2000-11-13 10:35:02 +00:00
|
|
|
class Converters {
|
2000-08-30 03:40:51 +00:00
|
|
|
public:
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
typedef std::vector<int> EdgePath; // to be removed SOON
|
|
|
|
///
|
2002-03-21 17:27:08 +00:00
|
|
|
typedef std::vector<Converter> ConverterList;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2000-11-13 10:35:02 +00:00
|
|
|
typedef ConverterList::const_iterator const_iterator;
|
2000-10-23 12:16:05 +00:00
|
|
|
///
|
2007-10-23 21:41:17 +00:00
|
|
|
Converter const & get(int i) const { return converterlist_[i]; }
|
2000-11-06 11:20:22 +00:00
|
|
|
///
|
2004-01-31 15:30:24 +00:00
|
|
|
Converter const * getConverter(std::string const & from,
|
|
|
|
std::string const & to) const;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2004-01-31 15:30:24 +00:00
|
|
|
int getNumber(std::string const & from, std::string const & to) const;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void add(std::string const & from, std::string const & to,
|
|
|
|
std::string const & command, std::string const & flags);
|
2000-11-13 10:35:02 +00:00
|
|
|
//
|
2003-10-06 15:43:21 +00:00
|
|
|
void erase(std::string const & from, std::string const & to);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2001-07-30 11:56:00 +00:00
|
|
|
void sort();
|
2000-10-16 13:27:56 +00:00
|
|
|
///
|
2000-11-13 10:35:02 +00:00
|
|
|
std::vector<Format const *> const
|
2003-10-06 15:43:21 +00:00
|
|
|
getReachableTo(std::string const & target, bool clear_visited);
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
|
|
|
std::vector<Format const *> const
|
2003-10-06 15:43:21 +00:00
|
|
|
getReachable(std::string const & from, bool only_viewable,
|
2000-11-13 10:35:02 +00:00
|
|
|
bool clear_visited);
|
2007-10-25 06:09:38 +00:00
|
|
|
|
|
|
|
std::vector<Format const *> importableFormats();
|
2009-05-02 08:43:22 +00:00
|
|
|
std::vector<Format const *> exportableFormats(bool only_viewable);
|
2007-10-25 06:09:38 +00:00
|
|
|
|
|
|
|
std::vector<std::string> loaders() const;
|
2009-05-02 08:43:22 +00:00
|
|
|
std::vector<std::string> savers() const;
|
2007-10-25 06:09:38 +00:00
|
|
|
|
2004-11-08 08:22:03 +00:00
|
|
|
/// Does a conversion path from format \p from to format \p to exist?
|
2003-10-06 15:43:21 +00:00
|
|
|
bool isReachable(std::string const & from, std::string const & to);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2007-10-25 06:09:38 +00:00
|
|
|
Graph::EdgePath getPath(std::string const & from, std::string const & to);
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
2003-11-27 16:38:47 +00:00
|
|
|
OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
|
2006-11-13 10:27:57 +00:00
|
|
|
/// Flags for converting files
|
|
|
|
enum ConversionFlags {
|
|
|
|
/// No special flags
|
|
|
|
none = 0,
|
|
|
|
/// Use the default converter if no converter is defined
|
|
|
|
try_default = 1 << 0,
|
|
|
|
/// Get the converted file from cache if possible
|
|
|
|
try_cache = 1 << 1
|
|
|
|
};
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
2001-07-30 11:56:00 +00:00
|
|
|
bool convert(Buffer const * buffer,
|
2007-05-28 22:27:45 +00:00
|
|
|
support::FileName const & from_file, support::FileName const & to_file,
|
|
|
|
support::FileName const & orig_from,
|
|
|
|
std::string const & from_format, std::string const & to_format,
|
|
|
|
ErrorList & errorList, int conversionflags = none);
|
2000-09-05 13:16:19 +00:00
|
|
|
///
|
2001-07-30 11:56:00 +00:00
|
|
|
void update(Formats const & formats);
|
2000-11-08 09:39:46 +00:00
|
|
|
///
|
2001-07-30 11:56:00 +00:00
|
|
|
void updateLast(Formats const & formats);
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
bool formatIsUsed(std::string const & format);
|
2000-11-13 10:35:02 +00:00
|
|
|
///
|
2007-10-23 21:41:17 +00:00
|
|
|
const_iterator begin() const { return converterlist_.begin(); }
|
|
|
|
///
|
|
|
|
const_iterator end() const { return converterlist_.end(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
void buildGraph();
|
2000-08-30 03:40:51 +00:00
|
|
|
private:
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
std::vector<Format const *> const
|
2003-10-08 11:31:51 +00:00
|
|
|
intToFormat(std::vector<int> const & input);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
bool scanLog(Buffer const & buffer, std::string const & command,
|
2006-12-04 17:43:49 +00:00
|
|
|
support::FileName const & filename, ErrorList & errorList);
|
2000-10-02 16:44:47 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
bool runLaTeX(Buffer const & buffer, std::string const & command,
|
2006-08-13 16:16:43 +00:00
|
|
|
OutputParams const &, ErrorList & errorList);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2001-07-30 11:56:00 +00:00
|
|
|
ConverterList converterlist_;
|
2000-09-11 15:42:17 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string latex_command_;
|
2004-11-08 08:22:03 +00:00
|
|
|
/// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
|
|
|
|
/// this method moves each /path/file*.ext file to /path2/file2*.ext2
|
2004-10-26 18:39:13 +00:00
|
|
|
bool move(std::string const & fmt,
|
2006-11-26 21:30:39 +00:00
|
|
|
support::FileName const & from, support::FileName const & to,
|
2004-10-26 18:39:13 +00:00
|
|
|
bool copy);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
Graph G_;
|
2000-08-30 03:40:51 +00:00
|
|
|
};
|
|
|
|
|
2007-01-17 13:18:16 +00:00
|
|
|
/// The global instance.
|
2007-04-26 04:41:58 +00:00
|
|
|
/// Implementation is in LyX.cpp.
|
2007-01-17 13:18:16 +00:00
|
|
|
extern Converters & theConverters();
|
2000-11-06 11:20:22 +00:00
|
|
|
|
2007-01-17 13:18:16 +00:00
|
|
|
/// The global copy after reading lyxrc.defaults.
|
2007-04-26 04:41:58 +00:00
|
|
|
/// Implementation is in LyX.cpp.
|
2007-01-17 13:18:16 +00:00
|
|
|
extern Converters & theSystemConverters();
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#endif //CONVERTER_H
|