xref: /xnu-12377.41.6/libsyscall/xcodescripts/filter_mig.awk (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions#!/usr/bin/awk -f
2*bbb1b6f9SApple OSS Distributions
3*bbb1b6f9SApple OSS Distributions# Usage: foo <template> <file>
4*bbb1b6f9SApple OSS Distributions# Searches through file for instances of 'kern_return_t $FOO'
5*bbb1b6f9SApple OSS Distributions# where $FOO is an line in the template file
6*bbb1b6f9SApple OSS Distributions# and prepends the first line in the template file.
7*bbb1b6f9SApple OSS Distributions
8*bbb1b6f9SApple OSS Distributions# Example template format:
9*bbb1b6f9SApple OSS Distributions#       %{
10*bbb1b6f9SApple OSS Distributions#       __WATCHOS_PROHIBITED
11*bbb1b6f9SApple OSS Distributions#       %}
12*bbb1b6f9SApple OSS Distributions#       act_get_state
13*bbb1b6f9SApple OSS Distributions#       thread_get_state
14*bbb1b6f9SApple OSS Distributions#
15*bbb1b6f9SApple OSS Distributions
16*bbb1b6f9SApple OSS Distributions# BEGIN { print ARGV[1]; print ARGV[2] }
17*bbb1b6f9SApple OSS Distributions
18*bbb1b6f9SApple OSS Distributions# In the first file, build array of lines
19*bbb1b6f9SApple OSS DistributionsNR==FNR && /^ *$/ {
20*bbb1b6f9SApple OSS Distributions	next
21*bbb1b6f9SApple OSS Distributions}
22*bbb1b6f9SApple OSS DistributionsNR==FNR && /^#/ {
23*bbb1b6f9SApple OSS Distributions	next
24*bbb1b6f9SApple OSS Distributions}
25*bbb1b6f9SApple OSS DistributionsNR==FNR && /%{/ {
26*bbb1b6f9SApple OSS Distributions	parse_prefix = 1
27*bbb1b6f9SApple OSS Distributions	prefix = ""
28*bbb1b6f9SApple OSS Distributions	next
29*bbb1b6f9SApple OSS Distributions}
30*bbb1b6f9SApple OSS DistributionsNR==FNR && /^%}/ {
31*bbb1b6f9SApple OSS Distributions	parse_prefix = 0
32*bbb1b6f9SApple OSS Distributions	next
33*bbb1b6f9SApple OSS Distributions}
34*bbb1b6f9SApple OSS DistributionsNR==FNR {
35*bbb1b6f9SApple OSS Distributions	if (parse_prefix && length(prefix)) {
36*bbb1b6f9SApple OSS Distributions		prefix = sprintf("%s\n%s", prefix, $0)
37*bbb1b6f9SApple OSS Distributions	} else if (parse_prefix) {
38*bbb1b6f9SApple OSS Distributions		prefix = $0
39*bbb1b6f9SApple OSS Distributions	} else if (length(templates[$0])) {
40*bbb1b6f9SApple OSS Distributions		templates[$0] = sprintf("%s\n%s", templates[$0], prefix)
41*bbb1b6f9SApple OSS Distributions	} else {
42*bbb1b6f9SApple OSS Distributions		templates[$0] = prefix
43*bbb1b6f9SApple OSS Distributions	}
44*bbb1b6f9SApple OSS Distributions	next
45*bbb1b6f9SApple OSS Distributions}
46*bbb1b6f9SApple OSS Distributions
47*bbb1b6f9SApple OSS Distributions# In the second file, match kern_return_t <template>
48*bbb1b6f9SApple OSS Distributions# at the beginning of the line
49*bbb1b6f9SApple OSS Distributions# print the prefix line if found
50*bbb1b6f9SApple OSS Distributions
51*bbb1b6f9SApple OSS Distributions/^kern_return_t/ {
52*bbb1b6f9SApple OSS Distributions#	print "match"
53*bbb1b6f9SApple OSS Distributions	if ($2 in templates) {
54*bbb1b6f9SApple OSS Distributions		print templates[$2]
55*bbb1b6f9SApple OSS Distributions	}
56*bbb1b6f9SApple OSS Distributions}
57*bbb1b6f9SApple OSS Distributions
58*bbb1b6f9SApple OSS Distributions# Pass through everything in the second file
59*bbb1b6f9SApple OSS Distributions{ print }
60