mirror of
https://github.com/holub/mame
synced 2025-05-22 21:58:57 +03:00
Vas Crabb feedback:
1. Changed the Win32 code to use _O_U8TEXT() 2. Reordered system #includes 3. Changed a number of 'std::wcout << ...' to use util::stream_format() I'm getting massive code compilation issues, and it isn't clear to me what the problem is. I'm committing my WIP right now, with the intention of reviewing the specifics soon.
This commit is contained in:
parent
3231c3f648
commit
b1eed07ad9
@ -8,9 +8,6 @@
|
|||||||
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <codecvt>
|
|
||||||
#include <locale>
|
|
||||||
|
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -20,6 +17,9 @@
|
|||||||
|
|
||||||
#include "utf8proc/utf8proc.h"
|
#include "utf8proc/utf8proc.h"
|
||||||
|
|
||||||
|
#include <codecvt>
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// uchar_isvalid - return true if a given
|
// uchar_isvalid - return true if a given
|
||||||
|
@ -8,6 +8,11 @@
|
|||||||
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "imgtool.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "modules.h"
|
||||||
|
#include "strformat.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -20,21 +25,18 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "imgtool.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "modules.h"
|
|
||||||
#include "strformat.h"
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
static void writeusage(std::wostream &output, int write_word_usage, const struct command *c, char *argv[])
|
static void writeusage(std::wostream &output, bool write_word_usage, const struct command *c, char *argv[])
|
||||||
{
|
{
|
||||||
std::string cmdname = core_filename_extract_base(argv[0]);
|
std::string cmdname = core_filename_extract_base(argv[0]);
|
||||||
output << (write_word_usage ? L"Usage: " : L" ")
|
|
||||||
<< wstring_from_utf8(cmdname)
|
util::stream_format(output,
|
||||||
<< L" "
|
L"%s %s %s %s\n",
|
||||||
<< c->name
|
(write_word_usage ? L"Usage:" : L" "),
|
||||||
<< c->usage ? wstring_from_utf8(c->usage) : L"";
|
cmdname,
|
||||||
|
c->name,
|
||||||
|
c->usage ? wstring_from_utf8(c->usage) : std::wstring());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -111,15 +113,15 @@ static int parse_options(int argc, char *argv[], int minunnamed, int maxunnamed,
|
|||||||
return lastunnamed;
|
return lastunnamed;
|
||||||
|
|
||||||
filternotfound:
|
filternotfound:
|
||||||
std::wcerr << wstring_from_utf8(value) << L": Unknown filter type" << std::endl;
|
util::stream_format(std::wcerr, L"%s: Unknown filter type\n", wstring_from_utf8(value));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
optionalreadyspecified:
|
optionalreadyspecified:
|
||||||
std::wcerr << L"Cannot specify multiple " << wstring_from_utf8(name) << L"s" << std::endl;
|
util::stream_format(std::wcerr, L"Cannot specify multiple %ss\n", wstring_from_utf8(name));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
std::wcerr << wstring_from_utf8(argv[i]) << L": Unrecognized option" << std::endl;
|
util::stream_format(std::wcerr, L"%s: Unrecognized option\n", wstring_from_utf8(argv[i]));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ void reporterror(imgtoolerr_t err, const struct command *c, const char *format,
|
|||||||
|
|
||||||
if (!src)
|
if (!src)
|
||||||
src = c->name;
|
src = c->name;
|
||||||
std::wcerr << wstring_from_utf8(src) << L": " << wstring_from_utf8(err_name) << std::endl;
|
util::stream_format(std::wcerr, L"%s: %s\n", wstring_from_utf8(src), wstring_from_utf8(err_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -218,13 +220,13 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
|||||||
total_count = 0;
|
total_count = 0;
|
||||||
total_size = 0;
|
total_size = 0;
|
||||||
|
|
||||||
std::wcout << L"Contents of " << wstring_from_utf8(argv[1]) << L":" << wstring_from_utf8(path) << std::endl;;
|
util::stream_format(std::wcout, L"Contents of %s:%s\n", wstring_from_utf8(argv[1]), wstring_from_utf8(path));
|
||||||
|
|
||||||
info = image->info();
|
info = image->info();
|
||||||
if (!info.empty())
|
if (!info.empty())
|
||||||
std::wcout << wstring_from_utf8(info) << std::endl;
|
util::stream_format(std::wcout, L"%s\n", info);
|
||||||
|
|
||||||
std::wcout << wstring_from_utf8(separator) << std::endl;
|
util::stream_format(std::wcout, L"%s\n", wstring_from_utf8(separator));
|
||||||
|
|
||||||
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
|
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
|
||||||
{
|
{
|
||||||
@ -239,18 +241,18 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
|||||||
if (ent.hardlink)
|
if (ent.hardlink)
|
||||||
strcat(ent.filename, " <hl>");
|
strcat(ent.filename, " <hl>");
|
||||||
|
|
||||||
std::wcout << wstring_from_utf8(util::string_format(
|
util::stream_format(std::wcout,
|
||||||
"%*s %*s %*s %*s",
|
L"%*s %*s %*s %*s\n",
|
||||||
-columnwidth_filename, ent.filename,
|
-columnwidth_filename, wstring_from_utf8(ent.filename),
|
||||||
columnwidth_filesize, filesize_string,
|
columnwidth_filesize, wstring_from_utf8(filesize_string),
|
||||||
columnwidth_attributes, ent.attr,
|
columnwidth_attributes, ent.attr,
|
||||||
columnwidth_lastmodified, last_modified)) << std::endl;
|
columnwidth_lastmodified, wstring_from_utf8(last_modified));
|
||||||
|
|
||||||
if (ent.softlink && ent.softlink[0] != '\0')
|
if (ent.softlink && ent.softlink[0] != '\0')
|
||||||
std::wcout << L"-> " << wstring_from_utf8(ent.softlink) << std::endl;
|
util::stream_format(std::wcout, L"-> %s\n", wstring_from_utf8(ent.softlink));
|
||||||
|
|
||||||
if (ent.comment && ent.comment[0] != '\0')
|
if (ent.comment && ent.comment[0] != '\0')
|
||||||
std::wcout << L": " << wstring_from_utf8(ent.comment) << std::endl;
|
util::stream_format(std::wcout, L": %s\n", wstring_from_utf8(ent.comment));
|
||||||
|
|
||||||
total_count++;
|
total_count++;
|
||||||
total_size += ent.filesize;
|
total_size += ent.filesize;
|
||||||
@ -263,10 +265,10 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
|||||||
if (err)
|
if (err)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
std::wcout << wstring_from_utf8(separator) << std::endl;
|
util::stream_format(std::wcout, L"%s\n", wstring_from_utf8(separator));
|
||||||
std::wcout << wstring_from_utf8(util::string_format("%8i File(s) %8i bytes", total_count, total_size)) << std::endl;
|
util::stream_format(std::wcout, L"%8i File(s) %8i bytes", total_count, total_size);
|
||||||
if (!freespace_err)
|
if (!freespace_err)
|
||||||
std::wcout << wstring_from_utf8(util::string_format(" %8u bytes free", (unsigned int)freespace)) << std::endl;
|
util::string_format(std::wcout, L" %8u bytes free\n", (unsigned int)freespace);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (err)
|
if (err)
|
||||||
@ -387,7 +389,7 @@ static int cmd_put(const struct command *c, int argc, char *argv[])
|
|||||||
for (i = 0; i < filename_count; i++)
|
for (i = 0; i < filename_count; i++)
|
||||||
{
|
{
|
||||||
filename = filename_list[i];
|
filename = filename_list[i];
|
||||||
std::wcout << L"Putting file '" << wstring_from_utf8(filename) << L"'..." << std::endl;
|
util::stream_format(std::wcout, L"Putting file '%s'...\n", wstring_from_utf8(filename));
|
||||||
err = partition->put_file(new_filename, fork, filename, resolution.get(), filter);
|
err = partition->put_file(new_filename, fork, filename, resolution.get(), filter);
|
||||||
if (err)
|
if (err)
|
||||||
goto done;
|
goto done;
|
||||||
@ -440,7 +442,7 @@ static int cmd_getall(const struct command *c, int argc, char *argv[])
|
|||||||
|
|
||||||
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
|
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
|
||||||
{
|
{
|
||||||
std::wcout << L"Retrieving " << wstring_from_utf8(ent.filename) << L" (" << (unsigned int)ent.filesize << L" bytes)" << std::endl;
|
util::stream_format(std::wcout, L"Retrieving %s (%u bytes)\n", wstring_from_utf8(ent.filename), (unsigned int)ent.filesize);
|
||||||
|
|
||||||
err = partition->get_file(ent.filename, nullptr, nullptr, filter);
|
err = partition->get_file(ent.filename, nullptr, nullptr, filter);
|
||||||
if (err)
|
if (err)
|
||||||
@ -552,7 +554,7 @@ static int cmd_identify(const struct command *c, int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
for (i = 0; modules[i]; i++)
|
for (i = 0; modules[i]; i++)
|
||||||
{
|
{
|
||||||
std::wcout << wstring_from_utf8(util::string_format("%.16s %s", modules[i]->name, modules[i]->description)) << std::endl;
|
util::stream_format(std::wcout, L"%.16s %s\n", wstring_from_utf8(modules[i]->name), wstring_from_utf8(modules[i]->description));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -685,11 +687,11 @@ done:
|
|||||||
|
|
||||||
static int cmd_listformats(const struct command *c, int argc, char *argv[])
|
static int cmd_listformats(const struct command *c, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::wcout << L"Image formats supported by imgtool:" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"Image formats supported by imgtool:\n\n");
|
||||||
|
|
||||||
for (const auto &module : imgtool_get_modules())
|
for (const auto &module : imgtool_get_modules())
|
||||||
{
|
{
|
||||||
std::wcout << wstring_from_utf8(util::string_format(" %-25s%s", module->name, module->description)) << std::endl;
|
util::stream_format(std::wcout, L" %-25s%s\n", wstring_from_utf8(module->name), wstring_from_utf8(module->description));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -701,14 +703,13 @@ static int cmd_listfilters(const struct command *c, int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
std::wcout << L"Filters supported by imgtool:" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"Filters supported by imgtool:\n\n");
|
||||||
|
|
||||||
for (i = 0; filters[i]; i++)
|
for (i = 0; filters[i]; i++)
|
||||||
{
|
{
|
||||||
std::wcout << wstring_from_utf8(util::string_format(
|
util::stream_format(std::wcout, L" %-11s%s\n",
|
||||||
" %-11s%s",
|
|
||||||
filter_get_info_string(filters[i], FILTINFO_STR_NAME),
|
filter_get_info_string(filters[i], FILTINFO_STR_NAME),
|
||||||
filter_get_info_string(filters[i], FILTINFO_STR_HUMANNAME))) << std::endl;
|
filter_get_info_string(filters[i], FILTINFO_STR_HUMANNAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -719,8 +720,8 @@ static void listoptions(const util::option_guide &opt_guide, const char *opt_spe
|
|||||||
util::option_resolution resolution(opt_guide);
|
util::option_resolution resolution(opt_guide);
|
||||||
resolution.set_specification(opt_spec);
|
resolution.set_specification(opt_spec);
|
||||||
|
|
||||||
std::wcout << L"Option Allowed values Description" << std::endl;
|
util::stream_format(std::wcout, L"Option Allowed values Description\n");
|
||||||
std::wcout << L"---------------- ------------------------------ -----------" << std::endl;
|
util::stream_format(std::wcout, L"---------------- ------------------------------ -----------\n");
|
||||||
|
|
||||||
for (auto iter = resolution.entries_begin(); iter != resolution.entries_end(); iter++)
|
for (auto iter = resolution.entries_begin(); iter != resolution.entries_end(); iter++)
|
||||||
{
|
{
|
||||||
@ -767,11 +768,10 @@ static void listoptions(const util::option_guide &opt_guide, const char *opt_spe
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wcout << wstring_from_utf8(util::string_format(
|
util::stream_format(std::wcout, L"%16s %-30s %s\n",
|
||||||
"%16s %-30s %s",
|
|
||||||
opt_name,
|
opt_name,
|
||||||
description_buffer.str(),
|
description_buffer.str(),
|
||||||
opt_desc)) << std::endl;
|
opt_desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,33 +790,33 @@ static int cmd_listdriveroptions(const struct command *c, int argc, char *argv[]
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wcout << L"Driver specific options for module '" << wstring_from_utf8(argv[0]) << L":" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"Driver specific options for module '%s':\n\n", wstring_from_utf8(argv[0]));
|
||||||
|
|
||||||
/* list write options */
|
/* list write options */
|
||||||
opt_guide = (const util::option_guide *) imgtool_get_info_ptr(&mod->imgclass, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE);
|
opt_guide = (const util::option_guide *) imgtool_get_info_ptr(&mod->imgclass, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE);
|
||||||
opt_spec = imgtool_get_info_string(&mod->imgclass, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC);
|
opt_spec = imgtool_get_info_string(&mod->imgclass, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC);
|
||||||
if (opt_guide)
|
if (opt_guide)
|
||||||
{
|
{
|
||||||
std::wcout << L"Image specific file options (usable on the 'put' command):" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"Image specific file options (usable on the 'put' command):\n\n");
|
||||||
listoptions(*opt_guide, opt_spec);
|
listoptions(*opt_guide, opt_spec);
|
||||||
std::wcout << std::endl;
|
util::stream_format(std::wcout, L"\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::wcout << L"No image specific file options" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"No image specific file options\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* list create options */
|
/* list create options */
|
||||||
opt_guide = mod->createimage_optguide;
|
opt_guide = mod->createimage_optguide;
|
||||||
if (opt_guide)
|
if (opt_guide)
|
||||||
{
|
{
|
||||||
std::wcout << L"Image specific creation options (usable on the 'create' command):" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"Image specific creation options (usable on the 'create' command):\n\n");
|
||||||
listoptions(*opt_guide, mod->createimage_optspec);
|
listoptions(*opt_guide, mod->createimage_optspec);
|
||||||
std::wcout << std::endl;
|
util::stream_format(std::wcout, L"\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::wcout << L"No image specific creation options" << std::endl << std::endl;
|
util::stream_format(std::wcout, L"No image specific creation options\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -856,7 +856,7 @@ int main(int argc, char *argv[])
|
|||||||
std::string cmdname = core_filename_extract_base(argv[0]);
|
std::string cmdname = core_filename_extract_base(argv[0]);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_setmode(_fileno(stdout), _O_U16TEXT);
|
_setmode(_fileno(stdout), _O_U8TEXT);
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
#ifdef MAME_DEBUG
|
#ifdef MAME_DEBUG
|
||||||
@ -864,7 +864,7 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
#endif // MAME_DEBUG
|
#endif // MAME_DEBUG
|
||||||
|
|
||||||
std::wcout << std::endl;
|
util::stream_format(std::wcout, L"\n");
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
@ -907,20 +907,18 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Usage
|
// Usage
|
||||||
std::wcerr << L"imgtool - Generic image manipulation tool for use with MAME" << std::endl << std::endl;
|
util::stream_format(std::wcerr, L"imgtool - Generic image manipulation tool for use with MAME\n\n");
|
||||||
for (i = 0; i < ARRAY_LENGTH(cmds); i++)
|
for (i = 0; i < ARRAY_LENGTH(cmds); i++)
|
||||||
{
|
{
|
||||||
writeusage(std::wcout, (i == 0), &cmds[i], argv);
|
writeusage(std::wcerr, (i == 0), &cmds[i], argv);
|
||||||
}
|
}
|
||||||
std::wcerr << std::endl;
|
util::stream_format(std::wcerr, L"\n<format> is the image format, e.g. %s\n", wstring_from_utf8(sample_format));
|
||||||
std::wcerr << L"<format> is the image format, e.g. " << wstring_from_utf8(sample_format) << std::endl;
|
util::stream_format(std::wcerr, L"<imagename> is the image filename; can specify a ZIP file for image name\n");
|
||||||
std::wcerr << L"<imagename> is the image filename; can specify a ZIP file for image name" << std::endl;
|
|
||||||
|
|
||||||
std::wcerr << std::endl;
|
util::stream_format(std::wcerr, L"\nExample usage:\n");
|
||||||
std::wcerr << L"Example usage:" << std::endl;
|
util::stream_format(std::wcerr, L"\t%s dir %s myimageinazip.zip\n", wstring_from_utf8(cmdname), wstring_from_utf8(sample_format));
|
||||||
std::wcerr << L"\t" << wstring_from_utf8(cmdname) << L" dir " << wstring_from_utf8(sample_format) << L" myimageinazip.zip" << std::endl;
|
util::stream_format(std::wcerr, L"\t%s get %s myimage.dsk myfile.bin mynewfile.txt\n", wstring_from_utf8(cmdname), wstring_from_utf8(sample_format));
|
||||||
std::wcerr << L"\t" << wstring_from_utf8(cmdname) << L" get " << wstring_from_utf8(sample_format) << L" myimage.dsk myfile.bin mynewfile.txt" << std::endl;
|
util::stream_format(std::wcerr, L"\t%s getall %s myimage.dsk\n", wstring_from_utf8(cmdname), wstring_from_utf8(sample_format));
|
||||||
std::wcerr << L"\t" << wstring_from_utf8(cmdname) << L" getall " << wstring_from_utf8(sample_format) << L" myimage.dsk" << std::endl;
|
|
||||||
result = 0;
|
result = 0;
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user