#! /bin/sh1#2# SPDX-License-Identifier: BSD-2-Clause3#4# Copyright (c) 2018-2025 Gavin D. Howard and contributors.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions are met:8#9# * Redistributions of source code must retain the above copyright notice, this10# list of conditions and the following disclaimer.11#12# * Redistributions in binary form must reproduce the above copyright notice,13# this list of conditions and the following disclaimer in the documentation14# and/or other materials provided with the distribution.15#16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE26# POSSIBILITY OF SUCH DAMAGE.27#2829export LANG=C30export LC_CTYPE=C3132progname=${0##*/}3334script="$0"35scriptdir=$(dirname "$script")36. "$scriptdir/../scripts/functions.sh"3738# Just print the usage and exit with an error. This can receive a message to39# print.40# @param 1 A message to print.41usage() {42if [ $# -eq 1 ]; then43printf '%s\n\n' "$1"44fi45printf 'usage: %s input output exclude name [label [define [remove_tabs]]]\n' "$progname"46exit 147}4849# See strgen.c comment on main() for what these mean. Note, however, that this50# script generates a string literal, not a char array. To understand the51# consequences of that, see manuals/development.md#strgenc.52if [ $# -lt 3 ]; then53usage "Not enough arguments"54fi5556input="$1"57check_file_arg "$input"58output="$2"59exclude="$3"60name="$4"61label="$5"62define="$6"63remove_tabs="$7"64if [ "$remove_tabs" != "" ]; then65check_bool_arg "$remove_tabs"66fi6768tmpinput=$(mktemp -t "${input##*/}_XXXXXX")6970if [ "$exclude" -ne 0 ]; then71filter_text "$input" "$tmpinput" "E"72else73filter_text "$input" "$tmpinput" "A"74fi7576exec < "$tmpinput"77exec > "$output"7879rm -f "$tmpinput"8081if [ -n "$label" ]; then82nameline="const char *${label} = \"${input}\";"83labelexternline="extern const char *${label};"84fi8586if [ -n "$define" ]; then87condstart="#if ${define}"88condend="#endif"89fi9091if [ -n "$remove_tabs" ]; then92if [ "$remove_tabs" -ne 0 ]; then93remtabsexpr='s: ::g;'94fi95fi9697cat<<EOF98// Copyright (c) 2018-2025 Gavin D. Howard and contributors.99// Licensed under the 2-clause BSD license.100// *** AUTOMATICALLY GENERATED FROM ${input}. DO NOT MODIFY. ***101102${condstart}103$labelexternline104105extern const char $name[];106107$nameline108109const char ${name}[] =110$(sed -e "$remtabsexpr " -e '1,/^$/d; s:\\n:\\\\n:g; s:":\\":g; s:^:":; s:$:\\n":')111;112${condend}113EOF114115#if [ "$exclude" -ne 0 ]; then116#rm -rf "$input"117#fi118119120