summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pmain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/pmain.cpp')
-rw-r--r--src/lib/netlist/plib/pmain.cpp79
1 files changed, 23 insertions, 56 deletions
diff --git a/src/lib/netlist/plib/pmain.cpp b/src/lib/netlist/plib/pmain.cpp
index 1ecf0a4d032..ef1f47077e5 100644
--- a/src/lib/netlist/plib/pmain.cpp
+++ b/src/lib/netlist/plib/pmain.cpp
@@ -1,80 +1,47 @@
-// license:GPL-2.0+
+// license:BSD-3-Clause
// copyright-holders:Couriersud
-/*
- * pmain.cpp
- *
- */
#include "pmain.h"
-#ifdef _WIN32
-#include <windows.h>
-#include <string.h>
-#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
-
-/***************************************************************************
- Application
-***************************************************************************/
-
app::app()
- : options()
- , pout(&std::cout)
- , perr(&std::cerr)
+ : std_out(&std::cout)
+ , std_err(&std::cerr)
{
}
- int app::main_utfX(int argc, char **argv)
+ int app::main_utfX(const std::vector<putf8string> &argv)
{
- auto r = this->parse(argc, argv);
- int ret = 0;
+ auto r = this->parse(argv);
- if (r != argc)
+ if (r != argv.size())
{
- this->perr("Error parsing {}\n", argv[r]);
- //FIXME: usage_short
- this->perr(this->usage());
- ret = 1;
+ this->std_err("Error parsing {}\n", argv[r]);
+ this->std_err(this->usage_short());
+ return 1;
}
- else
- ret = this->execute();
- return ret;
+ 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 < narrow_cast<std::size_t>(argc); i++)
+ arg.emplace_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 < narrow_cast<std::size_t>(argc); i++)
+ arg.emplace_back(putf8string(pwstring(argv[i])));
- // run utf8_main
- return main_utfX(argc, utf8_argv.data());
+ return main_utfX(arg);
}
-#endif
} // namespace plib