mirror of
https://github.com/holub/mame
synced 2025-06-07 13:23:50 +03:00
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:
parent
6a89b25745
commit
bdd2a33776
0
scripts/build/complay.py
Normal file → Executable file
0
scripts/build/complay.py
Normal file → Executable file
96
scripts/build/file2lines.py
Executable file
96
scripts/build/file2lines.py
Executable 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)
|
@ -176,3 +176,11 @@ files {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pchsource(MAME_DIR .. "src/frontend/mame/audit.cpp")
|
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" } },
|
||||||
|
}
|
||||||
|
@ -17,6 +17,12 @@
|
|||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
#include "copying.ipp"
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
|
|
||||||
ABOUT MODAL
|
ABOUT MODAL
|
||||||
@ -33,48 +39,6 @@ menu_about::menu_about(mame_ui_manager &mui, render_container &container)
|
|||||||
, m_pause_checked(false)
|
, m_pause_checked(false)
|
||||||
, m_was_paused(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;
|
m_pause_checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::string line : m_lines)
|
for (char const *const *line = copying_text; *line; ++line)
|
||||||
{
|
item_append(*line, "", 0, nullptr);
|
||||||
item_append(line.c_str(), "", 0, nullptr);
|
|
||||||
}
|
|
||||||
item_append(menu_item_type::SEPARATOR);
|
item_append(menu_item_type::SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,16 +7,17 @@
|
|||||||
"About" modal
|
"About" modal
|
||||||
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#ifndef MAME_FRONTEND_UI_ABOUT_H
|
#ifndef MAME_FRONTEND_UI_ABOUT_H
|
||||||
#define MAME_FRONTEND_UI_ABOUT_H
|
#define MAME_FRONTEND_UI_ABOUT_H
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ui/menu.h"
|
#include "ui/menu.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
class menu_about : public menu
|
class menu_about : public menu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -29,7 +30,6 @@ private:
|
|||||||
|
|
||||||
bool m_pause_checked;
|
bool m_pause_checked;
|
||||||
bool m_was_paused;
|
bool m_was_paused;
|
||||||
std::vector<std::string> m_lines;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
Loading…
Reference in New Issue
Block a user