]>
Commit | Line | Data |
---|---|---|
f8fc5a23 MK |
1 | #!/bin/sh |
2 | # | |
3 | # unformat_parens.sh | |
4 | # | |
2b50ade4 MK |
5 | # The manual pages before 2.10 format parentheses |
6 | # inconsistently. In some cases they are like: | |
f8fc5a23 MK |
7 | # |
8 | # .B name() | |
9 | # | |
10 | # while in others they are like: | |
11 | # | |
12 | # .BR name () | |
13 | # | |
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. | |
17 | # | |
18 | # Use the "-n" option for a dry run, in order to see what would be | |
19 | # done, without actually doing it. | |
20 | # | |
21 | ###################################################################### | |
22 | # | |
404b6a03 MK |
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. | |
28 | # | |
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). | |
34 | # | |
35 | # | |
f8fc5a23 MK |
36 | |
37 | file_base="tmp.$(basename $0)" | |
38 | ||
39 | work_dst_file="$file_base.dst" | |
40 | work_src_file="$file_base.src" | |
41 | ||
42 | all_files="$work_dst_file $work_src_file" | |
43 | ||
44 | # Command-line option processing | |
45 | ||
46 | really_do_it=1 | |
47 | while getopts "n" optname; do | |
48 | case "$optname" in | |
49 | n) really_do_it=0; | |
50 | ;; | |
51 | *) echo "Unknown option: $OPTARG" | |
52 | exit 1 | |
53 | ;; | |
54 | esac | |
55 | done | |
56 | ||
3511dcdb | 57 | shift $(( $OPTIND - 1 )) |
f8fc5a23 MK |
58 | |
59 | # Only process files with > 1 line -- single-line files are link files | |
60 | ||
3511dcdb | 61 | for page in $(wc "$@" 2> /dev/null | awk '$1 > 1 {print $4}'| \ |
f8fc5a23 MK |
62 | grep -v '^total'); do |
63 | ||
64 | cp $page $work_dst_file | |
65 | ||
66 | echo ">>>>>>>>>>>>>>>>>>>>>>>>>" $page "<<<<<<<<<<<<<<<<<<<<<<<<<" | |
67 | ||
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 '###' | |
78 | fi | |
79 | ||
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 | |
86 | ||
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 | |
92 | ||
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 | |
98 | ||
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 | |
105 | ||
106 | if ! cmp -s $page $work_dst_file; then | |
107 | diff -u $page $work_dst_file | |
108 | ||
109 | if test $really_do_it -ne 0; then | |
110 | cat $work_dst_file > $page | |
111 | fi | |
112 | ||
113 | else | |
114 | echo "### NOTHING CHANGED" | |
115 | fi | |
116 | done | |
117 | ||
118 | # clean up | |
119 | ||
120 | rm -f $all_files | |
121 | exit 0 |