From aec01e740736db267e452f0ed5947649f79e3408 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 28 Feb 2016 11:09:00 +1100 Subject: Replace strformat, strprintf and strcatprintf with type-safe steam_format and string_format Update MAME to use new function Instantiate ODR-used static constant members Make some of the UI code more localisable Remove use of retired functions in tools --- src/lib/util/corestr.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'src/lib/util/corestr.cpp') diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index ce5976869d4..3c65bcb3db6 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -208,25 +208,6 @@ int strvprintf(std::string &str, const char *format, va_list args) return result; } -int strprintf(std::string &str, const char *format, ...) -{ - va_list ap; - va_start(ap, format); - int retVal = strvprintf(str, format, ap); - va_end(ap); - return retVal; -} - -std::string strformat(const char *format, ...) -{ - std::string retVal; - va_list ap; - va_start(ap, format); - strvprintf(retVal, format, ap); - va_end(ap); - return retVal; -} - int strcatvprintf(std::string &str, const char *format, va_list args) { char tempbuf[4096]; @@ -237,15 +218,6 @@ int strcatvprintf(std::string &str, const char *format, va_list args) return result; } -int strcatprintf(std::string &str, const char *format, ...) -{ - va_list ap; - va_start(ap, format); - int retVal = strcatvprintf(str, format, ap); - va_end(ap); - return retVal; -} - void strdelchr(std::string& str, char chr) { for (size_t i = 0; i < str.length(); i++) -- cgit v1.2.3-70-g09d2 From 9224c862b2c4c42b375fd58b7d99077439cbe635 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 1 Mar 2016 18:57:06 +1100 Subject: Move more things to type-safe printf --- src/emu/debug/debugcon.cpp | 44 ++++++++++++++------------------------------ src/emu/debug/debugcon.h | 35 ++++++++++++++++++++++++----------- src/emu/debug/debugcpu.cpp | 7 ++----- src/emu/debug/debugcpu.h | 8 +++++++- src/lib/util/corestr.cpp | 10 ---------- src/lib/util/corestr.h | 1 - 6 files changed, 47 insertions(+), 58 deletions(-) (limited to 'src/lib/util/corestr.cpp') diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index 7bf80dd6118..8aebfd1d979 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -466,39 +466,22 @@ const char *debug_cmderr_to_string(CMDERR error) ***************************************************************************/ /*------------------------------------------------- - debug_console_printf - printfs the given + debug_console_vprintf - vprintfs the given arguments using the format to the debug console -------------------------------------------------*/ -void CLIB_DECL debug_console_printf(running_machine &machine, const char *format, ...) +void debug_console_vprintf(running_machine &machine, util::format_argument_pack const &args) { - std::string buffer; - va_list arg; - - va_start(arg, format); - strvprintf(buffer, format, arg); - va_end(arg); - - text_buffer_print(console_textbuf, buffer.c_str()); + text_buffer_print(console_textbuf, util::string_format(args).c_str()); /* force an update of any console views */ machine.debug_view().update_all(DVT_CONSOLE); } - -/*------------------------------------------------- - debug_console_vprintf - printfs the given - arguments using the format to the debug - console --------------------------------------------------*/ - -void CLIB_DECL debug_console_vprintf(running_machine &machine, const char *format, va_list args) +void debug_console_vprintf(running_machine &machine, util::format_argument_pack &&args) { - std::string buffer; - - strvprintf(buffer, format, args); - text_buffer_print(console_textbuf, buffer.c_str()); + text_buffer_print(console_textbuf, util::string_format(std::move(args)).c_str()); /* force an update of any console views */ machine.debug_view().update_all(DVT_CONSOLE); @@ -506,21 +489,22 @@ void CLIB_DECL debug_console_vprintf(running_machine &machine, const char *forma /*------------------------------------------------- - debug_console_printf_wrap - printfs the given + debug_console_vprintf_wrap - vprintfs the given arguments using the format to the debug console -------------------------------------------------*/ -void CLIB_DECL debug_console_printf_wrap(running_machine &machine, int wrapcol, const char *format, ...) +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack const &args) { - std::string buffer; - va_list arg; + text_buffer_print_wrap(console_textbuf, util::string_format(args).c_str(), wrapcol); - va_start(arg, format); - strvprintf(buffer, format, arg); - va_end(arg); + /* force an update of any console views */ + machine.debug_view().update_all(DVT_CONSOLE); +} - text_buffer_print_wrap(console_textbuf, buffer.c_str(), wrapcol); +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack &&args) +{ + text_buffer_print_wrap(console_textbuf, util::string_format(std::move(args)).c_str(), wrapcol); /* force an update of any console views */ machine.debug_view().update_all(DVT_CONSOLE); diff --git a/src/emu/debug/debugcon.h b/src/emu/debug/debugcon.h index 7c688332ed4..c15874184af 100644 --- a/src/emu/debug/debugcon.h +++ b/src/emu/debug/debugcon.h @@ -74,22 +74,35 @@ typedef UINT32 CMDERR; ***************************************************************************/ /* initialization */ -void debug_console_init(running_machine &machine); +void debug_console_init(running_machine &machine); /* command handling */ -CMDERR debug_console_execute_command(running_machine &machine, const char *command, int echo); -CMDERR debug_console_validate_command(running_machine &machine, const char *command); -void debug_console_register_command(running_machine &machine, const char *command, UINT32 flags, int ref, int minparams, int maxparams, void (*handler)(running_machine &machine, int ref, int params, const char **param)); -const char * debug_cmderr_to_string(CMDERR error); +CMDERR debug_console_execute_command(running_machine &machine, const char *command, int echo); +CMDERR debug_console_validate_command(running_machine &machine, const char *command); +void debug_console_register_command(running_machine &machine, const char *command, UINT32 flags, int ref, int minparams, int maxparams, void (*handler)(running_machine &machine, int ref, int params, const char **param)); +const char * debug_cmderr_to_string(CMDERR error); /* console management */ -void CLIB_DECL debug_console_printf(running_machine &machine, const char *format, ...) ATTR_PRINTF(2,3); -void CLIB_DECL debug_console_vprintf(running_machine &machine, const char *format, va_list args); -void CLIB_DECL debug_console_printf_wrap(running_machine &machine, int wrapcol, const char *format, ...) ATTR_PRINTF(3,4); -text_buffer * debug_console_get_textbuf(void); +void debug_console_vprintf(running_machine &machine, util::format_argument_pack const &args); +void debug_console_vprintf(running_machine &machine, util::format_argument_pack &&args); +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack const &args); +void debug_console_vprintf_wrap(running_machine &machine, int wrapcol, util::format_argument_pack &&args); +text_buffer * debug_console_get_textbuf(void); /* errorlog management */ -void debug_errorlog_write_line(const running_machine &machine, const char *line); -text_buffer * debug_errorlog_get_textbuf(void); +void debug_errorlog_write_line(const running_machine &machine, const char *line); +text_buffer * debug_errorlog_get_textbuf(void); + +/* convenience templates */ +template +inline void debug_console_printf(running_machine &machine, Format &&fmt, Params &&...args) +{ + debug_console_vprintf(machine, util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); +} +template +inline void debug_console_printf_wrap(running_machine &machine, int wrapcol, Format &&fmt, Params &&...args) +{ + debug_console_vprintf_wrap(machine, wrapcol, util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); +} #endif diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index 4bcb66588a9..2b8595b3c30 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -2231,10 +2231,9 @@ void device_debug::go_next_device() // debugger on the next instruction //------------------------------------------------- -void device_debug::halt_on_next_instruction(const char *fmt, ...) +void device_debug::halt_on_next_instruction_impl(util::format_argument_pack &&args) { debugcpu_private *global = m_device.machine().debugcpu_data; - va_list arg; assert(m_exec != nullptr); @@ -2243,9 +2242,7 @@ void device_debug::halt_on_next_instruction(const char *fmt, ...) return; // output the message to the console - va_start(arg, fmt); - debug_console_vprintf(m_device.machine(), fmt, arg); - va_end(arg); + debug_console_vprintf(m_device.machine(), std::move(args)); // if we are live, stop now, otherwise note that we want to break there if (&m_device == global->livecpu) diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h index 754411cb3f0..5222c1c6ab5 100644 --- a/src/emu/debug/debugcpu.h +++ b/src/emu/debug/debugcpu.h @@ -209,7 +209,11 @@ public: void go_exception(int exception); void go_milliseconds(UINT64 milliseconds); void go_next_device(); - void halt_on_next_instruction(const char *fmt, ...) ATTR_PRINTF(2,3); + template + void halt_on_next_instruction(Format &&fmt, Params &&... args) + { + halt_on_next_instruction_impl(util::make_format_argument_pack(std::forward(fmt), std::forward(args)...)); + } // breakpoints breakpoint *breakpoint_first() const { return m_bplist; } @@ -275,6 +279,8 @@ public: static const int HISTORY_SIZE = 256; private: + void halt_on_next_instruction_impl(util::format_argument_pack &&args); + // internal helpers void compute_debug_flags(); void prepare_for_step_overout(offs_t pc); diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index 3c65bcb3db6..2f39bc06ad9 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -198,16 +198,6 @@ char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal) #include -int strvprintf(std::string &str, const char *format, va_list args) -{ - char tempbuf[4096]; - int result = vsprintf(tempbuf, format, args); - - // set the result - str.assign(tempbuf); - return result; -} - int strcatvprintf(std::string &str, const char *format, va_list args) { char tempbuf[4096]; diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h index 209cde389e1..cfd30d2c653 100644 --- a/src/lib/util/corestr.h +++ b/src/lib/util/corestr.h @@ -66,7 +66,6 @@ char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal); char *core_i64_hex_format(UINT64 value, UINT8 mindigits); char *core_i64_oct_format(UINT64 value, UINT8 mindigits); -int strvprintf(std::string &str, const char *format, va_list args); int strcatvprintf(std::string &str, const char *format, va_list args); void strdelchr(std::string& str, char chr); -- cgit v1.2.3-70-g09d2 From 42ea68285296b7838fe9a3ce7e5d66061c8f7e21 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 3 Mar 2016 02:48:20 +1100 Subject: core_i64_hex_format is now a static function in memory.cpp --- src/emu/memory.cpp | 29 +++++++++++++++++++++ src/lib/util/corestr.cpp | 67 ------------------------------------------------ src/lib/util/corestr.h | 4 --- 3 files changed, 29 insertions(+), 71 deletions(-) (limited to 'src/lib/util/corestr.cpp') diff --git a/src/emu/memory.cpp b/src/emu/memory.cpp index f5ebf5e3361..4401cc0d05e 100644 --- a/src/emu/memory.cpp +++ b/src/emu/memory.cpp @@ -187,6 +187,35 @@ #define VPRINTF(x) do { if (VERBOSE) printf x; } while (0) +/*------------------------------------------------- + core_i64_hex_format - i64 format printf helper +-------------------------------------------------*/ + +static char *core_i64_hex_format(UINT64 value, UINT8 mindigits) +{ + static char buffer[16][64]; + // TODO: this can overflow - e.g. when a lot of unmapped writes are logged + static int index; + char *bufbase = &buffer[index++ % 16][0]; + char *bufptr = bufbase; + INT8 curdigit; + + for (curdigit = 15; curdigit >= 0; curdigit--) + { + int nibble = (value >> (curdigit * 4)) & 0xf; + if (nibble != 0 || curdigit < mindigits) + { + mindigits = curdigit; + *bufptr++ = "0123456789ABCDEF"[nibble]; + } + } + if (bufptr == bufbase) + *bufptr++ = '0'; + *bufptr = 0; + + return bufbase; +} + //************************************************************************** diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index 2f39bc06ad9..7daad5cc0cb 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -125,73 +125,6 @@ char *core_strdup(const char *str) } -/*------------------------------------------------- - core_i64_hex_format - i64 format printf helper --------------------------------------------------*/ - -char *core_i64_hex_format(UINT64 value, UINT8 mindigits) -{ - static char buffer[16][64]; - // TODO: this can overflow - e.g. when a lot of unmapped writes are logged - static int index; - char *bufbase = &buffer[index++ % 16][0]; - char *bufptr = bufbase; - INT8 curdigit; - - for (curdigit = 15; curdigit >= 0; curdigit--) - { - int nibble = (value >> (curdigit * 4)) & 0xf; - if (nibble != 0 || curdigit < mindigits) - { - mindigits = curdigit; - *bufptr++ = "0123456789ABCDEF"[nibble]; - } - } - if (bufptr == bufbase) - *bufptr++ = '0'; - *bufptr = 0; - - return bufbase; -} - -/*------------------------------------------------- - core_i64_oct_format - i64 format printf helper --------------------------------------------------*/ - -char *core_i64_oct_format(UINT64 value, UINT8 mindigits) -{ - static char buffer[22][64]; - // TODO: this can overflow - static int index; - char *bufbase = &buffer[index++ % 22][0]; - char *bufptr = bufbase; - INT8 curdigit; - - for (curdigit = 21; curdigit >= 0; curdigit--) - { - int octdigit = (value >> (curdigit * 3)) & 0x7; - if (octdigit != 0 || curdigit < mindigits) - { - mindigits = curdigit; - *bufptr++ = "01234567"[octdigit]; - } - } - if (bufptr == bufbase) - *bufptr++ = '0'; - *bufptr = 0; - - return bufbase; -} - -/*------------------------------------------------- - core_i64_format - i64 format printf helper --------------------------------------------------*/ - -char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal) -{ - return is_octal ? core_i64_oct_format(value,mindigits) : core_i64_hex_format(value,mindigits); -} - /*------------------------------------------------- std::string helpers -------------------------------------------------*/ diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h index bd08da1483c..29f98d06dc6 100644 --- a/src/lib/util/corestr.h +++ b/src/lib/util/corestr.h @@ -61,10 +61,6 @@ char *core_strdup(const char *str); int core_strwildcmp(const char *sp1, const char *sp2); -/* I64 printf helper */ -char *core_i64_format(UINT64 value, UINT8 mindigits, bool is_octal); -char *core_i64_hex_format(UINT64 value, UINT8 mindigits); - int strcatvprintf(std::string &str, const char *format, va_list args); void strdelchr(std::string& str, char chr); -- cgit v1.2.3-70-g09d2