]> git.ipfire.org Git - thirdparty/man-pages.git/blob - scripts/convert_to_utf_8.sh
fuse.4: ffix
[thirdparty/man-pages.git] / scripts / convert_to_utf_8.sh
1 #!/bin/sh
2 #
3 # convert_to_utf_8.sh
4 #
5 # Find man pages with encoding other than us-ascii, and convert them
6 # to the utf-8 encoding.
7 #
8 # Example usage:
9 #
10 # cd man-pages-x.yy
11 # sh convert_to_utf_8.sh <output_dir> man?/*
12 #
13 ######################################################################
14 #
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.
20 #
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).
26 #
27
28 if [[ $# -lt 2 ]]; then
29 echo "Usage: ${0} <output_dir> man?/*" 1>&2
30 exit 1
31 fi
32
33 out_dir="$1"
34 shift
35
36 enc_line="'\\\" t -*- coding: UTF-8 -*-"
37
38 for f in "$@"; do
39 enc=$(file -bi "$f" | cut -d = -f 2)
40 if [[ $enc != "us-ascii" ]]; then
41 dirn=$(dirname "$f")
42 basen=$(basename "$f")
43 new_dir="${out_dir}/${dirn}"
44 if [[ ! -e "$new_dir" ]]; then
45 mkdir -p "$new_dir"
46 fi
47 case "$basen" in
48 armscii-8.7 | cp1251.7 | iso_8859-*.7 | koi8-?.7)
49
50 # iconv does not understand some encoding names that
51 # start "iso_", but does understand the corresponding
52 # forms that start with "iso-"
53
54 from_enc="$(echo $basen | sed 's/\.7$//;s/iso_/iso-/')"
55 ;;
56 *)
57 echo "NULL TRANSFORM: $f"
58 from_enc=$enc
59 ;;
60 esac
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}"
65 fi
66 done
67
68 exit 0