2000-08-30 03:40:51 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#ifndef CONVERTER_H
|
|
|
|
#define CONVERTER_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include "LString.h"
|
|
|
|
|
|
|
|
class Buffer;
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
///
|
|
|
|
class Format {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
Format() {}
|
|
|
|
///
|
|
|
|
Format(string const & n, string const & e, string const & p,
|
2000-11-06 11:20:22 +00:00
|
|
|
string const & s, string const & v) :
|
|
|
|
name(n), extension(e), prettyname(p), shortcut(s),
|
|
|
|
viewer(v) {};
|
2000-10-23 12:16:05 +00:00
|
|
|
///
|
|
|
|
string name;
|
|
|
|
///
|
|
|
|
string extension;
|
|
|
|
///
|
|
|
|
string prettyname;
|
|
|
|
///
|
|
|
|
string shortcut;
|
|
|
|
///
|
|
|
|
string viewer;
|
2000-11-06 11:20:22 +00:00
|
|
|
///
|
|
|
|
bool dummy() const;
|
|
|
|
///
|
|
|
|
string const getname() const {
|
|
|
|
return name;
|
|
|
|
}
|
2000-10-23 12:16:05 +00:00
|
|
|
};
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2000-08-30 03:40:51 +00:00
|
|
|
struct Command {
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
Command(Format const * f, Format const * t, string const & c)
|
2000-11-06 11:20:22 +00:00
|
|
|
: from(f), to(t), command(c), importer(false),
|
2000-10-23 12:16:05 +00:00
|
|
|
latex(false), original_dir(false), need_aux(false) {}
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
Format const * from;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
Format const * to;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
|
|
|
string command;
|
2000-11-06 11:20:22 +00:00
|
|
|
/// The converter is used for importing
|
|
|
|
bool importer;
|
2000-10-23 12:16:05 +00:00
|
|
|
/// The converter is latex or its derivatives
|
|
|
|
bool latex;
|
2000-09-11 15:42:17 +00:00
|
|
|
/// Do we need to run the converter in the original directory?
|
2000-08-30 03:40:51 +00:00
|
|
|
bool original_dir;
|
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
|
|
|
|
string result_dir;
|
|
|
|
/// If the converter put the result in a directory, then result_file
|
|
|
|
/// is the name of the main file in that directory
|
|
|
|
string result_file;
|
2000-10-02 16:44:47 +00:00
|
|
|
/// Command to convert the program output to a LaTeX log file format
|
|
|
|
string parselog;
|
2000-10-23 12:16:05 +00:00
|
|
|
/// Backends in which the converter is not used
|
|
|
|
std::vector<string> disable;
|
2000-10-02 16:44:47 +00:00
|
|
|
|
|
|
|
/// Used by the BFS algorithm
|
2000-08-30 03:40:51 +00:00
|
|
|
bool visited;
|
2000-10-02 16:44:47 +00:00
|
|
|
/// Used by the BFS algorithm
|
2000-08-30 03:40:51 +00:00
|
|
|
std::vector<Command>::iterator previous;
|
|
|
|
};
|
|
|
|
|
2000-10-16 13:27:56 +00:00
|
|
|
class FormatPair {
|
|
|
|
public:
|
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
Format const * format;
|
2000-10-16 13:27:56 +00:00
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
Format const * from;
|
2000-10-16 13:27:56 +00:00
|
|
|
///
|
|
|
|
string command;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
FormatPair(Format const * f1, Format const * f2, string c)
|
2000-10-16 13:27:56 +00:00
|
|
|
: format(f1), from(f2), command(c) {}
|
2000-08-30 03:40:51 +00:00
|
|
|
};
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2000-08-30 03:40:51 +00:00
|
|
|
class Formats {
|
|
|
|
public:
|
2000-11-06 11:20:22 +00:00
|
|
|
///
|
|
|
|
typedef std::map<string, Format> FormatList;
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
|
|
|
void Add(string const & name);
|
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
void Add(string const & name, string const & extension,
|
|
|
|
string const & prettyname, string const & shortcut);
|
|
|
|
///
|
2000-08-30 03:40:51 +00:00
|
|
|
void SetViewer(string const & name, string const & command);
|
|
|
|
///
|
2000-10-23 12:16:05 +00:00
|
|
|
bool View(Buffer const * buffer, string const & filename,
|
|
|
|
string const & format_name);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
|
|
|
Format * GetFormat(string const & name);
|
|
|
|
///
|
2000-08-30 04:38:32 +00:00
|
|
|
string const PrettyName(string const & name);
|
2000-10-23 12:16:05 +00:00
|
|
|
///
|
|
|
|
string const Extension(string const & name);
|
2000-11-06 11:20:22 +00:00
|
|
|
///
|
|
|
|
std::vector<Format> const GetAllFormats();
|
2000-08-30 03:40:51 +00:00
|
|
|
private:
|
|
|
|
///
|
2000-11-06 11:20:22 +00:00
|
|
|
FormatList formats;
|
2000-08-30 03:40:51 +00:00
|
|
|
};
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
///
|
2000-08-30 03:40:51 +00:00
|
|
|
class Converter {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
static
|
|
|
|
void Add(string const & from, string const & to,
|
|
|
|
string const & command, string const & flags);
|
|
|
|
///
|
2000-11-06 11:20:22 +00:00
|
|
|
static
|
|
|
|
std::vector<FormatPair> const GetReachableTo(string const & target);
|
2000-10-16 13:27:56 +00:00
|
|
|
///
|
2000-08-30 03:40:51 +00:00
|
|
|
static
|
2000-10-16 13:27:56 +00:00
|
|
|
std::vector<FormatPair> const
|
2000-11-06 11:20:22 +00:00
|
|
|
GetReachable(string const & from, bool only_viewable);
|
2000-10-23 12:16:05 +00:00
|
|
|
///
|
|
|
|
static
|
|
|
|
bool IsReachable(string const & from, string const & to);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
|
|
|
static
|
2000-10-23 12:16:05 +00:00
|
|
|
bool Convert(Buffer const * buffer,
|
|
|
|
string const & from_file, string const & to_file_base,
|
|
|
|
string const & from_format, string const & to_format,
|
|
|
|
string const & using_format, string & to_file);
|
2000-10-16 13:27:56 +00:00
|
|
|
///
|
|
|
|
static
|
2000-10-23 12:16:05 +00:00
|
|
|
bool Convert(Buffer const * buffer,
|
|
|
|
string const & from_file, string const & to_file_base,
|
|
|
|
string const & from_format, string const & to_format,
|
|
|
|
string const & using_format = string());
|
2000-09-14 17:53:12 +00:00
|
|
|
///
|
2000-09-05 13:16:19 +00:00
|
|
|
static
|
|
|
|
string const SplitFormat(string const & str, string & format);
|
|
|
|
///
|
|
|
|
static
|
2000-09-14 17:53:12 +00:00
|
|
|
string const dvi_papersize(Buffer const * buffer);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
|
|
|
static
|
2000-09-14 17:53:12 +00:00
|
|
|
string const dvips_options(Buffer const * buffer);
|
2000-10-16 13:27:56 +00:00
|
|
|
///
|
|
|
|
static
|
|
|
|
void init();
|
2000-08-30 03:40:51 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
static
|
2000-10-12 15:17:42 +00:00
|
|
|
bool scanLog(Buffer const * buffer, string const & command,
|
2000-10-02 16:44:47 +00:00
|
|
|
string const & filename);
|
|
|
|
///
|
|
|
|
static
|
2000-10-12 15:17:42 +00:00
|
|
|
bool runLaTeX(Buffer const * buffer, string const & command);
|
2000-08-30 03:40:51 +00:00
|
|
|
///
|
|
|
|
static
|
|
|
|
std::vector<Command> commands;
|
2000-09-11 15:42:17 +00:00
|
|
|
///
|
|
|
|
static
|
|
|
|
string latex_command;
|
2000-08-30 03:40:51 +00:00
|
|
|
};
|
|
|
|
|
2000-11-06 11:20:22 +00:00
|
|
|
extern Formats formats;
|
|
|
|
extern Formats system_formats;
|
|
|
|
|
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
#endif
|