# !/bin/sh

#================================================================
# jhtmllint
# wrapper for htmllint for UTF-8 in Japanese
#================================================================


# set variables
LANG=C ; export LANG
LC_ALL=C ; export LC_ALL
progname="jhtmllint"
tmpfile="/tmp/$progname.$$"
htmllint="/usr/local/htmllint/htmllint -d mailto-link"


# function to remove the temporary file
tmpclean(){
  rm -rf "$tmpfile"
}


# set the exit trap
trap tmpclean 1 2 3 13 15


# make the temporary file
if [ $# -le 1 ]
then
  cat "$1" | iconv -f UTF-8 -t EUC-JP -c |
    sed -e 's/lang="en"/lang="ja"/g' -e 's/charset=UTF-8/charset=EUC-JP/g' \
      -e 's/encoding="UTF-8"/encoding="EUC-JP"/g' > "$tmpfile"
else
  cat | iconv -f UTF-8 -t EUC-JP -c |
    sed -e 's/lang="en"/lang="ja"/g' -e 's/charset=UTF-8/charset=EUC-JP/g' \
      -e 's/encoding="UTF-8"/encoding="EUC-JP"/g' > "$tmpfile"
fi


# check the HTML
$htmllint "$tmpfile"


# clean up the temporary directory
tmpclean


# exit normally
exit 0



# END OF FILE
