#!/bin/sh

set -e

if [ "$#" -lt 1 ]
then
  echo "usage: $0 <stflfile> [<extension>]"
  exit 1
fi

filename="$1"
extension="$2"
id="`basename \"$filename\" \"$extension\"`"
uppercase_id="`echo \"${id}\" | tr 'a-z' 'A-Z'`"
define="NEWSBOAT_${uppercase_id}_H_"

printf "#ifndef ${define}\n"
printf "#define ${define}\n"
printf "\n"
printf "static char ${id}_str[] = \"\" "

cat "$filename" | sed -e 's/"/\\"/g; s/\(.*\)/"\1\\n"/'

printf ";\n\n"
printf "#endif /* ${define} */\n"
