3 # Find all man pages, and check they do not have groff syntax errors
6 # Sami Kerola <kerolasa@iki.fi>
8 set -e # exit on errors
9 set -o pipefail
# exit if pipe writer fails
10 set -u # disallow usage of unset variables
11 set -C # disallow redirection file overwriting
12 SCRIPT_INVOCATION_SHORT_NAME
=$
(basename ${0})
13 trap 'echo "${SCRIPT_INVOCATION_SHORT_NAME}: exit on error"; exit 1' ERR
16 echo "Usage: ${0} [-vVh]"
17 echo " -v verbose messaging"
18 echo " -V print version and exit"
19 echo " -h print this help and exit"
23 while getopts vVh OPTIONS
; do
29 echo "util-linux: ${SCRIPT_INVOCATION_SHORT_NAME}: v2.1"
42 # Try to find missing manuals matching build targets with manual files.
43 declare -A MAN_LIST BIN_LIST
46 declare -i COUNT_GROG
=0
47 declare -i COUNT_TROFF
=0
48 declare -i COUNT_REPEATS
=0
50 declare -A KNOWN_REPEATS
51 KNOWN_REPEATS
[mount
.8]='foo l2 l c'
52 KNOWN_REPEATS
[hexdump.1]='l'
53 KNOWN_REPEATS
[flock
.1]='"$0"'
54 KNOWN_REPEATS
[switch_root
.8]='$DIR'
59 for KN
in ${KNOWN_REPEATS[${I##*/}]}; do
60 if [ "${KN}" = "${REPEATS[$1]}" ]; then
62 echo "info: ${I} removing repeat: ${REPEATS[$1]}"
70 cd $
(git rev-parse
--show-toplevel)
73 find .
-type f
-name '*[[:alpha:]].[1-8]' |
grep -v "autom4te.cache\|\.libs/"
76 MAN_LIST
[${MAN_FILE%%.[0-9]}]=1
77 if awk '{if (1 < NR) {exit 1}; if ($1 ~ /^.so$/) {exit 0}}' ${I}; then
78 # Some manuals, such as x86_64, call inclusion and they
79 # should not be tested any further.
81 printf "skipping: ${I}: includes "
90 cat ${I} | troff
-mandoc -ww -z |
& grep "<" && RET
=$?
92 echo "From: cat ${I} | troff -mandoc -ww -z"
93 echo "=================================================="
97 if command -v lexgrog
&> /dev
/null
; then
98 if ! lexgrog
${I} >/dev
/null
; then
99 echo "error: run: lexgrog ${I}"
100 echo "=================================================="
103 elif command -v grog
&> /dev
/null
; then
104 if ! grog
${I} |
grep man
>/dev
/null
; then
105 echo "error: grog ${I} is not a man file"
106 echo "=================================================="
112 REPEATS
=( $
(cat ${I} | troff
-mandoc -Tascii 2>/dev
/null | grotty |
114 sed -e 's/\s\+/\n/g; /^$/d' |
115 awk 'BEGIN { p="" } { if (0 < length($0)) { if (p == $0) { print } } p = $0 }') )
116 if [ 0 -lt "${#REPEATS[@]}" ]; then
117 ITER
=${#REPEATS[@]}+1
119 remove_repeats
${ITER}
121 if [ 0 -lt "${#REPEATS[@]}" ]; then
122 echo "warning: ${I} has repeating words: ${REPEATS[@]}"
123 echo "=================================================="
129 # Create a list of build targets.
130 for I
in $
(find $
(git rev-parse
--show-toplevel) -name 'Make*.am' |
xargs awk '
133 $1 ~ /^no(inst|dist)/ ||
139 if ($1 ~ /^lib.*_la/) {
144 sub(/switch.root/, "switch_root")
145 sub(/pivot.root/, "pivot_root")
151 # Find if build target does not have manual.
153 for I
in ${!BIN_LIST[@]}; do
154 if [ -v ${MAN_LIST[$I]} ]; then
155 echo "warning: ${SCRIPT_INVOCATION_SHORT_NAME}: ${I} does not have man page"
160 echo "${SCRIPT_INVOCATION_SHORT_NAME}: ${#BIN_LIST[*]} build targets were found"
161 echo "${SCRIPT_INVOCATION_SHORT_NAME}: ${#MAN_LIST[*]} files were tested"
163 if [ ${GROG} = 0 ]; then
164 echo "warning: neither grog nor lexgrog commands were found"
167 if [ ${COUNT_GROG} -ne 0 -o ${COUNT_TROFF} -ne 0 -o ${COUNT_REPEATS} -ne 0 ]; then
168 echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_GROG} files failed (lex)grog man-page test"
169 echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_TROFF} files failed troff parsing test"
170 echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_REPEATS} files have repeating words"
171 ITER
=${#MAN_LIST[*]}-${COUNT_GROG}-${COUNT_TROFF}-${COUNT_REPEATS}
172 echo "${SCRIPT_INVOCATION_SHORT_NAME}: ${ITER} man-pages approved"
176 if ! ${VERBOSE}; then
177 echo "${SCRIPT_INVOCATION_SHORT_NAME}: success"