source: trunk/include/os2wrap2_gen.sh@ 21609

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

os2wrap2.h: Added CREATE_, EXLST_ and XCPT_ defines.

  • 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#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
42sed -nr '
43{
44 s/^[[:space:]]*typedef[[:space:]]+struct[[:space:]]+([A-Za-z_][A-Za-z0-9_]+)([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#define \1 os2_\1/p
45 td
46 s/^[[:space:]]*}[[:space:]]*([A-Z_][A-Z0-9_]+)[[:space:]]*;[[:space:]]*$/#define \1 os2_\1/p
47 td
48 s/^[[:space:]]*typedef[[:space:]]+.+[[:space:]]+\**([A-Z_][A-Z0-9_]+)[[:space:]]*(\[.*\])?[[:space:]]*;([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#define \1 os2_\1/p
49 td
50}
51/^[[:space:]]*#define[[:space:]]+/ {
52 :a;/\\$/{N;ba}
53 s/([^A-Za-z0-9_])(MAKE[A-Z0-9]+)([^A-Za-z0-9_])/\1 \2 \3/g
54 s/([^A-Za-z0-9_])(((BM|CLR|CONTEXT|CREATE|CS|DM|DT|EH|ERROR|EXCEPTION|EXLST|FDM|FNTM|HWND|LM|MB|MIA|MM|NP|OBJ|PAG|QS|QSV|RGN|RT|SEM|SEVERITY|SIS|SV|SWP|TA|WC|WM|WS|XCPT|(WIN|GPI|DEV|SPL)ERR)_([A-Z0-9_]+))|((P?VOID|(API|EXP)ENTRY|P(CMD|CHR|MSE)MSG|ERRORID|NO_ERROR|PCMDMSG|SEL|HWND|MPARAM|MRESULT|LHANDLE|SHANDLE|BOOL|(LO|HI|P)?U?(LONG|SHORT|CHAR|BYTE)|MPFROM[A-Z0-9]+|MAKE[A-Z0-9]+)([^A-Za-z0-9_])))/\1os2_\2/g
55 tb;bd
56 :b
57 s/^[[:space:]]*#define[[:space:]]+((Dos|Win|Gpi)[A-Za-z_][A-Za-z0-9_]+)([[:space:](].*)//
58 s/^[[:space:]]*#define[[:space:]]+(os2_)?([A-Za-z_][A-Za-z0-9_]+)[[:space:]]*(.*)/#define os2_\2 \3/p
59}
60:d
61' < "$OS2EMX_H" >> "$OS2WRAP2_H"
62
63#
64# Fixed middle
65#
66
67echo \
68'
69/* include the main OS/2 API wrapper */
70#include <os2wrap.h>
71
72#undef _THUNK_PASCAL_FUNCTION
73#undef MAKE16P
74#undef MAKEP
75#undef SELECTOROF
76#undef OFFSETOF
77#undef _THUNK_PTR_SIZE_OK
78' >> "$OS2WRAP2_H"
79
80#
81# Undefine all typedefs prefixed with "os2_" at the beginning and original
82# versions of macros. The command to generate this block is:
83#
84
85sed -nr '
86{
87 s/^[[:space:]]*typedef[[:space:]]+struct[[:space:]]+([A-Za-z_][A-Za-z0-9_]+)([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#undef \1/p
88 td
89 s/^[[:space:]]*}[[:space:]]*([A-Z_][A-Z0-9_]+)[[:space:]]*;[[:space:]]*$/#undef \1/p
90 td
91 s/^[[:space:]]*typedef[[:space:]]+.+[[:space:]]+\**([A-Z_][A-Z0-9_]+)[[:space:]]*(\[.*\])?[[:space:]]*;([[:space:]]*[/]\*.*\*[/])?[[:space:]]*$/#undef \1/p
92 td
93}
94/^[[:space:]]*#define[[:space:]]+/ {
95 :a;/\\$/{N;ba}
96 s/([^A-Za-z0-9_])(MAKE[A-Z0-9]+)([^A-Za-z0-9_])/\1 \2 \3/g
97 s/([^A-Za-z0-9_])(((BM|CLR|CONTEXT|CREATE|CS|DM|DT|EH|ERROR|EXCEPTION|EXLST|FDM|FNTM|HWND|LM|MB|MIA|MM|NP|OBJ|PAG|QS|QSV|RGN|RT|SEM|SEVERITY|SIS|SV|SWP|TA|WC|WM|WS|XCPT|(WIN|GPI|DEV|SPL)ERR)_([A-Z0-9_]+))|((P?VOID|(API|EXP)ENTRY|P(CMD|CHR|MSE)MSG|ERRORID|NO_ERROR|PCMDMSG|SEL|HWND|MPARAM|MRESULT|LHANDLE|SHANDLE|BOOL|(LO|HI|P)?U?(LONG|SHORT|CHAR|BYTE)|MPFROM[A-Z0-9]+|MAKE[A-Z0-9]+)([^A-Za-z0-9_])))/\1os2_\2/g
98 tb;bd
99 :b
100 s/^[[:space:]]*#define[[:space:]]+((Dos|Win|Gpi)[A-Za-z_][A-Za-z0-9_]+)([[:space:](].*)/#undef \1\
101#define \1\3/p
102 s/^[[:space:]]*#define[[:space:]]+(os2_)?([A-Za-z_][A-Za-z0-9_]+)[[:space:]]*(.*)/#undef \2/p
103}
104:d
105' < "$OS2EMX_H" >> "$OS2WRAP2_H"
106
107#
108# Fixed footer
109#
110
111echo \
112'
113#endif /* __OS2WRAP2_H__ */
114' >> "$OS2WRAP2_H"
Note: See TracBrowser for help on using the repository browser.