summaryrefslogtreecommitdiffstats
path: root/src/tools/find_badmacros
blob: 58f43086e9a4e8ab037e9091daab8185bbe46d96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

# This script attempts to find bad ifdef's, i.e. ifdef's that use braces
# but not the do { ... } while (0) syntax
#
# src/tools/find_badmacros
#
# This is useful for running before pgindent

for FILE
do
	awk '	BEGIN		{was_define = "N"}
				{ if (was_define == "Y" &&
				      $0 ~ /^{/)
					printf "%s  %d\n", FILENAME, NR
				  if ($0 ~ /^#define/)
					was_define = "Y"
				  else
					was_define = "N"
				}' "$FILE"
	grep -on '^#define.*{' "$FILE" | grep -v 'do[ 	]*{'
done