summaryrefslogtreecommitdiffstats
path: root/src/lib/kStuff/kProfiler2/kPrf2WinApi-pre.sed
blob: de90156b6f686c21dee7b84c8140d226414e916a (plain)
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
# $Id: kPrf2WinApi-pre.sed 29 2009-07-01 20:30:29Z bird $
## @file
# This SED script will try normalize a windows header
# in order to make it easy to pick out function prototypes.
#

#
# Copyright (c) 2008 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#


# Drop all preprocessor lines (#if/#else/#endif/#define/#undef/#pragma/comments)
# (we don't bother with multi line comments ATM.)
/^[[:space:]]*#/b drop_line
/^[[:space:]]*\/\//b drop_line

# Drop empty lines.
/^[[:space:]]*$/b drop_line

# Drop trailing comments and trailing whitespace
s/[[:space:]][[:space:]]*\/\.*$//g
s,[[:space:]][[:space:]]*/\*[^*/]*\*/[[:space:]]*$,,g
s/[[:space:]][[:space:]]*$//g

# Pick out the WINBASEAPI stuff (WinBase.h)
/^WINBASEAPI/b winapi
/^NTSYSAPI/b winapi
/^WINAPI$/b winapi_perhaps
/^APIENTRY$/b winapi_perhaps
h
d
b end

# No WINBASEAPI, so we'll have to carefully check the hold buffer.
:winapi_perhaps
x
/^[A-Z][A-Z0-9_][A-Z0-9_]*[A-Z0-9]$/!b drop_line
G
s/\r/ /g
s/\n/ /g
b winapi

# Make it one line and a bit standardized
:winapi
/;/b winapi_got_it
N
b winapi
:winapi_got_it
s/\n/ /g
s/[[:space:]][[:space:]]*\/\*[^*/]*\*\/[[:space:]]*//g
s/[[:space:]][[:space:]]*(/(/g
s/)[[:space:]][[:space:]]*/)/g
s/(\([^[:space:]]\)/( \1/g
s/\([^[:space:]]\))/\1 )/g
s/[*]\([^[:space:]]\)/* \1/g
s/\([^[:space:]]\)[*]/\1 */g
s/[[:space:]][[:space:]]*/ /g
s/[[:space:]][[:space:]]*,/,/g
s/,/, /g
s/,[[:space:]][[:space:]]*/, /g

# Drop the nasty bit of the sal.h / SpecString.h stuff.
s/[[:space:]]__[a-z][a-z_]*([^()]*)[[:space:]]*/ /g
s/[[:space:]]__out[a-z_]*[[:space:]]*/ /g
s/[[:space:]]__in[a-z_]*[[:space:]]*/ /g
s/[[:space:]]__deref[a-z_]*[[:space:]]*/ /g
s/[[:space:]]__reserved[[:space:]]*/ /g
s/[[:space:]]__nullnullterminated[[:space:]]*/ /g
s/[[:space:]]__checkReturn[[:space:]]*/ /g

# Drop some similar stuff.
s/[[:space:]]OPTIONAL[[:space:]]/ /g
s/[[:space:]]OPTIONAL,/ ,/g

# The __declspec() bit isn't necessary
s/WINBASEAPI *//
s/NTSYSAPI *//
s/DECLSPEC_NORETURN *//
s/__declspec([^()]*) *//

# Normalize spaces.
s/[[:space:]]/ /g

# Clear the hold space
x
s/^.*$//
x
b end

:drop_line
s/^.*$//
h
d

:end