X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeXPackages.cpp;h=e708df1dfe2b2ac0d52dcd6a2ccd44a3d0d79a47;hb=1d637b8af0f76d7c758db91ee3a196306f861a21;hp=a8d775cfc16baa501da8f146c90dcc0a530aca49;hpb=2e6ea5f61334889d5b1329b97c64e790f5f48199;p=lyx.git diff --git a/src/LaTeXPackages.cpp b/src/LaTeXPackages.cpp index a8d775cfc1..e708df1dfe 100644 --- a/src/LaTeXPackages.cpp +++ b/src/LaTeXPackages.cpp @@ -19,11 +19,11 @@ #include "Lexer.h" #include "support/convert.h" +#include "support/debug.h" #include "support/FileName.h" #include "support/filetools.h" #include "support/lstrings.h" - -#include +#include "support/Package.h" using namespace std; @@ -52,6 +52,7 @@ void LaTeXPackages::getAvailable() packages_.clear(); bool finished = false; + string lstformat = "1"; // Parse config-file while (lex.isOK() && !finished) { switch (lex.lex()) { @@ -63,10 +64,20 @@ void LaTeXPackages::getAvailable() // 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(); + } } @@ -91,45 +102,20 @@ bool LaTeXPackages::isAvailableAtLeastFrom(string const & name, if (packages_.empty()) getAvailable(); - bool result = false; - // Check for yyyy[-/]mm[-/]dd - static regex const reg("([\\d]{4})[-/]?([\\d]{2})[-/]?([\\d]{2})"); + // 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()) { - smatch sub; - if (regex_match(package.second, sub, reg)) { - // Test whether date is same or newer. - // - // Test for year first - int const avail_y = convert(sub.str(1)); - if (avail_y < y) - // our year is older: bad! - break; - if (avail_y > y) { - // our year is newer: good! - result = true; - break; - } - // Same year: now test month - int const avail_m = convert(sub.str(2)); - if (avail_m < m) - // our month is older: bad! - break; - if (avail_m > m) { - // our month is newer: good! - result = true; - break; - } - // Same year and month: test day - if (convert(sub.str(3)) >= d) { - // day same or newer: good! - result = true; - break; - } + 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(package.second); } } - return result; + return false; } } // namespace lyx