#! /bin/tcsh
# -*- mode: perl; -*-
####################################################################
#	動物の森”用手紙追伸データ変換
#	$Id: convert.sh,v 1.3 1999-12-06 16:08:37+09 komatu Exp $
####################################################################

#####使用するファイル名
set data_file_bmp="ps_data.bmp"
set data_file_c="ps_data.c"
set tmp_data_file_c="tmp_ps_data.c"
set table_file_bmp="ps_data_table.bmp"
set table_file_c="ps_data_table.c"
set tmp_table_file_c="tmp_ps_data_table.c"
set enum_file="ps_data_enum.h"
set decl_file="convert.decl"
set decl_ps_euc_unix_file=$decl_file.ps.euc.unix


#####定義ファイルのチェック
if(!(-f $decl_file)) then
    echo "定義ファイルがオープン出来ません $decl_file"
    exit 1
endif


#####手紙宛名リストファイルの作成
\rm -f $decl_ps_euc_unix_file
foreach label (`\cat $decl_file`)
    echo "$label.ps.euc.unix" >>$decl_ps_euc_unix_file
end


#####手紙宛名データを"UNIXコード"かつ"EUCコード"に変換したテンポラリーファイルの作成
foreach label (`\cat $decl_file`)
    nkf -e $label.ps | to_unix >$label.ps.euc.unix
end


#####手紙宛名データの変換
## forest_m -b -e -l16 $data_file_bmp $table_file_bmp $enum_file $decl_ps_euc_unix_file
#####手紙宛名データの変換	(18 = 16 + 2(pf?))
## forest_m -b -e -l18 $data_file_bmp $table_file_bmp $enum_file $decl_ps_euc_unix_file
#####手紙宛名データの変換	(26 = 16 + 10(pf?展開size))
## forest_m -b -e -l26 $data_file_bmp $table_file_bmp $enum_file $decl_ps_euc_unix_file
#####手紙宛名データの変換	(32 = 16 + 16(pf?展開size))
forest_m_nes -b -e -l32 $data_file_bmp $table_file_bmp $enum_file $decl_ps_euc_unix_file

echo '#include "m_basic.h"' > $tmp_data_file_c
echo "\n" >> $tmp_data_file_c
echo "const unsigned char PS_data[] = {" >> $tmp_data_file_c
echo -n "@ " >> $tmp_data_file_c
bintoc $data_file_bmp >> $tmp_data_file_c

echo '#include "m_basic.h"' > $tmp_table_file_c
echo "\n" >> $tmp_table_file_c
echo "const unsigned char PS_TABLE_data[] = {" >> $tmp_table_file_c
echo -n "@ " >> $tmp_table_file_c
bintoc $table_file_bmp >> $tmp_table_file_c


# (@行を削除)
sed '/^@/d' $tmp_data_file_c > $data_file_c
sed '/^@/d' $tmp_table_file_c > $table_file_c


#####テンポラリーファイルの削除
\rm -f $tmp_data_file_c
\rm -f $tmp_table_file_c
\rm -f $decl_ps_euc_unix_file
\rm -f $enum_file
foreach label (`\cat $decl_file`)
    \rm -f $label.ps.euc.unix
end
