aboutsummaryrefslogtreecommitdiff
path: root/lib/enca/script/b-cstocs.in
diff options
context:
space:
mode:
Diffstat (limited to 'lib/enca/script/b-cstocs.in')
-rw-r--r--lib/enca/script/b-cstocs.in50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/enca/script/b-cstocs.in b/lib/enca/script/b-cstocs.in
new file mode 100644
index 0000000000..2e85b146b0
--- /dev/null
+++ b/lib/enca/script/b-cstocs.in
@@ -0,0 +1,50 @@
+#! /bin/sh
+# @(#) $Id: b-cstocs.in,v 1.3 2003/12/22 15:32:37 yeti Exp $
+# cstocs batch-call wrapper.
+# To be called by enca, don't use directly. See enca(1) for calling convention.
+#
+# Copyright (C) 2000-2003 David Necas (Yeti) <yeti@physics.muni.cz>.
+# This is free software; it can be copied and/or modified under the terms of
+# version 2 of GNU General Public License, see COPYING for details. There is
+# NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+transform_enc_name() {
+ case "$1" in
+ ASCII*) echo ascii ; return ;;
+ CP1250*) echo 1250 ; return ;;
+ IBM852*) echo pc2 ; return ;;
+ ISO-8859-2*) echo il2 ; return ;;
+ KEYBCS2*) echo kam ; return ;;
+ KOI-8_CS2*) echo koi ; return ;;
+ UTF-8*) echo utf8 ; return ;;
+ TeX*) echo tex ; return ;;
+ esac
+ echo "$1"|sed -e 's:/.*::'
+}
+if test "x$3" = "x"; then
+ echo "$0 has to be called by enca" 1>&2
+ exit 1
+fi
+umask 077
+inenc=`transform_enc_name "$1"`
+outenc=`transform_enc_name "$2"`
+if test "$4" = "-"; then
+ if cstocs "$inenc" "$outenc" <"$3"; then
+ rm -- "$3"
+ else
+ echo "$0: cstocs $inenc $outenc failed" 1>&2
+ rm -- "$3"
+ exit 1
+ fi
+else
+ temp=@SHELL_RANDOM_FILENAME@ || exit 1
+ if cstocs "$inenc" "$outenc" <"$3" >>"$temp"; then
+ # use cat > to preserve permissions
+ cat $temp >"$3"
+ else
+ echo "$0: cstocs $inenc $outenc $3 failed, file $3 unchanged" 1>&2
+ rm -f $temp
+ exit 1
+ fi
+ rm -f $temp
+fi
+