Mercurial > hg > xemacs-beta
annotate lib-src/make-mswin-unicode.pl @ 5921:68639fb08af8 cygwin
no obvious 64 vs. 32 pblms in compilation, but still crashing in event-msw
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Wed, 23 Apr 2014 22:22:37 +0100 |
parents | 0f2338afbabf |
children | 2f34b59f451a |
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 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
13 ## XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
14 ## under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
15 ## Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
16 ## option) any later version. |
771 | 17 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
18 ## XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
19 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
20 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
21 ## for more details. |
771 | 22 |
23 ## You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4911
diff
changeset
|
24 ## along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
771 | 25 |
26 eval 'exec perl -w -S $0 ${1+"$@"}' | |
27 if 0; | |
28 | |
29 use strict; | |
30 use File::Basename; | |
31 use Getopt::Long; | |
32 | |
33 my ($myName, $myPath) = fileparse ($0); | |
34 | |
35 my $usage=" | |
36 Usage: $myName [--c-output FILE] [--h-output FILE] [--help] [FILES ...] | |
37 | |
38 The purpose of this script is to auto-generate Unicode-encapsulation | |
39 code for MS Windows library functions that come in two versions (ANSI | |
40 and Unicode). The MS Windows header files provide a way of | |
41 automatically calling the right version, but only at compile-time, | |
42 which is *NOT* sufficient for any real-world program. The solution is | |
43 run-time Unicode encapsulation, which is not conceptually difficult | |
44 but is time-consuming, and is not supported standardly only due to | |
45 evil marketing decisions made by Microsoft. See src/intl-win32.c | |
46 for more information. | |
47 | |
800 | 48 In XEmacs, this file is normally run using `nmake -f xemacs.mak |
49 unicode-encapsulate'. | |
50 | |
771 | 51 This script processes the specified files, looking for commands |
52 indicating library routines to Unicode-encapsulate, as follows: | |
53 | |
54 Portions of the files that should be processed are enclosed in lines | |
55 consisting only of the words \"begin-unicode-encapsulation-script\" | |
56 and \"end-unicode-encapsulation-script\". More than one section can | |
57 occur in a single file. Processed lines begin with a command word, | |
58 followed by one or more args (no quotes are necessary for spaces): | |
59 | |
60 file specifies a file to start reading from. | |
61 yes indicates a function to be automatically Unicode-encapsulated. | |
62 (All parameters either need no special processing or are LPTSTR or | |
63 LPCTSTR.) | |
4911 | 64 override indidates a function where the prototype can be overridden |
65 due to errors in Cygwin or Visual Studio. | |
771 | 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 |
5920
0f2338afbabf
Minimum necessary to get started:
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
186 my $rettype_re = "(SHSTDAPI_\\([${tok_ch} *]+\\)|${tok_ch}" . "[A-Za-z_0-9 \t\n\r\f]*?${tok_ch})"; |
4903
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) |
5920
0f2338afbabf
Minimum necessary to get started:
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
192 my $wfun_re = "(?:#endif|#ifndef ${tok_ch}+)?${ws_re}${rettype_re}${ws_re}${funname_re}W${ws_re}${args_re};"; |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
193 |
5920
0f2338afbabf
Minimum necessary to get started:
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
194 #print "regexp: $wfun_re\n"; |
4903
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]; | |
5920
0f2338afbabf
Minimum necessary to get started:
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
253 #print "$current_file : $fun = $command, $reason\n"; |
771 | 254 $bracket{$current_file}{$fun} = |
255 $current_bracket[$#current_bracket]; | |
256 } | |
257 } | |
258 else | |
259 { | |
260 print "WARNING: Unknown line $_\n"; | |
261 } | |
262 } | |
263 } | |
264 | |
265 | |
266 foreach my $file (keys %files) | |
267 { | |
268 $slurp = &FileContents ($file); | |
269 print "Processing file $file\n"; | |
270 print HOUT "\n/* Processing file $file */\n\n"; | |
271 my $totalspace = 70 - length ("Processing file $file"); | |
272 $totalspace = 0 if $totalspace < 0; | |
273 my $alignspaceleft = $totalspace / 2; | |
274 my $alignspaceright = ($totalspace + 1) / 2; | |
275 print COUT " | |
276 /*----------------------------------------------------------------------*/ | |
277 /*" . (" " x $alignspaceleft) . "Processing file $file" . | |
278 (" " x $alignspaceright) . "*/ | |
279 /*----------------------------------------------------------------------*/ | |
280 | |
281 "; | |
282 | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
283 while ($slurp =~ /$wfun_re/g) |
771 | 284 { |
285 my ($rettype, $fun, $args) = ($1, $2, $3); | |
5920
0f2338afbabf
Minimum necessary to get started:
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
286 #print "slurped: $1 $2 $3\n"; |
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
|
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 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
|
289 { |
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 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
|
291 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
|
292 } |
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 $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
|
295 |
771 | 296 print "Processing: $fun"; |
297 | |
4903
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}[0], $files{$file}{$fun}[1]); |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
299 # 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
|
300 # my ($command, $reason) = @$files{$file}{$fun}; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
301 # 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
|
302 my $filesarr = $files{$file}{$fun}; |
5920
0f2338afbabf
Minimum necessary to get started:
Henry Thompson <ht@markup.co.uk>
parents:
5402
diff
changeset
|
303 if (!defined ($filesarr)) {print "\nlosing: |$file|$fun|\n"; next} |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
304 my ($command, $reason) = @$filesarr; |
771 | 305 if (!defined ($command)) |
306 { | |
307 print " (no command found)\n"; | |
308 } | |
309 else | |
310 { | |
311 print "\n"; | |
312 my $bracket = $bracket{$file}{$fun}; | |
313 if (defined ($bracket)) | |
314 { | |
315 print HOUT "#if $bracket\n"; | |
316 print COUT "#if $bracket\n\n"; | |
317 } | |
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
|
318 if ($command eq "no" || $command eq "review") |
771 | 319 { |
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
|
320 $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
|
321 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
|
322 |
771 | 323 if (!defined ($reason)) |
324 { | |
325 print "WARNING: No reason given for `no' with function $fun\n"; | |
326 $reason = ""; | |
327 } | |
328 | |
329 print HOUT "#undef $fun\n"; | |
2367 | 330 (my $munged_reason = $reason) =~ s/[^A-Za-z0-9]/_/g; |
331 print HOUT "#define $fun error_$munged_reason\n"; | |
771 | 332 print COUT "/* Error if $fun used: $reason */\n\n"; |
333 } | |
334 elsif ($command eq "skip") | |
335 { | |
336 if (!defined ($reason)) | |
337 { | |
338 print "WARNING: No reason given for `skip' with function $fun\n"; | |
339 $reason = ""; | |
340 } | |
341 | |
342 print HOUT "/* Skipping $fun because $reason */\n"; | |
343 print COUT "/* Skipping $fun because $reason */\n\n"; | |
344 } | |
345 elsif ($command eq "soon") | |
346 { | |
347 $reason = "" if !defined ($reason); | |
348 | |
349 print HOUT "/* Not yet: $fun $reason */\n"; | |
350 print COUT "/* Not yet: $fun $reason */\n\n"; | |
351 } | |
352 else | |
353 { | |
354 my (@args, %argtype, %ansiarg, %xarg, $split_struct, | |
355 $split_rettype); | |
356 if ($command eq "split") | |
357 { | |
358 ($split_struct, $reason) = split /\s+/, $reason, 2; | |
359 } | |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
360 elsif ($command eq "override") |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
361 { |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
362 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
|
363 $reason = "$reason.\n NOTE: " if $reason; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
364 $reason = "${reason}Prototype manually overridden. |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
365 Header file claims: |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
366 $rettype $fun($args) |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
367 Overridden with: |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
368 $nrettype $nfun($nargs) |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
369 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
|
370 "; |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
371 ($rettype, $fun, $args) = ($nrettype, $nfun, $nargs); |
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
372 } |
771 | 373 my $argno = 0; |
4903
70089046adef
fix compile problems in intl-encap* under VS6
Ben Wing <ben@xemacs.org>
parents:
4875
diff
changeset
|
374 while ($args =~ /$argmatch_re/g) |
771 | 375 { |
376 $argno++; | |
377 my ($argtype, $argname) = ($1, $2); | |
378 $argtype =~ s/\s*$//; | |
379 next if $argtype eq "void" || $argtype eq "VOID"; | |
380 $argname = "arg$argno" if !defined ($argname); | |
381 $argtype{$argname} = $argtype; | |
382 $ansiarg{$argname} = $argtype; | |
383 $ansiarg{$argname} =~ s/\bLPWSTR\b/LPSTR/; | |
384 $ansiarg{$argname} =~ s/\bLPCWSTR\b/LPCSTR/; | |
385 $xarg{$argname} = $argtype; | |
386 $xarg{$argname} =~ s/\bLPWSTR\b/Extbyte */; | |
387 $xarg{$argname} =~ s/\bLPCWSTR\b/const Extbyte */; | |
388 if (defined ($split_struct)) | |
389 { | |
390 my $fuck_cperl1 = "\\b${split_struct}W\\b"; | |
391 my $fuck_cperl2 = "${split_struct}A"; | |
392 $ansiarg{$argname} =~ s/$fuck_cperl1/$fuck_cperl2/; | |
393 } | |
394 push @args, $argname; | |
395 } | |
396 $rettype =~ s/\bSHSTDAPI_\((.*)\)/$1/; | |
397 $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
|
398 $rettype =~ s/\bAPIENTRY\b\s*//; |
771 | 399 $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
|
400 $rettype =~ s/\bextern\b\s*//; |
771 | 401 if ($rettype =~ /LPC?WSTR/) |
402 { | |
403 $split_rettype = 1; | |
404 $rettype =~ s/\bLPWSTR\b/Extbyte */; | |
405 $rettype =~ s/\bLPCWSTR\b/const Extbyte */; | |
406 } | |
800 | 407 print HOUT "#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED\n"; |
408 print HOUT "#undef $fun\n"; | |
2367 | 409 print HOUT "#define $fun error_use_qxe${fun}_or_${fun}A_and_${fun}W\n"; |
800 | 410 print HOUT "#endif\n"; |
771 | 411 if (defined ($reason)) |
412 { | |
413 print COUT "/* NOTE: $reason */\n"; | |
414 } | |
415 print COUT "$rettype\nqxe$fun ("; | |
416 print HOUT "$rettype qxe$fun ("; | |
417 my $first = 1; | |
418 if (!@args) | |
419 { | |
420 print COUT "void"; | |
421 print HOUT "void"; | |
422 } | |
423 else | |
424 { | |
425 foreach my $x (@args) | |
426 { | |
427 print COUT ", " if !$first; | |
428 print HOUT ", " if !$first; | |
429 $first = 0; | |
430 print COUT "$xarg{$x} $x"; | |
431 print HOUT "$xarg{$x} $x"; | |
432 } | |
433 } | |
434 print HOUT ");\n"; | |
435 print COUT ")\n{\n if (XEUNICODE_P)\n "; | |
436 if ($rettype ne "void" && $rettype ne "VOID") | |
437 { | |
438 print COUT "return "; | |
439 print COUT "($rettype) " if $split_rettype; | |
440 } | |
441 print COUT "${fun}W ("; | |
442 $first = 1; | |
443 foreach my $x (@args) | |
444 { | |
445 print COUT ", " if !$first; | |
446 $first = 0; | |
447 print COUT ($argtype{$x} eq $xarg{$x} ? $x : | |
448 "($argtype{$x}) $x"); | |
449 } | |
450 print COUT ");\n else\n "; | |
451 if ($rettype ne "void" && $rettype ne "VOID") | |
452 { | |
453 print COUT "return "; | |
454 print COUT "($rettype) " if $split_rettype; | |
455 } | |
456 print COUT "${fun}A ("; | |
457 $first = 1; | |
458 foreach my $x (@args) | |
459 { | |
460 print COUT ", " if !$first; | |
461 $first = 0; | |
462 print COUT ($argtype{$x} eq $ansiarg{$x} ? $x : | |
463 "($ansiarg{$x}) $x"); | |
464 } | |
465 print COUT ");\n}\n\n"; | |
466 } | |
467 if (defined ($bracket)) | |
468 { | |
469 print HOUT "#endif /* $bracket */\n"; | |
470 print COUT "#endif /* $bracket */\n\n"; | |
471 } | |
800 | 472 print HOUT "\n"; |
771 | 473 } |
474 } | |
475 } | |
476 | |
477 foreach my $file (keys %files) | |
478 { | |
479 foreach my $fun (keys %{$files{$file}}) | |
480 { | |
481 if (!$processed{$fun} && $files{$file}{$fun}[0] =~ /^(yes|soon|split)$/) | |
482 { | |
483 print "WARNING: Can't locate prototype for $fun\n"; | |
484 } | |
485 } | |
486 } | |
487 | |
488 | |
489 sub FileContents | |
490 { | |
491 local $/ = undef; | |
778 | 492 open (FILE, "< $dir/$_[0]") or die "$dir/$_[0]: $!"; |
771 | 493 my $retval = scalar <FILE>; |
494 # must hack away CRLF junk. | |
495 $retval =~ s/\r\n/\n/g; | |
496 return $retval; | |
497 } |