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 overlay'
52 KNOWN_REPEATS
[hexdump.1]='l'
53 KNOWN_REPEATS
[flock
.1]='"$0"'
54 KNOWN_REPEATS
[switch_root
.8]='$DIR'
55 KNOWN_REPEATS
[logger
.1]='-'
60 for KN
in ${KNOWN_REPEATS[${I##*/}]}; do
61 if [ "${KN}" = "${REPEATS[$1]}" ]; then
63 echo "info: ${I} removing repeat: ${REPEATS[$1]}"
71 cd $
(git rev-parse
--show-toplevel)
74 find .
-type f
-name '*[[:alpha:]].[1-8]' |
grep -v "autom4te.cache\|\.libs/\|\.git"
77 MAN_LIST
[${MAN_FILE%%.[0-9]}]=1
78 if awk '{if (1 < NR) {exit 1}; if ($1 ~ /^.so$/) {exit 0}}' ${I}; then
79 # Some manuals, such as x86_64, call inclusion and they
80 # should not be tested any further.
82 printf "skipping: ${I}: includes "
91 cat ${I} | troff
-mandoc -ww -z |
& grep "<" && RET
=$?
93 echo "From: cat ${I} | troff -mandoc -ww -z"
94 echo "=================================================="
98 if command -v lexgrog
&> /dev
/null
; then
99 if ! lexgrog
${I} >/dev
/null
; then
100 echo "error: run: lexgrog ${I}"
101 echo "=================================================="
104 elif command -v grog
&> /dev
/null
; then
105 if ! grog
${I} |
grep man
>/dev
/null
; then
106 echo "error: grog ${I} is not a man file"
107 echo "=================================================="
113 REPEATS
=( $
(cat ${I} | troff
-mandoc -Tascii 2>/dev
/null | grotty |
115 sed -e 's/\s\+/\n/g; /^$/d' |
116 awk 'BEGIN { p="" } { if (0 < length($0)) { if (p == $0) { print } } p = $0 }') )
117 if [ 0 -lt "${#REPEATS[@]}" ]; then
118 ITER
=${#REPEATS[@]}+1
120 remove_repeats
${ITER}
122 if [ 0 -lt "${#REPEATS[@]}" ]; then
123 echo "warning: ${I} has repeating words: ${REPEATS[@]}"
124 echo "=================================================="
130 # Create a list of build targets.
131 for I
in $
(find $
(git rev-parse
--show-toplevel) -name 'Make*.am' |
xargs awk '
134 $1 ~ /^no(inst|dist)/ ||
140 if ($1 ~ /^lib.*_la/) {
145 sub(/switch.root/, "switch_root")
146 sub(/pivot.root/, "pivot_root")
152 # Find if build target does not have manual.
154 for I
in ${!BIN_LIST[@]}; do
155 if [ -v ${MAN_LIST[$I]} ]; then
156 echo "warning: ${SCRIPT_INVOCATION_SHORT_NAME}: ${I} does not have man page"
161 echo "${SCRIPT_INVOCATION_SHORT_NAME}: ${#BIN_LIST[*]} build targets were found"
162 echo "${SCRIPT_INVOCATION_SHORT_NAME}: ${#MAN_LIST[*]} files were tested"
164 if [ ${GROG} = 0 ]; then
165 echo "warning: neither grog nor lexgrog commands were found"
168 if [ ${COUNT_GROG} -ne 0 ]; then
169 echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_GROG} files failed (lex)grog man-page test"
171 if [ ${COUNT_TROFF} -ne 0 ]; then
172 echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_TROFF} files failed troff parsing test"
174 if [ ${COUNT_REPEATS} -ne 0 ]; then
175 echo "error: ${SCRIPT_INVOCATION_SHORT_NAME}: ${COUNT_REPEATS} files have repeating words"
177 ITER
=${#MAN_LIST[*]}-${COUNT_GROG}-${COUNT_TROFF}-${COUNT_REPEATS}
178 echo "${SCRIPT_INVOCATION_SHORT_NAME}: ${ITER} man-pages approved"
180 if [ ${COUNT_GROG} -ne 0 -o ${COUNT_TROFF} -ne 0 -o ${COUNT_REPEATS} -ne 0 ]; then
184 if ! ${VERBOSE}; then
185 echo "${SCRIPT_INVOCATION_SHORT_NAME}: success"