aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QTC.cc
blob: cbaf558b21c8c8f56790209c960909a91c0f3964 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <qpdf/QTC.hh>

#include <set>
#include <stdio.h>
#include <qpdf/QUtil.hh>

static bool tc_active(char const* const scope)
{
    std::string value;
    return (QUtil::get_env("TC_SCOPE", &value) && (value == scope));
}

void QTC::TC(char const* const scope, char const* const ccase, int n)
{
    static std::set<std::pair<std::string, int> > cache;

    if (! tc_active(scope))
    {
	return;
    }

    std::string filename;
#ifdef _WIN32
# define TC_ENV "TC_WIN_FILENAME"
#else
# define TC_ENV "TC_FILENAME"
#endif
    if (! QUtil::get_env(TC_ENV, &filename))
    {
	return;
    }
#undef TC_ENV

    if (cache.count(std::make_pair(ccase, n)))
    {
	return;
    }
    cache.insert(std::make_pair(ccase, n));

    FILE* tc = QUtil::safe_fopen(filename.c_str(), "ab");
    fprintf(tc, "%s %d\n", ccase, n);
    fclose(tc);
}