1*cdf0e10cSrcweir: 2*cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3*cdf0e10cSrcweir if 0; 4*cdf0e10cSrcweir#************************************************************************* 5*cdf0e10cSrcweir# 6*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7*cdf0e10cSrcweir# 8*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 9*cdf0e10cSrcweir# 10*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 11*cdf0e10cSrcweir# 12*cdf0e10cSrcweir# This file is part of OpenOffice.org. 13*cdf0e10cSrcweir# 14*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir# 18*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir# 24*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir# 29*cdf0e10cSrcweir#************************************************************************* 30*cdf0e10cSrcweir# Description: Wrapper script to change '/' to '\' in command-line 31*cdf0e10cSrcweir# arguments. 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir#--------------------------------------------------------------------------- 34*cdf0e10cSrcweir# external modules 35*cdf0e10cSrcweiruse Text::ParseWords; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir# global vars 38*cdf0e10cSrcweir@params = (); 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir#--------------------------------------------------------------------------- 41*cdf0e10cSrcweir# procedures 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir#---------------------------------------------------------- 45*cdf0e10cSrcweir# Function name: WinFormat 46*cdf0e10cSrcweir# Description: Format variables to Windows Format. 47*cdf0e10cSrcweir# Arguments: 1. Variable (string) with one token 48*cdf0e10cSrcweir# Return value: Reformatted String 49*cdf0e10cSrcweir#---------------------------------------------------------- 50*cdf0e10cSrcweirsub WinFormat { 51*cdf0e10cSrcweir my $variable = shift @_; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir $variable =~ s!(.)/!$1\\!g; # Replace all but the leading slashes with backslashes 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir if ( defined $debug ) { 56*cdf0e10cSrcweir print(STDERR "WinFormat:\nresult:$variable\n"); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir return $variable; 60*cdf0e10cSrcweir} 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir#---------------------------------------------------------- 63*cdf0e10cSrcweir# Function name: replace_cyg 64*cdf0e10cSrcweir# Description: Process all arguments and change them to Windows Format. 65*cdf0e10cSrcweir# Arguments: Reference to array with arguments 66*cdf0e10cSrcweir# Return value: - 67*cdf0e10cSrcweir#---------------------------------------------------------- 68*cdf0e10cSrcweirsub replace_cyg { 69*cdf0e10cSrcweir my $args = shift; 70*cdf0e10cSrcweir my( @cmd_file, @cmd_temp ); 71*cdf0e10cSrcweir my $atchars; 72*cdf0e10cSrcweir foreach my $para ( @$args ) { 73*cdf0e10cSrcweir if ( $para =~ "^@" ) { 74*cdf0e10cSrcweir # it's a command file 75*cdf0e10cSrcweir if ( defined $debug ) { 76*cdf0e10cSrcweir print(STDERR "----------------------------\n"); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir ; 79*cdf0e10cSrcweir # Workaround, iz28717, keep number of @'s. 80*cdf0e10cSrcweir $para =~ s/(^\@+)//; 81*cdf0e10cSrcweir $atchars = $1; 82*cdf0e10cSrcweir $filename = $para; 83*cdf0e10cSrcweir if ( defined $debug ) { 84*cdf0e10cSrcweir print(STDERR "filename = $filename \n"); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir ; 87*cdf0e10cSrcweir # open this command file for reading 88*cdf0e10cSrcweir open(CMD, "$filename"); 89*cdf0e10cSrcweir while ( <CMD> ) { 90*cdf0e10cSrcweir # Remove DOS lineendings. Bug in Cygwin / Perl? 91*cdf0e10cSrcweir $_ =~ s/\r//g; 92*cdf0e10cSrcweir # Remove lineendings and trailing spaces. ( Needed by &parse_line ) 93*cdf0e10cSrcweir $_ =~ s/\n$//g; 94*cdf0e10cSrcweir $_ =~ s/\s+$//g; 95*cdf0e10cSrcweir # Fill all tokens into array 96*cdf0e10cSrcweir @cmd_temp = &parse_line('\s+', 1, $_ ); 97*cdf0e10cSrcweir if ( $#cmd_temp > -1 ) { 98*cdf0e10cSrcweir push( @cmd_file, @cmd_temp); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir close(CMD); 102*cdf0e10cSrcweir # reformat all tokens 103*cdf0e10cSrcweir replace_cyg(\@cmd_file); 104*cdf0e10cSrcweir if ( defined $debug ) { 105*cdf0e10cSrcweir print(STDERR "Tokens processed:\n"); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir ; 108*cdf0e10cSrcweir foreach $i (@cmd_file) { 109*cdf0e10cSrcweir if ( defined $debug ) { 110*cdf0e10cSrcweir print(STDERR "!".$i."!\n"); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir ; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir # open this filename for writing (truncate) Textmode? 115*cdf0e10cSrcweir open(CMD, '>', $filename); 116*cdf0e10cSrcweir # write all tokens back into this file 117*cdf0e10cSrcweir print(CMD join(' ', @cmd_file)); 118*cdf0e10cSrcweir close(CMD); 119*cdf0e10cSrcweir # convert '@filename' to dos style 120*cdf0e10cSrcweir $para = WinFormat( $para ); 121*cdf0e10cSrcweir if ( defined $debug ) { 122*cdf0e10cSrcweir print(STDERR "----------------------------\n"); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir ; 125*cdf0e10cSrcweir if ( (defined $debug_light) or (defined $debug) ) { 126*cdf0e10cSrcweir print(STDERR "\nParameter in File:".join(' ', @cmd_file).":\n"); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir $para = $atchars.$para; 129*cdf0e10cSrcweir } else { 130*cdf0e10cSrcweir # it's just a parameter 131*cdf0e10cSrcweir if ( defined $debug ) { 132*cdf0e10cSrcweir print(STDERR "\nParameter:---${para}---\n"); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir ; 135*cdf0e10cSrcweir # If $tmp1 is empty then $para is a parameter. 136*cdf0e10cSrcweir my $is_no_para = 1; 137*cdf0e10cSrcweir # remove .exe and convert to lower case 138*cdf0e10cSrcweir $shortcommand = lc $command ; 139*cdf0e10cSrcweir $shortcommand =~ s/\.exe$//; 140*cdf0e10cSrcweir $shortcommand =~ /([^\/]+$)/; 141*cdf0e10cSrcweir $shortcommand = $1; 142*cdf0e10cSrcweir if ( $is_no_para ) { 143*cdf0e10cSrcweir $para = WinFormat($para); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir if ( defined $debug ) { 146*cdf0e10cSrcweir print(STDERR "Converted line:${para}:\n" ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } # else 149*cdf0e10cSrcweir } # foreach loop 150*cdf0e10cSrcweir} 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir#--------------------------------------------------------------------------- 154*cdf0e10cSrcweir# main 155*cdf0e10cSrcweir@params = @ARGV; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir$command = shift(@params); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweirwhile ( $command =~ /^-/ ) 160*cdf0e10cSrcweir{ 161*cdf0e10cSrcweir if ( $command eq "-dbg" ) { 162*cdf0e10cSrcweir $debug="true"; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir elsif ( $command eq "-ldbg" ) { 165*cdf0e10cSrcweir $debug_light="true"; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir $command = shift(@params); 169*cdf0e10cSrcweir} 170*cdf0e10cSrcweir 171*cdf0e10cSrcweirif ( (defined $debug_light) or (defined $debug) ) { print( STDERR "Command: $command\n" ); } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweirreplace_cyg(\@params); 174*cdf0e10cSrcweirif ( (defined $debug_light) or (defined $debug) ) { print(STDERR "\n---------------------\nExecute: $command @params\n----------------\n");}; 175*cdf0e10cSrcweirexec( "$command", @params) or die( "\nError: slfl.pl: executing $command failed!\n" ); 176*cdf0e10cSrcweir 177