This commit is contained in:
2025-07-20 15:50:48 -04:00
parent 5ea2f16ba9
commit 41cfafbaf0
10 changed files with 221 additions and 66 deletions

View File

@@ -1,42 +0,0 @@
#!/usr/bin/env python3
import argparse
def c_escape_byte(b):
if b == 0x09:
return r'\t'
elif b == 0x0A:
return r'\n'
elif b == 0x0D:
return r'\r'
elif b == 0x5C: # \
return r'\\'
elif b == 0x22: # "
return r'\"'
elif 0x20 <= b <= 0x7E:
return chr(b)
elif b == 0x25: # %
return '%%'
else:
return f'\\x{b:02x}'
def file_to_c_string(filepath):
with open(filepath, 'rb') as f:
content = f.read()
escaped = ''.join(c_escape_byte(b) for b in content)
return f'"{escaped}"'
def main():
parser = argparse.ArgumentParser(
description='Convert file contents to a valid C string literal.')
parser.add_argument('input', help='Path to input file')
args = parser.parse_args()
c_string = file_to_c_string(args.input)
print(c_string)
if __name__ == '__main__':
main()

10
tools/gen-embed-header Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/env bash
files=./embed/*
touch embed_header.h
echo "" > embed_header.h
for f in $files; do
xxd -i >> embed_header.h
done