summaryrefslogtreecommitdiff
path: root/scripts/unformat_parens.sh
blob: 4b68bdd5787acbbf24d65a6dfe09deb94e15bc87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
#
# unformat_parens.sh
#
# The manual pages before 2.10 treat format parentheses
# inconsistently.  In some cases they are like
#
#       .B name()
#
# while in others they are like:
#
#       .BR name ()
#
# This script changes instances to the latter format.
# It does not fix all such instances: some will have to be 
# done manually.
#
# Use the "-n" option for a dry run, in order to see what would be
# done, without actually doing it.
#
######################################################################
#

file_base="tmp.$(basename $0)"

work_dst_file="$file_base.dst"
work_src_file="$file_base.src"

all_files="$work_dst_file $work_src_file"

# Command-line option processing

really_do_it=1
while getopts "n" optname; do
    case "$optname" in
    n)	really_do_it=0;
    	;;
    *)  echo "Unknown option: $OPTARG"
        exit 1
	;;
    esac
done

shift $(( OPTIND - 1 ))

# Only process files with > 1 line -- single-line files are link files 

for page in $(wc $* 2> /dev/null | awk '$1 > 1 {print $4}'| \
    grep -v '^total'); do

    cp $page $work_dst_file

    echo ">>>>>>>>>>>>>>>>>>>>>>>>>" $page "<<<<<<<<<<<<<<<<<<<<<<<<<"

    if false; then
    grep '^\.I *[a-z0-9_][a-z0-9_]*()$' $page
    grep '^\.B *[a-z0-9_][a-z0-9_]*()$' $page
    echo '###'
    grep '^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*()$' $page
    echo '###'
    grep '^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*() [^"]*$' $page
    echo '###'
    grep '()\\f[PR]' $page
    echo '###'
    fi

    cp $work_dst_file $work_src_file
    cat $work_src_file | \
	sed \
	-e '/^\.B *[a-z0-9_][a-z0-9_]*() *$/s/^\.B/.BR/' \
	-e '/^\.I *[a-z0-9_][a-z0-9_]*() *$/s/^\.I/.IR/' \
	> $work_dst_file

    cp $work_dst_file $work_src_file
    cat $work_src_file | \
	sed \
	-e '/^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*()$/s/()/ ()/' \
	> $work_dst_file

    cp $work_dst_file $work_src_file
    cat $work_src_file | \
	sed \
	-e '/^\.[BIR][BIR] *[a-z0-9_][a-z0-9_]*() [^"]*$/s/() / ()/' \
	> $work_dst_file

    cp $work_dst_file $work_src_file
    cat $work_src_file | \
	sed \
	-e '/()\\fP/s/()\\fP/\\fP()/g' \
	-e '/()\\fR/s/()\\fR/\\fR()/g' \
	> $work_dst_file

    if ! cmp -s $page $work_dst_file; then
        diff -u $page $work_dst_file

	if test $really_do_it -ne 0; then
            cat $work_dst_file > $page
	fi

    else
        echo "### NOTHING CHANGED"
    fi
done

# clean up

rm -f $all_files
exit 0