summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2020-06-06 20:41:11 +0200
committer couriersud <couriersud@gmx.org>2020-06-06 20:43:10 +0200
commit3f9bb5d1eae63463ee7b193d8544a98f36a2fe55 (patch)
tree914031a1938ce104f0169193e4d797a107c13d35
parentc891603d86f08eecc7e7d9620fd4211173461aec (diff)
netlist: Enable utf7 filenames on windows. (nw)
-rw-r--r--src/lib/netlist/devices/nld_log.cpp2
-rw-r--r--src/lib/netlist/nl_setup.cpp2
-rw-r--r--src/lib/netlist/plib/pconfig.h6
-rwxr-xr-xsrc/lib/netlist/plib/pmain.h5
-rw-r--r--src/lib/netlist/plib/pstream.h44
-rw-r--r--src/lib/netlist/plib/putil.cpp7
-rw-r--r--src/lib/netlist/plib/putil.h1
-rw-r--r--src/lib/netlist/prg/nltool.cpp21
-rwxr-xr-xsrc/lib/netlist/prg/nlwav.cpp4
9 files changed, 75 insertions, 17 deletions
diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp
index cf9ed418fe7..f12229edaa3 100644
--- a/src/lib/netlist/devices/nld_log.cpp
+++ b/src/lib/netlist/devices/nld_log.cpp
@@ -44,7 +44,7 @@ namespace netlist
NETLIB_RESETI() { m_reset = true; }
protected:
analog_input_t m_I;
- std::ofstream m_strm;
+ plib::ofstream m_strm;
plib::putf8_writer m_writer;
bool m_reset;
};
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index 5960cae62d6..10c70b109a1 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -1611,7 +1611,7 @@ source_mem_t::stream_ptr source_mem_t::stream(const pstring &name)
source_file_t::stream_ptr source_file_t::stream(const pstring &name)
{
plib::unused_var(name);
- auto ret(plib::make_unique<std::ifstream>(plib::filesystem::u8path(m_filename)));
+ auto ret(plib::make_unique<plib::ifstream>(plib::filesystem::u8path(m_filename)));
return (ret->is_open()) ? std::move(ret) : stream_ptr(nullptr);
}
diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h
index 8b169260360..4e116b90344 100644
--- a/src/lib/netlist/plib/pconfig.h
+++ b/src/lib/netlist/plib/pconfig.h
@@ -42,7 +42,7 @@
/// OpenMP adds about 10% to 20% performance for analog netlists.
///
#ifndef PUSE_OPENMP
-#define PUSE_OPENMP (0)
+#define PUSE_OPENMP (1)
#endif
/// \brief Use aligned optimizations.
@@ -173,7 +173,9 @@ typedef __float128 FLOAT128;
#if (PUSE_OPENMP)
#if (!(PHAS_OPENMP))
-#error To use openmp compile and link with "-fopenmp"
+//#error To use openmp compile and link with "-fopenmp"
+#undef PUSE_OPENMP
+#define PUSE_OPENMP (0)
#endif
#endif
diff --git a/src/lib/netlist/plib/pmain.h b/src/lib/netlist/plib/pmain.h
index fa57363926d..756bcf49f18 100755
--- a/src/lib/netlist/plib/pmain.h
+++ b/src/lib/netlist/plib/pmain.h
@@ -15,6 +15,7 @@
#include "putil.h"
#include <memory>
+#include <vector>
#ifdef _WIN32
#include <cwchar>
@@ -52,8 +53,8 @@ namespace plib {
template <class C, typename T>
static int mainrun(int argc, T **argv)
{
- auto a = plib::make_unique<C>();
- return a->main_utfX(argc, argv);
+ C application;;
+ return application.main_utfX(argc, argv);
}
private:
diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h
index 04ca9e4344c..e5fc0e24b80 100644
--- a/src/lib/netlist/plib/pstream.h
+++ b/src/lib/netlist/plib/pstream.h
@@ -21,6 +21,7 @@
#include <ios>
#include <iostream>
#include <sstream>
+#include <fstream>
#include <type_traits>
#include <vector>
@@ -261,6 +262,49 @@ inline void copystream(std::ostream &dest, std::istream &src)
}
}
+///
+/// \brief utf8 filename aware ifstream wrapper
+///
+class ifstream : public std::ifstream
+{
+public:
+#ifdef _WIN32
+ template <typename T>
+ explicit ifstream(const pstring_t<T> name, ios_base::openmode mode = ios_base::in)
+ : std::ifstream(reinterpret_cast<const wchar_t *>(pstring_t<putf16_traits>(name).c_str()), mode)
+ {
+ }
+#else
+ template <typename T>
+ explicit ifstream(const pstring_t<T> name, ios_base::openmode mode = ios_base::in)
+ : std::ifstream(pstring_t<putf8_traits>(name).c_str(), mode)
+ {
+ }
+#endif
+};
+
+///
+/// \brief utf8 filename aware ofstream wrapper
+///
+class ofstream : public std::ofstream
+{
+public:
+#ifdef _WIN32
+ template <typename T>
+ explicit ofstream(const pstring_t<T> name, ios_base::openmode mode = ios_base::in)
+ : std::ofstream(reinterpret_cast<const wchar_t *>(pstring_t<putf16_traits>(name).c_str()), mode)
+ {
+ }
+#else
+ template <typename T>
+ explicit ofstream(const pstring_t<T> name, ios_base::openmode mode = ios_base::in)
+ : std::ofstream(pstring_t<putf8_traits>(name).c_str(), mode)
+ {
+ }
+#endif
+};
+
+
struct perrlogger
{
template <typename ... Args>
diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp
index 56ada5c2dd9..44e8141f10a 100644
--- a/src/lib/netlist/plib/putil.cpp
+++ b/src/lib/netlist/plib/putil.cpp
@@ -5,6 +5,7 @@
#include "penum.h"
#include "pstrutil.h"
#include "ptypes.h"
+#include "pstream.h"
#include <algorithm>
#include <cstdlib> // needed for getenv ...
@@ -42,6 +43,12 @@ namespace plib
return filename.substr(0, p);
}
+ bool exists (const pstring &filename)
+ {
+ plib::ifstream f(filename);
+ return f.good();
+ }
+
pstring buildpath(std::initializer_list<pstring> list )
{
pstring ret = "";
diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h
index 502aa433f06..401cc35e262 100644
--- a/src/lib/netlist/plib/putil.h
+++ b/src/lib/netlist/plib/putil.h
@@ -253,6 +253,7 @@ namespace plib
{
pstring basename(const pstring &filename, const pstring &suffix = "");
pstring path(const pstring &filename);
+ bool exists(const pstring &filename);
pstring buildpath(std::initializer_list<pstring> list );
pstring environment(const pstring &var, const pstring &default_val);
} // namespace util
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index 1f024ce99f3..938fe4b32ed 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -201,7 +201,7 @@ public:
stream_ptr stream(const pstring &file) override
{
pstring name = m_folder + "/" + file;
- auto strm(plib::make_unique<std::ifstream>(plib::filesystem::u8path(name)));
+ auto strm(plib::make_unique<plib::ifstream>(plib::filesystem::u8path(name)));
if (strm->fail())
return stream_ptr(nullptr);
@@ -385,7 +385,7 @@ static std::vector<input_t> read_input(const netlist::setup_t &setup, const pstr
std::vector<input_t> ret;
if (fname != "")
{
- plib::putf8_reader r = plib::putf8_reader(plib::make_unique<std::ifstream>(plib::filesystem::u8path(fname)));
+ plib::putf8_reader r = plib::putf8_reader(plib::make_unique<plib::ifstream>(plib::filesystem::u8path(fname)));
if (r.stream().fail())
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(fname));
r.stream().imbue(std::locale::classic());
@@ -411,6 +411,9 @@ void tool_app_t::run()
if (opt_files().size() != 1)
throw netlist::nl_exception("nltool: run needs exactly one file");
+ if (!plib::util::exists(opt_files()[0]))
+ throw netlist::nl_exception("nltool: file doesn't exists: {}", opt_files()[0]);
+
netlist_tool_t nt(*this, "netlist", opt_boostlib());
{
@@ -441,7 +444,7 @@ void tool_app_t::run()
// FIXME: error handling
if (opt_loadstate.was_specified())
{
- std::ifstream strm(plib::filesystem::u8path(opt_loadstate()));
+ plib::ifstream strm(plib::filesystem::u8path(opt_loadstate()));
if (strm.fail())
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(opt_loadstate()));
strm.imbue(std::locale::classic());
@@ -484,7 +487,7 @@ void tool_app_t::run()
if (opt_savestate.was_specified())
{
auto savestate = nt.save_state();
- std::ofstream strm(plib::filesystem::u8path(opt_savestate()), std::ios_base::binary);
+ plib::ofstream strm(plib::filesystem::u8path(opt_savestate()), std::ios_base::binary);
if (strm.fail())
throw plib::file_open_e(opt_savestate());
strm.imbue(std::locale::classic());
@@ -608,7 +611,7 @@ void tool_app_t::static_compile()
for (auto &e : mp)
{
- std::ofstream sout(opt_dir() + "/" + e.first + ".c" );
+ plib::ofstream sout(opt_dir() + "/" + e.first + ".c" );
sout << e.second.m_code;
}
}
@@ -623,7 +626,7 @@ void tool_app_t::static_compile()
names.push_back(opt_name());
else
{
- plib::putf8_reader r = plib::putf8_reader(plib::make_unique<std::ifstream>(plib::filesystem::u8path(f)));
+ plib::putf8_reader r = plib::putf8_reader(plib::make_unique<plib::ifstream>(plib::filesystem::u8path(f)));
if (r.stream().fail())
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(f));
r.stream().imbue(std::locale::classic());
@@ -655,7 +658,7 @@ void tool_app_t::static_compile()
compile_one_and_add_to_map(f, name, target, map);
}
}
- std::ofstream sout = std::ofstream(opt_out());
+ plib::ofstream sout(opt_out());
sout << "#include \"plib/pdynlib.h\"\n\n";
for (auto &e : map)
@@ -703,7 +706,7 @@ struct doc_ext
static doc_ext read_docsrc(const pstring &fname, const pstring &id)
{
- plib::putf8_reader r = plib::putf8_reader(plib::make_unique<std::ifstream>(plib::filesystem::u8path(fname)));
+ plib::putf8_reader r = plib::putf8_reader(plib::make_unique<plib::ifstream>(plib::filesystem::u8path(fname)));
if (r.stream().fail())
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(fname));
r.stream().imbue(std::locale::classic());
@@ -1109,7 +1112,7 @@ void tool_app_t::convert()
}
else
{
- std::ifstream strm(plib::filesystem::u8path(opt_files()[0]));
+ plib::ifstream strm(plib::filesystem::u8path(opt_files()[0]));
if (strm.fail())
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(opt_files()[0]));
strm.imbue(std::locale::classic());
diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp
index 288e14ae028..291aa5b2ff7 100755
--- a/src/lib/netlist/prg/nlwav.cpp
+++ b/src/lib/netlist/prg/nlwav.cpp
@@ -723,7 +723,7 @@ static void open_ostream_and_exec(const pstring &fname, bool binary, F func)
if (fname != "-")
{
// FIXME: binary depends on format!
- std::ofstream outstrm(plib::filesystem::u8path(fname),
+ plib::ofstream outstrm(plib::filesystem::u8path(fname),
binary ? (std::ios::out | std::ios::binary) : std::ios::out);
if (outstrm.fail())
throw plib::file_open_e(fname);
@@ -802,7 +802,7 @@ int nlwav_app::execute()
}
else
{
- fin = plib::make_unique<std::ifstream>(plib::filesystem::u8path(oi), std::ios::in);
+ fin = plib::make_unique<plib::ifstream>(plib::filesystem::u8path(oi), std::ios::in);
if (fin->fail())
throw plib::file_open_e(oi);
}