#!/usr/bin/perl # LEGAL WARNING: # # This software is provided on an "AS IS", basis, # without warranty of any kind, including without # limitation the warranties of merchantability, fitness for # a particular purpose and non-infringement. The entire # risk as to the quality and performance of the Software is # borne by you. Should the Software prove defective, you # and not the author assume the entire cost of any service # and repair. # $version = '1.0'; if( $#ARGV == 0 && $ARGV[0] eq '-h' ){ print < ){ if( /^\s*%\s*file\s+(.*?)\s*$/ ){ my $new_output = $1; &save_buffer($output); $buffer = ''; $output = "$dir/$subdir/${new_output}"; $output =~ s{//}{/}; next; } if( /^\s*%\s*dir\s+(.*?)\s*$/ ){ $subdir = $1; next; } $buffer .= $_; } &save_buffer($output); close F; exit; sub save_buffer { my $file = shift; return unless $output || $buffer ; if( $buffer && !$output ){ die "Is there text before the first '%file' ??"; } if( open(OUT,"<$file") ){ my $os = $/; undef $/; my $sbuffer = ; $/ = $os; close OUT; return if $buffer eq $sbuffer; } &make_dir($file); open(OUT,">$file") or die "Can not output $file"; print OUT $buffer; close OUT; } sub make_dir { my $dir = shift; my @dlist = split '/' , $dir; pop @dlist; # pop off file name return if $#dlist == -1; $root = ''; for( @dlist ){ $root .= '/' if $root; $root .= $_; # take the next subdirectory mkdir $root, 0777 unless -d $root } }