xref: /trunk/main/solenv/bin/mkdir.pl (revision 841807c9)
1cdf0e10cSrcweir: # -*- perl -*-
2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3cdf0e10cSrcweir    if 0;
4*841807c9SAndrew Rist#**************************************************************
5*841807c9SAndrew Rist#
6*841807c9SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*841807c9SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*841807c9SAndrew Rist#  distributed with this work for additional information
9*841807c9SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*841807c9SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*841807c9SAndrew Rist#  "License"); you may not use this file except in compliance
12*841807c9SAndrew Rist#  with the License.  You may obtain a copy of the License at
13*841807c9SAndrew Rist#
14*841807c9SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15*841807c9SAndrew Rist#
16*841807c9SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*841807c9SAndrew Rist#  software distributed under the License is distributed on an
18*841807c9SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*841807c9SAndrew Rist#  KIND, either express or implied.  See the License for the
20*841807c9SAndrew Rist#  specific language governing permissions and limitations
21*841807c9SAndrew Rist#  under the License.
22*841807c9SAndrew Rist#
23*841807c9SAndrew Rist#**************************************************************
24cdf0e10cSrcweir#
25cdf0e10cSrcweir# mkdir - a perl script to substitute mkdir -p
26cdf0e10cSrcweir# accepts "/", ":", and "\" as delimiters of subdirectories
27cdf0e10cSrcweir# options -p (for compatibility)
28cdf0e10cSrcweir#         -mode mode
29cdf0e10cSrcweir#
30cdf0e10cSrcweir
31cdf0e10cSrcweiruse Cwd;
32cdf0e10cSrcweir
33cdf0e10cSrcweir$currdir = cwd;
34cdf0e10cSrcweir
35cdf0e10cSrcweir$MODE = 00777 ;
36cdf0e10cSrcweir
37cdf0e10cSrcweirwhile ( $#ARGV >= 0 ) {
38cdf0e10cSrcweir	if ( $ARGV[0] eq "-mode" ) {
39cdf0e10cSrcweir		$MODE = oct $ARGV[1] ;
40cdf0e10cSrcweir		shift @ARGV ;
41cdf0e10cSrcweir		shift @ARGV ;
42cdf0e10cSrcweir		}
43cdf0e10cSrcweir	elsif ( $ARGV[0] eq "-p" ) {
44cdf0e10cSrcweir		shift @ARGV ;
45cdf0e10cSrcweir        # -p does not do anything, it's supported just for compatibility
46cdf0e10cSrcweir		}
47cdf0e10cSrcweir	else {
48cdf0e10cSrcweir
49cdf0e10cSrcweir        $ARGV[0] =~ s?\\|:?/?g ;
50cdf0e10cSrcweir        @SUBDIRS = split "/", $ARGV[0] ;
51cdf0e10cSrcweir
52cdf0e10cSrcweir        # absolute path UNIX
53cdf0e10cSrcweir        if ( $SUBDIRS[0] eq "" ) {
54cdf0e10cSrcweir            chdir '/' ;
55cdf0e10cSrcweir            shift @SUBDIRS ;
56cdf0e10cSrcweir        }
57cdf0e10cSrcweir        # absolute path WINDOWS
58cdf0e10cSrcweir        if ( $#SUBDIRS > 1 ) {
59cdf0e10cSrcweir            if ( $SUBDIRS[1] eq "" ) {
60cdf0e10cSrcweir                if ( $SUBDIRS[0] =~ /\w/ ) {
61cdf0e10cSrcweir                    chdir "$SUBDIRS[0]:\\" ;
62cdf0e10cSrcweir                    shift @SUBDIRS ;
63cdf0e10cSrcweir                    shift @SUBDIRS ;
64cdf0e10cSrcweir                } ;
65cdf0e10cSrcweir            } ;
66cdf0e10cSrcweir        }
67cdf0e10cSrcweir
68cdf0e10cSrcweir        while (@SUBDIRS) {
69cdf0e10cSrcweir            if ( -e $SUBDIRS[0] ) {
70cdf0e10cSrcweir                if ( ! -d $SUBDIRS[0] ) {
71cdf0e10cSrcweir                    die "file exists\n"
72cdf0e10cSrcweir                }
73cdf0e10cSrcweir            }
74cdf0e10cSrcweir            else {
75cdf0e10cSrcweir                mkdir $SUBDIRS[0], $MODE or die "Can't create directory $SUBDIRS[0]"
76cdf0e10cSrcweir            }
77cdf0e10cSrcweir            chdir $SUBDIRS[0] or die "Can't cd to $SUBDIRS[0]" ;
78cdf0e10cSrcweir            shift @SUBDIRS ;
79cdf0e10cSrcweir        } ;
80cdf0e10cSrcweir
81cdf0e10cSrcweir        shift @ARGV ;
82cdf0e10cSrcweir    } ;
83cdf0e10cSrcweir	chdir $currdir;
84cdf0e10cSrcweir}
85