1#!/usr/bin/env python3 2# 3# Copyright (c) 2022 Golioth, Inc. 4# 5# SPDX-License-Identifier: Apache-2.0 6 7from argparse import ArgumentParser 8from math import ceil 9 10 11CHUNK = "This is a fragment of generated C string. " 12 13 14parser = ArgumentParser(description="Generate C string of arbitrary size", allow_abbrev=False) 15parser.add_argument("-s", "--size", help="Size of string (without NULL termination)", 16 required=True, type=int) 17parser.add_argument("filepath", help="Output filepath") 18args = parser.parse_args() 19 20 21with open(args.filepath, "w", encoding="UTF-8") as fp: 22 fp.write('"') 23 chunks = CHUNK * ceil(args.size / len(CHUNK)) 24 fp.write(chunks[:args.size]) 25 fp.write('"') 26