1#! /usr/bin/env python3 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (c) 2023 Stephen Hemminger <stephen@networkplumber.org> 4 5""" 6Script to read a text file and convert it into a header file. 7""" 8import sys 9import os 10 11 12def main(): 13 '''program main function''' 14 print(f'/* File autogenerated by {sys.argv[0]} */') 15 for path in sys.argv[1:]: 16 name = os.path.basename(path) 17 print() 18 print(f'/* generated from {name} */') 19 with open(path, "r") as f: 20 array = name.replace(".", "_") 21 print(f'static const char {array}[] = ' + '{') 22 line = f.readline() 23 24 # make sure empty string is null terminated 25 if not line: 26 print(' ""') 27 28 while line: 29 s = repr(line) 30 print(' {}'.format(s.replace("'", '"'))) 31 line = f.readline() 32 print('};') 33 34 35if __name__ == "__main__": 36 main() 37