File: stripmine.awk

package info (click to toggle)
fis-gtm 7.1-006-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,908 kB
  • sloc: ansic: 344,906; asm: 5,184; csh: 4,859; sh: 2,000; awk: 294; makefile: 73; sed: 13
file content (152 lines) | stat: -rw-r--r-- 4,357 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#################################################################
#								#
# Copyright (c) 2010-2024 Fidelity National Information		#
# Services, Inc. and/or its subsidiaries. All rights reserved.	#
#								#
#	This source code contains the intellectual property	#
#	of its copyright holder(s), and is made available	#
#	under a license.  If you do not know the terms of	#
#	the license, please stop and do not read further.	#
#								#
#################################################################
#
# Part of gengtmdeftypes.
#
# Script to scrub preprocessor output of routine with all header files. Actions performed:
#   a. Eliminates all statements other than "typedef" statements.
#   b. Puts spaces around all tokens, all special chars.
#   c. Eliminates multiple adjacent white space chars to make easy parsing for $ZPiece().
#
BEGIN \
{
	curlylevel = 0;
	bracketlevel = 0;
	parenlevel = 0;
	typedefactv = 0;
	prevfield = "";
	#
	# Read in the list of structures we are interested in
	#
	while (0 < (getline < "gtmtypelist.txt"))
		structs[$1]=""
	#
	# Read in the list of excluded structures and remove them from structs
	#
	while (0 < (getline < "gtmexcludetypelist.txt"))
	{
		if ("#" == $1)
			continue;
		delete structs[$1]
	}
}

#
# Main
#
{
	gsub("\".*\"", " ");	# Eliminate double-quoted strings from consideration - don't need them for our parse
	gsub("'.*'", " ");	# Eliminate single-quoted strings from consideration - don't need them for our parse
	#
	# These gsubs are to isolate specific chars with surrounding spaces so our parse can recognize them
	#
	gsub("\\[", " & ");	# AIX awk doesn't (at least at one point) allow for putting [ within a [] block hence
	                        # this is separate from the following line(s).
	gsub("\\]", " & ");
	gsub("[#;:,)({}=*]", " & ");
	#
	# Change 2 word types to single word for more consistent (less complex) parsing
	#
	gsub("unsigned long long", "unsigned-long-long");
	gsub("long long", "long-long");
	gsub("unsigned int", "unsigned-int");
	gsub("unsigned long", "unsigned-long");
	gsub("unsigned short", "unsigned-short");
	gsub("unsigned char", "unsigned-char");
	gsub("unsigned int", "unsigned-int");
	gsub("short unsigned", "unsigned-short");
	gsub("signed int", "int");
	gsub("short int", "short");
	gsub("signed short", "short");
	gsub("signed char", "char");
	#
	# Select only typedef types records
	#
	if ("#" == $1)
		next;
	if ("typedef" == $1)
	{
		if (1 == typedefactv)
		{
			print "ERROR - found typedef while typedefactv is set at record", NR;
			exit 1;
		}
		tokenssincetypedef = -1;	# Since we increment it for the typedef as well
		parenssincetypedef = 0;
		isfnptr=0;
		typedefactv = 1;
		foundstruct = 0;
		linecnt = 0;
	}
	if (typedefactv)
	{
		if ("" == $1)
			next;			# Ignore blank lines
		for (i = 1; NF >= i; ++i)	# Process fields of this line in streaming mode
		{
			tokenssincetypedef++;	# allow us to track topside
			if ("{" == $i)
				curlylevel++;	# So we know when we are done with this typedef
			else if ("}" == $i)
				curlylevel--;
			else if ("[" == $i)
				bracketlevel++;
			else if ("]" == $i)
				bracketlevel--;
			else if ("(" == $i)
			{
				parenlevel++;
				if (2 == tokenssincetypedef && 0 == parenssincetypedef && "*" == $(i+1))
				{	# Probable function pointer definition
					i++;	# Get rid of "("
					i++;	# Get rid of "*"
					if ("volatile" == $i) i++;	# Ignore volatile in this definition
					prevfield = $i;
					prevfldnum = i;
					isfnptr = 1;	# Prevents prevfield from being updated thus maintaining the type we found
				}
				parenssincetypedef++;
			} else if (")" == $i)
				parenlevel--;
			else if (0 == curlylevel && 0 == bracketlevel && (";" == $i || "," == $i))
			{
				if (prevfield in structs)
					foundstruct = 1;
				if (";" == $i)
					typedefactv = 0;
			}
			if (0 == bracketlevel && "]" != $i && 0 == parenlevel && ")" != $i && !isfnptr)
				prevfield = $i;
		}
		#
		# space elimination for easier (and faster) GT.M parsing
		#
		line = "";
		for (i = 1; NF >= i; ++i)
		{
			if (1 != i)
				line = line " " $i
			else
				line = $i
		}
		lines[++linecnt] = line;
		if (0 == typedefactv)
		{	# end of typedef - flush out accumulated lines if this was a structure we care about
			if (foundstruct)
			{
				for (i = 1; linecnt >= i; ++i)
					print lines[i];
				printf("\n");
			}
		}
	}
}