VirtualBox

source: kStuff/trunk/kProfiler2/kPrf2WinApi-gencode.sed@ 11

Last change on this file since 11 was 11, checked in by bird, 17 years ago

Wrappers for the win32/64 api.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
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
45s/([[:space:]]*\([A-Z][A-Z0-9_]*\)[[:space:]]*)/( \1 a)/
46:no_hacking_void
47
48
49# Save the pattern space.
50h
51
52# Make the typedef.
53s/[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(/ FN_\1(/
54s/^/typedef /
55p
56
57# Function definition
58g
59s/\n//g
60s/\r//g
61s/[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(/ kPrf2Wrap_\1(/
62s/^/__declspec(dllexport) /
63s/;//
64p
65i\
66{
67
68# static FN_FindActCtxSectionGuid *pfn = 0;
69# if (!pfn)
70g
71s/^.*[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(.*$/ static FN_\1 *pfn = 0;/
72p
73i\
74 if (!pfn)
75
76# kPrfWrapResolve((void **)&pfn, "FindActCtxSectionGuid", &g_Kernel32);
77g
78s/^.*[[:space:]]\([A-Za-z_][A-Za-z0-9_]*\)(.*$/ kPrf2WrapResolve((void **)\&pfn, "\1\", \&g_Kernel32);/
79p
80
81# The invocation and return statement.
82# Some trouble here....
83g
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
90s/^.*(/ return pfn(/
91b morph_params
92
93:void_return
94s/^.*(/ pfn(/
95
96:morph_params
97s/ *\[\] *//
98s/ \*/ /g
99s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *)\)/, \1/g
100s/( *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *[,)]\)/( \1/g
101s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
102s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
103s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
104s/, *[a-zA-Z_][^,)]* \([a-zA-Z_][a-zA-Z_0-9]* *,\)/, \1/g
105s/( VOID )/ ()/
106s/( void )/ ()/
107p
108i\
109}
110i\
111
112# Done
113:delete
114d
115
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette