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