chiark / gitweb /
Silence two -Wlogical-op warnings.
[gnupg2.git] / build-aux / potomo
1 #!/bin/sh
2 # potomo - Convert a .po file to an utf-8 encoded .mo file.
3 # Copyright 2008 g10 Code GmbH
4 # Copyright 2010 Free Software Foundation, Inc.
5 #
6 # This file is free software; as a special exception the author gives
7 # unlimited permission to copy and/or distribute it, with or without
8 # modifications, as long as this notice is preserved.
9 #
10 # This file is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
12 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 # This script is used to create the mo files for applications using
15 # the simple gettext implementation provided by libgpg-error.  That
16 # gettext can only cope with utf-8 encoded mo files; thus we make this
17 # sure while creating the mo.  A conversion is not done if the source
18 # file does not exist or if it is not newer than the mo file.
19
20 if [ "$1" = "--get-linguas" -a $# -eq 2 ]; then
21    if [ ! -f "$2/LINGUAS" ]; then
22        echo "potomo: directory '$2' has no LINGUAS file" >&2
23        exit 1
24    fi
25    echo $(sed -e "/^#/d" -e "s/#.*//" "$2"/LINGUAS)
26    exit 0
27 fi
28
29 if [ $# -ne 2 ]; then
30   echo "usage: potomo INFILE.PO OUTFILE.MO" >&2
31   echo "       potomo --get-linguas DIR"    >&2
32   exit 1
33 fi
34 infile="$1"
35 outfile="$2"
36
37 if [ ! -f "$infile" ]; then
38   echo "potomo: '$infile' not found - ignored" 2>&1
39   exit 0
40 fi
41
42 if [ "$outfile" -nt "$infile" ]; then
43   echo "potomo: '$outfile' is newer than source - keeping" 2>&1
44   exit 0
45 fi
46
47 # Note that we could use the newer msgconv.  However this tool was not
48 # widely available back in 2008.
49
50 fromset=`sed -n '/^"Content-Type:/ s/.*charset=\([a-zA-Z0-9_-]*\).*/\1/p' \
51          "$infile"`
52
53 case "$fromset" in
54     utf8|utf-8|UTF8|UTF-8)
55         echo "potomo: '$infile' keeping $fromset" >&2
56         msgfmt --output-file="$outfile" "$infile"
57         ;;
58     *)
59         echo "potomo: '$infile' converting from $fromset to utf-8" >&2
60         iconv --silent --from-code=$fromset --to-code=utf-8 < "$infile" |\
61             sed "/^\"Content-Type:/ s/charset=[a-zA-Z0-9_-]*/charset=utf-8/"|\
62             msgfmt --output-file="$outfile" -
63         ;;
64 esac