5 # Find man pages with encoding other than us-ascii, and convert them
6 # to the utf-8 encoding.
11 # sh convert_to_utf_8.sh <output_dir> man?/*
13 ######################################################################
15 # (C) Copyright 2013, Peter Schiffer <pschiffe@redhat.com>
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details
25 # (http://www.gnu.org/licenses/gpl-2.0.html).
28 if [[ $# -lt 2 ]]; then
29 echo "Usage: ${0} <output_dir> man?/*" 1>&2
39 enc
=$
(file -bi "$f" | cut
-d = -f 2)
40 if [[ $enc != "us-ascii" ]]; then
42 basen
=$
(basename "$f")
43 new_dir
="${out_dir}/${dirn}"
44 if [[ ! -e "$new_dir" ]]; then
48 armscii-8.7 | cp1251.7 | iso_8859-
*.7 | koi8-?
.7)
50 # iconv does not understand some encoding names that
51 # start "iso_", but does understand the corresponding
52 # forms that start with "iso-"
54 from_enc
="$(echo $basen | sed 's/\.7$//;s/iso_/iso-/')"
57 echo "NULL TRANSFORM: $f"
61 printf "Converting %-23s from %s\n" "$f" "$from_enc"
62 echo "$enc_line" > "${new_dir}/${basen}"
63 iconv -f "$from_enc" -t utf-8
"$f" \
64 |
sed "/.*-\*- coding:.*/d;/.\\\" t$/d" >> "${new_dir}/${basen}"