source: trunk/include/os2wrap2_gen.sh@ 21970

Last change on this file since 21970 was 21970, checked in by dmik, 14 years ago

os2wrap2.h: Add a bunch of prefixless defines.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1#!/bin/sh
2
3OS2EMX_H=D:/Dev/gcc452/usr/include/os2emx.h
4OS2WRAP2_H=os2wrap2.h.new
5
6#
7# Fixed header
8#
9
10echo \
11'/*
12 * A full version of os2wrap.h that prefixes all OS/2 type and constant
13 * definitions with "os2_" which makes it possible to use the OS/2 APIs
14 * from the same source files that use the Windows APIs.
15 *
16 * Project Odin Software License can be found in LICENSE.TXT
17 */
18
19#ifndef __OS2WRAP2_H__
20#define __OS2WRAP2_H__
21
22#ifdef WINVER
23#error "os2wrap2.h must be included BEFORE any Windows include file!"
24#endif
25
26#define os2__THUNK_PASCAL_FUNCTION (FUN) os2_APIENTRY _16_##FUN
27#define os2_MAKE16P (sel,off) ((_far16ptr)((sel) << 16 | (off)))
28#define os2_MAKEP (sel,off) _libc_16to32 ( os2_MAKE16P (sel, off))
29#define os2_SELECTOROF (farptr) ((os2_SEL)((farptr) >> 16))
30#define os2_OFFSETOF (farptr) ((os2_USHORT)(farptr))
31#define os2__THUNK_PTR_SIZE_OK (ptr,size) \
32 (((os2_ULONG)(ptr) & ~0xffff) == (((os2_ULONG)(ptr) + (size) - 1) & ~0xffff))
33' > "$OS2WRAP2_H"
34
35#
36# Redefine all OS/2 typedefs to those having the "os2_" prefix to avoid
37# conflicts with Windows typedefs. Also define "os2_" versions of all
38# macros. The defines are generated with the following command on the
39# respective OS/2 headers:
40#
41
42DefinePrefixes=\
43'BM|CLR|CONTEXT|CREATE|CS|DM|DT|EH|ERROR|EXCEPTION|EXLST|FILE|FDM|FNTM|'\
44'HWND|LM|MB|MIA|MM|NP|OBJ|PAG|QS|QSV|RGN|RT|SEM|SEVERITY|SIS|SV|SWP|TA|'\
45'WC|WM|WS|XCPT|(WIN|GPI|DEV|SPL)ERR'
46
47Defines=\
48'ERRORID|NO_ERROR|PCMDMSG|SEL|HWND|MPARAM|MRESULT|LHANDLE|SHANDLE|BOOL|'\
49'ADDRESS|DRIVER_NAME|DRIVER_DATA|DATA_TYPE|COMMENT|PROC_NAME|'\
50'PROC_PARAMS|SPL_PARAMS|NETWORK_PARAMS|'\
51'(CCH|MPFROM|MAKE)[A-Z0-9]+|'\
52'P?VOID|(API|EXP)ENTRY|P(CMD|CHR|MSE)MSG|'\
53'(LO|HI|P)?U?(LONG|SHORT|CHAR|BYTE)'
54
55sed -nr '
56{
57 s/^[[:space:]]*typedef[[:space:]]+struct[[:space:]]+([A-Za-z_][A-Za-z0-9_]+)([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#define \1 os2_\1/p
58 td
59 s/^[[:space:]]*}[[:space:]]*([A-Z_][A-Z0-9_]+)[[:space:]]*;[[:space:]]*$/#define \1 os2_\1/p
60 td
61 s/^[[:space:]]*typedef[[:space:]]+.+[[:space:]]+\**([A-Z_][A-Z0-9_]+)[[:space:]]*(\[.*\])?[[:space:]]*;([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#define \1 os2_\1/p
62 td
63}
64/^[[:space:]]*#define[[:space:]]+/ {
65 :a;/\\$/{N;ba}
66 s/([^A-Za-z0-9_])(MAKE[A-Z0-9]+)([^A-Za-z0-9_])/\1 \2 \3/g
67 s/([^A-Za-z0-9_])((('$DefinePrefixes')_([A-Z0-9_]+))|(('$Defines')([^A-Za-z0-9_])))/\1os2_\2/g
68 tb;bd
69 :b
70 s/^[[:space:]]*#define[[:space:]]+((Dos|Win|Gpi)[A-Za-z_][A-Za-z0-9_]+)([[:space:](].*)//
71 s/^[[:space:]]*#define[[:space:]]+(os2_)?([A-Za-z_][A-Za-z0-9_]+)[[:space:]]*(.*)/#define os2_\2 \3/p
72}
73:d
74' < "$OS2EMX_H" >> "$OS2WRAP2_H"
75
76#
77# Fixed middle
78#
79
80echo \
81'
82/* include the main OS/2 API wrapper */
83#include <os2wrap.h>
84
85#undef _THUNK_PASCAL_FUNCTION
86#undef MAKE16P
87#undef MAKEP
88#undef SELECTOROF
89#undef OFFSETOF
90#undef _THUNK_PTR_SIZE_OK
91' >> "$OS2WRAP2_H"
92
93#
94# Undefine all typedefs prefixed with "os2_" at the beginning and original
95# versions of macros. The command to generate this block is:
96#
97
98sed -nr '
99{
100 s/^[[:space:]]*typedef[[:space:]]+struct[[:space:]]+([A-Za-z_][A-Za-z0-9_]+)([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#undef \1/p
101 td
102 s/^[[:space:]]*}[[:space:]]*([A-Z_][A-Z0-9_]+)[[:space:]]*;[[:space:]]*$/#undef \1/p
103 td
104 s/^[[:space:]]*typedef[[:space:]]+.+[[:space:]]+\**([A-Z_][A-Z0-9_]+)[[:space:]]*(\[.*\])?[[:space:]]*;([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#undef \1/p
105 td
106}
107/^[[:space:]]*#define[[:space:]]+/ {
108 :a;/\\$/{N;ba}
109 s/([^A-Za-z0-9_])(MAKE[A-Z0-9]+)([^A-Za-z0-9_])/\1 \2 \3/g
110 s/([^A-Za-z0-9_])((('$DefinePrefixes')_([A-Z0-9_]+))|(('$Defines')([^A-Za-z0-9_])))/\1os2_\2/g
111 tb;bd
112 :b
113 s/^[[:space:]]*#define[[:space:]]+((Dos|Win|Gpi)[A-Za-z_][A-Za-z0-9_]+)([[:space:](].*)/#undef \1\
114#define \1\3/p
115 s/^[[:space:]]*#define[[:space:]]+(os2_)?([A-Za-z_][A-Za-z0-9_]+)[[:space:]]*(.*)/#undef \2/p
116}
117:d
118' < "$OS2EMX_H" >> "$OS2WRAP2_H"
119
120#
121# Fixed footer
122#
123
124echo \
125'
126#endif /* __OS2WRAP2_H__ */
127' >> "$OS2WRAP2_H"
Note: See TracBrowser for help on using the repository browser.