futex.2: Rework the description of FUTEX_LOCK_PI2
[man-pages.git] / scripts / unformat_parens.sh
blob06bbb48cd3f22a0213c6bd0d3167e73296ec2c5e
1 #!/bin/sh
3 # unformat_parens.sh
5 # The manual pages before 2.10 format parentheses
6 # inconsistently. In some cases they are like:
8 # .B name()
10 # while in others they are like:
12 # .BR name ()
14 # This script changes instances to the latter format.
15 # It does not fix all such instances: some will have to be
16 # done manually.
18 # Use the "-n" option for a dry run, in order to see what would be
19 # done, without actually doing it.
21 ######################################################################
23 # (C) Copyright 2005 & 2013, Michael Kerrisk
24 # This program is free software; you can redistribute it and/or
25 # modify it under the terms of the GNU General Public License
26 # as published by the Free Software Foundation; either version 2
27 # of the License, or (at your option) any later version.
29 # This program is distributed in the hope that it will be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU General Public License for more details
33 # (http://www.gnu.org/licenses/gpl-2.0.html).
37 file_base="tmp.$(basename $0)"
39 work_dst_file="$file_base.dst"
40 work_src_file="$file_base.src"
42 all_files="$work_dst_file $work_src_file"
44 # Command-line option processing
46 really_do_it=1
47 while getopts "n" optname; do
48 case "$optname" in
49 n) really_do_it=0;
51 *) echo "Unknown option: $OPTARG"
52 exit 1
54 esac
55 done
57 shift $(( $OPTIND - 1 ))
59 # Only process files with > 1 line -- single-line files are link files
61 for page in $(wc "$@" 2> /dev/null | awk '$1 > 1 {print $4}'| \
62 grep -v '^total'); do
64 cp $page $work_dst_file
66 echo ">>>>>>>>>>>>>>>>>>>>>>>>>" $page "<<<<<<<<<<<<<<<<<<<<<<<<<"
68 if false; then
69 grep '^\.I *[a-z0-9_][a-z0-9_]*()$' $page
70 grep '^\.B *[a-z0-9_][a-z0-9_]*()$' $page
71 echo '###'
72 grep '^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*()$' $page
73 echo '###'
74 grep '^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*() [^"]*$' $page
75 echo '###'
76 grep '()\\f[PR]' $page
77 echo '###'
80 cp $work_dst_file $work_src_file
81 cat $work_src_file | \
82 sed \
83 -e '/^\.B *[a-z0-9_][a-z0-9_]*() *$/s/^\.B/.BR/' \
84 -e '/^\.I *[a-z0-9_][a-z0-9_]*() *$/s/^\.I/.IR/' \
85 > $work_dst_file
87 cp $work_dst_file $work_src_file
88 cat $work_src_file | \
89 sed \
90 -e '/^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*()$/s/()/ ()/' \
91 > $work_dst_file
93 cp $work_dst_file $work_src_file
94 cat $work_src_file | \
95 sed \
96 -e '/^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*() [^"]*$/s/() / ()/' \
97 > $work_dst_file
99 cp $work_dst_file $work_src_file
100 cat $work_src_file | \
101 sed \
102 -e '/()\\fP/s/()\\fP/\\fP()/g' \
103 -e '/()\\fR/s/()\\fR/\\fR()/g' \
104 > $work_dst_file
106 if ! cmp -s $page $work_dst_file; then
107 diff -u $page $work_dst_file
109 if test $really_do_it -ne 0; then
110 cat $work_dst_file > $page
113 else
114 echo "### NOTHING CHANGED"
116 done
118 # clean up
120 rm -f $all_files
121 exit 0