compile in the contents of the COPYING file for the about box - safer than assuming it will be in the working directory. no attempt at compressing it for now (nw)

This commit is contained in:
Vas Crabb 2020-03-22 00:03:07 +11:00
parent 6a89b25745
commit bdd2a33776
6 changed files with 118 additions and 51 deletions

0
scripts/build/complay.py Normal file → Executable file
View File

96
scripts/build/file2lines.py Executable file
View File

@ -0,0 +1,96 @@
#!/usr/bin/python
##
## license:BSD-3-Clause
## copyright-holders:Vas Crabb
import io
import os
import os.path
import re
import sys
def write_output(text):
try:
dst.write(text)
except IOError:
if dstfile is not None:
sys.stderr.write('Error writing to output file \'%s\'\n' % dstfile)
dst.close()
os.remove(dstfile)
else:
sys.stderr.write('Error writing to output\n')
sys.exit(3)
if __name__ == '__main__':
if (len(sys.argv) > 4) or (len(sys.argv) < 2):
print('Usage:')
print(' file2lines <source.txt> [<output.h> [<varname>]]')
sys.exit(0 if len(sys.argv) <= 1 else 1)
srcfile = sys.argv[1]
dstfile = sys.argv[2] if len(sys.argv) >= 3 else None
if len(sys.argv) >= 4:
varname = sys.argv[3]
else:
varname = os.path.basename(srcfile)
base, ext = os.path.splitext(varname)
if ext.lower() == '.txt':
varname = base
varname = 'lines_' + re.sub('[^0-9A-Za-z_]', '_', varname)
dst = None
try:
with io.open(srcfile, 'r', encoding='utf-8') as src:
if dstfile is not None:
try:
dst = io.open(dstfile, 'w', encoding='utf-8')
except IOError:
sys.stderr.write('Unable to open output file \'%s\'\n' % dstfile)
sys.exit(3)
else:
dst = sys.stdout
write_output(u'char const *const %s[] = {\n' % varname)
for line in src:
if line[-1] == u'\n':
line = line[:-1]
write_output(u'\t\t"')
i = 0
while i < len(line):
for j in range(i, len(line) + 1):
if j < len(line):
ch = line[j]
if (ch < u' ') or (ch > u'~') or (ch in u'\"\\'):
break
if j > i:
write_output(line[i:j])
if j < len(line):
ch = line[j]
if ch == u'\a':
write_output(u'\\a')
elif ch == u'\f':
write_output(u'\\f')
elif ch == u'\t':
write_output(u'\\t')
elif ch == u'\v':
write_output(u'\\v')
elif ch in u'\"\\':
write_output(u'\\' + ch)
else:
ch = ord(ch)
if ch < 0x20:
write_output(u'\\{0:03o}'.format(ch))
elif ch < 0x10000:
write_output(u'\\u{0:04X}'.format(ch))
else:
write_output(u'\\U{0:08X}'.format(ch))
i = j + 1
write_output(u'",\n')
write_output(u'\t\tnullptr };\n')
except IOError:
sys.stderr.write('Error reading input file \'%s\'\n' % srcfile)
if (dstfile is not None) and (dst is not None):
dst.close()
os.remove(dstfile)
sys.exit(2)

View File

