#!/bin/sh

VER=1.04

# ChangeLog:
# 1.04  Call to e-copyright removed.
# 1.03  -V shows more info
# 1.02	In the text file, ' is changed to \' and \ is changed to \\
# 1.01	-V flag implemented
# 1.00	First version

# e-txt2c: development tool
# just write up your usage in a file "usage.txt", then run
# 	e-txt2c DEFINENAME < usage.txt > usage.h
# then include usage.h in your program and refer to define DEFINENAME
# to address the string

# check args
if [ "$1" = "-V" ] ; then
    echo $VER TXT to C-string Translator
    exit 0
fi

if [ -z "$1" ] ; then
	cat << ENDUSAGE 1>&2
Usage: e-txt2c DEFINENAME <input.txt >output.h
E.g., when writing up your usage() function, just put your text in usage.txt.
Then run "e-txt2c USAGETEXT <usage.txt >usage.h" and include usage.h. Refer
to your text using the define symbol USAGETEXT. Typically this is a rule
in a Makefile, as in:
	# my "main.c" includes "usage.h", so it is dependent on that
	main.o: main.c usage.h

	# how to make usage.h
	usage.h: usage.txt
		e-txt2c USAGETEXT <usage.txt >usage.h

ENDUSAGE
	exit 1
fi

cat << ENDWARNING

/*
 * Warning: this file is auto-generated from an input file by e-txt2c.
 * Don't modify this, your changes will be overwritten (probably during
 * the next "make").
 * To change this text, find the sources, edit the text input, and
 * re-make the program.
 */

ENDWARNING

echo "#define $1 \\"

sed \
	-e 's:\\:\\\\:g' \
	-e "s:':\\\':g" \
	-e 's:":\\":g' \
 	-e 's:^:  ":'    \
	-e 's:$:\\n" \\:'

echo '  ""'
