vdso.7: Update CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE info for powerpc
[man-pages.git] / scripts / check_unbalanced_macros.sh
blobcd547e120407d2db32e5974ce5c1ad435b552516
1 #!/bin/bash
3 # check_unbalanced_macros.sh
5 # Dec 2007, Michael Kerrisk
7 # Look for unbalanced pairs of macros in man page source files, with
8 # $1 and $2 specifying the macro pair. These arguments should
9 # _not_ include the leading dot (.) in the macro.
10 # As output, the program prints the line numbers containing each macro,
11 # and if an unbalanced macro is detected, the string "UNBALANCED!"
12 # is printed.
14 # Example usage:
16 # sh check_unbalanced_macros.sh nf fi */*.[1-8]
17 # sh check_unbalanced_macros.sh RS RE */*.[1-8]
18 # sh check_unbalanced_macros.sh EX EE */*.[1-8]
20 ######################################################################
22 # (C) Copyright 2020, Michael Kerrisk
23 # This program is free software; you can redistribute it and/or
24 # modify it under the terms of the GNU General Public License
25 # as published by the Free Software Foundation; either version 2
26 # of the License, or (at your option) any later version.
28 # This program is distributed in the hope that it will be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 # GNU General Public License for more details
32 # (http://www.gnu.org/licenses/gpl-2.0.html).
35 if test $# -lt 4; then
36 echo "Usage: $0 opener closer pages..."
37 exit 1
40 opener="$1"
41 closer="$2"
42 shift 2
44 for f in $@; do
45 if egrep "^\.($opener|$closer)" $f > /dev/null; then
46 echo "================== $f"
48 nl -ba $f |
49 awk 'BEGIN { level = 0 }
51 $2 == "'".$opener"'" { level++ }
53 $2 == "'".$opener"'" || $2 == "'".$closer"'" {
54 printf "%s %s %d", $1, $2, level
55 if (level == 0)
56 print " UNBALANCED!"
57 else
58 print ""
61 $2 == "'".$closer"'" { level-- }
63 END {
64 if (level != 0)
65 print "UNBALANCED!"
68 done