diff options
Diffstat (limited to 'src/lib/netlist/plib/pmain.cpp')
-rw-r--r-- | src/lib/netlist/plib/pmain.cpp | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/src/lib/netlist/plib/pmain.cpp b/src/lib/netlist/plib/pmain.cpp index de7771b33f0..1e4791adea8 100644 --- a/src/lib/netlist/plib/pmain.cpp +++ b/src/lib/netlist/plib/pmain.cpp @@ -3,28 +3,8 @@ #include "pmain.h" -#ifdef _WIN32 -#include <windows.h> -#include <cstring> -#include <tchar.h> -#endif - namespace plib { - #ifdef _WIN32 - static pstring toutf8(const wchar_t *w) - { - auto wlen = wcslen(w); - int dst_char_count = WideCharToMultiByte(CP_UTF8, 0, w, wlen, nullptr, 0, nullptr, nullptr); - char *buf = new char[dst_char_count + 1]; - WideCharToMultiByte(CP_UTF8, 0, w, wlen, buf, dst_char_count, nullptr, nullptr); - buf[dst_char_count] = 0; - auto ret = pstring(buf); - delete [] buf; - return ret; - } - #endif - app::app() : pout(&std::cout) , perr(&std::cerr) @@ -32,11 +12,11 @@ namespace plib { } - int app::main_utfX(int argc, char **argv) + int app::main_utfX(const std::vector<putf8string> &argv) { - auto r = this->parse(argc, argv); + auto r = this->parse(argv); - if (r != argc) + if (r != argv.size()) { this->perr("Error parsing {}\n", argv[r]); this->perr(this->usage_short()); @@ -46,22 +26,22 @@ namespace plib { return this->execute(); } -#ifdef _WIN32 - int app::main_utfX(int argc, wchar_t *argv[]) + int app::main_utfX(int argc, char *argv[]) { - std::vector<pstring> argv_vectors(argc); - std::vector<char *> utf8_argv(argc); + std::vector<putf8string> arg; + for (std::size_t i = 0; i < static_cast<std::size_t>(argc); i++) + arg.push_back(putf8string(argv[i])); - // convert arguments to UTF-8 - for (int i = 0; i < argc; i++) - { - argv_vectors[i] = toutf8(argv[i]); - utf8_argv[i] = const_cast<char *>(argv_vectors[i].c_str()); - } + return main_utfX(arg); + } + + int app::main_utfX(int argc, wchar_t *argv[]) + { + std::vector<putf8string> arg; + for (std::size_t i = 0; i < static_cast<std::size_t>(argc); i++) + arg.push_back(putf8string(pwstring(argv[i]))); - // run utf8_main - return main_utfX(argc, utf8_argv.data()); + return main_utfX(arg); } -#endif } // namespace plib |