]> git.ipfire.org Git - thirdparty/man-pages.git/blob - scripts/unformat_parens.sh
Name change
[thirdparty/man-pages.git] / scripts / unformat_parens.sh
1 #!/bin/sh
2 #
3 # unformat_parens.sh
4 #
5 # The manual pages before 2.10 treat format parentheses
6 # inconsistently. In some cases they are like
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 #
23
24 file_base="tmp.$(basename $0)"
25
26 work_dst_file="$file_base.dst"
27 work_src_file="$file_base.src"
28
29 all_files="$work_dst_file $work_src_file"
30
31 # Command-line option processing
32
33 really_do_it=1
34 while getopts "n" optname; do
35 case "$optname" in
36 n) really_do_it=0;
37 ;;
38 *) echo "Unknown option: $OPTARG"
39 exit 1
40 ;;
41 esac
42 done
43
44 shift $(( OPTIND - 1 ))
45
46 # Only process files with > 1 line -- single-line files are link files
47
48 for page in $(wc $* 2> /dev/null | awk '$1 > 1 {print $4}'| \
49 grep -v '^total'); do
50
51 cp $page $work_dst_file
52
53 echo ">>>>>>>>>>>>>>>>>>>>>>>>>" $page "<<<<<<<<<<<<<<<<<<<<<<<<<"
54
55 if false; then
56 grep '^\.I *[a-z0-9_][a-z0-9_]*()$' $page
57 grep '^\.B *[a-z0-9_][a-z0-9_]*()$' $page
58 echo '###'
59 grep '^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*()$' $page
60 echo '###'
61 grep '^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*() [^"]*$' $page
62 echo '###'
63 grep '()\\f[PR]' $page
64 echo '###'
65 fi
66
67 cp $work_dst_file $work_src_file
68 cat $work_src_file | \
69 sed \
70 -e '/^\.B *[a-z0-9_][a-z0-9_]*() *$/s/^\.B/.BR/' \
71 -e '/^\.I *[a-z0-9_][a-z0-9_]*() *$/s/^\.I/.IR/' \
72 > $work_dst_file
73
74 cp $work_dst_file $work_src_file
75 cat $work_src_file | \
76 sed \
77 -e '/^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*()$/s/()/ ()/' \
78 > $work_dst_file
79
80 cp $work_dst_file $work_src_file
81 cat $work_src_file | \
82 sed \
83 -e '/^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*() [^"]*$/s/() / ()/' \
84 > $work_dst_file
85
86 cp $work_dst_file $work_src_file
87 cat $work_src_file | \
88 sed \
89 -e '/()\\fP/s/()\\fP/\\fP()/g' \
90 -e '/()\\fR/s/()\\fR/\\fR()/g' \
91 > $work_dst_file
92
93 if ! cmp -s $page $work_dst_file; then
94 diff -u $page $work_dst_file
95
96 if test $really_do_it -ne 0; then
97 cat $work_dst_file > $page
98 fi
99
100 else
101 echo "### NOTHING CHANGED"
102 fi
103 done
104
105 # clean up
106
107 rm -f $all_files
108 exit 0