2022-02-01 13:55:18 +00:00
|
|
|
#include <qpdf/qpdfjob-c.h>
|
|
|
|
|
|
|
|
#include <qpdf/QPDFJob.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <qpdf/QPDFUsage.hh>
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
|
2022-02-01 18:49:11 +00:00
|
|
|
int qpdfjob_run_from_argv(char const* const argv[])
|
2022-02-01 13:55:18 +00:00
|
|
|
{
|
2022-02-05 13:15:07 +00:00
|
|
|
auto whoami_p = QUtil::make_unique_cstr(argv[0]);
|
2022-02-01 18:37:31 +00:00
|
|
|
auto whoami = QUtil::getWhoami(whoami_p.get());
|
2022-02-01 13:55:18 +00:00
|
|
|
QUtil::setLineBuf(stdout);
|
|
|
|
|
|
|
|
QPDFJob j;
|
|
|
|
try
|
|
|
|
{
|
2022-02-01 18:49:11 +00:00
|
|
|
j.initializeFromArgv(argv);
|
2022-02-01 13:55:18 +00:00
|
|
|
j.run();
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2022-02-08 14:18:08 +00:00
|
|
|
std::cerr << whoami << ": " << e.what() << std::endl;
|
2022-02-01 13:55:18 +00:00
|
|
|
return QPDFJob::EXIT_ERROR;
|
|
|
|
}
|
|
|
|
return j.getExitCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QPDF_NO_WCHAR_T
|
2022-02-01 18:49:11 +00:00
|
|
|
int qpdfjob_run_from_wide_argv(wchar_t const* const argv[])
|
2022-02-01 13:55:18 +00:00
|
|
|
{
|
2022-02-01 18:49:11 +00:00
|
|
|
int argc = 0;
|
|
|
|
for (auto k = argv; *k; ++k)
|
|
|
|
{
|
|
|
|
++argc;
|
|
|
|
}
|
|
|
|
return QUtil::call_main_from_wmain(
|
|
|
|
argc, argv, [](int, char const* const new_argv[]) {
|
|
|
|
return qpdfjob_run_from_argv(new_argv);
|
|
|
|
});
|
2022-02-01 13:55:18 +00:00
|
|
|
}
|
|
|
|
#endif // QPDF_NO_WCHAR_T
|
|
|
|
|
|
|
|
int qpdfjob_run_from_json(char const* json)
|
|
|
|
{
|
|
|
|
QPDFJob j;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
j.initializeFromJson(json);
|
|
|
|
j.run();
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2022-02-08 14:18:08 +00:00
|
|
|
std::cerr << "qpdfjob json: " << e.what() << std::endl;
|
2022-02-01 13:55:18 +00:00
|
|
|
return QPDFJob::EXIT_ERROR;
|
|
|
|
}
|
|
|
|
return j.getExitCode();
|
|
|
|
}
|