1 | # $Id: kPrf2WinApi-pre.sed 13 2008-04-20 10:13:43Z 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 | # This file is part of kProfiler.
|
---|
11 | #
|
---|
12 | # kProfiler is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU Lesser General Public
|
---|
14 | # License as published by the Free Software Foundation; either
|
---|
15 | # version 2.1 of the License, or (at your option) any later version.
|
---|
16 | #
|
---|
17 | # kProfiler is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | # Lesser General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU Lesser General Public
|
---|
23 | # License along with kProfiler; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
25 | #
|
---|
26 |
|
---|
27 |
|
---|
28 | # Drop all preprocessor lines (#if/#else/#endif/#define/#undef/#pragma/comments)
|
---|
29 | # (we don't bother with multi line comments ATM.)
|
---|
30 | /^[[:space:]]*#/b drop_line
|
---|
31 | /^[[:space:]]*\/\//b drop_line
|
---|
32 |
|
---|
33 | # Drop empty lines.
|
---|
34 | /^[[:space:]]*$/b drop_line
|
---|
35 |
|
---|
36 | # Drop trailing comments and trailing whitespace
|
---|
37 | s/[[:space:]][[:space:]]*\/\.*$//g
|
---|
38 | s,[[:space:]][[:space:]]*/\*[^*/]*\*/[[:space:]]*$,,g
|
---|
39 | s/[[:space:]][[:space:]]*$//g
|
---|
40 |
|
---|
41 | # Pick out the WINBASEAPI stuff (WinBase.h)
|
---|
42 | /^WINBASEAPI/b winapi
|
---|
43 | /^NTSYSAPI/b winapi
|
---|
44 | /^WINAPI$/b winapi_perhaps
|
---|
45 | /^APIENTRY$/b winapi_perhaps
|
---|
46 | h
|
---|
47 | d
|
---|
48 | b end
|
---|
49 |
|
---|
50 | # No WINBASEAPI, so we'll have to carefully check the hold buffer.
|
---|
51 | :winapi_perhaps
|
---|
52 | x
|
---|
53 | /^[A-Z][A-Z0-9_][A-Z0-9_]*[A-Z0-9]$/!b drop_line
|
---|
54 | G
|
---|
55 | s/\r/ /g
|
---|
56 | s/\n/ /g
|
---|
57 | b winapi
|
---|
58 |
|
---|
59 | # Make it one line and a bit standardized
|
---|
60 | :winapi
|
---|
61 | /;/b winapi_got_it
|
---|
62 | N
|
---|
63 | b winapi
|
---|
64 | :winapi_got_it
|
---|
65 | s/\n/ /g
|
---|
66 | s/[[:space:]][[:space:]]*\/\*[^*/]*\*\/[[:space:]]*//g
|
---|
67 | s/[[:space:]][[:space:]]*(/(/g
|
---|
68 | s/)[[:space:]][[:space:]]*/)/g
|
---|
69 | s/(\([^[:space:]]\)/( \1/g
|
---|
70 | s/\([^[:space:]]\))/\1 )/g
|
---|
71 | s/[*]\([^[:space:]]\)/* \1/g
|
---|
72 | s/\([^[:space:]]\)[*]/\1 */g
|
---|
73 | s/[[:space:]][[:space:]]*/ /g
|
---|
74 | s/[[:space:]][[:space:]]*,/,/g
|
---|
75 | s/,/, /g
|
---|
76 | s/,[[:space:]][[:space:]]*/, /g
|
---|
77 |
|
---|
78 | # Drop the nasty bit of the sal.h / SpecString.h stuff.
|
---|
79 | s/[[:space:]]__[a-z][a-z_]*([^()]*)[[:space:]]*/ /g
|
---|
80 | s/[[:space:]]__out[a-z_]*[[:space:]]*/ /g
|
---|
81 | s/[[:space:]]__in[a-z_]*[[:space:]]*/ /g
|
---|
82 | s/[[:space:]]__deref[a-z_]*[[:space:]]*/ /g
|
---|
83 | s/[[:space:]]__reserved[[:space:]]*/ /g
|
---|
84 | s/[[:space:]]__nullnullterminated[[:space:]]*/ /g
|
---|
85 | s/[[:space:]]__checkReturn[[:space:]]*/ /g
|
---|
86 |
|
---|
87 | # Drop some similar stuff.
|
---|
88 | s/[[:space:]]OPTIONAL[[:space:]]/ /g
|
---|
89 | s/[[:space:]]OPTIONAL,/ ,/g
|
---|
90 |
|
---|
91 | # The __declspec() bit isn't necessary
|
---|
92 | s/WINBASEAPI *//
|
---|
93 | s/NTSYSAPI *//
|
---|
94 | s/DECLSPEC_NORETURN *//
|
---|
95 | s/__declspec([^()]*) *//
|
---|
96 |
|
---|
97 | # Normalize spaces.
|
---|
98 | s/[[:space:]]/ /g
|
---|
99 |
|
---|
100 | # Clear the hold space
|
---|
101 | x
|
---|
102 | s/^.*$//
|
---|
103 | x
|
---|
104 | b end
|
---|
105 |
|
---|
106 | :drop_line
|
---|
107 | s/^.*$//
|
---|
108 | h
|
---|
109 | d
|
---|
110 |
|
---|
111 | :end
|
---|
112 |
|
---|