add new CMake macro generate_from_any and extend PythonToCPP script to create source file from any text file

This commit is contained in:
wmayer
2019-10-14 22:20:59 +02:00
parent f7bff20ca6
commit eff400620c
2 changed files with 22 additions and 4 deletions

View File

@@ -9,19 +9,24 @@ import os,sys,string
file = open(sys.argv[1])
if(len(sys.argv) > 3):
sys.stderr.write("Wrong Parameter\n Usage:\n PythonToCPP Infile.py [Outfile]\n")
if(len(sys.argv) > 4):
sys.stderr.write("Wrong Parameter\n Usage:\n PythonToCPP Infile.py [Outfile][Variable]\n")
if(len(sys.argv) > 2):
out = open(sys.argv[2],"w");
else:
out = sys.stdout
if(len(sys.argv) > 3):
identifier = sys.argv[3]
else:
identifier = os.path.basename(sys.argv[1])
identifier = identifier[:-3]
lines = file.readlines()
# We want to use this script for files in another directory, so we extract the actual file name
fn = os.path.basename(sys.argv[1])
out.write("const char " + fn[:-3] + "[] =")
out.write("const char " + identifier + "[] =")
for line in lines:
# remove new line