#! /bin/sh
# first, you type 
# chmod +w *.bib && cp edit_here/*.bib .

#option_ja="--command jbibtex --sort-by-date -s ./jplain" 
#option_en="--command bibtex --sort-by-date"
option_ja="--command jbibtex --sort-by-date --revkeys -r -s ./tipsj" 
option_en="--command jbibtex --sort-by-date -revkeys -r -s ./tipsj "

################################################

for i in *.bib
do echo "diff" $i; diff $i edit_here/$i || exit
done

#cp edit_here/*.bib .

#qkc -e -u *_ja.bib # bibtex2html requires EUC
for j in *_ja.bib
do nkf -e $j > 0 && mv 0 $j
done

for i in *.bib
do
	sed -e 's/^year="in press"/year="999999999"/'  \
	      -e 's/^year=in_press/year="999999999"/' $i > 0 && mv 0 $i
done


# English
bibtex2html $option_en -title "Reviewed Articles in English" reviewed_en.bib
#bibtex2html $option_en -title "Misc. in Eng" misc_en.bib
bibtex2html $option_en -title "Reviewed Articles in Japanese with English abstract " reviewed_je.bib
bibtex2html $option_en --title "Geologic Maps(GSJ publ) with English annotations, captions and abstract" map_je.bib
bibtex2html $option_en --title "Misc. in Japanese" misc_je.bib

# Japanese
bibtex2html $option_ja --title "Reviewed Articles in Japanese" reviewed_ja.bib
bibtex2html $option_ja --title "Geologic Maps(GSJ publ) in Japanese" map_ja.bib
bibtex2html $option_ja --title "Misc. in Japanese" misc_ja.bib
bibtex2html $option_ja --title "Small Talks in Japanese" smalltalk_ja.bib
# --nodoc

for i in *.html
do
	#sed 's/999999999/<i>in_press<\/i>/' $i > 0 && mv 0 $i
#	 sed 's/999999999/<i><sup>presur\&aelig;<\/sup><\/i>/' $i > 0 && mv 0 $i
	 sed 's/999999999/<i><sup>stampat\&aelig;<\/sup><\/i>/' $i > 0 && mv 0 $i

#sed \
#'s/999999999,/<sup>i<\/sup><sub>n_<\/sub><sup>pr<\/sup><sub>e<\/sub><sup>s<\/sup><sub>s<\/sub>,/' $i > 0 && mv 0 $i

#sed 's/999999999,/<sup>in<\/sup><sub>press<\/sub><sup>,<\/sup>/' $i > 0 && mv 0 $i
#	sed 's/999999999/<font size="1">in press<\/font>/' $i > 0 && mv 0 $i
done


################################################
# Japanese version
lang="ja"
output=publica_${lang}.html
echo "---"
echo "Making $output"

nkf -e head_${lang}.html- > $output
echo "\$date:" `LANG=C ; date`"$" >> $output
echo "<hr>" >> $output

for i in reviewed_en.html reviewed_ja.html map_ja.html misc_ja.html smalltalk_ja.html
do
	sh deletedoc_sed.sh $i >> $output
done

nkf -e foot_${lang}.-html >> $output
#echo "</body></html>" >> $output

echo "$output done"

################################################
# English version
lang="en"
output=publica_${lang}.html
echo "---"
echo "Making $output"

nkf -e head_${lang}.html- > $output
echo "\$date:" `LANG=C ; date`"$" >> $output
echo "<hr>" >> $output

for i in reviewed_en.html reviewed_je.html map_je.html misc_je.html
do
	sh deletedoc_sed.sh $i >> $output
done

nkf -e foot_${lang}.-html >> $output

echo "$output done"
################################################
#qkc -j -u *_ja.bib 
for j in *_ja.bib
do nkf -j $j > 0 && mv 0 $j
done


for i in *.html
do
#jsed 's/doi:[[:space:]]*\([[:graph:]]\+\)/<a href="http:\/\/dx.doi.org\/\1">doi:<\/a> \1/' $i > 0 && mv 0 $i
jsed -nf doi.sed $i | jsed -nf name_underline.sed > 0 && mv 0 $i
done

######
# enbedding LANG infomation
for i in *_ja.html 
do
	sed 's/<\/title>/<\/title><meta http-equiv="Content-Type" content="text\/html; charset=EUC_JP">/' $i > 0 &&  mv 0 $i
done

chmod -w *.bib
