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