summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/buildtools/map-list-symbol.sh
blob: 5509b4a7faf7f32ab8afd566a4de827564e6795e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2018 David Marchand <david.marchand@redhat.com>

section=all
symbol=all
quiet=

while getopts 'S:s:q' name; do
	case $name in
	S)
		[ $section = 'all' ] || {
			echo 'Cannot list in multiple sections'
			exit 1
		}
		section=$OPTARG
	;;
	s)
		[ $symbol = 'all' ] || {
			echo 'Cannot list multiple symbols'
			exit 1
		}
		symbol=$OPTARG
	;;
	q)
		quiet='y'
	;;
	?)
		echo 'usage: $0 [-S section] [-s symbol] [-q]'
		exit 1
	;;
	esac
done

shift $(($OPTIND - 1))

for file in $@; do
	cat "$file" |awk '
	BEGIN {
		current_section = "";
		if ("'$section'" == "all" && "'$symbol'" == "all") {
			ret = 0;
		} else {
			ret = 1;
		}
	}
	/^.*{/ {
		if ("'$section'" == "all" || $1 == "'$section'") {
			current_section = $1;
		}
	}
	/.*}/ { current_section = ""; }
	/^[^}].*[^:*];/ {
		if (current_section != "") {
			gsub(";","");
			if ("'$symbol'" == "all" || $1 == "'$symbol'") {
				ret = 0;
				if ("'$quiet'" == "") {
					print "'$file' "current_section" "$1;
				}
				if ("'$symbol'" != "all") {
					exit 0;
				}
			}
		}
	}
	END {
		exit ret;
	}'
done