Skip to content

Commit 5dccd98

Browse files
committed
Adding C++ Support to VFS Python Script
1 parent e1ed5cd commit 5dccd98

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

  • examples/C/virtual_file_system

examples/C/virtual_file_system/vfs.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ def generate_vfs_header(directory, output_header):
2929
header.write(' int length;\n')
3030
header.write('} VirtualFile;\n\n')
3131

32-
header.write('static const VirtualFile virtual_files[] = {\n')
32+
for i, (relative_path, filepath) in enumerate(files):
33+
with open(filepath, 'rb') as f:
34+
data = f.read()
35+
header.write(f'static const unsigned char FILE_{i}[] = {{')
36+
header.write(','.join(f'0x{byte:02x}' for byte in data))
37+
header.write('};\n\n')
3338

34-
for relative_path, filepath in files:
39+
header.write('\nstatic const VirtualFile virtual_files[] = {\n')
40+
41+
for i, (relative_path, filepath) in enumerate(files):
3542
with open(filepath, 'rb') as f:
3643
data = f.read()
3744
header.write(' {\n')
3845
header.write(f' "{relative_path}",\n')
39-
header.write(' (const unsigned char[]){')
40-
header.write(','.join(f'0x{byte:02x}' for byte in data))
41-
header.write('},\n')
46+
header.write(f' FILE_{i},\n')
4247
header.write(f' {len(data)}\n')
4348
header.write(' },\n')
4449

0 commit comments

Comments
 (0)