@ -283,11 +283,11 @@ dependency {
}
custombuildtask {
{ MAME_DIR .. "scripts/font/NotoSans-Bold.bdc", GEN_DIR .. "emu/uismall.fh", { MAME_DIR .. "scripts/build/file2str.py" }, {"@echo Converting NotoSans-Bold.bdc...", PYTHON .. " $(1) $(<) $(@) font_uismall uint8_t" }},
{ MAME_DIR .. "scripts/font/NotoSans-Bold.bdc", GEN_DIR .. "emu/uismall.fh", { MAME_DIR .. "scripts/build/file2str.py" }, { "@echo Converting NotoSans-Bold.bdc...", PYTHON .. " $(1) $(<) $(@) font_uismall uint8_t" } },
}
custombuildtask {
{ MAME_DIR .. "src/frontend/mame/ui/uicmd14.png" , GEN_DIR .. "emu/ui/uicmd14.fh", { MAME_DIR.. "scripts/build/png2bdc.py", MAME_DIR .. "scripts/build/file2str.py" }, {"@echo Converting uicmd14.png...", PYTHON .. " $(1) $(<) temp_cmd.bdc", PYTHON .. " $(2) temp_cmd.bdc $(@) font_uicmd14 uint8_t" }},
{ MAME_DIR .. "src/frontend/mame/ui/uicmd14.png", GEN_DIR .. "emu/ui/uicmd14.fh", { MAME_DIR.. "scripts/build/png2bdc.py", MAME_DIR .. "scripts/build/file2str.py" }, { "@echo Converting uicmd14.png...", PYTHON .. " $(1) $(<) temp_cmd.bdc", PYTHON .. " $(2) temp_cmd.bdc $(@) font_uicmd14 uint8_t" } },
layoutbuildtask("emu/layout", "dualhovu"),
layoutbuildtask("emu/layout", "dualhsxs"),

View File

@ -176,3 +176,11 @@ files {
}
pchsource(MAME_DIR .. "src/frontend/mame/audit.cpp")
dependency {
{ MAME_DIR .. "src/frontend/mame/ui/about.cpp", GEN_DIR .. "emu/copying.ipp" },
}
custombuildtask {
{ MAME_DIR .. "COPYING", GEN_DIR .. "emu/copying.ipp", { MAME_DIR .. "scripts/build/file2lines.py" }, { "@echo Converting COPYING...", PYTHON .. " $(1) $(<) $(@) copying_text" } },
}

View File

@ -17,6 +17,12 @@
namespace ui {
namespace {
#include "copying.ipp"
} // anonymous namespace
/**************************************************
ABOUT MODAL
@ -33,48 +39,6 @@ menu_about::menu_about(mame_ui_manager &mui, render_container &container)
, m_pause_checked(false)
, m_was_paused(false)
{
std::vector<char> text;
osd_file::ptr file;
uint64_t filesize = 0;
osd_file::error error = osd_file::open("COPYING", OPEN_FLAG_READ, file, filesize);
if (error != osd_file::error::NONE)
{
stack_pop();
osd_printf_debug("Unable to open COPYING file\n");
return;
}
uint32_t actual = 0;
text.reserve(filesize);
file->read(&text[0], 0, (uint32_t)filesize, actual);
if (actual != (uint32_t)filesize)
{
stack_pop();
osd_printf_debug("Unable to fully load COPYING file\n");
return;
}
m_lines.clear();
uint32_t i = 0;
uint32_t line_index = 0;
std::string curr_line;
while (i < (uint32_t)filesize)
{
if (text[i] == 0x0a)
{
curr_line += '\n';
m_lines.push_back(curr_line);
curr_line = "";
line_index++;
i++;
continue;
}
curr_line += text[i];
i++;
}
}
@ -106,10 +70,9 @@ void menu_about::populate(float &customtop, float &custombottom)
m_pause_checked = true;
}
for (std::string line : m_lines)
{
item_append(line.c_str(), "", 0, nullptr);
}
for (char const *const *line = copying_text; *line; ++line)
item_append(*line, "", 0, nullptr);
item_append(menu_item_type::SEPARATOR);
}
@ -130,4 +93,4 @@ void menu_about::handle()
}
}
};
};

View File

@ -7,16 +7,17 @@
"About" modal
***************************************************************************/
#ifndef MAME_FRONTEND_UI_ABOUT_H
#define MAME_FRONTEND_UI_ABOUT_H
#pragma once
#include "ui/menu.h"
#include <vector>
namespace ui {
class menu_about : public menu
{
public:
@ -29,7 +30,6 @@ private:
bool m_pause_checked;
bool m_was_paused;
std::vector<std::string> m_lines;
};
} // namespace ui