1#! /bin/sh
2# cstocs batch-call wrapper.
3# To be called by enca, don't use directly. See enca(1) for calling convention.
4#
5# Copyright (C) 2000-2003 David Necas (Yeti) <yeti@physics.muni.cz>.
6# This is free software; it can be copied and/or modified under the terms of
7# version 2 of GNU General Public License, see COPYING for details.  There is
8# NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9transform_enc_name() {
10  case "$1" in
11  ASCII*) echo ascii ; return ;;
12  CP1250*) echo 1250 ; return ;;
13  IBM852*) echo pc2 ; return ;;
14  ISO-8859-2*) echo il2 ; return ;;
15  KEYBCS2*) echo kam ; return ;;
16  KOI-8_CS2*) echo koi ; return ;;
17  UTF-8*) echo utf8 ; return ;;
18  TeX*) echo tex ; return ;;
19  esac
20  echo "$1"|sed -e 's:/.*::'
21}
22if test "x$3" = "x"; then
23  echo "$0 has to be called by enca" 1>&2
24  exit 1
25fi
26umask 077
27inenc=`transform_enc_name "$1"`
28outenc=`transform_enc_name "$2"`
29if test "$4" = "-"; then
30  if cstocs "$inenc" "$outenc" <"$3"; then
31    rm -- "$3"
32  else
33    echo "$0: cstocs $inenc $outenc failed" 1>&2
34    rm -- "$3"
35    exit 1
36  fi
37else
38  temp=@SHELL_RANDOM_FILENAME@ || exit 1
39  if cstocs "$inenc" "$outenc" <"$3" >>"$temp"; then
40    # use cat > to preserve permissions
41    cat $temp >"$3"
42  else
43    echo "$0: cstocs $inenc $outenc $3 failed, file $3 unchanged" 1>&2
44    rm -f $temp
45    exit 1
46  fi
47  rm -f $temp
48fi
49
50