File: generate-data-header

package info (click to toggle)
pegsolitaire 0.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: ansic: 494; xml: 142; makefile: 73; sh: 11
file content (16 lines) | stat: -rwxr-xr-x 535 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
# Embeds the files given as arguments in a C header.
# Copyright (C) 2018 Juhani Numminen
set -e
echo "/* This is an autogenerated file. */"
echo "#ifndef DATA_H"
echo "#define DATA_H"
for f in $@; do
    token=$(basename $f | tr . _)
    # Remove \n, remove spaces after >, replace multiple spaces with single one,
    # escape double quote.
    escaped=$(tr -d '\n' < $f |
        sed -E -e 's,>[[:space:]]+,>,g' -e 's,[[:space:]]+, ,g' -e 's,",\\",g')
    printf '#define %s "%s"\n' "$token" "$escaped"
done
echo "#endif"