Code: Select all
@rem = '--*-Perl-*--
@echo off
perl "%~dpnx0" %*
goto endofperl
@rem ';
#!perl
#line 8
use strict;
use warnings;
use File::Path;
my $i = "";
my $job;
my $id;
my $sid;
my $file;
my $prev;
my $header = "";
my $header2 = "";
my $dir = $ARGV[0];
$dir =~ s/\.dsx$//;
my $sub;
my $vol;
my $path;
my $name;
rmtree ("$dir");
mkdir($dir);
while ( <> ) {
if (/ =\+=\+=\+=$/ .. /^=\+=\+=\+=/) {
unless (/ =\+=\+=\+=$/) { # Don't concatenate the line prior to the beginning =+=+=+=
$_ = $prev . $_;
}
unless (/^=\+=\+=\+=/m) { # Don't skip the rest of the processing on the ending =+=+=+=
next;
}
}
if (/^BEGIN HEADER/../^END HEADER/) {
if (/^BEGIN HEADER/) {
$header = $_;
} else {
$header .= $_;
}
next;
}
if (/^${i}BEGIN /) {
if (/ DSJOB/) {
$sub = "Jobs";
$header2 = "";
print;
}
if (/ DSSHAREDCONTAINER/) {
$sub = "SharedContainers";
$header2 = "";
print;
}
if (/ DSEXECJOB/) {
$sub = "ExecJobs";
$header2 = "";
print;
}
if (/ DSTABLEDEFS/) {
$sub = "TableDefs";
$header2 = $_;
$i = " ";
print;
}
if (/ DSTRANSFORMS/) {
$sub = "Transforms";
$header2 = $_;
$i = " ";
print;
}
if (/ DSROUTINES/) {
$sub = "Routines";
$header2 = $_;
$i = " ";
print;
}
$job = $header.$header2.$_;
next;
}
if ($sub eq "Jobs" or $sub eq "SharedContainers" or $sub eq "ExecJobs") {
if (/^ Identifier "(.+)"/) {
$id = $1;
$sid = "";
}
}
if ($sub eq "ExecJobs") {
if (/^ Identifier "(.+)"/) {
$sid = $1;
}
}
if ($sub eq "TableDefs") {
if (/^ Identifier "(.+)"/) {
$id = $1;
$id =~ s/\\\\/\//g;
}
}
if ($sub eq "Transforms" or $sub eq "Routines") {
if (/^ Identifier "(.+)"/) {
$id = $1;
}
}
if (/^ Category "(.+)"/ or
($id eq $sid and /^ F28 "(.+)"/)) {
$file = $1;
$file =~ s/\\\\/\//g;
$file =~ s/ /_/g;
$file .= "/" . $id . ".dsx";
($vol,$path,$name) = File::Spec->splitpath( "$dir/$sub/$file" );
chop $path;
mkpath($vol.$path);
print "$vol$path\n$file\n";
open OUT,">$dir/$sub/$file" or die "Can't open output file $dir/$sub/$file\n";
print OUT $job;
}
if (defined $file) {
print OUT $_;
} else {
$job .= $_;
}
if (/^${i}END (DSJOB|HEADER|DSSHAREDCONTAINER|DSEXECJOB|DSRECORD)/) {
unless (defined $file) {
$file = $id . ".dsx";
($vol,$path,$name) = File::Spec->splitpath( "$dir/$sub/$file" );
chop $path;
mkpath($vol.$path);
print "$vol$path\n$file\n";
open OUT,">$dir/$sub/$file" or die "Can't open output file $dir/$sub/$file\n";
print OUT $job;
}
if (/DSRECORD/) {
my $trailer = $header2;
$trailer =~ s/BEGIN/END/;
print OUT $trailer;
}
close OUT;
$file = undef;
}
if (/^END/) { $i = "" }
} continue {
$prev = $_;
}
__END__
:endofperl