orca/scripts/embed_text_files.py

49 lines
1.5 KiB
Python
Raw Normal View History

import os
from datetime import datetime
from argparse import ArgumentParser
def embed_text_files(outputpath, prefix, files):
output = open(outputpath, "w")
output.write("/*********************************************************************\n")
output.write("*\n")
output.write("*\tfile: %s\n" % os.path.basename(outputpath))
output.write("*\tnote: string literals auto-generated by build_runtime.py\n")
output.write("*\tdate: %s\n" % datetime.now().strftime("%d/%m%Y"))
output.write("*\n")
output.write("**********************************************************************/\n")
outSymbol = (os.path.splitext(os.path.basename(outputpath))[0]).upper()
output.write("#ifndef __%s_H__\n" % outSymbol)
output.write("#define __%s_H__\n" % outSymbol)
output.write("\n\n")
for fileName in files:
f = open(fileName, "r")
lines = f.read().splitlines()
output.write("//NOTE: string imported from %s\n" % fileName)
stringName = os.path.splitext(os.path.basename(fileName))[0]
output.write(f"const char* {prefix}{stringName} = ")
for line in lines:
output.write("\n\"%s\\n\"" % line)
output.write(";\n\n")
f.close()
output.write("#endif // __%s_H__\n" % outSymbol)
output.close()
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("inputFiles", nargs="+")
parser.add_argument("-o", "--output")
parser.add_argument("-p", "--prefix")
args = parser.parse_args()
embed_text_files(args.output, args.prefix, args.inputFiles)