2020-04-04 01:34:45 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#ifndef QPDF_NO_WCHAR_T
|
|
|
|
void
|
|
|
|
wmain_test()
|
|
|
|
{
|
2022-02-01 18:37:31 +00:00
|
|
|
// writable args and function args
|
2020-04-04 01:34:45 +00:00
|
|
|
auto realmain = [](int argc, char* argv[]) {
|
2022-02-01 18:37:31 +00:00
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
std::cout << argv[i] << std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
2020-04-04 01:34:45 +00:00
|
|
|
wchar_t* argv[3];
|
2022-02-01 18:37:31 +00:00
|
|
|
// This works because call_main_from_wmain doesn't actually write
|
|
|
|
// to the arguments and neither does our function. Otherwise, this
|
|
|
|
// cast would be unsafe.
|
2020-04-04 01:34:45 +00:00
|
|
|
argv[0] = const_cast<wchar_t*>(L"ascii");
|
|
|
|
argv[1] = const_cast<wchar_t*>(L"10 \xf7 2 = 5");
|
|
|
|
argv[2] = const_cast<wchar_t*>(L"qwww\xf7\x03c0");
|
|
|
|
QUtil::call_main_from_wmain(3, argv, realmain);
|
|
|
|
}
|
2022-02-01 18:37:31 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
cwmain_test()
|
|
|
|
{
|
|
|
|
// const args and function args
|
|
|
|
auto realmain = [](int argc, char const* const argv[]) {
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
std::cout << "const " << argv[i] << std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
wchar_t const* argv[3] = {
|
|
|
|
L"ascii",
|
|
|
|
L"10 \xf7 2 = 5",
|
|
|
|
L"qwww\xf7\x03c0",
|
|
|
|
};
|
|
|
|
QUtil::call_main_from_wmain(3, argv, realmain);
|
|
|
|
}
|
2020-04-04 01:34:45 +00:00
|
|
|
#endif // QPDF_NO_WCHAR_T
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
#ifndef QPDF_NO_WCHAR_T
|
|
|
|
try {
|
2022-02-08 14:18:08 +00:00
|
|
|
wmain_test();
|
|
|
|
cwmain_test();
|
2020-04-04 01:34:45 +00:00
|
|
|
} catch (std::exception& e) {
|
2022-02-08 14:18:08 +00:00
|
|
|
std::cout << "unexpected exception: " << e.what() << std::endl;
|
2020-04-04 01:34:45 +00:00
|
|
|
}
|
|
|
|
#endif // QPDF_NO_WCHAR_T
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|