1*cdf0e10cSrcweir: # -*- perl -*- 2*cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3*cdf0e10cSrcweir if 0; 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# mkdir - a perl script to substitute mkdir -p 6*cdf0e10cSrcweir# accepts "/", ":", and "\" as delimiters of subdirectories 7*cdf0e10cSrcweir# options -p (for compatibility) 8*cdf0e10cSrcweir# -mode mode 9*cdf0e10cSrcweir# 10*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 11*cdf0e10cSrcweir 12*cdf0e10cSrcweiruse Cwd; 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir$currdir = cwd; 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir$MODE = 00777 ; 17*cdf0e10cSrcweir 18*cdf0e10cSrcweirwhile ( $#ARGV >= 0 ) { 19*cdf0e10cSrcweir if ( $ARGV[0] eq "-mode" ) { 20*cdf0e10cSrcweir $MODE = oct $ARGV[1] ; 21*cdf0e10cSrcweir shift @ARGV ; 22*cdf0e10cSrcweir shift @ARGV ; 23*cdf0e10cSrcweir } 24*cdf0e10cSrcweir elsif ( $ARGV[0] eq "-p" ) { 25*cdf0e10cSrcweir shift @ARGV ; 26*cdf0e10cSrcweir # -p does not do anything, it's supported just for compatibility 27*cdf0e10cSrcweir } 28*cdf0e10cSrcweir else { 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir $ARGV[0] =~ s?\\|:?/?g ; 31*cdf0e10cSrcweir @SUBDIRS = split "/", $ARGV[0] ; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir # absolute path UNIX 34*cdf0e10cSrcweir if ( $SUBDIRS[0] eq "" ) { 35*cdf0e10cSrcweir chdir '/' ; 36*cdf0e10cSrcweir shift @SUBDIRS ; 37*cdf0e10cSrcweir } 38*cdf0e10cSrcweir # absolute path WINDOWS 39*cdf0e10cSrcweir if ( $#SUBDIRS > 1 ) { 40*cdf0e10cSrcweir if ( $SUBDIRS[1] eq "" ) { 41*cdf0e10cSrcweir if ( $SUBDIRS[0] =~ /\w/ ) { 42*cdf0e10cSrcweir chdir "$SUBDIRS[0]:\\" ; 43*cdf0e10cSrcweir shift @SUBDIRS ; 44*cdf0e10cSrcweir shift @SUBDIRS ; 45*cdf0e10cSrcweir } ; 46*cdf0e10cSrcweir } ; 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir while (@SUBDIRS) { 50*cdf0e10cSrcweir if ( -e $SUBDIRS[0] ) { 51*cdf0e10cSrcweir if ( ! -d $SUBDIRS[0] ) { 52*cdf0e10cSrcweir die "file exists\n" 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir else { 56*cdf0e10cSrcweir mkdir $SUBDIRS[0], $MODE or die "Can't create directory $SUBDIRS[0]" 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir chdir $SUBDIRS[0] or die "Can't cd to $SUBDIRS[0]" ; 59*cdf0e10cSrcweir shift @SUBDIRS ; 60*cdf0e10cSrcweir } ; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir shift @ARGV ; 63*cdf0e10cSrcweir } ; 64*cdf0e10cSrcweir chdir $currdir; 65*cdf0e10cSrcweir} 66