summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
authorGravatarGravatar Vas Crabb <vas@vastheman.com>2019-09-26 20:53:06 +1000
committerGravatarGravatar Vas Crabb <vas@vastheman.com>2019-09-26 20:53:06 +1000
commit9a12ab37afb3e43d9d3c296b34348b835bafb2ea (patch)
tree6af7ce1fc5f52b1518100a1be926514cd2f34feb /src/osd
parent9d4b7b02acdb79fac05606f57c3fddd08593cba8 (diff)
Make osd_printf_* use util/strformat semantics.
(nw) This has been a long time coming but it's here at last. It should be easier now that logerror, popmessage and osd_printf_* behave like string_format and stream_format. Remember the differences from printf: * Any object with a stream out operator works with %s * %d, %i, %o, %x, %X, etc. work out the size by magic * No sign extending promotion to int for short/char * No widening/narrowing conversions for characters/strings * Same rules on all platforms, insulated from C runtime library * No format warnings from compiler * Assert in debug builds if number of arguments doesn't match format (nw) Also removed a pile of redundant c_str and string_format, and some workarounds for not being able to portably format 64-bit integers or long long.
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/modules/debugger/debuggdbstub.cpp4
-rw-r--r--src/osd/modules/font/font_dwrite.cpp2
-rw-r--r--src/osd/modules/font/font_osx.cpp6
-rw-r--r--src/osd/modules/font/font_sdl.cpp6
-rw-r--r--src/osd/modules/input/input_sdlcommon.h2
-rw-r--r--src/osd/modules/input/input_x11.cpp4
-rw-r--r--src/osd/modules/lib/osdobj_common.cpp37
-rw-r--r--src/osd/modules/lib/osdobj_common.h4
-rw-r--r--src/osd/modules/monitor/monitor_dxgi.cpp2
-rw-r--r--src/osd/modules/monitor/monitor_mac.cpp2
-rw-r--r--src/osd/modules/monitor/monitor_sdl.cpp5
-rw-r--r--src/osd/modules/monitor/monitor_win32.cpp2
-rw-r--r--src/osd/modules/render/bgfx/effect.cpp2
-rw-r--r--src/osd/modules/render/bgfx/targetmanager.cpp2
-rw-r--r--src/osd/modules/render/drawd3d.cpp4
-rw-r--r--src/osd/osdcore.cpp82
-rw-r--r--src/osd/osdcore.h57
-rw-r--r--src/osd/sdl/osdsdl.h8
-rw-r--r--src/osd/sdl/window.cpp5
-rw-r--r--src/osd/windows/winmain.cpp11
20 files changed, 121 insertions, 126 deletions
diff --git a/src/osd/modules/debugger/debuggdbstub.cpp b/src/osd/modules/debugger/debuggdbstub.cpp
index 4c7e4e3707e..e30f8712d2f 100644
--- a/src/osd/modules/debugger/debuggdbstub.cpp
+++ b/src/osd/modules/debugger/debuggdbstub.cpp
@@ -544,7 +544,7 @@ void debug_gdbstub::wait_for_debugger(device_t &device, bool firststop)
uint64_t datamask = entry->datamask();
int index = entry->index();
const std::string &format_string = entry->format_string();
- osd_printf_info("[%3d] datasize %d mask %016" PRIx64 " [%s] [%s]\n", index, datasize, datamask, symbol, format_string.c_str());
+ osd_printf_info("[%3d] datasize %d mask %016" PRIx64 " [%s] [%s]\n", index, datasize, datamask, symbol, format_string);
}
#endif
@@ -583,7 +583,7 @@ void debug_gdbstub::wait_for_debugger(device_t &device, bool firststop)
#if 0
for ( const auto &reg: m_gdb_registers )
- osd_printf_info(" %3d (%d) %d %d [%s]\n", reg.gdb_regnum, reg.state_index, reg.gdb_bitsize, reg.gdb_type, reg.gdb_name.c_str());
+ osd_printf_info(" %3d (%d) %d %d [%s]\n", reg.gdb_regnum, reg.state_index, reg.gdb_bitsize, reg.gdb_type, reg.gdb_name);
#endif
std::string socket_name = string_format("socket.localhost:%d", m_debugger_port);
diff --git a/src/osd/modules/font/font_dwrite.cpp b/src/osd/modules/font/font_dwrite.cpp
index f60ef7580c4..04ccf11a7ce 100644
--- a/src/osd/modules/font/font_dwrite.cpp
+++ b/src/osd/modules/font/font_dwrite.cpp
@@ -624,7 +624,7 @@ private:
HR_RETHR(fonts->FindFamilyName(familyName.c_str(), &family_index, &exists));
if (!exists)
{
- osd_printf_error("Font with family name %S does not exist.\n", familyName.c_str());
+ osd_printf_error("Font with family name %s does not exist.\n", osd::text::from_wstring(familyName));
return E_FAIL;
}
diff --git a/src/osd/modules/font/font_osx.cpp b/src/osd/modules/font/font_osx.cpp
index 5074c1f4bcd..e621a715675 100644
--- a/src/osd/modules/font/font_osx.cpp
+++ b/src/osd/modules/font/font_osx.cpp
@@ -54,7 +54,7 @@ private:
bool osd_font_osx::open(std::string const &font_path, std::string const &name, int &height)
{
- osd_printf_verbose("osd_font_osx::open: name=\"%s\"\n", name.c_str());
+ osd_printf_verbose("osd_font_osx::open: name=\"%s\"\n", name);
CFStringRef const font_name(CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8));
if (!font_name)
{
@@ -73,7 +73,7 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &name, i
CFRelease(font_name);
if (!font_descriptor)
{
- osd_printf_verbose("osd_font_osx::open: failed to create CoreText font descriptor for \"%s\"\n", name.c_str());
+ osd_printf_verbose("osd_font_osx::open: failed to create CoreText font descriptor for \"%s\"\n", name);
return false;
}
@@ -81,7 +81,7 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &name, i
CFRelease(font_descriptor);
if (!ct_font)
{
- osd_printf_verbose("osd_font_osx::open: failed to create CoreText font for \"%s\"\n", name.c_str());
+ osd_printf_verbose("osd_font_osx::open: failed to create CoreText font for \"%s\"\n", name);
return false;
}
diff --git a/src/osd/modules/font/font_sdl.cpp b/src/osd/modules/font/font_sdl.cpp
index 62a97d39149..a473b71b35a 100644
--- a/src/osd/modules/font/font_sdl.cpp
+++ b/src/osd/modules/font/font_sdl.cpp
@@ -88,7 +88,7 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name,
// if no success, try the font path
if (!font)
{
- osd_printf_verbose("Searching font %s in -%s path/s\n", family.c_str(), font_path.c_str());
+ osd_printf_verbose("Searching font %s in -%s path/s\n", family, font_path);
//emu_file file(options().font_path(), OPEN_FLAG_READ);
emu_file file(font_path.c_str(), OPEN_FLAG_READ);
if (file.open(family.c_str()) == osd_file::error::NONE)
@@ -96,7 +96,7 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name,
std::string full_name = file.fullpath();
font = TTF_OpenFont_Magic(full_name, POINT_SIZE, 0);
if (font)
- osd_printf_verbose("Found font %s\n", full_name.c_str());
+ osd_printf_verbose("Found font %s\n", full_name);
}
}
@@ -112,7 +112,7 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name,
{
if (!BDF_Check_Magic(name))
{
- osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name.c_str());
+ osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name);
}
return false;
}
diff --git a/src/osd/modules/input/input_sdlcommon.h b/src/osd/modules/input/input_sdlcommon.h
index 377b04d71c9..ee13ce307dd 100644
--- a/src/osd/modules/input/input_sdlcommon.h
+++ b/src/osd/modules/input/input_sdlcommon.h
@@ -195,7 +195,7 @@ static inline void devmap_init(running_machine &machine, device_map_t *devmap, c
{
// remove the spaces from the name store it in the index
devmap->map[dev].name = remove_spaces(dev_name);
- osd_printf_verbose("%s: Logical id %d: %s\n", label, dev + 1, devmap->map[dev].name.c_str());
+ osd_printf_verbose("%s: Logical id %d: %s\n", label, dev + 1, devmap->map[dev].name);
devmap->initialized = 1;
}
}
diff --git a/src/osd/modules/input/input_x11.cpp b/src/osd/modules/input/input_x11.cpp
index 40df3d528b6..07ade15c764 100644
--- a/src/osd/modules/input/input_x11.cpp
+++ b/src/osd/modules/input/input_x11.cpp
@@ -469,7 +469,7 @@ public:
// Register and add the device
devinfo = create_lightgun_device(machine, index);
- osd_printf_verbose("%i: %s\n", index, name.c_str());
+ osd_printf_verbose("%i: %s\n", index, name);
// Find the device info associated with the name
info = find_device_info(m_display, name.c_str(), 0);
@@ -477,7 +477,7 @@ public:
// If we couldn't find the device, skip
if (info == nullptr)
{
- osd_printf_verbose("Can't find device %s!\n", name.c_str());
+ osd_printf_verbose("Can't find device %s!\n", name);
continue;
}
diff --git a/src/osd/modules/lib/osdobj_common.cpp b/src/osd/modules/lib/osdobj_common.cpp
index 51474b810b0..3cba4c81cfb 100644
--- a/src/osd/modules/lib/osdobj_common.cpp
+++ b/src/osd/modules/lib/osdobj_common.cpp
@@ -13,6 +13,9 @@
#include "osdepend.h"
#include "modules/lib/osdobj_common.h"
+#include <iostream>
+
+
const options_entry osd_options::s_option_entries[] =
{
{ nullptr, nullptr, OPTION_HEADER, "OSD KEYBOARD MAPPING OPTIONS" },
@@ -381,28 +384,28 @@ void osd_common_t::update_option(const std::string &key, std::vector<const char
//-------------------------------------------------
// output_callback - callback for osd_printf_...
//-------------------------------------------------
-void osd_common_t::output_callback(osd_output_channel channel, const char *msg, va_list args)
+void osd_common_t::output_callback(osd_output_channel channel, const util::format_argument_pack<std::ostream> &args)
{
switch (channel)
{
- case OSD_OUTPUT_CHANNEL_ERROR:
- case OSD_OUTPUT_CHANNEL_WARNING:
- vfprintf(stderr, msg, args);
- break;
- case OSD_OUTPUT_CHANNEL_INFO:
- case OSD_OUTPUT_CHANNEL_LOG:
- vfprintf(stdout, msg, args);
- break;
- case OSD_OUTPUT_CHANNEL_VERBOSE:
- if (verbose()) vfprintf(stdout, msg, args);
- break;
- case OSD_OUTPUT_CHANNEL_DEBUG:
+ case OSD_OUTPUT_CHANNEL_ERROR:
+ case OSD_OUTPUT_CHANNEL_WARNING:
+ util::stream_format(std::cerr, args);
+ break;
+ case OSD_OUTPUT_CHANNEL_INFO:
+ case OSD_OUTPUT_CHANNEL_LOG:
+ util::stream_format(std::cout, args);
+ break;
+ case OSD_OUTPUT_CHANNEL_VERBOSE:
+ if (verbose()) util::stream_format(std::cout, args);
+ break;
+ case OSD_OUTPUT_CHANNEL_DEBUG:
#ifdef MAME_DEBUG
- vfprintf(stdout, msg, args);
+ util::stream_format(std::cout, args);
#endif
- break;
- default:
- break;
+ break;
+ default:
+ break;
}
}
diff --git a/src/osd/modules/lib/osdobj_common.h b/src/osd/modules/lib/osdobj_common.h
index 37e043f53ad..4a377276855 100644
--- a/src/osd/modules/lib/osdobj_common.h
+++ b/src/osd/modules/lib/osdobj_common.h
@@ -245,7 +245,7 @@ public:
virtual osd_options &options() { return m_options; }
// osd_output interface ...
- virtual void output_callback(osd_output_channel channel, const char *msg, va_list args) override;
+ virtual void output_callback(osd_output_channel channel, const util::format_argument_pack<std::ostream> &args) override;
bool verbose() const { return m_print_verbose; }
virtual void set_verbose(bool print_verbose) override { m_print_verbose = print_verbose; }
@@ -279,7 +279,7 @@ private:
opt_val = "";
else if (!m_mod_man.type_has_name(opt_name.c_str(), opt_val.c_str()))
{
- osd_printf_warning("Value %s not supported for option %s - falling back to auto\n", opt_val.c_str(), opt_name.c_str());
+ osd_printf_warning("Value %s not supported for option %s - falling back to auto\n", opt_val, opt_name);
opt_val = "";
}
return m_mod_man.select_module(opt_name.c_str(), opt_val.c_str());
diff --git a/src/osd/modules/monitor/monitor_dxgi.cpp b/src/osd/modules/monitor/monitor_dxgi.cpp
index 3eadadced24..6638f98806c 100644
--- a/src/osd/modules/monitor/monitor_dxgi.cpp
+++ b/src/osd/modules/monitor/monitor_dxgi.cpp
@@ -166,7 +166,7 @@ protected:
{
for (auto monitor : list())
{
- osd_printf_verbose("Video: Monitor %I64u = \"%s\" %s\n", monitor->oshandle(), monitor->devicename().c_str(), monitor->is_primary() ? "(primary)" : "");
+ osd_printf_verbose("Video: Monitor %I64u = \"%s\" %s\n", monitor->oshandle(), monitor->devicename(), monitor->is_primary() ? "(primary)" : "");
}
}
diff --git a/src/osd/modules/monitor/monitor_mac.cpp b/src/osd/modules/monitor/monitor_mac.cpp
index 74523105cf0..8e79978433b 100644
--- a/src/osd/modules/monitor/monitor_mac.cpp
+++ b/src/osd/modules/monitor/monitor_mac.cpp
@@ -115,7 +115,7 @@ protected:
// allocate a new monitor info
std::shared_ptr<osd_monitor_info> monitor = std::make_shared<mac_monitor_info>(*this, displayList[disp], temp, 1.0f);
- osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->devicename().c_str(),
+ osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->devicename(),
monitor->position_size().width(), monitor->position_size().height());
// guess the aspect ratio assuming square pixels
diff --git a/src/osd/modules/monitor/monitor_sdl.cpp b/src/osd/modules/monitor/monitor_sdl.cpp
index b32ade230e1..e3a97fef7ec 100644
--- a/src/osd/modules/monitor/monitor_sdl.cpp
+++ b/src/osd/modules/monitor/monitor_sdl.cpp
@@ -118,8 +118,9 @@ protected:
// allocate a new monitor info
std::shared_ptr<osd_monitor_info> monitor = std::make_shared<sdl_monitor_info>(*this, i, temp, 1.0f);
- osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->devicename().c_str(),
- monitor->position_size().width(), monitor->position_size().height());
+ osd_printf_verbose("Adding monitor %s (%d x %d)\n",
+ monitor->devicename(),
+ monitor->position_size().width(), monitor->position_size().height());
// guess the aspect ratio assuming square pixels
monitor->set_aspect(static_cast<float>(monitor->position_size().width()) / static_cast<float>(monitor->position_size().height()));
diff --git a/src/osd/modules/monitor/monitor_win32.cpp b/src/osd/modules/monitor/monitor_win32.cpp
index 5a7405c463c..6bcd6094e83 100644
--- a/src/osd/modules/monitor/monitor_win32.cpp
+++ b/src/osd/modules/monitor/monitor_win32.cpp
@@ -96,7 +96,7 @@ protected:
{
for (auto monitor : list())
{
- osd_printf_verbose("Video: Monitor %I64u = \"%s\" %s\n", monitor->oshandle(), monitor->devicename().c_str(), monitor->is_primary() ? "(primary)" : "");
+ osd_printf_verbose("Video: Monitor %I64u = \"%s\" %s\n", monitor->oshandle(), monitor->devicename(), monitor->is_primary() ? "(primary)" : "");
}
}
diff --git a/src/osd/modules/render/bgfx/effect.cpp b/src/osd/modules/render/bgfx/effect.cpp
index fb3d7d933ba..da5207f114b 100644
--- a/src/osd/modules/render/bgfx/effect.cpp
+++ b/src/osd/modules/render/bgfx/effect.cpp
@@ -21,7 +21,7 @@ bgfx_effect::bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx:
{
if (m_uniforms[uniforms[i]->name()] != nullptr)
{
- osd_printf_verbose("Uniform %s appears to be duplicated in one or more effects, please double-check the effect JSON files.\n", uniforms[i]->name().c_str());
+ osd_printf_verbose("Uniform %s appears to be duplicated in one or more effects, please double-check the effect JSON files.\n", uniforms[i]->name());
delete uniforms[i];
continue;
}
diff --git a/src/osd/modules/render/bgfx/targetmanager.cpp b/src/osd/modules/render/bgfx/targetmanager.cpp
index dfc1678ee34..35973ee584f 100644
--- a/src/osd/modules/render/bgfx/targetmanager.cpp
+++ b/src/osd/modules/render/bgfx/targetmanager.cpp
@@ -81,7 +81,7 @@ bgfx_target* target_manager::target(uint32_t screen, std::string name)
bgfx_target* target = m_targets[full_name];
if (target == nullptr)
{
- osd_printf_verbose("Warning: Attempting to retrieve a nonexistent target '%s' for screen %d\n", name.c_str(), screen);
+ osd_printf_verbose("Warning: Attempting to retrieve a nonexistent target '%s' for screen %d\n", name, screen);
}
return target;
}
diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp
index fd1331c47eb..140315620d9 100644
--- a/src/osd/modules/render/drawd3d.cpp
+++ b/src/osd/modules/render/drawd3d.cpp
@@ -1227,7 +1227,7 @@ int renderer_d3d9::config_adapter_mode()
// make sure it's a pixel format we can get behind
if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8)
{
- osd_printf_error("Device %s currently in an unsupported mode\n", win->monitor()->devicename().c_str());
+ osd_printf_error("Device %s currently in an unsupported mode\n", win->monitor()->devicename());
return 1;
}
}
@@ -1250,7 +1250,7 @@ int renderer_d3d9::config_adapter_mode()
result = d3dintf->d3dobj->CheckDeviceType(m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !win->fullscreen());
if (FAILED(result))
{
- osd_printf_error("Proposed video mode not supported on device %s\n", win->monitor()->devicename().c_str());
+ osd_printf_error("Proposed video mode not supported on device %s\n", win->monitor()->devicename());
return 1;
}
diff --git a/src/osd/osdcore.cpp b/src/osd/osdcore.cpp
index 51032555438..250f51a90bc 100644
--- a/src/osd/osdcore.cpp
+++ b/src/osd/osdcore.cpp
@@ -59,122 +59,80 @@ void osd_output::pop(osd_output *delegate)
***************************************************************************/
/*-------------------------------------------------
- osd_printf_error - output an error to the
+ osd_vprintf_error - output an error to the
appropriate callback
-------------------------------------------------*/
-void CLIB_DECL osd_printf_error(const char *format, ...)
+void osd_vprintf_error(util::format_argument_pack<std::ostream> const &args)
{
- va_list argptr;
-
- /* do the output */
- va_start(argptr, format);
#if defined(SDLMAME_ANDROID)
- SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, format, argptr);
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "%s", util::string_format(args).c_str());
#else
- if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_ERROR, format, argptr);
+ if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_ERROR, args);
#endif
- va_end(argptr);
}
/*-------------------------------------------------
- osd_printf_warning - output a warning to the
+ osd_vprintf_warning - output a warning to the
appropriate callback
-------------------------------------------------*/
-void CLIB_DECL osd_printf_warning(const char *format, ...)
+void osd_vprintf_warning(util::format_argument_pack<std::ostream> const &args)
{
- va_list argptr;
-
- /* do the output */
- va_start(argptr, format);
#if defined(SDLMAME_ANDROID)
- SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, format, argptr);
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "%s", util::string_format(args).c_str());
#else
- if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_WARNING, format, argptr);
+ if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_WARNING, args);
#endif
- va_end(argptr);
}
/*-------------------------------------------------
- osd_printf_info - output info text to the
+ osd_vprintf_info - output info text to the
appropriate callback
-------------------------------------------------*/
-void CLIB_DECL osd_printf_info(const char *format, ...)
+void osd_vprintf_info(util::format_argument_pack<std::ostream> const &args)
{
- va_list argptr;
-
- /* do the output */
- va_start(argptr, format);
#if defined(SDLMAME_ANDROID)
- SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, argptr);
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "%s", util::string_format(args).c_str());
#else
- if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_INFO, format, argptr);
+ if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_INFO, args);
#endif
- va_end(argptr);
}
/*-------------------------------------------------
- osd_printf_verbose - output verbose text to
+ osd_vprintf_verbose - output verbose text to
the appropriate callback
-------------------------------------------------*/
-void CLIB_DECL osd_printf_verbose(const char *format, ...)
+void osd_vprintf_verbose(util::format_argument_pack<std::ostream> const &args)
{
- va_list argptr;
-
- /* do the output */
- va_start(argptr, format);
#if defined(SDLMAME_ANDROID)
- SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE, format, argptr);
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE, "%s", util::string_format(args).c_str());
#else
- if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_VERBOSE, format, argptr);
+ if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_VERBOSE, args);
#endif
- va_end(argptr);
}
/*-------------------------------------------------
- osd_printf_debug - output debug text to the
+ osd_vprintf_debug - output debug text to the
appropriate callback
-------------------------------------------------*/
-void CLIB_DECL osd_printf_debug(const char *format, ...)
+void osd_vprintf_debug(util::format_argument_pack<std::ostream> const &args)
{
- va_list argptr;
-
- /* do the output */
- va_start(argptr, format);
#if defined(SDLMAME_ANDROID)
- SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, format, argptr);
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "%s", util::string_format(args).c_str());
#else
- if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_DEBUG, format, argptr);
+ if (m_ptr >= 0) m_stack[m_ptr]->output_callback(OSD_OUTPUT_CHANNEL_DEBUG, args);
#endif
- va_end(argptr);
}
-/*-------------------------------------------------
- osd_printf_log - output log text to the
- appropriate callback
--------------------------------------------------*/
-
-#ifdef UNUSED_FUNCTION
-void CLIB_DECL osd_printf_log(const char *format, ...)
-{
- va_list argptr;
-
- /* do the output */
- va_start(argptr, format);
- output_cb[OSD_OUTPUT_CHANNEL_LOG])(format, argptr);
- va_end(argptr);
-}
-#endif
-
//============================================================
// osd_ticks
//============================================================
diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h
index 22179f9da45..95233b4eb14 100644
--- a/src/osd/osdcore.h
+++ b/src/osd/osdcore.h
@@ -13,19 +13,23 @@
broken out into several categories.
***************************************************************************/
+#ifndef MAME_OSD_OSDCORE_H
+#define MAME_OSD_OSDCORE_H
#pragma once
-#ifndef MAME_OSD_OSDCORE_H
-#define MAME_OSD_OSDCORE_H
#include "osdcomm.h"
+#include "strformat.h"
+
#include <chrono>
#include <cstdarg>
#include <cstdint>
+#include <iosfwd>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
@@ -1013,30 +1017,55 @@ public:
class osd_output
{
public:
- osd_output() : m_chain(nullptr) { }
+ osd_output() { }
virtual ~osd_output() { }
- virtual void output_callback(osd_output_channel channel, const char *msg, va_list args) = 0;
+ virtual void output_callback(osd_output_channel channel, util::format_argument_pack<std::ostream> const &args) = 0;
static void push(osd_output *delegate);
static void pop(osd_output *delegate);
+
protected:
- void chain_output(osd_output_channel channel, const char *msg, va_list args) const
+ void chain_output(osd_output_channel channel, util::format_argument_pack<std::ostream> const &args) const
{
- if (m_chain != nullptr)
- m_chain->output_callback(channel, msg, args);
+ if (m_chain)
+ m_chain->output_callback(channel, args);
}
+
private:
- osd_output *m_chain;
+ osd_output *m_chain = nullptr;
};
-/* calls to be used by the code */
-void CLIB_DECL osd_printf_error(const char *format, ...) ATTR_PRINTF(1,2);
-void CLIB_DECL osd_printf_warning(const char *format, ...) ATTR_PRINTF(1,2);
-void CLIB_DECL osd_printf_info(const char *format, ...) ATTR_PRINTF(1,2);
-void CLIB_DECL osd_printf_verbose(const char *format, ...) ATTR_PRINTF(1,2);
-void CLIB_DECL osd_printf_debug(const char *format, ...) ATTR_PRINTF(1,2);
+
+// diagnostic output
+void osd_vprintf_error(util::format_argument_pack<std::ostream> const &args);
+void osd_vprintf_warning(util::format_argument_pack<std::ostream> const &args);
+void osd_vprintf_info(util::format_argument_pack<std::ostream> const &args);
+void osd_vprintf_verbose(util::format_argument_pack<std::ostream> const &args);
+void osd_vprintf_debug(util::format_argument_pack<std::ostream> const &args);
+
+template <typename Format, typename... Params> void osd_printf_error(Format &&fmt, Params &&...args)
+{
+ return osd_vprintf_error(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
+}
+template <typename Format, typename... Params> void osd_printf_warning(Format &&fmt, Params &&...args)
+{
+ return osd_vprintf_warning(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
+}
+template <typename Format, typename... Params> void osd_printf_info(Format &&fmt, Params &&...args)
+{
+ return osd_vprintf_info(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
+}
+template <typename Format, typename... Params> void osd_printf_verbose(Format &&fmt, Params &&...args)
+{
+ return osd_vprintf_verbose(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
+}
+template <typename Format, typename... Params> void osd_printf_debug(Format &&fmt, Params &&...args)
+{
+ return osd_vprintf_debug(util::make_format_argument_pack(std::forward<Format>(fmt), std::forward<Params>(args)...));
+}
+
// returns command line arguments as an std::vector<std::string> in UTF-8
std::vector<std::string> osd_get_command_line(int argc, char *argv[]);
diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h
index 4a320319f44..2fe9a239c8c 100644
--- a/src/osd/sdl/osdsdl.h
+++ b/src/osd/sdl/osdsdl.h
@@ -1,7 +1,9 @@
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont
-#ifndef _osdsdl_h_
-#define _osdsdl_h_
+#ifndef MAME_OSD_SDL_OSDSDL_H
+#define MAME_OSD_SDL_OSDSDL_H
+
+#pragma once
#include "modules/lib/osdobj_common.h"
#include "modules/osdmodule.h"
@@ -161,4 +163,4 @@ private:
extern int osd_num_processors;
-#endif
+#endif // MAME_OSD_SDL_OSDSDL_H
diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp
index 875e06a7b3d..3916ad25b79 100644
--- a/src/osd/sdl/window.cpp
+++ b/src/osd/sdl/window.cpp
@@ -140,7 +140,10 @@ bool sdl_osd_interface::window_init()
osd_printf_verbose("\nHints:\n");
for (int i = 0; hints[i] != nullptr; i++)
- osd_printf_verbose("\t%-40s %s\n", hints[i], SDL_GetHint(hints[i]));
+ {
+ char const *const hint(SDL_GetHint(hints[i]));
+ osd_printf_verbose("\t%-40s %s\n", hints[i], hint ? hint : "(NULL)");
+ }
// set up the window list
osd_printf_verbose("Leave sdlwindow_init\n");
diff --git a/src/osd/windows/winmain.cpp b/src/osd/windows/winmain.cpp
index 721407a777a..1ce656c2a37 100644
--- a/src/osd/windows/winmain.cpp
+++ b/src/osd/windows/winmain.cpp
@@ -66,21 +66,20 @@ using namespace Windows::UI::Popups;
class winui_output_error : public osd_output
{
public:
- virtual void output_callback(osd_output_channel channel, const char *msg, va_list args) override
+ virtual void output_callback(osd_output_channel channel, const util::format_argument_pack<std::ostream> &args) override
{
if (channel == OSD_OUTPUT_CHANNEL_ERROR)
{
- char buffer[1024];
-
// if we are in fullscreen mode, go to windowed mode
if ((video_config.windowed == 0) && !osd_common_t::s_window_list.empty())
winwindow_toggle_full_screen();
- vsnprintf(buffer, ARRAY_LENGTH(buffer), msg, args);
- win_message_box_utf8(!osd_common_t::s_window_list.empty() ? std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front())->platform_window() : nullptr, buffer, emulator_info::get_appname(), MB_OK);
+ std::ostringstream buffer;
+ util::stream_format(buffer, args);
+ win_message_box_utf8(!osd_common_t::s_window_list.empty() ? std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front())->platform_window() : nullptr, buffer.str().c_str(), emulator_info::get_appname(), MB_OK);
}
else
- chain_output(channel, msg, args);
+ chain_output(channel, args);
}
};