| 1 |
#!/bin/bash |
| 2 |
# SPDX-License-Identifier: BSD-3-Clause |
| 3 |
# Copyright 2019, Intel Corporation |
| 4 |
|
| 5 |
# check-manpage -- a tool to check a single man page against errors |
| 6 |
# |
| 7 |
# While it can handle multiple files, it's recommended to use |
| 8 |
# check-manpages instead. |
| 9 |
set -e |
| 10 |
|
| 11 |
check_link() |
| 12 |
{ |
| 13 |
[ $(wc -l <"$file") = 1 ] || |
| 14 |
{ echo ".so link isn't the only line" && return; } |
| 15 |
link=$(cat "$file") |
| 16 |
link=${link#.so } |
| 17 |
[ "${link##*/}" = "$link" ] || |
| 18 |
grep -q '^\.so man\([0-9]\)/[a-z0-9+_-]\+\.\1$' "$file" || |
| 19 |
{ echo ".so link directory is not matching manX" && return; } |
| 20 |
[ -e "${link##*/}" ] || |
| 21 |
{ echo ".so link target doesn't exist: ${link##*/}" && return; } |
| 22 |
} |
| 23 |
|
| 24 |
for m in "$@"; do |
| 25 |
dir="$(dirname $m)" |
| 26 |
file="$(basename $m)" |
| 27 |
[ -n "$dir" ] && pushd "$dir" >/dev/null |
| 28 |
|
| 29 |
if grep -q '^\.so' "$file"; then |
| 30 |
err=$(check_link) |
| 31 |
[ -z "$err" ] || { |
| 32 |
echo >&2 "$file: $err" |
| 33 |
FAILED=1 |
| 34 |
} |
| 35 |
popd >/dev/null 2>/dev/null |
| 36 |
continue |
| 37 |
fi |
| 38 |
|
| 39 |
# man can emit warnings and errors. Even non-fatal errors are normally |
| 40 |
# suppressed if a pager is in use (ie, all interactive usage). Common |
| 41 |
# messages include an unknown macro, an unbreakable line, etc. |
| 42 |
err=$(MANWIDTH=80 man --warnings -E UTF-8 -l -Tutf8 -Z "$file" 2>&1 >/dev/null| |
| 43 |
grep -v 'cannot adjust line' || true) |
| 44 |
[ -z "$err" ] || { |
| 45 |
echo >&2 "$file: $err" |
| 46 |
FAILED=1 |
| 47 |
} |
| 48 |
|
| 49 |
# If a "NAME" section exists, call lexgrog to see if it's properly |
| 50 |
# formatted. |
| 51 |
if grep -q '^\.SH NAME' "$file"; then |
| 52 |
if ! lexgrog "$file" >/dev/null; then |
| 53 |
# lexgrog doesn't give any interesting messages. |
| 54 |
echo 2>&1 "lexgrog failed on $file" |
| 55 |
FAILED=1 |
| 56 |
fi |
| 57 |
fi |
| 58 |
|
| 59 |
popd >/dev/null 2>/dev/null |
| 60 |
done |
| 61 |
|
| 62 |
exit $FAILED |