aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2020-11-16 08:55:59 +0100
committerMichael Kerrisk <mtk.manpages@gmail.com>2020-11-16 11:26:23 +0100
commit5a659c0829e71e516b354200c48f6e0f7348d1b6 (patch)
tree8738571eaa74040a5cd5ac84d1716e2c6bf71358
parentb2d7a6f8d8dd29c79afdf35b8148d8e89bf25baa (diff)
downloadman-pages-5a659c0829e71e516b354200c48f6e0f7348d1b6.tar.gz
check_unbalanced_macros.sh: A script to look for unbalanced *roff/man macro pairs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rwxr-xr-xscripts/check_unbalanced_macros.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/check_unbalanced_macros.sh b/scripts/check_unbalanced_macros.sh
new file mode 100755
index 0000000000..cd547e1204
--- /dev/null
+++ b/scripts/check_unbalanced_macros.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+#
+# check_unbalanced_macros.sh
+#
+# Dec 2007, Michael Kerrisk
+#
+# Look for unbalanced pairs of macros in man page source files, with
+# $1 and $2 specifying the macro pair. These arguments should
+# _not_ include the leading dot (.) in the macro.
+# As output, the program prints the line numbers containing each macro,
+# and if an unbalanced macro is detected, the string "UNBALANCED!"
+# is printed.
+#
+# Example usage:
+#
+# sh check_unbalanced_macros.sh nf fi */*.[1-8]
+# sh check_unbalanced_macros.sh RS RE */*.[1-8]
+# sh check_unbalanced_macros.sh EX EE */*.[1-8]
+#
+######################################################################
+#
+# (C) Copyright 2020, Michael Kerrisk
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details
+# (http://www.gnu.org/licenses/gpl-2.0.html).
+#
+
+if test $# -lt 4; then
+ echo "Usage: $0 opener closer pages..."
+ exit 1
+fi
+
+opener="$1"
+closer="$2"
+shift 2
+
+for f in $@; do
+ if egrep "^\.($opener|$closer)" $f > /dev/null; then
+ echo "================== $f"
+
+ nl -ba $f |
+ awk 'BEGIN { level = 0 }
+
+ $2 == "'".$opener"'" { level++ }
+
+ $2 == "'".$opener"'" || $2 == "'".$closer"'" {
+ printf "%s %s %d", $1, $2, level
+ if (level == 0)
+ print " UNBALANCED!"
+ else
+ print ""
+ }
+
+ $2 == "'".$closer"'" { level-- }
+
+ END {
+ if (level != 0)
+ print "UNBALANCED!"
+ }'
+ fi
+done