]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXPackages.cpp
Spaces in typewriter font never expand in justified text
[lyx.git] / src / LaTeXPackages.cpp
index a231a2294a469bd23f89e081a6410238a46e9535..e708df1dfe2b2ac0d52dcd6a2ccd44a3d0d79a47 100644 (file)
 
 #include "Lexer.h"
 
+#include "support/convert.h"
+#include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
+#include "support/Package.h"
 
 
 using namespace std;
@@ -49,15 +52,31 @@ void LaTeXPackages::getAvailable()
        packages_.clear();
 
        bool finished = false;
+       string lstformat = "1";
        // Parse config-file
        while (lex.isOK() && !finished) {
                switch (lex.lex()) {
                case Lexer::LEX_FEOF:
                        finished = true;
                        break;
-               default:
-                       packages_.insert(lex.getString());
+               default: {
+                       string const p = lex.getString();
+                       // Parse optional version info
+                       lex.eatLine();
+                       string const v = trim(lex.getString());
+                       if (p == "!!fileformat") {
+                               lstformat = v;
+                               continue;
+                       }
+                       packages_.insert(make_pair(p, v));
                }
+               }
+       }
+       // Check if the pkglist has current format.
+       // Reconfigure and re-parse if not.
+       if (lstformat != "2") {
+               package().reconfigureUserLyXDir("");
+               getAvailable();
        }
 }
 
@@ -69,7 +88,34 @@ bool LaTeXPackages::isAvailable(string const & name)
        string n = name;
        if (suffixIs(n, ".sty"))
                n.erase(name.length() - 4);
-       return packages_.find(n) != packages_.end();
+       for (auto const & package : packages_) {
+               if (package.first == n)
+                       return true;
+       }
+       return false;
+}
+
+
+bool LaTeXPackages::isAvailableAtLeastFrom(string const & name,
+                                          int const y, int const m, int const d)
+{
+       if (packages_.empty())
+               getAvailable();
+
+       // required date as int (yyyymmdd)
+       int const req_date = (y * 10000) + (m * 100) + d;
+       for (auto const & package : packages_) {
+               if (package.first == name && !package.second.empty()) {
+                       if (!isStrInt(package.second)) {
+                               LYXERR0("Warning: Invalid date of package "
+                                       << package.first << " (" << package.second << ")");
+                               continue;
+                       }
+                       // required date not newer than available date
+                       return req_date <= convert<int>(package.second);
+               }
+       }
+       return false;
 }
 
 } // namespace lyx