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