mirror of
https://github.com/holub/mame
synced 2025-04-20 23:42:22 +03:00
netlist: Enable utf7 filenames on windows. (nw)
This commit is contained in:
parent
c891603d86
commit
3f9bb5d1ea
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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>
|
||||
|
@ -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 = "";
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user