2
0
mirror of https://github.com/boostorg/build.git synced 2026-01-19 16:12:14 +00:00
Files
build/example/customization/inline_file.py
github-actions[bot] def908ed01 [Backport version/4.10.0] python3 shebang (#266)
* python3 shebang

(cherry picked from commit 9f0d565b06482a90b59d07ef9e7b9aadd698926c)

* CI: execute python scripts via shebang

(cherry picked from commit cf36b637abe2125cf6895bec593b4cbcf71ae570)

---------

Co-authored-by: Nikita Kniazev <nok.raven@gmail.com>
2023-04-17 14:23:50 -05:00

45 lines
1.1 KiB
Python

#!/usr/bin/env python3
# Copyright 2003 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
import sys
from string import strip
def quote_line(line):
result = ""
for i in line:
if (i == '\\'):
result = result + '\\\\'
elif (i == '\"'):
result = result + '\\\"'
elif (i != '\r' and i != '\n'):
result = result + i;
return '\"' + result + '\\n\"'
def quote_file(file):
result = ""
for i in file.readlines():
result = result + quote_line(i) + "\n"
return result
if len(sys.argv) < 3:
print "Usage: inline_file.py output_c_file file_to_include"
else:
output_c_file = sys.argv[1]
out_file = open(output_c_file, "w");
file_to_include = sys.argv[2]
in_file = open(file_to_include, "r");
variable_name = strip(in_file.readline())
out_file.write("extern const char %s[] = {\n%s};\n\n" % (variable_name, quote_file(in_file)))
in_file.close()
out_file.close()