#!/bin/sh

tmp=/tmp/lnl_msg$$
out=msg.h
in=msg_jpn.h

cp /dev/null $out
echo '#ifndef	__MSG_H__' >> $out
echo '#define	__MSG_H__' >> $out
echo '' >> $out
echo '/* This file is auto generated from '$in' by '$0' */' >> $out
echo '' >> $out
echo 'typedef enum {' >> $out

sed -n \
	-e '/^#if	0/,/#endif/d' \
	-e '/{ N_MSG/s/{ N_MSG/N_MSG/' \
	-e '/N_MSG/p' \
	$in >> $out

echo '	N_MSG_MAX_N' >> $out
echo '} n_msg_t;' >> $out
echo '' >> $out
echo '/**********************************/' >> $out
echo '' >> $out
echo 'char	*ary_msg[N_MSG_MAX_N];' >> $out
echo '#define	MSG( n )	(ary_msg[n])' >> $out
echo '' >> $out

sed -n \
	-e '/^#if	0/,/#endif/d' \
	-e 's/,$//' \
	-e 's/^	{ N_MSG/N_MSG/' -e '/^N_MSG/p' \
	-e 's/^N_MSG/0N_MSG/' -e '/^0N_MSG/p' \
	$in > $tmp

sed -e '/^N_MSG/s/$/	\\/' -e '/^N_MSG/s/^N_MSG/#define	MSG/' \
	-e '/0N_MSG/s/$/ )/' \
	-e '/0N_MSG/s/^0N_MSG/		MSG\( N_MSG/' \
	$tmp >> $out

echo '#endif	/* __MSG_H__ */' >> $out
