Update ooo320-m1
[ooovba.git] / solenv / bin / mhids.pl
blob52269806a6c1923fd90d1b50cf81a3288bea2513
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: mhids.pl,v $
14 # $Revision: 1.11 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
35 my $filename;
36 my $srs;
37 my $prjname;
38 my $defs;
39 my $solarincludes;
40 my $verbose = 0;
42 my $debug = 0;
43 my $filebase;
44 my $workfile;
45 my $shell_workfile;
46 my @cleanuplist = ();
48 # variables to setup the compiler line
49 my $appext;
50 my $compiler;
51 my $outbin_flag;
52 my $outobj_flag;
53 my $objext;
54 my $preprocess_flag; # preprocess to stdout
56 my $no_hid_files;
58 sub cleandie
60 my $errstring = shift @_;
61 my $erroreval = $@;
63 print STDERR "$errstring\n";
64 if ( not $debug ) {
65 foreach my $i (@cleanuplist) {
66 unlink "$workfile$i" if -f "$workfile$i" or print STDERR "ERROR - couldn't remove $workfile$i\n";
69 die "$erroreval\n";
72 sub setcompiler
74 my $whichcom = $ENV{COM};
75 my $extra_cflags = $ENV{EXTRA_CFLAGS};
76 $extra_cflags = "" if (!$extra_cflags);
77 if ( "$whichcom" eq "GCC" ) {
78 $appext = ""; # windows for now
79 $compiler = "gcc -x c $extra_cflags";
80 $outbin_flag = "-o ";
81 $outobj_flag = "";
82 $objext = ".o";
83 $preprocess_flag = "-E"; # preprocess to stdout
84 } elsif ( "$whichcom" eq "MSC" ) {
85 $appext = ".exe"; # windows for now
86 $compiler = "cl";
87 $outbin_flag = "-Fe";
88 $outobj_flag = "-Fo";
89 $objext = ".obj";
90 $preprocess_flag = "-EP"; # preprocess to stdout
91 } elsif ( "$whichcom" eq "C52" ) {
92 $appext = ""; # windows for now
93 $compiler = "cc";
94 $outbin_flag = "-o ";
95 $outobj_flag = "";
96 $objext = ".o";
97 $preprocess_flag = "-E"; # preprocess to stdout
99 # hack for SO cc wrapper
100 $ENV{wrapper_override_cc_wrapper} = "TRUE";
101 $solarincludes =~ s/stl/xstlx/g;
102 $defs =~ s/\/stl/\/xstlx/g;
103 } else {
104 print STDERR "----------------------------------------------------------------------\n";
105 print STDERR "OOops... looks like your compiler isn't known to \n$0\n";
106 print STDERR "please edit the \"setcompiler\" section of this script to make it work.\n";
107 print STDERR "----------------------------------------------------------------------\n";
108 die "ERROR - compiler (or \$COM settings) unknown!\n";
112 #---------------------------------------------------
113 $filename = undef;
114 $srs = undef;
115 $prjname = undef;
117 my @expectedArgs = ( \$filename, \$srs, \$prjname );
118 my $expectedArgsIndex = 0;
119 while ( ( $#ARGV >= 0 ) && ( $expectedArgsIndex < 3 ) )
121 $_ = shift @ARGV;
122 if ( /^-verbose$/ )
124 $verbose = 1;
125 next;
127 ${$expectedArgs[ $expectedArgsIndex ]} = $_;
128 ++$expectedArgsIndex;
131 $defs = join " ",@ARGV if ($#ARGV);
133 if ( !defined $prjname ) { die "ERROR - check usage\n"; }
135 if ( $ENV{NO_HID_FILES} ) {
136 $no_hid_files = $ENV{"NO_HID_FILES"};
138 $solarincludes = $ENV{SOLARINCLUDES};
139 if (defined $ENV{TMPDIR}) {
140 $tmpdir = $ENV{TMPDIR};
141 } elsif (defined $ENV{TMP}) {
142 $tmpdir = $ENV{TMP};
143 } else {
144 die "ERROR - \"TMPDIR\" & \"TMP\" environment variables not set\n";
146 die "ERROR - \"$tmpdir\" doesn't exist\n" if ( ! -d $tmpdir );
148 setcompiler();
150 # convert windows only?
151 $srs =~ s/\\/\//g;
152 $filename =~ s/\\/\//g;
154 $filebase = $filename;
155 $filebase =~ s/.*[\\\/]//;
156 $filebase =~ s/\..*?$//;
157 $workfile = "$tmpdir/${filebase}_".$$;
158 #$workfile =~ s/setup/set_up/;
160 # now get $workfile ready for shell usage...
161 $shell_workfile = $workfile;
163 print "workfile: $workfile\n" if $verbose;
165 #remove old objects which remained in place by a former bug
166 unlink "$workfile.obj";
168 # can't do this for modules with mixed case!
169 #$prjname =~ lc $prjname;
171 if ( -f "$workfile.hid" )
173 unlink "$workfile.hid" or die "ERRROR - cannot remove $workfile.hid\n";;
176 # hack to quit for files which cannot be handled
177 if ( defined $ENV{"NO_HID_FILES"} ) {
178 foreach $fname ( split / /, $ENV{"NO_HID_FILES"} )
180 if ( $fname eq $filename )
182 print "No hid generation for $filename due to NO_HID_FILES\n";
183 print "Touching $srs/$filebase.hid anyways\n";
184 open TOUCH, ">$srs/$filebase.hid" or die "ERRROR - cannot open $srs/$filebase.hid for writing\n";
185 close TOUCH;
186 exit 0;
191 #echo "perl5 -p -e "s/=[ \t]*\".*\"/=\"\"/go; s/\".*\"[ \t]*;/\"\" ;/go ; s/(\".*)\/\/(.*\")/$1\/\\\/$2/go ;" < %filename% > %srs%\%workfile%.c0"
192 #call perl5 -p -e "s/=[ \t]*\".*\"/=\"\"/go; s/\".*\"[ \t]*;/\"\" ;/go ; s/(\".*)\/\/(.*\")/$1\/\\\/$2/go ;" < %filename% > %srs%\%workfile%.c0
194 print "$ENV{SOLARBINDIR}/hidc $filename ${shell_workfile}.c1 $prjname \n";
195 $ret = system "$ENV{SOLARBINDIR}/hidc $filename ${shell_workfile}.c1 $prjname";
196 if ( $ret ) {
197 push @cleanuplist, ".c1";
198 cleandie("ERROR - calling \"hidc\" failed");
200 push @cleanuplist, ".c1";
202 print "$compiler $solarincludes $defs $preprocess_flag ${shell_workfile}.c1 > ${shell_workfile}.c2\n";
203 $ret = system "$compiler $solarincludes $defs $preprocess_flag ${shell_workfile}.c1 > ${shell_workfile}.c2";
204 if ( $ret ) {
205 push @cleanuplist, ".c2";
206 cleandie("ERROR - calling compiler for preprocessing failed");
208 push @cleanuplist, ".c2";
210 if (!open C_PROG, ">$workfile.c") {
211 push @cleanuplist, ".c";
212 cleandie("ERROR - open $workfile.c\n for writing failed");
214 push @cleanuplist, ".c";
215 print C_PROG "#include <stdio.h>\n";
216 print C_PROG "#include <wctype.h>\n";
218 if ( !open PRE, "<$workfile.c2" ) {
219 cleandie("ERROR - open $workfile.c2\n for reading failed");
222 $InMain = 0;
223 while (<PRE>)
225 if ( /int\s*main/ )
227 $InMain = 1;
230 if ( $InMain && !/^\s*$/ )
232 print C_PROG;
236 close PRE;
237 close C_PROG;
239 #cl %SOLARINCLUDES% %_srs%\%_workfile%.c /Fe%_srs%\%_workfile%$appext
240 my $outobj_param = "";
241 if ( $outobj_flag ne "" )
243 $outobj_param = "$outobj_flag${shell_workfile}$objext";
245 print "$compiler $solarincludes $defs ${shell_workfile}.c $outobj_param $outbin_flag${shell_workfile}$appext \n" if $verbose;
246 $ret = system "$compiler $solarincludes $defs ${shell_workfile}.c $outobj_param $outbin_flag${shell_workfile}$appext";
247 if ( $ret ) {
248 push @cleanuplist, "$appext";
249 cleandie("ERROR - compiling $workfile.c failed");
251 push @cleanuplist, "$objext";
252 push @cleanuplist, "$appext";
254 #awk -f %ENV_TOOLS%\hidcode.awk < %srs%\%workfile%.c3 > %srs%\%workfile%.hid
255 if ( !open C3,"$workfile$appext|" ) {
256 cleandie("ERROR - executing $workfile$appext failed");
258 if ( !open HID,">$srs/$filebase.hid.$ENV{INPATH}" ) {
259 cleandie("ERROR - open $srs/$filebase.hid.$ENV{INPATH} for writing failed");
262 while (<C3>)
264 @fields = split /\s+/;
266 if ( $fields[1] eq "HelpID" )
268 print HID "$fields[0] $fields[2]\n";
269 next;
272 @arr = split /:/, $fields[0];
273 if( $arr[1] =~ /^leer$|^bitmap$|^font$|^color$|^image$|^imagelist$|^date$|^brush$|^fixedtext$|^keycode$|^time$|^mapmode$/i )
275 #print "skipping $arr[1]\n";
276 next;
279 if ( $fields[1] eq "Norm" )
281 # Felder der Zeile auf Variable verteilen
282 $helpIDString = $fields[0];
283 $GClass = lc($fields[2]);
284 $GID = $fields[3];
285 $LClass = lc($fields[4]);
286 $LID = $fields[5] || 0;
288 #print $LID
289 #print $LClass
290 #print $GID
291 #print $GClass
293 $nHID=0;
295 $VAL1 = 536870912; #2 hoch 29
296 if ( $GClass eq "workwindow" ) { $nHID= $VAL1 *5; }
297 elsif( $GClass eq "modelessdialog" ) { $nHID= $VAL1 *4; }
298 elsif( $GClass eq "floatingwindow" ) { $nHID= $VAL1 *3; }
299 elsif( $GClass eq "modaldialog" ) { $nHID= $VAL1 *2; }
300 elsif( $GClass eq "tabpage" ) { $nHID= $VAL1 *1; }
301 elsif( $GClass eq "dockingwindow" ) { $nHID= $VAL1 *6; }
302 #Maximal bis 7 dann sind 32Bit ausgeschoepft
303 else {
304 $nHID=0;
305 $outline = "No GClass ".$helpIDString." ".$nHID." ".$GClass;
306 #print "$outline\n";
307 next;
309 if( $LID != 0 ) {
310 if ( $LClass eq "tabcontrol" ) { $nHID += 0; }
311 elsif( $LClass eq "radiobutton" ) { $nHID += 2*256; }
312 elsif( $LClass eq "checkbox" ) { $nHID += 4*256; }
313 elsif( $LClass eq "tristatebox" ) { $nHID += 6*256; }
314 elsif( $LClass eq "edit" ) { $nHID += 8*256; }
315 elsif( $LClass eq "multilineedit" ) { $nHID += 10*256; }
316 elsif( $LClass eq "multilistbox" ) { $nHID += 12*256; }
317 elsif( $LClass eq "listbox" ) { $nHID += 14*256; }
318 elsif( $LClass eq "combobox" ) { $nHID += 16*256; }
319 elsif( $LClass eq "pushbutton" ) { $nHID += 18*256; }
320 elsif( $LClass eq "spinfield" ) { $nHID += 20*256; }
321 elsif( $LClass eq "patternfield" ) { $nHID += 22*256; }
322 elsif( $LClass eq "numericfield" ) { $nHID += 24*256; }
323 elsif( $LClass eq "metricfield" ) { $nHID += 26*256; }
324 elsif( $LClass eq "currencyfield" ) { $nHID += 28*256; }
325 elsif( $LClass eq "datefield" ) { $nHID += 30*256; }
326 elsif( $LClass eq "timefield" ) { $nHID += 32*256; }
327 elsif( $LClass eq "imageradiobutton" ) { $nHID += 34*256; }
328 elsif( $LClass eq "numericbox" ) { $nHID += 36*256; }
329 elsif( $LClass eq "metricbox" ) { $nHID += 38*256; }
330 elsif( $LClass eq "currencybox" ) { $nHID += 40*256; }
331 elsif( $LClass eq "datebox" ) { $nHID += 42*256; }
332 elsif( $LClass eq "timebox" ) { $nHID += 44*256; }
333 elsif( $LClass eq "imagebutton" ) { $nHID += 46*256; }
334 elsif( $LClass eq "menubutton" ) { $nHID += 48*256; }
335 elsif( $LClass eq "morebutton" ) { $nHID += 50*256; }
336 else {
337 $nHID=0;
338 $outline = "No LClass ".$helpIDString." ".$nHID;
339 #print "$outline\n";
340 next;
343 #GID und LID auch beruecksichtigen
344 $nHID += $LID;
346 $nHID += $GID * 16384; #14 Bit nach links shiften
348 # check here and not above to avoid warnings for restypes not generated anyways
349 if( $GID == 0 || $GID >32767 || $LID > 511 )
351 #GID & LID ungueltig
352 print STDERR "Invalid Global or Local ID: 0 < GID <= 32767 ; LID <= 511\n";
353 print STDERR "$helpIDString GID = $GID; LID = $LID\n";
354 next;
358 # 1. Stelle selber ausgeben, falls groesser als 2^21
359 # wg. problemen von awk/gawk bei printf mit %u
361 $x=0;
362 if( $nHID >= 4000000000 ) {
363 $nHID -= 4000000000;
364 $x=4;
365 }elsif( $nHID >= 3000000000) {
366 $nHID -= 3000000000;
367 $x=3;
368 }elsif( $nHID >= 2000000000) {
369 $nHID -= 2000000000;
370 $x=2;
372 if( $x != 0)
373 { printf HID "%s %d%u \n",$helpIDString,$x, $nHID; }
374 else
375 { printf HID "%s %u \n",$helpIDString, $nHID; }
379 close C3;
380 close HID;
382 rename("$srs/$filebase.hid.$ENV{INPATH}", "$srs/$filebase.hid") or cleandie("ERROR - couldn't rename tmp file to final for $filebase");
384 if ( not $debug ) {
385 foreach my $i (@cleanuplist) {
386 if ( -f "$workfile$i" ) {
387 unlink "$workfile$i" or cleandie("");