Squashed 'deps/nostalgia/' changes from 9676ea59..26fe266b
26fe266b [ox/mc] Fix break from using strnlen_s inappropriately 091eda7b Merge commit 'ce53be92716b0f5201882d6959c398b61c6cc93c' ac29f7a0 Merge commit 'ec6cf92c4763be5933ee6debbf97bce25b9fcfc9' eef51a6d [olympic] Improve error handling in file-to-cpp git-subtree-dir: deps/nostalgia git-subtree-split: 26fe266b09971d3e638654515f41226afc7f4625
This commit is contained in:
parent
ce53be9271
commit
8e033b2460
7
deps/ox/src/ox/mc/write.hpp
vendored
7
deps/ox/src/ox/mc/write.hpp
vendored
@ -211,11 +211,14 @@ constexpr Error MetalClawWriter<Writer>::field(const char *name, const IString<L
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<Writer_c Writer>
|
template<Writer_c Writer>
|
||||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t buffLen) noexcept {
|
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept {
|
||||||
bool fieldSet = false;
|
bool fieldSet = false;
|
||||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
const auto strLen = *val ? ox::strnlen_s(*val, buffLen) : 0;
|
// this strlen is tolerated because sometimes 0 gets passed to
|
||||||
|
// the size param, which is a lie
|
||||||
|
// this code should be cleaned up at some point...
|
||||||
|
const auto strLen = *val ? ox::strlen(*val) : 0;
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||||
|
@ -15,6 +15,9 @@ import pathlib
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
tool_name = 'file-to-cpp'
|
||||||
|
|
||||||
|
|
||||||
def write_txt_file(path: str, txt: str):
|
def write_txt_file(path: str, txt: str):
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
f.write(txt)
|
f.write(txt)
|
||||||
@ -22,6 +25,7 @@ def write_txt_file(path: str, txt: str):
|
|||||||
|
|
||||||
|
|
||||||
def file_to_hex(path: str, line_prefix: str) -> tuple[str, int]:
|
def file_to_hex(path: str, line_prefix: str) -> tuple[str, int]:
|
||||||
|
try:
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
out = line_prefix
|
out = line_prefix
|
||||||
data = f.read()
|
data = f.read()
|
||||||
@ -31,6 +35,9 @@ def file_to_hex(path: str, line_prefix: str) -> tuple[str, int]:
|
|||||||
out += '\n\t' if i % 10 == 0 else ' '
|
out += '\n\t' if i % 10 == 0 else ' '
|
||||||
i += 1
|
i += 1
|
||||||
return out[:-1], len(data)
|
return out[:-1], len(data)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f'{tool_name}: included file not found: {path}', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def file_to_cpp(path: str, cpp_name: str) -> tuple[str, str]:
|
def file_to_cpp(path: str, cpp_name: str) -> tuple[str, str]:
|
||||||
@ -67,11 +74,11 @@ def proc_rsrc_file(rsrc_path: str):# Open and read the JSON file
|
|||||||
all_files_func += f'\nox::Vector<ox::SpanView<uint8_t>> {all_files}() noexcept {{\n\treturn {{\n'
|
all_files_func += f'\nox::Vector<ox::SpanView<uint8_t>> {all_files}() noexcept {{\n\treturn {{\n'
|
||||||
for f in data['files']:
|
for f in data['files']:
|
||||||
if 'path' not in f:
|
if 'path' not in f:
|
||||||
print('src file path missing', file=sys.stderr)
|
print(f'{tool_name}: src file path missing', file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
path = f['path']
|
path = f['path']
|
||||||
if 'cpp_name' not in f:
|
if 'cpp_name' not in f:
|
||||||
print('var name missing', file=sys.stderr)
|
print(f'{tool_name}: var name missing', file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
cpp_name = f['cpp_name']
|
cpp_name = f['cpp_name']
|
||||||
c, h = file_to_cpp(os.path.join(base_path, path), cpp_name)
|
c, h = file_to_cpp(os.path.join(base_path, path), cpp_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user