#!/bin/sh
# CHANGELOG.md as C, for src/changelog.inc: the text pic's /changelog shows,
# compiled in so the binary needs no file. The text is the elements of a
# NULL-terminated array of chunks of at most 3500 bytes, split at line ends
# (C11 promises string literals of 4095 bytes); the reader joins them.
set -eu
awk 'BEGIN { print "/* Generated from CHANGELOG.md by tools/changelog-inc.sh; do not edit. */"; size = 0 }
{
line = $0
if (size > 0 && size + length(line) + 1 > 3500) { printf ",\n"; size = 0 }
size += length(line) + 1
gsub(/\\/, "\\\\", line); gsub(/"/, "\\\"", line); gsub(/\?\?/, "?\\?", line)
printf "%s\"%s\\n\"", (size == length($0) + 1 ? "" : "\n"), line
}
END { printf ",\nNULL\n" }' "${1:-CHANGELOG.md}"