summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-03-09 18:02:13 +1100
committer Vas Crabb <vas@vastheman.com>2016-03-09 23:04:12 +1100
commit5aea0893a03648efe27025f88d6b98cd48129869 (patch)
treea60611742f99e96efd2bf0106a8aac1356fbdaad /src/tools
parent262fc7035a2f5328b97adea11cae1a7d58cd8653 (diff)
Use type-safe printf for core_file and emu_file, surprisingly few knock-on effects
Properly fix up a couple of places I64FMT was being used, still more to deal with
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/chdman.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp
index 0358a4c5620..1a80bc76e13 100644
--- a/src/tools/chdman.cpp
+++ b/src/tools/chdman.cpp
@@ -23,8 +23,10 @@
#include <stdio.h>
#include <time.h>
#include <ctype.h>
-#include <unordered_map>
+
+#include <iostream>
#include <new>
+#include <unordered_map>
@@ -105,7 +107,7 @@ const int MODE_GDI = 2;
typedef std::unordered_map<std::string,std::string *> parameters_t;
-static void report_error(int error, const char *format, ...) ATTR_PRINTF(2,3);
+template <typename Format, typename... Params> static void report_error(int error, Format &&fmt, Params &&...args);
static void do_info(parameters_t &params);
static void do_verify(parameters_t &params);
static void do_create_raw(parameters_t &params);
@@ -727,15 +729,11 @@ static const command_description s_commands[] =
// report_error - report an error
//-------------------------------------------------
-static void report_error(int error, const char *format, ...)
+template <typename Format, typename... Params> static void report_error(int error, Format &&fmt, Params &&...args)
{
// output to stderr
- va_list arg;
- va_start(arg, format);
- vfprintf(stderr, format, arg);
- fflush(stderr);
- va_end(arg);
- fprintf(stderr, "\n");
+ util::stream_format(std::cerr, std::forward<Format>(fmt), std::forward<Params>(args)...);
+ std::cerr << std::endl;
// reset time for progress and return the error
lastprogress = 0;
@@ -747,7 +745,7 @@ static void report_error(int error, const char *format, ...)
// progress - generic progress callback
//-------------------------------------------------
-static void ATTR_PRINTF(2,3) progress(bool forceit, const char *format, ...)
+template <typename Format, typename... Params> static void progress(bool forceit, Format &&fmt, Params &&...args)
{
// skip if it hasn't been long enough
clock_t curtime = clock();
@@ -756,11 +754,8 @@ static void ATTR_PRINTF(2,3) progress(bool forceit, const char *format, ...)
lastprogress = curtime;
// standard vfprintf stuff here
- va_list arg;
- va_start(arg, format);
- vfprintf(stderr, format, arg);
- fflush(stderr);
- va_end(arg);
+ util::stream_format(std::cerr, std::forward<Format>(fmt), std::forward<Params>(args)...);
+ std::cerr << std::flush;
}
@@ -1237,7 +1232,7 @@ void output_track_metadata(int mode, util::core_file &file, int tracknum, const
break;
}
bool needquote = strchr(filename, ' ') != nullptr;
- file.printf("%s",string_format("%d %d %d %d %s%s%s %I64d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs).c_str());
+ file.printf("%d %d %d %d %s%s%s %d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs);
}
else if (mode == MODE_CUEBIN)
{
@@ -2598,7 +2593,7 @@ static void do_extract_ld(parameters_t &params)
if (err != CHDERR_NONE)
{
UINT64 filepos = static_cast<util::core_file &>(input_chd).tell();
- report_error(1, "%s",string_format("Error reading hunk %I64d at offset %I64d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err)).c_str());
+ report_error(1, "Error reading hunk %d at offset %d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
}
// write audio
@@ -2606,7 +2601,7 @@ static void do_extract_ld(parameters_t &params)
{
avi_error avierr = avi_append_sound_samples(output_file, chnum, avconfig.audio[chnum], actsamples, 0);
if (avierr != AVIERR_NONE)
- report_error(1, "%s",string_format("Error writing samples for hunk %I64d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr)).c_str());
+ report_error(1, "Error writing samples for hunk %d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr));
}
// write video
@@ -2614,7 +2609,7 @@ static void do_extract_ld(parameters_t &params)
{
avi_error avierr = avi_append_video_frame(output_file, fullbitmap);
if (avierr != AVIERR_NONE)
- report_error(1, "%s",string_format("Error writing video for hunk %I64d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr)).c_str());
+ report_error(1, "Error writing video for hunk %d to file (%s): %s\n", framenum, output_file_str->second->c_str(), avi_error_string(avierr));
}
}