]> git.lyx.org Git - lyx.git/blobdiff - src/lyxtextclasslist.C
Add margin to paragraph dialog.
[lyx.git] / src / lyxtextclasslist.C
index d0be70ff77546d8ab12b068dd67189481526bfa3..d5eeeefdbe7c7f3ba4d3cc9b2c4d559ffbb61582 100644 (file)
 #include <boost/regex.hpp>
 #include <boost/filesystem/operations.hpp>
 #include <fstream>
-namespace fs = boost::filesystem;
 
-using lyx::textclass_type;
 
-using lyx::support::libFileSearch;
-using lyx::support::makeDisplayPath;
+namespace lyx {
+namespace fs = boost::filesystem;
+
+using support::FileName;
+using support::addName;
+using support::libFileSearch;
+using support::makeDisplayPath;
 
 using boost::bind;
 using boost::regex;
 using boost::smatch;
 
-#ifndef CXX_GLOBAL_CSTD
-using std::exit;
-#endif
-
 using std::endl;
 using std::equal_to;
 using std::find_if;
@@ -98,13 +97,14 @@ public:
 bool LyXTextClassList::read()
 {
        LyXLex lex(0, 0);
-       string real_file = libFileSearch("", "textclass.lst");
-       lyxerr[Debug::TCLASS] << "Reading textclasses from `"
+       support::FileName const real_file = libFileSearch("", "textclass.lst");
+       LYXERR(Debug::TCLASS) << "Reading textclasses from `"
                              << real_file << '\'' << endl;
 
        if (real_file.empty()) {
                lyxerr << "LyXTextClassList::Read: unable to find "
-                       "textclass file  `" << makeDisplayPath(real_file, 1000)
+                         "textclass file  `"
+                      << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
                       << "'. Exiting." << endl;
                return false;
                // This causes LyX to end... Not a desirable behaviour. Lgb
@@ -122,7 +122,8 @@ bool LyXTextClassList::read()
 
        if (!lex.isOK()) {
                lyxerr << "LyXTextClassList::Read: unable to open "
-                       "textclass file  `" << makeDisplayPath(real_file, 1000)
+                         "textclass file  `"
+                      << to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
                       << "'\nCheck your installation. LyX can't continue."
                       << endl;
                return false;
@@ -130,25 +131,25 @@ bool LyXTextClassList::read()
 
        bool finished = false;
        // Parse config-file
-       lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
+       LYXERR(Debug::TCLASS) << "Starting parsing of textclass.lst" << endl;
        while (lex.isOK() && !finished) {
-               lyxerr[Debug::TCLASS] << "\tline by line" << endl;
+               LYXERR(Debug::TCLASS) << "\tline by line" << endl;
                switch (lex.lex()) {
                case LyXLex::LEX_FEOF:
                        finished = true;
                        break;
                default:
                        string const fname = lex.getString();
-                       lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
+                       LYXERR(Debug::TCLASS) << "Fname: " << fname << endl;
                        if (lex.next()) {
                                string const clname = lex.getString();
-                               lyxerr[Debug::TCLASS] << "Clname: " << clname << endl;
+                               LYXERR(Debug::TCLASS) << "Clname: " << clname << endl;
                                if (lex.next()) {
                                        string const desc = lex.getString();
-                                       lyxerr[Debug::TCLASS] << "Desc: " << desc << endl;
+                                       LYXERR(Debug::TCLASS) << "Desc: " << desc << endl;
                                        if (lex.next()) {
                                                bool avail = lex.getBool();
-                                               lyxerr[Debug::TCLASS] << "Avail: " << avail << endl;
+                                               LYXERR(Debug::TCLASS) << "Avail: " << avail << endl;
                                                // This code is run when we have
                                                // fname, clname, desc, and avail
                                                LyXTextClass tmpl(fname, clname, desc, avail);
@@ -161,7 +162,7 @@ bool LyXTextClassList::read()
                        }
                }
        }
-       lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
+       LYXERR(Debug::TCLASS) << "End of parsing of textclass.lst" << endl;
 
        if (classlist_.empty()) {
                lyxerr << "LyXTextClassList::Read: no textclasses found!"
@@ -174,21 +175,21 @@ bool LyXTextClassList::read()
 }
 
 
-std::pair<bool, lyx::textclass_type> const
+std::pair<bool, textclass_type> const
 LyXTextClassList::addTextClass(std::string const & textclass, std::string const & path)
 {
        // only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS
        // NOTE: latex class name is defined in textclass.layout, which can be different from textclass
-       string layout_file = path + "/" + textclass + ".layout";
-       if (fs::exists(layout_file)) {
-               lyxerr[Debug::TCLASS] << "Adding class " << textclass << " from directory " << path << endl;
+       FileName const layout_file(addName(path, textclass + ".layout"));
+       if (fs::exists(layout_file.toFilesystemEncoding())) {
+               LYXERR(Debug::TCLASS) << "Adding class " << textclass << " from directory " << path << endl;
                // Read .layout file and get description, real latex classname etc
                //
                // This is a C++ version of function processLayoutFile in configure.py,
                // which uses the following regex
-               //     \Declare(LaTeX|DocBook|LinuxDoc)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}
-               ifstream ifs(layout_file.c_str());
-               static regex const reg("^#\\s*\\\\Declare(LaTeX|DocBook|LinuxDoc)Class\\s*"
+               //     \Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}
+               ifstream ifs(layout_file.toFilesystemEncoding().c_str());
+               static regex const reg("^#\\s*\\\\Declare(LaTeX|DocBook)Class\\s*"
                        "(?:\\[([^,]*)(?:,.*)*\\])*\\s*\\{(.*)\\}\\s*");
                string line;
                while (getline(ifs, line)) {
@@ -217,15 +218,19 @@ LyXTextClassList textclasslist;
 
 
 // Reads the style files
-void LyXSetStyle()
+bool LyXSetStyle()
 {
-       lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration..." << endl;
+       LYXERR(Debug::TCLASS) << "LyXSetStyle: parsing configuration..." << endl;
 
        if (!textclasslist.read()) {
-               lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
+               LYXERR(Debug::TCLASS) << "LyXSetStyle: an error occured "
                        "during parsing.\n             Exiting." << endl;
-               exit(1);
+               return false;
        }
 
-       lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
+       LYXERR(Debug::TCLASS) << "LyXSetStyle: configuration parsed." << endl;
+       return true;
 }
+
+
+} // namespace lyx