elf.5, ld.so.8: Undeprecate DT_RPATH; explain DT_RPATH vs DT_RUNPATH
[man-pages.git] / scripts / convert_to_utf_8.sh
blobb0d222c1270dfd93f42661f490af964720550d99
1 #!/bin/sh
3 # convert_to_utf_8.sh
5 # Find man pages with encoding other than us-ascii, and convert them
6 # to the utf-8 encoding.
8 # Example usage:
10 # cd man-pages-x.yy
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
30 exit 1
33 out_dir="$1"
34 shift
36 enc_line=""
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"
47 case "$basen" in
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"
58 from_enc=$enc
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}"
66 done
68 exit 0