2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/QTC.hh>
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2023-05-20 18:13:09 +00:00
|
|
|
#include <cstdio>
|
2022-08-07 18:23:05 +00:00
|
|
|
#include <map>
|
2022-08-29 15:52:34 +00:00
|
|
|
#include <set>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static bool
|
|
|
|
tc_active(char const* const scope)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
std::string value;
|
|
|
|
return (QUtil::get_env("TC_SCOPE", &value) && (value == scope));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
2022-08-07 19:49:54 +00:00
|
|
|
QTC::TC_real(char const* const scope, char const* const ccase, int n)
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
2022-08-07 18:23:05 +00:00
|
|
|
static std::map<std::string, bool> active;
|
|
|
|
auto is_active = active.find(scope);
|
|
|
|
if (is_active == active.end()) {
|
|
|
|
active[scope] = tc_active(scope);
|
|
|
|
is_active = active.find(scope);
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2022-08-07 18:23:05 +00:00
|
|
|
if (!is_active->second) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-07 18:23:05 +00:00
|
|
|
static std::set<std::pair<std::string, int>> cache;
|
|
|
|
|
2008-04-29 12:55:25 +00:00
|
|
|
std::string filename;
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define TC_ENV "TC_WIN_FILENAME"
|
|
|
|
#else
|
|
|
|
# define TC_ENV "TC_FILENAME"
|
|
|
|
#endif
|
2022-04-02 21:14:10 +00:00
|
|
|
if (!QUtil::get_env(TC_ENV, &filename)) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
#undef TC_ENV
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if (cache.count(std::make_pair(ccase, n))) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
cache.insert(std::make_pair(ccase, n));
|
|
|
|
|
2013-02-28 21:45:11 +00:00
|
|
|
FILE* tc = QUtil::safe_fopen(filename.c_str(), "ab");
|
2008-04-29 12:55:25 +00:00
|
|
|
fprintf(tc, "%s %d\n", ccase, n);
|
|
|
|
fclose(tc);
|
|
|
|
}
|