OOO330
[LibreOffice.git] / solenv / bin / mhids.pl
blob33f873bc386d3cecdb2d20121529d95c3e5e8307
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
31 my $filename;
32 my $srs;
33 my $prjname;
34 my $defs;
35 my $solarincludes;
36 my $verbose = 0;
38 my $debug = 0;
39 my $filebase;
40 my $workfile;
41 my $shell_workfile;
42 my @cleanuplist = ();
44 # variables to setup the compiler line
45 my $appext;
46 my $compiler;
47 my $outbin_flag;
48 my $outobj_flag;
49 my $objext;
50 my $preprocess_flag; # preprocess to stdout
52 my $no_hid_files;
54 sub cleandie
56 my $errstring = shift @_;
57 my $erroreval = $@;
59 print STDERR "$errstring\n";
60 if ( not $debug ) {
61 foreach my $i (@cleanuplist) {
62 # unlink "$workfile$i" if -f "$workfile$i" or print STDERR "ERROR - couldn't remove $workfile$i\n";
63 if ( -f "$workfile$i" ) {
64 unlink "$workfile$i" or print STDERR "ERROR - couldn't remove $workfile$i\n";
68 die "$erroreval\n";
71 sub setcompiler
73 my $whichcom = $ENV{COM};
74 my $extra_cflags = $ENV{EXTRA_CFLAGS};
75 $extra_cflags = "" if (!$extra_cflags);
76 if ( "$whichcom" eq "GCC" ) {
77 $appext = ""; # windows for now
78 $compiler = "gcc -x c $extra_cflags";
79 $outbin_flag = "-o ";
80 $outobj_flag = "";
81 $objext = ".o";
82 $preprocess_flag = "-E"; # preprocess to stdout
83 } elsif ( "$whichcom" eq "MSC" ) {
84 $appext = ".exe"; # windows for now
85 $compiler = "cl -nologo";
86 $outbin_flag = "-Fe";
87 $outobj_flag = "-Fo";
88 $objext = ".obj";
89 $preprocess_flag = "-EP"; # preprocess to stdout
90 $solarincludes =~ s/\/stl/\/xstlx/g;
91 $defs =~ s/\/stl/\/xstlx/g;
92 } elsif ( "$whichcom" eq "C52" ) {
93 $appext = ""; # windows for now
94 $compiler = "cc";
95 $outbin_flag = "-o ";
96 $outobj_flag = "";
97 $objext = ".o";
98 $preprocess_flag = "-E"; # preprocess to stdout
100 # hack for SO cc wrapper
101 $ENV{wrapper_override_cc_wrapper} = "TRUE";
102 $solarincludes =~ s/stl/xstlx/g;
103 $defs =~ s/\/stl/\/xstlx/g;
104 } else {
105 print STDERR "----------------------------------------------------------------------\n";
106 print STDERR "OOops... looks like your compiler isn't known to \n$0\n";
107 print STDERR "please edit the \"setcompiler\" section of this script to make it work.\n";
108 print STDERR "----------------------------------------------------------------------\n";
109 die "ERROR - compiler (or \$COM settings) unknown!\n";
113 #---------------------------------------------------
114 $filename = undef;
115 $srs = undef;
116 $prjname = undef;
118 my @expectedArgs = ( \$filename, \$srs, \$prjname );
119 my $expectedArgsIndex = 0;
120 while ( ( $#ARGV >= 0 ) && ( $expectedArgsIndex < 3 ) )
122 $_ = shift @ARGV;
123 if ( /^-verbose$/ )
125 $verbose = 1;
126 next;
128 ${$expectedArgs[ $expectedArgsIndex ]} = $_;
129 ++$expectedArgsIndex;
132 $defs = join " ",@ARGV if ($#ARGV);
134 if ( !defined $prjname ) { die "ERROR - check usage\n"; }
136 if ( $ENV{NO_HID_FILES} ) {
137 $no_hid_files = $ENV{"NO_HID_FILES"};
139 $solarincludes = $ENV{SOLARINCLUDES};
140 if (defined $ENV{TMPDIR}) {
141 $tmpdir = $ENV{TMPDIR};
142 } elsif (defined $ENV{TMP}) {
143 $tmpdir = $ENV{TMP};
144 } else {
145 die "ERROR - \"TMPDIR\" & \"TMP\" environment variables not set\n";
147 die "ERROR - \"$tmpdir\" doesn't exist\n" if ( ! -d $tmpdir );
149 setcompiler();
151 # convert windows only?
152 $srs =~ s/\\/\//g;
153 $filename =~ s/\\/\//g;
155 $filebase = $filename;
156 $filebase =~ s/.*[\\\/]//;
157 $filebase =~ s/\..*?$//;
158 # now stript it to something that doesn't togger vista execution prevention :(
159 $flbs = $filebase;
160 $flbs =~ s/[aeiou]//g;
161 # call srand ony once per script!
162 srand();
163 $workfile = "$tmpdir/${flbs}_".$$.rand();
164 #$workfile =~ s/setup/set_up/;
166 # now get $workfile ready for shell usage...
167 $shell_workfile = $workfile;
169 print "workfile: $workfile\n" if $verbose;
171 #remove old objects which remained in place by a former bug
172 unlink "$workfile.obj";
174 # can't do this for modules with mixed case!
175 #$prjname =~ lc $prjname;
177 if ( -f "$workfile.hid" )
179 unlink "$workfile.hid" or die "ERRROR - cannot remove $workfile.hid\n";
182 # hack to quit for files which cannot be handled
183 if ( defined $ENV{"NO_HID_FILES"} ) {
184 foreach $fname ( split / /, $ENV{"NO_HID_FILES"} )
186 if ( $fname eq $filename )
188 print "No hid generation for $filename due to NO_HID_FILES\n";
189 print "Touching $srs/$filebase.hid anyways\n";
190 open TOUCH, ">$srs/$filebase.hid" or die "ERRROR - cannot open $srs/$filebase.hid for writing\n";
191 close TOUCH;
192 exit 0;
197 #echo "perl5 -p -e "s/=[ \t]*\".*\"/=\"\"/go; s/\".*\"[ \t]*;/\"\" ;/go ; s/(\".*)\/\/(.*\")/$1\/\\\/$2/go ;" < %filename% > %srs%\%workfile%.c0"
198 #call perl5 -p -e "s/=[ \t]*\".*\"/=\"\"/go; s/\".*\"[ \t]*;/\"\" ;/go ; s/(\".*)\/\/(.*\")/$1\/\\\/$2/go ;" < %filename% > %srs%\%workfile%.c0
200 my $verboseSwitch = $verbose ? "-verbose" : "";
201 print "$ENV{SOLARBINDIR}/hidc $verboseSwitch $filename ${shell_workfile}.c1 $prjname\n" if $verbose;
202 $ret = system "$ENV{SOLARBINDIR}/hidc $verboseSwitch $filename ${shell_workfile}.c1 $prjname";
203 if ( $ret ) {
204 push @cleanuplist, ".c1";
205 cleandie("ERROR - calling \"hidc\" failed");
207 push @cleanuplist, ".c1";
209 print "$compiler $defs $solarincludes $preprocess_flag ${shell_workfile}.c1 > ${shell_workfile}.c2\n" if $verbose;
210 $ret = system "$compiler $defs $solarincludes $preprocess_flag ${shell_workfile}.c1 > ${shell_workfile}.c2";
211 if ( $ret ) {
212 push @cleanuplist, ".c2";
213 cleandie("ERROR - calling compiler for preprocessing failed");
215 push @cleanuplist, ".c2";
217 if (!open C_PROG, ">$workfile.c") {
218 push @cleanuplist, ".c";
219 cleandie("ERROR - open $workfile.c\n for writing failed");
221 push @cleanuplist, ".c";
222 print C_PROG "#include <stdio.h>\n";
223 print C_PROG "#include <wctype.h>\n";
225 if ( !open PRE, "<$workfile.c2" ) {
226 cleandie("ERROR - open $workfile.c2\n for reading failed");
229 $InMain = 0;
230 while (<PRE>)
232 if ( /int\s*main/ )
234 $InMain = 1;
237 if ( $InMain && !/^\s*$/ )
239 print C_PROG;
243 close PRE;
244 close C_PROG;
246 #cl %SOLARINCLUDES% %_srs%\%_workfile%.c /Fe%_srs%\%_workfile%$appext
247 my $outobj_param = "";
248 if ( $outobj_flag ne "" )
250 $outobj_param = "$outobj_flag${shell_workfile}$objext";
252 print "$compiler $defs $solarincludes ${shell_workfile}.c $outobj_param $outbin_flag${shell_workfile}$appext \n" if $verbose;
253 $ret = system "$compiler $defs $solarincludes ${shell_workfile}.c $outobj_param $outbin_flag${shell_workfile}$appext";
254 if ( $ret ) {
255 push @cleanuplist, "$appext";
256 cleandie("ERROR - compiling $workfile.c failed");
258 push @cleanuplist, "$objext";
259 push @cleanuplist, "$appext";
261 #awk -f %ENV_TOOLS%\hidcode.awk < %srs%\%workfile%.c3 > %srs%\%workfile%.hid
262 if ( !open C3,"$workfile$appext|" ) {
263 cleandie("ERROR - executing $workfile$appext failed");
265 if ( !open HID,">$srs/$filebase.hid.$ENV{INPATH}" ) {
266 cleandie("ERROR - open $srs/$filebase.hid.$ENV{INPATH} for writing failed");
269 while (<C3>)
271 @fields = split /\s+/;
273 if ( $fields[1] eq "HelpID" )
275 print HID "$fields[0] $fields[2]\n";
276 next;
279 @arr = split /:/, $fields[0];
280 if( $arr[1] =~ /^leer$|^bitmap$|^font$|^color$|^image$|^imagelist$|^date$|^brush$|^fixedtext$|^keycode$|^time$|^mapmode$/i )
282 #print "skipping $arr[1]\n";
283 next;
286 if ( $fields[1] eq "Norm" )
288 # Felder der Zeile auf Variable verteilen
289 $helpIDString = $fields[0];
290 $GClass = lc($fields[2]);
291 $GID = $fields[3];
292 $LClass = lc($fields[4]);
293 $LID = $fields[5] || 0;
295 #print $LID
296 #print $LClass
297 #print $GID
298 #print $GClass
300 $nHID=0;
302 $VAL1 = 536870912; #2 hoch 29
303 if ( $GClass eq "workwindow" ) { $nHID= $VAL1 *5; }
304 elsif( $GClass eq "modelessdialog" ) { $nHID= $VAL1 *4; }
305 elsif( $GClass eq "floatingwindow" ) { $nHID= $VAL1 *3; }
306 elsif( $GClass eq "modaldialog" ) { $nHID= $VAL1 *2; }
307 elsif( $GClass eq "tabpage" ) { $nHID= $VAL1 *1; }
308 elsif( $GClass eq "dockingwindow" ) { $nHID= $VAL1 *6; }
309 #Maximal bis 7 dann sind 32Bit ausgeschoepft
310 else {
311 $nHID=0;
312 $outline = "No GClass ".$helpIDString." ".$nHID." ".$GClass;
313 #print "$outline\n";
314 next;
316 if( $LID != 0 ) {
317 if ( $LClass eq "tabcontrol" ) { $nHID += 0; }
318 elsif( $LClass eq "radiobutton" ) { $nHID += 2*256; }
319 elsif( $LClass eq "checkbox" ) { $nHID += 4*256; }
320 elsif( $LClass eq "tristatebox" ) { $nHID += 6*256; }
321 elsif( $LClass eq "edit" ) { $nHID += 8*256; }
322 elsif( $LClass eq "multilineedit" ) { $nHID += 10*256; }
323 elsif( $LClass eq "multilistbox" ) { $nHID += 12*256; }
324 elsif( $LClass eq "listbox" ) { $nHID += 14*256; }
325 elsif( $LClass eq "combobox" ) { $nHID += 16*256; }
326 elsif( $LClass eq "pushbutton" ) { $nHID += 18*256; }
327 elsif( $LClass eq "spinfield" ) { $nHID += 20*256; }
328 elsif( $LClass eq "patternfield" ) { $nHID += 22*256; }
329 elsif( $LClass eq "numericfield" ) { $nHID += 24*256; }
330 elsif( $LClass eq "metricfield" ) { $nHID += 26*256; }
331 elsif( $LClass eq "currencyfield" ) { $nHID += 28*256; }
332 elsif( $LClass eq "datefield" ) { $nHID += 30*256; }
333 elsif( $LClass eq "timefield" ) { $nHID += 32*256; }
334 elsif( $LClass eq "imageradiobutton" ) { $nHID += 34*256; }
335 elsif( $LClass eq "numericbox" ) { $nHID += 36*256; }
336 elsif( $LClass eq "metricbox" ) { $nHID += 38*256; }
337 elsif( $LClass eq "currencybox" ) { $nHID += 40*256; }
338 elsif( $LClass eq "datebox" ) { $nHID += 42*256; }
339 elsif( $LClass eq "timebox" ) { $nHID += 44*256; }
340 elsif( $LClass eq "imagebutton" ) { $nHID += 46*256; }
341 elsif( $LClass eq "menubutton" ) { $nHID += 48*256; }
342 elsif( $LClass eq "morebutton" ) { $nHID += 50*256; }
343 else {
344 $nHID=0;
345 $outline = "No LClass ".$helpIDString." ".$nHID;
346 #print "$outline\n";
347 next;
350 #GID und LID auch beruecksichtigen
351 $nHID += $LID;
353 $nHID += $GID * 16384; #14 Bit nach links shiften
355 # check here and not above to avoid warnings for restypes not generated anyways
356 if( $GID == 0 || $GID >32767 || $LID > 511 )
358 #GID & LID ungueltig
359 print STDERR "Invalid Global or Local ID: 0 < GID <= 32767 ; LID <= 511\n";
360 print STDERR "$helpIDString GID = $GID; LID = $LID\n";
361 next;
365 # 1. Stelle selber ausgeben, falls groesser als 2^21
366 # wg. problemen von awk/gawk bei printf mit %u
368 $x=0;
369 if( $nHID >= 4000000000 ) {
370 $nHID -= 4000000000;
371 $x=4;
372 }elsif( $nHID >= 3000000000) {
373 $nHID -= 3000000000;
374 $x=3;
375 }elsif( $nHID >= 2000000000) {
376 $nHID -= 2000000000;
377 $x=2;
379 if( $x != 0)
380 { printf HID "%s %d%u \n",$helpIDString,$x, $nHID; }
381 else
382 { printf HID "%s %u \n",$helpIDString, $nHID; }
386 close C3;
387 close HID;
389 rename("$srs/$filebase.hid.$ENV{INPATH}", "$srs/$filebase.hid") or cleandie("ERROR - couldn't rename tmp file to final for $filebase");
391 if ( not $debug ) {
392 foreach my $i (@cleanuplist) {
393 sleep 1;
394 if ( -f "$workfile$i" ) {
395 unlink "$workfile$i" or cleandie("");