source: trunk/include/os2wrap2_gen.sh@ 22145

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

os2wrap2.h: Add more defines and define OS2_WRAP_INCLUDED.

This is to detect that all OS/2 APIs are in a prefixed form.

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