1#!/bin/bash
2# This script expects that its first argument is the path prefix and the
3# remaining ones are file paths. It generates a C source code containing
4# the definition of the array of the 'FileToc' items. FileToc is a struct
5# with two strings. The first is the file path with path prefix removed,
6# and the second is the file contents as string. The last array element
7# is a sentinel (both strings are null). One of the Kythe applications
8# relies on this code (Kythe is the source code indexer: http://kythe.io/)
9
10set -eu
11declare prefix="$1"
12shift
13printf 'static const struct FileToc kPackedFiles[] = {\n'
14[[ "$prefix" =~ /\/$/ ]] || prefix="$prefix/"
15for hfile in "$@"; do
16  printf '{"%s",\nR"filecontent(' "${hfile#$prefix}"
17  cat "$hfile"
18  printf ')filecontent"\n},\n'
19done
20printf '{nullptr, nullptr}};\n'
21