]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tools: add checkmans.sh
authorSami Kerola <kerolasa@iki.fi>
Sat, 2 Jun 2012 12:36:43 +0000 (14:36 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sat, 2 Jun 2012 18:29:07 +0000 (20:29 +0200)
A script to find whether all manuals has proper groff syntax.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Makefile.am
tools/checkmans.sh [new file with mode: 0755]

index 12e110336a2b7122e4ebf54bbd16186d4b228587..055cc4d8bcd00f250f80da1d95ea1332f991c331 100644 (file)
@@ -84,6 +84,9 @@ checkconfig:
                -name '*.[hcS]' -type f -print | sort -u \
                | xargs $(top_srcdir)/tools/checkconfig.sh $(top_srcdir)
 
+checkmans:
+       @$(top_srcdir)/tools/checkmans.sh
+
 checkxalloc:
        @ $(top_srcdir)/tools/checkxalloc.sh
 
diff --git a/tools/checkmans.sh b/tools/checkmans.sh
new file mode 100755 (executable)
index 0000000..e54ebed
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+#
+# Find all man pages, and check they do not have groff syntax errors
+# or warnings.
+#
+# Sami Kerola <kerolasa@iki.fi>
+
+set -e         # exit on errors
+set -o pipefail        # exit if pipe writer fails
+set -u         # disallow usage of unset variables
+set -C         # disallow redirection file overwriting
+SCRIPT_INVOCATION_SHORT_NAME=$(basename ${0})
+trap 'echo "${SCRIPT_INVOCATION_SHORT_NAME}: exit on error"; exit 1' ERR
+
+usage() {
+       echo "Usage: ${0} [-ph]"
+       echo " -p   print file names before checking"
+}
+
+PRINT_FILE_NAMES='false'
+while getopts ph OPTIONS; do
+       case ${OPTIONS} in
+               p)
+                       PRINT_FILE_NAMES='true'
+                       ;;
+               h)
+                       usage
+                       exit 0
+                       ;;
+               *)
+                       usage
+                       exit 1
+       esac
+done
+
+ERROR_FILE=$(mktemp ${SCRIPT_INVOCATION_SHORT_NAME}.XXXXXXXXXX)
+# remove tmp file at exit
+trap "rm -f ${ERROR_FILE}" 0
+
+for I in $(
+       find $(git rev-parse --show-toplevel) -name '*.[1-8]' |
+       egrep -v '(Documentation|.git|/.libs/|autom4te.cache|ru/ddate)'
+); do
+       # FIXME: the determination whether a manual does include
+       # should probably be somewhat smarter.
+       IS_INCLUDE=$(wc -w ${I} | awk '{print $1}')
+       if [ ${IS_INCLUDE} -eq 2 ]; then
+               # Some manuals, such as x86_64, call include which
+               # will read system manual.  Testing what comes from
+               # package does not make much sense, so skip doing it.
+               if ${PRINT_FILE_NAMES}; then
+                       echo "skipping: ${I}"
+               fi
+               continue
+       fi
+       if ${PRINT_FILE_NAMES}; then
+               echo "testing: ${I}"
+               man --warnings=all ${I} >/dev/null
+       else
+               man --warnings=all ${I} >/dev/null 2>> ${ERROR_FILE}
+       fi
+done
+
+COUNT_ERRORS=$(awk 'END {print NR}' ${ERROR_FILE})
+if [ ${COUNT_ERRORS} -ne 0 ]; then
+       echo "${SCRIPT_INVOCATION_SHORT_NAME}: failed"
+       echo "use: $(readlink -f ${0}) -p"
+       echo "     to find where the problems are."
+       exit 1
+fi
+
+if ! ${PRINT_FILE_NAMES}; then
+       echo "${SCRIPT_INVOCATION_SHORT_NAME}: success"
+fi
+exit 0