1cdf0e10cSrcweir: 2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 4*7e90fac2SAndrew Rist#************************************************************** 5*7e90fac2SAndrew Rist# 6*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 7*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 8*7e90fac2SAndrew Rist# distributed with this work for additional information 9*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 10*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 11*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 12*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 13*7e90fac2SAndrew Rist# 14*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 15*7e90fac2SAndrew Rist# 16*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 17*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 18*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 20*7e90fac2SAndrew Rist# specific language governing permissions and limitations 21*7e90fac2SAndrew Rist# under the License. 22*7e90fac2SAndrew Rist# 23*7e90fac2SAndrew Rist#************************************************************** 24*7e90fac2SAndrew Rist 25*7e90fac2SAndrew Rist 26cdf0e10cSrcweir# Description: Wrapper script to change '/' to '\' in command-line 27cdf0e10cSrcweir# arguments. 28cdf0e10cSrcweir 29cdf0e10cSrcweir#--------------------------------------------------------------------------- 30cdf0e10cSrcweir# external modules 31cdf0e10cSrcweiruse Text::ParseWords; 32cdf0e10cSrcweir 33cdf0e10cSrcweir# global vars 34cdf0e10cSrcweir@params = (); 35cdf0e10cSrcweir 36cdf0e10cSrcweir#--------------------------------------------------------------------------- 37cdf0e10cSrcweir# procedures 38cdf0e10cSrcweir 39cdf0e10cSrcweir 40cdf0e10cSrcweir#---------------------------------------------------------- 41cdf0e10cSrcweir# Function name: WinFormat 42cdf0e10cSrcweir# Description: Format variables to Windows Format. 43cdf0e10cSrcweir# Arguments: 1. Variable (string) with one token 44cdf0e10cSrcweir# Return value: Reformatted String 45cdf0e10cSrcweir#---------------------------------------------------------- 46cdf0e10cSrcweirsub WinFormat { 47cdf0e10cSrcweir my $variable = shift @_; 48cdf0e10cSrcweir 49cdf0e10cSrcweir $variable =~ s!(.)/!$1\\!g; # Replace all but the leading slashes with backslashes 50cdf0e10cSrcweir 51cdf0e10cSrcweir if ( defined $debug ) { 52cdf0e10cSrcweir print(STDERR "WinFormat:\nresult:$variable\n"); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir return $variable; 56cdf0e10cSrcweir} 57cdf0e10cSrcweir 58cdf0e10cSrcweir#---------------------------------------------------------- 59cdf0e10cSrcweir# Function name: replace_cyg 60cdf0e10cSrcweir# Description: Process all arguments and change them to Windows Format. 61cdf0e10cSrcweir# Arguments: Reference to array with arguments 62cdf0e10cSrcweir# Return value: - 63cdf0e10cSrcweir#---------------------------------------------------------- 64cdf0e10cSrcweirsub replace_cyg { 65cdf0e10cSrcweir my $args = shift; 66cdf0e10cSrcweir my( @cmd_file, @cmd_temp ); 67cdf0e10cSrcweir my $atchars; 68cdf0e10cSrcweir foreach my $para ( @$args ) { 69cdf0e10cSrcweir if ( $para =~ "^@" ) { 70cdf0e10cSrcweir # it's a command file 71cdf0e10cSrcweir if ( defined $debug ) { 72cdf0e10cSrcweir print(STDERR "----------------------------\n"); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir ; 75cdf0e10cSrcweir # Workaround, iz28717, keep number of @'s. 76cdf0e10cSrcweir $para =~ s/(^\@+)//; 77cdf0e10cSrcweir $atchars = $1; 78cdf0e10cSrcweir $filename = $para; 79cdf0e10cSrcweir if ( defined $debug ) { 80cdf0e10cSrcweir print(STDERR "filename = $filename \n"); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir ; 83cdf0e10cSrcweir # open this command file for reading 84cdf0e10cSrcweir open(CMD, "$filename"); 85cdf0e10cSrcweir while ( <CMD> ) { 86cdf0e10cSrcweir # Remove DOS lineendings. Bug in Cygwin / Perl? 87cdf0e10cSrcweir $_ =~ s/\r//g; 88cdf0e10cSrcweir # Remove lineendings and trailing spaces. ( Needed by &parse_line ) 89cdf0e10cSrcweir $_ =~ s/\n$//g; 90cdf0e10cSrcweir $_ =~ s/\s+$//g; 91cdf0e10cSrcweir # Fill all tokens into array 92cdf0e10cSrcweir @cmd_temp = &parse_line('\s+', 1, $_ ); 93cdf0e10cSrcweir if ( $#cmd_temp > -1 ) { 94cdf0e10cSrcweir push( @cmd_file, @cmd_temp); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir close(CMD); 98cdf0e10cSrcweir # reformat all tokens 99cdf0e10cSrcweir replace_cyg(\@cmd_file); 100cdf0e10cSrcweir if ( defined $debug ) { 101cdf0e10cSrcweir print(STDERR "Tokens processed:\n"); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir ; 104cdf0e10cSrcweir foreach $i (@cmd_file) { 105cdf0e10cSrcweir if ( defined $debug ) { 106cdf0e10cSrcweir print(STDERR "!".$i."!\n"); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir ; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir # open this filename for writing (truncate) Textmode? 111cdf0e10cSrcweir open(CMD, '>', $filename); 112cdf0e10cSrcweir # write all tokens back into this file 113cdf0e10cSrcweir print(CMD join(' ', @cmd_file)); 114cdf0e10cSrcweir close(CMD); 115cdf0e10cSrcweir # convert '@filename' to dos style 116cdf0e10cSrcweir $para = WinFormat( $para ); 117cdf0e10cSrcweir if ( defined $debug ) { 118cdf0e10cSrcweir print(STDERR "----------------------------\n"); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir ; 121cdf0e10cSrcweir if ( (defined $debug_light) or (defined $debug) ) { 122cdf0e10cSrcweir print(STDERR "\nParameter in File:".join(' ', @cmd_file).":\n"); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir $para = $atchars.$para; 125cdf0e10cSrcweir } else { 126cdf0e10cSrcweir # it's just a parameter 127cdf0e10cSrcweir if ( defined $debug ) { 128cdf0e10cSrcweir print(STDERR "\nParameter:---${para}---\n"); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir ; 131cdf0e10cSrcweir # If $tmp1 is empty then $para is a parameter. 132cdf0e10cSrcweir my $is_no_para = 1; 133cdf0e10cSrcweir # remove .exe and convert to lower case 134cdf0e10cSrcweir $shortcommand = lc $command ; 135cdf0e10cSrcweir $shortcommand =~ s/\.exe$//; 136cdf0e10cSrcweir $shortcommand =~ /([^\/]+$)/; 137cdf0e10cSrcweir $shortcommand = $1; 138cdf0e10cSrcweir if ( $is_no_para ) { 139cdf0e10cSrcweir $para = WinFormat($para); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir if ( defined $debug ) { 142cdf0e10cSrcweir print(STDERR "Converted line:${para}:\n" ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } # else 145cdf0e10cSrcweir } # foreach loop 146cdf0e10cSrcweir} 147cdf0e10cSrcweir 148cdf0e10cSrcweir 149cdf0e10cSrcweir#--------------------------------------------------------------------------- 150cdf0e10cSrcweir# main 151cdf0e10cSrcweir@params = @ARGV; 152cdf0e10cSrcweir 153cdf0e10cSrcweir$command = shift(@params); 154cdf0e10cSrcweir 155cdf0e10cSrcweirwhile ( $command =~ /^-/ ) 156cdf0e10cSrcweir{ 157cdf0e10cSrcweir if ( $command eq "-dbg" ) { 158cdf0e10cSrcweir $debug="true"; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir elsif ( $command eq "-ldbg" ) { 161cdf0e10cSrcweir $debug_light="true"; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir $command = shift(@params); 165cdf0e10cSrcweir} 166cdf0e10cSrcweir 167cdf0e10cSrcweirif ( (defined $debug_light) or (defined $debug) ) { print( STDERR "Command: $command\n" ); } 168cdf0e10cSrcweir 169cdf0e10cSrcweirreplace_cyg(\@params); 170cdf0e10cSrcweirif ( (defined $debug_light) or (defined $debug) ) { print(STDERR "\n---------------------\nExecute: $command @params\n----------------\n");}; 171cdf0e10cSrcweirexec( "$command", @params) or die( "\nError: slfl.pl: executing $command failed!\n" ); 172cdf0e10cSrcweir 173