Fix an issue with kaitai_regenerate.sh creating backup files on modern macOS

This commit is contained in:
Nikolaj Schlej 2025-02-14 04:58:59 +01:00
parent fd76e896cc
commit 0af36bdcd9
2 changed files with 15 additions and 12 deletions

View file

@ -5,7 +5,7 @@
ami_nvar_t::ami_nvar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, ami_nvar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m__root = this; (void)p__root;
m_entries = nullptr;
_read();
}
@ -188,7 +188,7 @@ void ami_nvar_t::nvar_entry_t::_clean_up() {
int32_t ami_nvar_t::nvar_entry_t::offset() {
if (f_offset)
return m_offset;
m_offset = _io()->pos();
m_offset = (int32_t)_io()->pos();
f_offset = true;
return m_offset;
}
@ -196,7 +196,7 @@ int32_t ami_nvar_t::nvar_entry_t::offset() {
int32_t ami_nvar_t::nvar_entry_t::end_offset() {
if (f_end_offset)
return m_end_offset;
m_end_offset = _io()->pos();
m_end_offset = (int32_t)_io()->pos();
f_end_offset = true;
return m_end_offset;
}
@ -292,7 +292,7 @@ ami_nvar_t::nvar_extended_attributes_t* ami_nvar_t::nvar_entry_body_t::extended_
int32_t ami_nvar_t::nvar_entry_body_t::data_start_offset() {
if (f_data_start_offset)
return m_data_start_offset;
m_data_start_offset = _io()->pos();
m_data_start_offset = (int32_t)_io()->pos();
f_data_start_offset = true;
return m_data_start_offset;
}
@ -353,7 +353,7 @@ uint8_t ami_nvar_t::nvar_entry_body_t::extended_header_checksum() {
int32_t ami_nvar_t::nvar_entry_body_t::data_end_offset() {
if (f_data_end_offset)
return m_data_end_offset;
m_data_end_offset = _io()->pos();
m_data_end_offset = (int32_t)_io()->pos();
f_data_end_offset = true;
return m_data_end_offset;
}

17
kaitai_regenerate.sh Executable file → Normal file
View file

@ -7,12 +7,10 @@ if [ "$UTARGET" = "Darwin" ]; then
export UPLATFORM="mac"
export UFIND="find -E"
export UFINDOPT=""
export USEDOPT="''"
elif [ "$UTARGET" = "Linux" ]; then
export UPLATFORM="linux_$(uname -m)"
export UFIND="find"
export UFINDOPT="-regextype posix-extended"
export USEDOPT=""
else
export UPLATFORM="$UTARGET"
echo "Please run this script on Linux or macOS"
@ -30,26 +28,31 @@ ${UFIND} common/generated ${UFINDOPT} \
# Replace global includes for kaitai with local ones (<> -> "")
${UFIND} common/generated ${UFINDOPT} \
-regex '.*\.(cpp|h)' \
-exec sed -i ${USEDOPT} '/^#include <kaitai/s/[<>]/\"/g' {} + || exit 1
-exec sed -i.bak '/^#include <kaitai/s/[<>]/\"/g' {} + || exit 1
# Add .. to the include path for kaitai includes
${UFIND} common/generated ${UFINDOPT} \
-regex '.*\.(cpp|h)' \
-exec sed -i ${USEDOPT} '/^#include \"kaitai\//s/kaitai\//..\/kaitai\//g' {} + || exit 1
-exec sed -i.bak '/^#include \"kaitai\//s/kaitai\//..\/kaitai\//g' {} + || exit 1
# Suppress "p__root - unused parameter" warning
${UFIND} common/generated ${UFINDOPT} \
-regex '.*\.(cpp)' \
-exec sed -i ${USEDOPT} '/^ m__root = this;/s/;/; (void)p__root;/g' {} + || exit 1
-exec sed -i.bak '/^ m__root = this;/s/;/; (void)p__root;/g' {} + || exit 1
# Add uint64_t to enum structure_ids_t
${UFIND} common/generated ${UFINDOPT} \
-regex '.*\.(h)' \
-exec sed -i ${USEDOPT} '/^ enum structure_ids_t {/s/{/: uint64_t {/g' {} + || exit 1
-exec sed -i.bak '/^ enum structure_ids_t {/s/{/: uint64_t {/g' {} + || exit 1
# Suppress type downcast warning in ami_nvar.cpp
${UFIND} common/generated ${UFINDOPT} \
-name 'ami_nvar.cpp' \
-exec sed -i ${USEDOPT} 's/_offset = _io()->pos();/_offset = (int32_t)_io()->pos();/g' {} + || exit 1
-exec sed -i.bak 's/_offset = _io()->pos();/_offset = (int32_t)_io()->pos();/g' {} + || exit 1
# Remove backup files
${UFIND} common/generated ${UFINDOPT} \
-regex '.*\.(bak)' \
-exec rm {} + || exit 1
exit 0