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"
29 using namespace lyx::support;
34 LaTeXPackages::Packages LaTeXPackages::packages_;
37 void LaTeXPackages::getAvailable()
40 support::FileName const real_file = libFileSearch("", "packages.lst");
42 if (real_file.empty())
45 lex.setFile(real_file);
50 // Make sure that we are clean
53 bool finished = false;
55 while (lex.isOK() && !finished) {
61 string const p = lex.getString();
62 // Parse optional version info
64 string const v = trim(lex.getString());
65 packages_.insert(make_pair(p, v));
72 bool LaTeXPackages::isAvailable(string const & name)
74 if (packages_.empty())
77 if (suffixIs(n, ".sty"))
78 n.erase(name.length() - 4);
79 for (auto const & package : packages_) {
80 if (package.first == n)
87 bool LaTeXPackages::isAvailableAtLeastFrom(string const & name,
88 int const y, int const m, int const d)
90 if (packages_.empty())
93 // required date as int (yyyymmdd)
94 int const req_date = (y * 10000) + (m * 100) + d;
95 for (auto const & package : packages_) {
96 if (package.first == name && !package.second.empty()) {
97 if (!isStrInt(package.second)) {
98 LYXERR0("Warning: Invalid date of package "
99 << package.first << " (" << package.second << ")");
102 // required date not newer than available date
103 return req_date <= convert<int>(package.second);