2023-05-05 19:05:39 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
r"""
|
2024-08-22 11:42:12 +00:00
|
|
|
Embeds a file into a String, a la #embed from C++23
|
2023-05-05 19:05:39 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
epilog=__doc__,
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
|
|
parser.add_argument('input', help='input file to stringify')
|
|
|
|
parser.add_argument('-o', '--output', required=True,
|
|
|
|
help='output file')
|
|
|
|
parser.add_argument('-n', '--variable-name', required=True,
|
|
|
|
help='name of the C++ variable')
|
|
|
|
parser.add_argument('-s', '--namespace', required=False,
|
|
|
|
help='C++ namespace to put the string into')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
with open(args.output, 'w') as f:
|
2024-08-22 11:42:12 +00:00
|
|
|
f.write("#include <AK/String.h>\n")
|
2023-05-05 19:05:39 +00:00
|
|
|
if args.namespace:
|
|
|
|
f.write(f"namespace {args.namespace} {{\n")
|
2024-08-22 11:42:12 +00:00
|
|
|
f.write(f"extern String {args.variable_name};\n")
|
|
|
|
f.write(f"String {args.variable_name} = R\"~~~(")
|
2023-05-05 19:05:39 +00:00
|
|
|
with open(args.input, 'r') as input:
|
|
|
|
for line in input.readlines():
|
|
|
|
f.write(f"{line}")
|
2024-08-22 11:42:12 +00:00
|
|
|
f.write(")~~~\"_string;\n")
|
2023-05-05 19:05:39 +00:00
|
|
|
if args.namespace:
|
|
|
|
f.write("}\n")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|