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