2 * \file LaTeXPackages.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
17 #include "LaTeXPackages.h"
21 #include "support/convert.h"
22 #include "support/debug.h"
23 #include "support/FileName.h"
24 #include "support/filetools.h"
25 #include "support/lstrings.h"
26 #include "support/Package.h"
30 using namespace lyx::support;
35 LaTeXPackages::Packages LaTeXPackages::packages_;
38 void LaTeXPackages::getAvailable()
41 support::FileName const real_file = libFileSearch("", "packages.lst");
43 if (real_file.empty())
46 lex.setFile(real_file);
51 // Make sure that we are clean
54 bool finished = false;
55 string lstformat = "1";
57 while (lex.isOK() && !finished) {
63 string const p = lex.getString();
64 // Parse optional version info
66 string const v = trim(lex.getString());
67 if (p == "!!fileformat") {
71 packages_.insert(make_pair(p, v));
75 // Check if the pkglist has current format.
76 // Reconfigure and re-parse if not.
77 if (lstformat != "2") {
78 package().reconfigureUserLyXDir("");
84 bool LaTeXPackages::isAvailable(string const & name)
86 if (packages_.empty())
89 if (suffixIs(n, ".sty"))
90 n.erase(name.length() - 4);
91 for (auto const & package : packages_) {
92 if (package.first == n)
99 bool LaTeXPackages::isAvailableAtLeastFrom(string const & name,
100 int const y, int const m, int const d)
102 if (packages_.empty())
105 // required date as int (yyyymmdd)
106 int const req_date = (y * 10000) + (m * 100) + d;
107 for (auto const & package : packages_) {
108 if (package.first == name && !package.second.empty()) {
109 if (!isStrInt(package.second)) {
110 LYXERR0("Warning: Invalid date of package "
111 << package.first << " (" << package.second << ")");
114 // required date not newer than available date
115 return req_date <= convert<int>(package.second);