File: audit-man-spell

package info (click to toggle)
pcp 6.3.8-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 235,180 kB
  • sloc: ansic: 1,253,622; sh: 173,998; xml: 160,490; cpp: 83,331; python: 20,482; perl: 18,302; yacc: 6,886; makefile: 2,955; lex: 2,862; fortran: 60; java: 52
file content (151 lines) | stat: -rwxr-xr-x 3,233 bytes parent folder | download
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
#
# Audit the man-spell +ok+ exceptions in man pages
#
# Copyright (c) 2024 Ken McDonell, Inc.  All Rights Reserved.
#

usage="Usage: audit-man-spell [-d] [man-src-file ...]"

export LC_COLATE=POSIX

if which ispell >/dev/null 2>&1
then
    :
else
    echo "Arrgh: ispell not installed, no dice"
    exit 1
fi

if which man-spell >/dev/null 2>&1
then
    :
else
    echo "Arrgh: man-spell not on $PATH, no dice"
    exit 1
fi

tmp=/tmp/audit-man-spell-$$
rm -f $tmp.*
status=1	# failure is the default
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

# file(1) does not work, so need some heuristics
# ... assume existance of $1 already established
#
_istroff()
{
    # shell or other script?
    head -1 "$1" | grep -q '^#!' && return 1
    # generated by podman?
    head -1 "$1" | grep -q 'by Pod::Man' && return 1
    # -man macros?
    grep -q '^\.SH ' <"$1" && return 0
    return 1
}

debug=0
while getopts "d?" c
do
    case $c
    in
	d)	debug=`expr $debug + 1`
		;;
	?)	echo >&2 "$usage"
		exit
		;;
    esac
done
shift `expr $OPTIND - 1`

# Algorithm ... for each input file ...
# - if there +ok+ ctl lines, then ...
#   + cut out the ctl lines (exceptions) and split into strings
#     and patterns
#   + man-spell the edited file
#   + for each exception string in the ctl lines ...
#     if it removes one or more misspelled words, that's good, else
#     flag the exception string as redundant
#   + patterns are a bit trickier to detect if they are making a
#     useful contribution (see below)
#
if [ $# -gt 0 ]
then
    for arg; do echo $arg; done
else
    find * -follow -name '*.[1-9]*' -type f
fi \
| while read file
do
    if [ ! -f "$file" ]
    then
	echo "$file: not found"
	continue
    fi
    if _istroff "$file"
    then
	# smells like troff man source ...
	#
	rm -f $tmp.errs
	[ $debug -gt 0 ] && echo "$file:"
	if grep -q '^\.\\" +ok+ ' <$file
	then
	    # has exceptions ...
	    #
	    grep '^\.\\" +ok+ ' <$file \
	    | sed \
		-e 's/^\.\\" +ok+ //' \
		-e 's/{[^}]*}//g' \
		-e 's/[ 	][ 	]*/ /g' \
		-e 's/ *$//' \
		-e 's/^ *//' \
		-e '/^ *$/d' \
	    | tr ' ' '\012' >$tmp.except
	    if [ $debug -gt 1 ]
	    then
		( echo "Current exceptions:"; cat $tmp.except ) | fmt >&2
	    fi
	    grep -v '^\.\\" +ok+ ' <$file >$tmp.in
	    man-spell $tmp.in 2>$tmp.err >$tmp.misspell
	    if [ $debug -gt 1 -a -s $tmp.err ]
	    then
		echo >&2 "Warnings from man-spell ..."
		cat >&2 $tmp.err
	    fi
	    cat $tmp.except \
	    | while read except
	    do
		if grep -q "^$except\$" <$tmp.misspell
		then
		    [ $debug -gt 2 ] && echo >&2 "= $except"
		    grep -v "^$except\$" <$tmp.misspell >$tmp.tmp
		    mv $tmp.tmp $tmp.misspell
		else
		    if [ ! -f $tmp.errs ]
		    then
			[ $debug -eq 0 ] && echo "$file:"
			echo "Exceptions not needed ..."
			touch $tmp.errs
		    fi
		    echo "- $except"
		fi
	    done
	    if [ -s $tmp.misspell ]
	    then
		if [ ! -f $tmp.errs -a $debug -eq 0 ]
		then
		    echo "$file:"
		    touch $tmp.errs
		fi
		echo "Additional exceptions required ..."
		sed -e 's/^/+ /' <$tmp.misspell
	    fi
	else
	    [ $debug -gt 0 ] && echo >&2 "$file: no exceptions"
	fi
    else
	[ $debug -gt 0 ] && echo >&2 "$file: skipped (not troff)"
    fi
done

exit