#! /bin/tcsh
# -*- mode: perl; -*-
####################################################################
#	動物の森”用手紙宛名データ変換
#	$Id: convert.sh,v 1.2 1999-11-29 11:07:29+09 komatu Exp $
####################################################################

#####使用するファイル名
set data_file_bmp="super_data.bmp"
set data_file_c="super_data.c"
set tmp_data_file_c="tmp_super_data.c"
set table_file_bmp="super_data_table.bmp"
set table_file_c="super_data_table.c"
set tmp_table_file_c="tmp_super_data_table.c"
set enum_file="super_data_enum.h"
set decl_file="convert.decl"
set decl_super_euc_unix_file=$decl_file.super.euc.unix


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


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


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


#####手紙宛名データの変換
## forest_m -b -e -l13 $data_file_bmp $table_file_bmp $enum_file $decl_super_euc_unix_file
#####手紙宛名データの変換	(13 = 10 + 1(return) + 2(pf?))
## forest_m -b -e -l13 $data_file_bmp $table_file_bmp $enum_file $decl_super_euc_unix_file
#####手紙宛名データの変換	(21 = 10 + 1(return) + 10(pf? 展開size))
forest_m -b -e -l21 $data_file_bmp $table_file_bmp $enum_file $decl_super_euc_unix_file

echo '#include "m_basic.h"' > $tmp_data_file_c
echo "\n" >> $tmp_data_file_c
echo "const unsigned char SUPER_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 SUPER_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_super_euc_unix_file
\rm -f $enum_file
foreach label (`\cat $decl_file`)
    \rm -f $label.super.euc.unix
end


