File: b-map.in

package info (click to toggle)
enca 1.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,948 kB
  • sloc: ansic: 10,297; sh: 5,858; xml: 2,132; makefile: 700; perl: 261
file content (40 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /bin/sh
# map 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() {
  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
  # Note map returns 0 on failure and 1 on success!
  if map --from "$inenc" --to "$outenc" <"$3"; then
    echo "$0: map --from $inenc --to $outenc failed" 1>&2
    rm -- "$3"
    exit 1
  else
    rm -- "$3"
  fi
else
  temp=@SHELL_RANDOM_FILENAME@ || exit 1
  # Note map returns 0 on failure and 1 on success!
  if map --from "$inenc" --to "$outenc" <"$3" >"$temp"; then
    echo "$0: map --from $inenc --to $outenc <$3 failed, file $3 unchanged" 1>&2
    rm -f $temp
    exit 1
  else
    # use cat > to preserve permissions
    cat $temp >"$3"
  fi
  rm -f $temp
fi