1 | # $Id: kPrf2WinApi-gencode.sed 11 2008-04-20 09:18:23Z bird $
|
---|
2 | ## @file
|
---|
3 | # Generate code (for kernel32).
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
8 | #
|
---|
9 | # This file is part of kProfiler.
|
---|
10 | #
|
---|
11 | # kProfiler is free software; you can redistribute it and/or
|
---|
12 | # modify it under the terms of the GNU Lesser General Public
|
---|
13 | # License as published by the Free Software Foundation; either
|
---|
14 | # version 2.1 of the License, or (at your option) any later version.
|
---|
15 | #
|
---|
16 | # kProfiler is distributed in the hope that it will be useful,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | # Lesser General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU Lesser General Public
|
---|
22 | # License along with kProfiler; if not, write to the Free Software
|
---|
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
24 | #
|
---|
25 |
|
---|
26 | # Example:
|
---|
27 | # BOOL WINAPI FindActCtxSectionGuid( DWORD dwFlags, const GUID * lpExtensionGuid, ULONG ulSectionId, const GUID * lpGuidToFind, PACTCTX_SECTION_KEYED_DATA ReturnedData );
|
---|
28 | #
|
---|
29 | # Should be turned into:
|
---|
30 | # typedef BOOL WINAPI FN_FindActCtxSectionGuid( DWORD dwFlags, const GUID * lpExtensionGuid, ULONG ulSectionId, const GUID * lpGuidToFind, PACTCTX_SECTION_KEYED_DATA ReturnedData );
|
---|
31 | # __declspec(dllexport) BOOL WINAPI kPrf2Wrap_FindActCtxSectionGuid( DWORD dwFlags, const GUID * lpExtensionGuid, ULONG ulSectionId, const GUID * lpGuidToFind, PACTCTX_SECTION_KEYED_DATA ReturnedData )
|
---|
32 | # {
|
---|
33 | # static FN_FindActCtxSectionGuid *pfn = 0;
|
---|
34 | # if (!pfn)
|
---|
35 | # kPrfWrapResolve((void **)&pfn, "FindActCtxSectionGuid", &g_Kernel32);
|
---|
36 | # return pfn( dwFlags, lpExtensionGuid, ulSectionId, lpGuidToFind, ReturnedData );
|
---|
37 | # }
|
---|
38 | #
|
---|
39 |
|
---|
40 | # Ignore empty lines.
|
---|
41 | /^[[:space:]]*$/b delete
|
---|
42 |
|
---|
43 | # Some hacks.
|
---|
44 | /([[:space:]]*VOID[[:space:]]*)/b no_hacking_void
|
---|
45 | s/([[:space:]]*\([A-Z][A-Z0-9_]*\)[[:space:]]*)/( \1 a)/
|
---|
46 | :no_hacking_void
|
---|
47 |
|
---|
48 |
|
---|
49 | # Save the pattern space.
|
---|
50 | h
|
---|
51 |
|
---|
52 | # Make the typedef.
|
---|
53 | s/[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(/ FN_\1(/
|
---|
54 | s/^/typedef /
|
---|
55 | p
|
---|
56 |
|
---|
57 | # Function definition
|
---|
58 | g
|
---|
59 | s/\n//g
|
---|
60 | s/\r//g
|
---|
61 | s/[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(/ kPrf2Wrap_\1(/
|
---|
62 | s/^/__declspec(dllexport) /
|
---|
63 | s/;//
|
---|
64 | p
|
---|
65 | i\
|
---|
66 | {
|
---|
67 |
|
---|
68 | # static FN_FindActCtxSectionGuid *pfn = 0;
|
---|
69 | # if (!pfn)
|
---|
70 | g
|
---|
71 | s/^.*[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(.*$/ static FN_\1 *pfn = 0;/
|
---|
72 | p
|
---|
73 | i\
|
---|
74 | if (!pfn)
|
---|
75 |
|
---|
76 | # kPrfWrapResolve((void **)&pfn, "FindActCtxSectionGuid", &g_Kernel32);
|
---|
77 | g
|
---|
78 | s/^.*[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(.*$/ kPrf2WrapResolve((void **)\&pfn, "\1\", \&g_Kernel32);/
|
---|
79 | p
|
---|
80 |
|
---|
81 | # The invocation and return statement.
|
---|
82 | # Some trouble here....
|
---|
83 | g
|
---|
84 | /^VOID WINAPI/b void_return
|
---|
85 | /^void WINAPI/b void_return
|
---|
86 | /^VOID __cdecl/b void_return
|
---|
87 | /^void __cdecl/b void_return
|
---|
88 | /^VOID NTAPI/b void_return
|
---|
89 | /^void NTAPI/b void_return
|
---|
90 | s/^.*(/ return pfn(/
|
---|
91 | b morph_params
|
---|
92 |
|
---|
93 | :void_return
|
---|
94 | s/^.*(/ pfn(/
|
---|
95 |
|
---|
96 | :morph_params
|
---|
97 | s/ *\[\] *//
|
---|
98 | s/ \*/ /g
|
---|
99 | s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *)\)/, \1/g
|
---|
100 | s/( *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *[,)]\)/( \1/g
|
---|
101 | s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
|
---|
102 | s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
|
---|
103 | s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
|
---|
104 | s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
|
---|
105 | s/( VOID )/ ()/
|
---|
106 | s/( void )/ ()/
|
---|
107 | p
|
---|
108 | i\
|
---|
109 | }
|
---|
110 | i\
|
---|
111 |
|
---|
112 | # Done
|
---|
113 | :delete
|
---|
114 | d
|
---|
115 |
|
---|