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
10CHUNK = "This is a fragment of generated C string. "
11
12
13parser = ArgumentParser(description="Generate C string of arbitrary size", allow_abbrev=False)
14parser.add_argument("-s", "--size", help="Size of string (without NULL termination)",
15                    required=True, type=int)
16parser.add_argument("filepath", help="Output filepath")
17args = parser.parse_args()
18
19
20with open(args.filepath, "w", encoding="UTF-8") as fp:
21    fp.write('"')
22    chunks = CHUNK * ceil(args.size / len(CHUNK))
23    fp.write(chunks[:args.size])
24    fp.write('"')
25