1 | # $Id: kPrf2WinApi-pre.sed 29 2009-07-01 20:30:29Z bird $
|
---|
2 | ## @file
|
---|
3 | # This SED script will try normalize a windows header
|
---|
4 | # in order to make it easy to pick out function prototypes.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (c) 2008 Knut St. Osmundsen <[email protected]>
|
---|
9 | #
|
---|
10 | # Permission is hereby granted, free of charge, to any person
|
---|
11 | # obtaining a copy of this software and associated documentation
|
---|
12 | # files (the "Software"), to deal in the Software without
|
---|
13 | # restriction, including without limitation the rights to use,
|
---|
14 | # copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
15 | # copies of the Software, and to permit persons to whom the
|
---|
16 | # Software is furnished to do so, subject to the following
|
---|
17 | # conditions:
|
---|
18 | #
|
---|
19 | # The above copyright notice and this permission notice shall be
|
---|
20 | # included in all copies or substantial portions of the Software.
|
---|
21 | #
|
---|
22 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
23 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
24 | # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
25 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
26 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
27 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
28 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
29 | # OTHER DEALINGS IN THE SOFTWARE.
|
---|
30 | #
|
---|
31 |
|
---|
32 |
|
---|
33 | # Drop all preprocessor lines (#if/#else/#endif/#define/#undef/#pragma/comments)
|
---|
34 | # (we don't bother with multi line comments ATM.)
|
---|
35 | /^[[:space:]]*#/b drop_line
|
---|
36 | /^[[:space:]]*\/\//b drop_line
|
---|
37 |
|
---|
38 | # Drop empty lines.
|
---|
39 | /^[[:space:]]*$/b drop_line
|
---|
40 |
|
---|
41 | # Drop trailing comments and trailing whitespace
|
---|
42 | s/[[:space:]][[:space:]]*\/\.*$//g
|
---|
43 | s,[[:space:]][[:space:]]*/\*[^*/]*\*/[[:space:]]*$,,g
|
---|
44 | s/[[:space:]][[:space:]]*$//g
|
---|
45 |
|
---|
46 | # Pick out the WINBASEAPI stuff (WinBase.h)
|
---|
47 | /^WINBASEAPI/b winapi
|
---|
48 | /^NTSYSAPI/b winapi
|
---|
49 | /^WINAPI$/b winapi_perhaps
|
---|
50 | /^APIENTRY$/b winapi_perhaps
|
---|
51 | h
|
---|
52 | d
|
---|
53 | b end
|
---|
54 |
|
---|
55 | # No WINBASEAPI, so we'll have to carefully check the hold buffer.
|
---|
56 | :winapi_perhaps
|
---|
57 | x
|
---|
58 | /^[A-Z][A-Z0-9_][A-Z0-9_]*[A-Z0-9]$/!b drop_line
|
---|
59 | G
|
---|
60 | s/\r/ /g
|
---|
61 | s/\n/ /g
|
---|
62 | b winapi
|
---|
63 |
|
---|
64 | # Make it one line and a bit standardized
|
---|
65 | :winapi
|
---|
66 | /;/b winapi_got_it
|
---|
67 | N
|
---|
68 | b winapi
|
---|
69 | :winapi_got_it
|
---|
70 | s/\n/ /g
|
---|
71 | s/[[:space:]][[:space:]]*\/\*[^*/]*\*\/[[:space:]]*//g
|
---|
72 | s/[[:space:]][[:space:]]*(/(/g
|
---|
73 | s/)[[:space:]][[:space:]]*/)/g
|
---|
74 | s/(\([^[:space:]]\)/( \1/g
|
---|
75 | s/\([^[:space:]]\))/\1 )/g
|
---|
76 | s/[*]\([^[:space:]]\)/* \1/g
|
---|
77 | s/\([^[:space:]]\)[*]/\1 */g
|
---|
78 | s/[[:space:]][[:space:]]*/ /g
|
---|
79 | s/[[:space:]][[:space:]]*,/,/g
|
---|
80 | s/,/, /g
|
---|
81 | s/,[[:space:]][[:space:]]*/, /g
|
---|
82 |
|
---|
83 | # Drop the nasty bit of the sal.h / SpecString.h stuff.
|
---|
84 | s/[[:space:]]__[a-z][a-z_]*([^()]*)[[:space:]]*/ /g
|
---|
85 | s/[[:space:]]__out[a-z_]*[[:space:]]*/ /g
|
---|
86 | s/[[:space:]]__in[a-z_]*[[:space:]]*/ /g
|
---|
87 | s/[[:space:]]__deref[a-z_]*[[:space:]]*/ /g
|
---|
88 | s/[[:space:]]__reserved[[:space:]]*/ /g
|
---|
89 | s/[[:space:]]__nullnullterminated[[:space:]]*/ /g
|
---|
90 | s/[[:space:]]__checkReturn[[:space:]]*/ /g
|
---|
91 |
|
---|
92 | # Drop some similar stuff.
|
---|
93 | s/[[:space:]]OPTIONAL[[:space:]]/ /g
|
---|
94 | s/[[:space:]]OPTIONAL,/ ,/g
|
---|
95 |
|
---|
96 | # The __declspec() bit isn't necessary
|
---|
97 | s/WINBASEAPI *//
|
---|
98 | s/NTSYSAPI *//
|
---|
99 | s/DECLSPEC_NORETURN *//
|
---|
100 | s/__declspec([^()]*) *//
|
---|
101 |
|
---|
102 | # Normalize spaces.
|
---|
103 | s/[[:space:]]/ /g
|
---|
104 |
|
---|
105 | # Clear the hold space
|
---|
106 | x
|
---|
107 | s/^.*$//
|
---|
108 | x
|
---|
109 | b end
|
---|
110 |
|
---|
111 | :drop_line
|
---|
112 | s/^.*$//
|
---|
113 | h
|
---|
114 | d
|
---|
115 |
|
---|
116 | :end
|
---|
117 |
|
---|