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