#! /bin/sh if [ $# = 0 ]; then echo "Convert file(s) between codepages" echo "Usage: conv [file{ file{ file{ ...}}}] [from codepage] [to codepage]" exit fi for x in $*; do if [ -n "$var" ]; then eval "$var=$x" var= continue fi case $x in [fF] | [fF][rR][oO][mM]) var=fromenc ;; [tT] | [tT][oO]) var=toenc ;; *) files="$files $x" ;; esac done iconv="iconv -c" [ -n "$fromenc" ] && iconv="$iconv -f $fromenc" [ -n "$toenc" ] && iconv="$iconv -t $toenc" TMPFILE=`mktemp -q /tmp/d2u.XXXXXX` if [ $? -ne 0 ]; then echo "$0: Can't create temp file, exiting..." exit 1 fi for x in $files; do echo -n "Converting $x ..." if [ ! -f "$x" ]; then echo " NO SUCH FILE" shift; continue fi $iconv $x -o $TMPFILE if [ $? -gt 1 ]; then echo " ERROR" shift; continue fi echo -n " ok" cmp -s $TMPFILE $x if [ $? -eq 0 ]; then echo ", no changes" shift; continue fi echo y|cp $TMPFILE $x 2>/dev/null if [ $? -ne 0 ]; then echo " CANT COPY $TMPFILE TO $x" shift; continue fi echo ", done" shift done rm -f $TMPFILE