Mercurial > hg > xemacs-beta
annotate lib-src/make-mswin-unicode.pl @ 4903:70089046adef
fix compile problems in intl-encap* under VS6
-------------------- ChangeLog entries follow: --------------------
lib-src/ChangeLog addition:
2010-01-30 Ben Wing <ben@xemacs.org>
* make-mswin-unicode.pl:
Make it possible to specify an overridden prototype in cases where
either Cygwin or Visual Studio has errors in their headers that
can be corrected by falling back to a less qualified type (typically
without const).
src/ChangeLog addition:
2010-01-30 Ben Wing <ben@xemacs.org>
* intl-auto-encap-win32.c:
* intl-auto-encap-win32.c (qxeExtractAssociatedIcon):
* intl-auto-encap-win32.c (qxeExtractIconEx):
* intl-auto-encap-win32.c (qxeCreateMDIWindow):
* intl-auto-encap-win32.c (qxeCreateWindowStation):
* intl-auto-encap-win32.c (qxeDdeCreateStringHandle):
* intl-auto-encap-win32.c (qxeAbortSystemShutdown):
* intl-auto-encap-win32.c (qxeRegConnectRegistry):
* intl-auto-encap-win32.c (qxeGetICMProfile):
* intl-auto-encap-win32.h:
Rebuild.
* intl-encap-win32.c:
* intl-encap-win32.c (qxeUpdateICMRegKey):
Delete manual definitions of functions with former errors in
Cygwin headers but no longer. Use "override" with some functions
where Cygwin or VS6 accidentally omits a const declaration or
includes an extra one. Use "no" on SendMessageTimeout, which
has an error in the VS6 prototype (you could manually fix this
with an ifdef to split the Cygwin vs. VS6 calls, if we ever
actually used this function).
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sat, 30 Jan 2010 20:34:23 -0600 |
parents | 49de55c09f18 |
children | 7eec2a1f3412 |
rev | line source |
---|---|
771 | 1 : #-*- Perl -*- |
2 | |
3 ### make-mswin-unicode --- generate Unicode-encapsulation code for MS Windows | |
4 | |
4875
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
5 ## Copyright (C) 2001, 2002, 2004, 2010 Ben Wing. |
771 | 6 |
7 ## Author: Ben Wing <ben@xemacs.org> | |
8 ## Maintainer: Ben Wing <ben@xemacs.org> | |
9 ## Current Version: 1.0, August 24, 2001 | |
10 | |
11 ## This file is part of XEmacs. | |
12 | |
13 ## XEmacs is free software; you can redistribute it and/or modify it | |
14 ## under the terms of the GNU General Public License as published by | |
15 ## the Free Software Foundation; either version 2, or (at your option) | |
16 ## any later version. | |
17 | |
18 ## XEmacs is distributed in the hope that it will be useful, but | |
19 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 ## General Public License for more details. | |
22 | |
23 ## You should have received a copy of the GNU General Public License | |
24 ## along with XEmacs; see the file COPYING. If not, write to the Free | |
25 ## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
26 ## 02111-1307, USA. | |
27 | |
28 eval 'exec perl -w -S $0 ${1+"$@"}' | |
29 if 0; | |
30 | |
31 use strict; | |
32 use File::Basename; | |
33 use Getopt::Long; | |
34 | |
35 my ($myName, $myPath) = fileparse ($0); | |
36 | |
37 my $usage=" | |
38 Usage: $myName [--c-output FILE] [--h-output FILE] [--help] [FILES ...] | |
39 | |
40 The purpose of this script is to auto-generate Unicode-encapsulation | |
41 code for MS Windows library functions that come in two versions (ANSI | |
42 and Unicode). The MS Windows header files provide a way of | |
43 automatically calling the right version, but only at compile-time, | |
44 which is *NOT* sufficient for any real-world program. The solution is | |
45 run-time Unicode encapsulation, which is not conceptually difficult | |
46 but is time-consuming, and is not supported standardly only due to | |
47 evil marketing decisions made by Microsoft. See src/intl-win32.c | |
48 for more information. | |
49 | |
800 | 50 In XEmacs, this file is normally run using `nmake -f xemacs.mak |
51 unicode-encapsulate'. | |
52 | |
771 | 53 This script processes the specified files, looking for commands |
54 indicating library routines to Unicode-encapsulate, as follows: | |
55 | |
56 Portions of the files that should be processed are enclosed in lines | |
57 consisting only of the words \"begin-unicode-encapsulation-script\" | |
58 and \"end-unicode-encapsulation-script\". More than one section can | |
59 occur in a single file. Processed lines begin with a command word, | |
60 followed by one or more args (no quotes are necessary for spaces): | |
61 | |
62 file specifies a file to start reading from. | |
63 yes indicates a function to be automatically Unicode-encapsulated. | |
64 (All parameters either need no special processing or are LPTSTR or | |
65 LPCTSTR.) | |
66 soon indicates a function that should be automatically Unicode-encapsulated, | |
67 but we're not ready to process it yet. | |
68 no indicates a function we don't support (it will be #defined to cause | |
69 a compile error, with the text after the function included in the | |
70 erroneous definition to indicate why we don't support it). | |
4875
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
71 review indicates a function that we still need to review to determine whether |
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
72 or how to support it. This has the same effect as `no', with a comment |
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
73 indicating that the function needs review. |
771 | 74 skip indicates a function we support manually; only a comment about this |
75 will be generated. | |
76 split indicates a function with a split structure (different versions | |
77 for Unicode and ANSI), but where the only difference is in pointer | |
78 types, and the actual size does not differ. The structure name | |
79 should follow the function name, and it will be automatically | |
80 Unicode-encapsulated with appropriate casts. | |
81 begin-bracket indicates a #if statement to be inserted here. | |
82 end-bracket indicates the corresponding #endif statement. | |
83 blank lines and lines beginning with // are ignored. | |
84 "; | |
85 | |
86 # ------------------ process command-line options ------------------ | |
87 | |
88 my %options; | |
89 my @SAVE_ARGV = @ARGV; | |
90 | |
91 $Getopt::Long::ignorecase = 0; | |
92 &GetOptions ( | |
93 \%options, | |
94 'c-output=s', | |
95 'h-output=s', | |
778 | 96 'includedir=s', |
771 | 97 'help', |
98 ); | |
99 | |
100 die $usage if $options{"help"}; | |
101 | |
102 my $in_script; | |
103 my $slurp; | |
104 | |
778 | 105 my ($cout, $hout, $dir) = ($options{"c-output"}, |
106 $options{"h-output"}, | |
107 $options{"includedir"}); | |
4873
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
108 |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
109 $dir = '/usr/include/w32api' if !$dir && -f '/usr/include/w32api/windows.h'; |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
110 |
778 | 111 if (!$dir) |
112 { | |
4467
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
113 for my $sdkroot (("WindowsSdkDir", "MSSdk", "MSVCDIR")) |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
114 { |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
115 if (defined $ENV{$sdkroot}) { |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
116 $dir = $ENV{$sdkroot}; |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
117 last; |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
118 } |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
119 } |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
120 unless (defined $dir) |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
121 { |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
122 die "Can't find the Windows SDK headers; run vcvars32.bat from your MSVC installation, or setenv.cmd from the Platform SDK installation"; |
23ef20edf6ba
Check %WindowsSdkDir%, %MSSddk% for the Windows header files too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3728
diff
changeset
|
123 } |
778 | 124 } |
4873
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
125 $dir.='/include' if ((-f $dir.'/include/WINDOWS.H') || |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
126 (-f $dir.'/include/windows.h')); |
3728 | 127 die "Can't find MSVC include files in \"$dir\"" unless ((-f $dir.'/WINDOWS.H') || (-f $dir.'/windows.h')); |
771 | 128 |
129 open (COUT, ">$cout") or die "Can't open C output file $cout: $!"; | |
130 open (HOUT, ">$hout") or die "Can't open C output file $hout: $!"; | |
131 | |
132 select (STDOUT); $| = 1; | |
133 | |
134 print COUT "/* Automatically-generated Unicode-encapsulation file, | |
135 using the command | |
136 | |
137 $myPath$myName @SAVE_ARGV | |
138 | |
139 Do not edit. See `$myName'. | |
140 */ | |
141 | |
142 #include <config.h> | |
143 #include \"lisp.h\" | |
144 | |
145 #include \"syswindows.h\" | |
146 | |
147 "; | |
148 print HOUT "/* Automatically-generated Unicode-encapsulation header file. | |
149 Do not edit. See `$myName'. | |
150 */\n\n"; | |
151 | |
152 my %files; | |
153 my %processed; | |
154 my %bracket; | |
155 | |
156 my $current_file; | |
157 my @current_bracket; | |
158 | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
159 my ($ws_re, $must_ws_re, $tok_ch) = |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
160 ("\\s*", "\\s+", "\\w"); |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
161 # unfortunately there is no surefire way short of |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
162 # parsing all include files for typedefs to |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
163 # distinguish types from parameters, and prototypes |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
164 # appear in the include files both with and without |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
165 # parameters -- the latter kinds appear in a very |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
166 # different style and were obviously added later. so |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
167 # we rely on the fact that defined types are all |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
168 # upper-case, and parameters generally are not, and |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
169 # special-case the exceptions. |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
170 my $typeword_re = |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
171 # note the negative lookahead assertions: the first |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
172 # one excludes the words "X" and "Y" from type |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
173 # words, since they appear as parameter names in |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
174 # CreateWindowEx; the second prevents "void |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
175 # *Argument" from being parsed as a type "void *A" |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
176 # followed by a parameter "rgument". |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
177 "(?:(?!(?:X\\b|Y\\b))(?:unsigned|int|long|const|short|va_list|[A-Z_0-9]+)(?!${tok_ch}))"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
178 my $typetoken_re = "(?:$typeword_re$ws_re\\**$ws_re)"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
179 # Regexp matching a particular argument |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
180 my $arg_re = "(?:(?:$typetoken_re+)(?:${tok_ch}+)?(?: OPTIONAL)?)"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
181 # Same, but with groups to match the type and name |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
182 my $argmatch_re = "(?:($typetoken_re+)(${tok_ch}+)?(?: OPTIONAL)?)"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
183 # regexp matching a parenthesized argument list in a prototype |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
184 my $args_re = "\\(((?:${ws_re}${arg_re}${ws_re},)*${ws_re}${arg_re}${ws_re})\\)"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
185 # regexp matching a return type in a protype |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
186 my $rettype_re = "(SHSTDAPI_\\(${tok_ch}+\\)|${tok_ch}" . "[A-Za-z_0-9 \t\n\r\f]*?${tok_ch})"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
187 # regexp matching a function name |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
188 my $funname_re = "(${tok_ch}+)"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
189 # Regexp matching a function prototype, $1 = rettype, $2 = name, $3 = args |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
190 my $fun_re = "${rettype_re}${ws_re}${funname_re}${ws_re}${args_re};"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
191 # Regexp matching a particular Unicode function (ending in ...W) |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
192 my $wfun_re = "${rettype_re}${ws_re}${funname_re}W${ws_re}${args_re};"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
193 |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
194 # print "regexp: $wfun_re\n"; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
195 |
771 | 196 while (<>) |
197 { | |
198 chomp; | |
800 | 199 # remove trailing CR. #### Should not be necessary! Perl should be |
200 # opening these in text mode by default, as the docs claim, and | |
201 # automatically remove the CR's. | |
202 tr/\r//d; | |
771 | 203 |
204 if (/^begin-unicode-encapsulation-script$/) | |
205 { | |
206 $in_script = 1; | |
207 } | |
208 elsif (/^end-unicode-encapsulation-script$/) | |
209 { | |
210 $in_script = 0; | |
211 } | |
212 elsif ($in_script) | |
213 { | |
214 next if (m!^//!); | |
215 next if (/^[ \t]*$/); | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
216 if (/(file|yes|soon|no|review|skip|split|begin-bracket|end-bracket|override)(?: (.*))?/) |
771 | 217 { |
218 my ($command, $parms) = ($1, $2); | |
778 | 219 if ($command eq "file") |
771 | 220 { |
221 $current_file = $parms; | |
222 } | |
223 elsif ($command eq "begin-bracket") | |
224 { | |
225 my $current_bracket = $current_bracket[$#current_bracket]; | |
226 if (defined ($current_bracket)) | |
227 { | |
228 $current_bracket .= "&& $parms"; | |
229 } | |
230 else | |
231 { | |
232 $current_bracket = "$parms"; | |
233 } | |
234 push @current_bracket, $current_bracket; | |
235 } | |
236 elsif ($command eq "end-bracket") | |
237 { | |
238 pop @current_bracket; | |
239 } | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
240 elsif ($command eq "override") |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
241 { |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
242 die "Cannot parse prototype $parms" unless $parms =~ /$wfun_re(?: ?(.*))?/; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
243 my ($rettype, $fun, $args, $reason) = ($1, $2, $3, $4); |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
244 $files{$current_file}{$fun} = |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
245 [$command, $reason, $rettype, $fun, $args]; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
246 $bracket{$current_file}{$fun} = |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
247 $current_bracket[$#current_bracket]; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
248 } |
771 | 249 else |
250 { | |
251 my ($fun, $reason) = split /\s+/, $parms, 2; | |
252 $files{$current_file}{$fun} = [$command, $reason]; | |
253 $bracket{$current_file}{$fun} = | |
254 $current_bracket[$#current_bracket]; | |
255 } | |
256 } | |
257 else | |
258 { | |
259 print "WARNING: Unknown line $_\n"; | |
260 } | |
261 } | |
262 } | |
263 | |
264 | |
265 foreach my $file (keys %files) | |
266 { | |
267 $slurp = &FileContents ($file); | |
268 print "Processing file $file\n"; | |
269 print HOUT "\n/* Processing file $file */\n\n"; | |
270 my $totalspace = 70 - length ("Processing file $file"); | |
271 $totalspace = 0 if $totalspace < 0; | |
272 my $alignspaceleft = $totalspace / 2; | |
273 my $alignspaceright = ($totalspace + 1) / 2; | |
274 print COUT " | |
275 /*----------------------------------------------------------------------*/ | |
276 /*" . (" " x $alignspaceleft) . "Processing file $file" . | |
277 (" " x $alignspaceright) . "*/ | |
278 /*----------------------------------------------------------------------*/ | |
279 | |
280 "; | |
281 | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
282 while ($slurp =~ /$wfun_re/g) |
771 | 283 { |
284 my ($rettype, $fun, $args) = ($1, $2, $3); | |
4873
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
285 |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
286 if ($processed{$fun}) |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
287 { |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
288 print "Warning: Function $fun already seen\n"; |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
289 next; |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
290 } |
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
291 |
771 | 292 $processed{$fun} = 1; |
4873
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
293 |
771 | 294 print "Processing: $fun"; |
295 | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
296 #my ($command, $reason) = ($files{$file}{$fun}[0], $files{$file}{$fun}[1]); |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
297 # Fuck perl! There seems to be no way to write something like |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
298 # my ($command, $reason) = @$files{$file}{$fun}; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
299 # You have to use a temporary var. |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
300 my $filesarr = $files{$file}{$fun}; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
301 my ($command, $reason) = @$filesarr; |
771 | 302 if (!defined ($command)) |
303 { | |
304 print " (no command found)\n"; | |
305 } | |
306 else | |
307 { | |
308 print "\n"; | |
309 my $bracket = $bracket{$file}{$fun}; | |
310 if (defined ($bracket)) | |
311 { | |
312 print HOUT "#if $bracket\n"; | |
313 print COUT "#if $bracket\n\n"; | |
314 } | |
4875
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
315 if ($command eq "no" || $command eq "review") |
771 | 316 { |
4875
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
317 $reason = "Function needs review to determine how to handle it" |
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
318 if !defined ($reason) && $command eq "review"; |
49de55c09f18
add "review" lines in intl-encap-win32.c for all unseen functions in processed headers
Ben Wing <ben@xemacs.org>
parents:
4873
diff
changeset
|
319 |
771 | 320 if (!defined ($reason)) |
321 { | |
322 print "WARNING: No reason given for `no' with function $fun\n"; | |
323 $reason = ""; | |
324 } | |
325 | |
326 print HOUT "#undef $fun\n"; | |
2367 | 327 (my $munged_reason = $reason) =~ s/[^A-Za-z0-9]/_/g; |
328 print HOUT "#define $fun error_$munged_reason\n"; | |
771 | 329 print COUT "/* Error if $fun used: $reason */\n\n"; |
330 } | |
331 elsif ($command eq "skip") | |
332 { | |
333 if (!defined ($reason)) | |
334 { | |
335 print "WARNING: No reason given for `skip' with function $fun\n"; | |
336 $reason = ""; | |
337 } | |
338 | |
339 print HOUT "/* Skipping $fun because $reason */\n"; | |
340 print COUT "/* Skipping $fun because $reason */\n\n"; | |
341 } | |
342 elsif ($command eq "soon") | |
343 { | |
344 $reason = "" if !defined ($reason); | |
345 | |
346 print HOUT "/* Not yet: $fun $reason */\n"; | |
347 print COUT "/* Not yet: $fun $reason */\n\n"; | |
348 } | |
349 else | |
350 { | |
351 my (@args, %argtype, %ansiarg, %xarg, $split_struct, | |
352 $split_rettype); | |
353 if ($command eq "split") | |
354 { | |
355 ($split_struct, $reason) = split /\s+/, $reason, 2; | |
356 } | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
357 elsif ($command eq "override") |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
358 { |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
359 my ($nrettype, $nfun, $nargs) = @$filesarr[2 .. 4]; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
360 $reason = "$reason.\n NOTE: " if $reason; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
361 $reason = "${reason}Prototype manually overridden. |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
362 Header file claims: |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
363 $rettype $fun($args) |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
364 Overridden with: |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
365 $nrettype $nfun($nargs) |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
366 Differences in return-type qualifiers, e.g. WINAPI, are not important. |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
367 "; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
368 ($rettype, $fun, $args) = ($nrettype, $nfun, $nargs); |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
369 } |
771 | 370 my $argno = 0; |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
371 while ($args =~ /$argmatch_re/g) |
771 | 372 { |
373 $argno++; | |
374 my ($argtype, $argname) = ($1, $2); | |
375 $argtype =~ s/\s*$//; | |
376 next if $argtype eq "void" || $argtype eq "VOID"; | |
377 $argname = "arg$argno" if !defined ($argname); | |
378 $argtype{$argname} = $argtype; | |
379 $ansiarg{$argname} = $argtype; | |
380 $ansiarg{$argname} =~ s/\bLPWSTR\b/LPSTR/; | |
381 $ansiarg{$argname} =~ s/\bLPCWSTR\b/LPCSTR/; | |
382 $xarg{$argname} = $argtype; | |
383 $xarg{$argname} =~ s/\bLPWSTR\b/Extbyte */; | |
384 $xarg{$argname} =~ s/\bLPCWSTR\b/const Extbyte */; | |
385 if (defined ($split_struct)) | |
386 { | |
387 my $fuck_cperl1 = "\\b${split_struct}W\\b"; | |
388 my $fuck_cperl2 = "${split_struct}A"; | |
389 $ansiarg{$argname} =~ s/$fuck_cperl1/$fuck_cperl2/; | |
390 } | |
391 push @args, $argname; | |
392 } | |
393 $rettype =~ s/\bSHSTDAPI_\((.*)\)/$1/; | |
394 $rettype =~ s/\s*WIN\w*?API\s*//g; | |
4873
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
395 $rettype =~ s/\bAPIENTRY\b\s*//; |
771 | 396 $rettype =~ s/\bSHSTDAPI\b/HRESULT/; |
4873
50861fea97f6
regenerate intl-auto-encap-win32.c, now possible from Cygwin /usr/include/w32api headers
Ben Wing <ben@xemacs.org>
parents:
4467
diff
changeset
|
397 $rettype =~ s/\bextern\b\s*//; |
771 | 398 if ($rettype =~ /LPC?WSTR/) |
399 { | |
400 $split_rettype = 1; | |
401 $rettype =~ s/\bLPWSTR\b/Extbyte */; | |
402 $rettype =~ s/\bLPCWSTR\b/const Extbyte */; | |
403 } | |
800 | 404 print HOUT "#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED\n"; |
405 print HOUT "#undef $fun\n"; | |
2367 | 406 print HOUT "#define $fun error_use_qxe${fun}_or_${fun}A_and_${fun}W\n"; |
800 | 407 print HOUT "#endif\n"; |
771 | 408 if (defined ($reason)) |
409 { | |
410 print COUT "/* NOTE: $reason */\n"; | |
411 } | |
412 print COUT "$rettype\nqxe$fun ("; | |
413 print HOUT "$rettype qxe$fun ("; | |
414 my $first = 1; | |
415 if (!@args) | |
416 { | |
417 print COUT "void"; | |
418 print HOUT "void"; | |
419 } | |
420 else | |
421 { | |
422 foreach my $x (@args) | |
423 { | |
424 print COUT ", " if !$first; | |
425 print HOUT ", " if !$first; | |
426 $first = 0; | |
427 print COUT "$xarg{$x} $x"; | |
428 print HOUT "$xarg{$x} $x"; | |
429 } | |
430 } | |
431 print HOUT ");\n"; | |
432 print COUT ")\n{\n if (XEUNICODE_P)\n "; | |
433 if ($rettype ne "void" && $rettype ne "VOID") | |
434 { | |
435 print COUT "return "; | |
436 print COUT "($rettype) " if $split_rettype; | |
437 } | |
438 print COUT "${fun}W ("; | |
439 $first = 1; | |
440 foreach my $x (@args) | |
441 { | |
442 print COUT ", " if !$first; | |
443 $first = 0; | |
444 print COUT ($argtype{$x} eq $xarg{$x} ? $x : | |
445 "($argtype{$x}) $x"); | |
446 } | |
447 print COUT ");\n else\n "; | |
448 if ($rettype ne "void" && $rettype ne "VOID") | |
449 { | |
450 print COUT "return "; | |
451 print COUT "($rettype) " if $split_rettype; | |
452 } | |
453 print COUT "${fun}A ("; | |
454 $first = 1; | |
455 foreach my $x (@args) | |
456 { | |
457 print COUT ", " if !$first; | |
458 $first = 0; | |
459 print COUT ($argtype{$x} eq $ansiarg{$x} ? $x : | |
460 "($ansiarg{$x}) $x"); | |
461 } | |
462 print COUT ");\n}\n\n"; | |
463 } | |
464 if (defined ($bracket)) | |
465 { | |
466 print HOUT "#endif /* $bracket */\n"; | |
467 print COUT "#endif /* $bracket */\n\n"; | |
468 } | |
800 | 469 print HOUT "\n"; |
771 | 470 } |
471 } | |
472 } | |
473 | |
474 foreach my $file (keys %files) | |
475 { | |
476 foreach my $fun (keys %{$files{$file}}) | |
477 { | |
478 if (!$processed{$fun} && $files{$file}{$fun}[0] =~ /^(yes|soon|split)$/) | |
479 { | |
480 print "WARNING: Can't locate prototype for $fun\n"; | |
481 } | |
482 } | |
483 } | |
484 | |
485 | |
486 sub FileContents | |
487 { | |
488 local $/ = undef; | |
778 | 489 open (FILE, "< $dir/$_[0]") or die "$dir/$_[0]: $!"; |
771 | 490 my $retval = scalar <FILE>; |
491 # must hack away CRLF junk. | |
492 $retval =~ s/\r\n/\n/g; | |
493 return $retval; | |
494 } |