]> git.lyx.org Git - lyx.git/blobdiff - src/lyxtextclass.C
minimal effort implementation of:
[lyx.git] / src / lyxtextclass.C
index 7fd0b30068636d1eca4d9fd0910159d0770482e0..040cad964961d3efd74390559901a9d18e15f9c7 100644 (file)
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 #include "support/filetools.h"
+#include "support/os.h"
+
+#include <boost/filesystem/operations.hpp>
+namespace fs = boost::filesystem;
 
 #include <sstream>
 
-using lyx::support::LibFileSearch;
-using lyx::support::MakeDisplayPath;
-using lyx::support::QuoteName;
+using lyx::support::libFileSearch;
+using lyx::support::makeDisplayPath;
+using lyx::support::quoteName;
 using lyx::support::rtrim;
 using lyx::support::subst;
+using lyx::support::addName;
 
 using std::endl;
 using std::find_if;
@@ -61,7 +66,7 @@ int const FORMAT = 2;
 
 bool layout2layout(string const & filename, string const & tempfile)
 {
-       string const script = LibFileSearch("scripts", "layout2layout.py");
+       string const script = libFileSearch("scripts", "layout2layout.py");
        if (script.empty()) {
                lyxerr << "Could not find layout conversion "
                          "script layout2layout.py." << endl;
@@ -69,15 +74,15 @@ bool layout2layout(string const & filename, string const & tempfile)
        }
 
        std::ostringstream command;
-       command << "python " << QuoteName(script)
-               << ' ' << QuoteName(filename)
-               << ' ' << QuoteName(tempfile);
+       command << lyx::support::os::python() << ' ' << quoteName(script)
+               << ' ' << quoteName(filename)
+               << ' ' << quoteName(tempfile);
        string const command_str = command.str();
 
        lyxerr[Debug::TCLASS] << "Running `" << command_str << '\'' << endl;
 
        lyx::support::cmd_ret const ret =
-               lyx::support::RunCommand(command_str);
+               lyx::support::runCommand(command_str);
        if (ret.first != 0) {
                lyxerr << "Could not run layout conversion "
                          "script layout2layout.py." << endl;
@@ -120,7 +125,7 @@ bool LyXTextClass::isTeXClassAvailable() const
 bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
 {
        lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
-       if (!lay.Read(lexrc, *this)) {
+       if (!lay.read(lexrc, *this)) {
                // Resolve fonts
                lay.resfont = lay.font;
                lay.resfont.realize(defaultfont());
@@ -165,9 +170,9 @@ enum TextClassTags {
 
 
 // Reads a textclass structure from file.
-bool LyXTextClass::Read(string const & filename, bool merge)
+bool LyXTextClass::read(string const & filename, bool merge)
 {
-       if (!lyx::support::IsFileReadable(filename)) {
+       if (!lyx::support::isFileReadable(filename)) {
                lyxerr << "Cannot read layout file `" << filename << "'."
                       << endl;
                return true;
@@ -205,11 +210,11 @@ bool LyXTextClass::Read(string const & filename, bool merge)
 
        if (!merge)
                lyxerr[Debug::TCLASS] << "Reading textclass "
-                                     << MakeDisplayPath(filename)
+                                     << makeDisplayPath(filename)
                                      << endl;
        else
                lyxerr[Debug::TCLASS] << "Reading input file "
-                                    << MakeDisplayPath(filename)
+                                    << makeDisplayPath(filename)
                                     << endl;
 
        LyXLex lexrc(textClassTags,
@@ -251,11 +256,11 @@ bool LyXTextClass::Read(string const & filename, bool merge)
 
                case TC_INPUT: // Include file
                        if (lexrc.next()) {
-                               string tmp = LibFileSearch("layouts",
+                               string tmp = libFileSearch("layouts",
                                                            lexrc.getString(),
                                                            "layout");
 
-                               if (Read(tmp, true)) {
+                               if (read(tmp, true)) {
                                        lexrc.printError("Error reading input"
                                                         "file: "+tmp);
                                        error = true;
@@ -435,14 +440,14 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                string const tempfile = lyx::support::tempName();
                error = !layout2layout(filename, tempfile);
                if (!error)
-                       error = Read(tempfile, merge);
+                       error = read(tempfile, merge);
                lyx::support::unlink(tempfile);
                return error;
        }
 
        if (!merge) { // we are at top level here.
                lyxerr[Debug::TCLASS] << "Finished reading textclass "
-                                     << MakeDisplayPath(filename)
+                                     << makeDisplayPath(filename)
                                      << endl;
                if (defaultlayout_.empty()) {
                        lyxerr << "Error: Textclass '" << name_
@@ -472,7 +477,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
 
        } else
                lyxerr[Debug::TCLASS] << "Finished reading input file "
-                                     << MakeDisplayPath(filename)
+                                     << makeDisplayPath(filename)
                                      << endl;
 
        return error;
@@ -511,7 +516,6 @@ void LyXTextClass::readOutputType(LyXLex & lexrc)
        keyword_item outputTypeTags[] = {
                { "docbook", DOCBOOK },
                { "latex", LATEX },
-               { "linuxdoc", LINUXDOC },
                { "literate", LITERATE }
        };
 
@@ -523,7 +527,6 @@ void LyXTextClass::readOutputType(LyXLex & lexrc)
                lexrc.printError("Unknown output type `$$Token'");
                return;
        case LATEX:
-       case LINUXDOC:
        case DOCBOOK:
        case LITERATE:
                outputType_ = static_cast<OutputType>(le);
@@ -910,18 +913,22 @@ bool LyXTextClass::delete_layout(string const & name)
 
 
 // Load textclass info if not loaded yet
-bool LyXTextClass::load() const
+bool LyXTextClass::load(string const & path) const
 {
        if (loaded_)
                return true;
 
-       // Read style-file
-       string const real_file = LibFileSearch("layouts", name_, "layout");
-       loaded_ = const_cast<LyXTextClass*>(this)->Read(real_file) == 0;
+       // Read style-file, provided path is searched before the system ones
+       string layout_file;
+       if (!path.empty())
+               layout_file = addName(path, name_ + ".layout");
+       if (layout_file.empty() || !fs::exists(layout_file))
+               layout_file = libFileSearch("layouts", name_, "layout");
+       loaded_ = const_cast<LyXTextClass*>(this)->read(layout_file) == 0;
 
        if (!loaded_) {
                lyxerr << "Error reading `"
-                      << MakeDisplayPath(real_file)
+                      << makeDisplayPath(layout_file)
                       << "'\n(Check `" << name_
                       << "')\nCheck your installation and "
                        "try Options/Reconfigure..." << endl;