#!/usr/bin/perl
# Require Perl5
#
# mainframe - convert a mainframe textual report into a unix textual report
#
# by SANFACE Software 01/25/2003
#
# mainframe version 1.0

use strict;
use warnings;
use Getopt::Long;
use File::DosGlob 'glob';
my $version="1.0";
my $producer="mainframe";
my $companyname="SANFACE Software";
my $SANFACEmail="mailto:sanface\@sanface.com";

my ($help,$verbose,$Version);

&GetOptions("help"           => \$help,
            "current"        => \$Version,
            "verbose"        => \$verbose) || printusage() ;

if($Version) {print "$producer $version\n";exit;}
$help and printusage();

if (@ARGV) {
  my @files;
  my ($i,$input);

  if ($^O =~ /^MSWin32$/i) {
    foreach $i (@ARGV) {
      if($i=~/\*|\?/) {push @files,glob($i)}
      else {push @files,$i}
      }
    }
  else {@files = @ARGV}
  foreach $input (@files) {
    my $tmpfile=$input.$$;
    open (IN, "$input") || die "$producer: couldn't open input file $input\n";
    open (TEMP, ">$tmpfile") || die "$producer: couldn't open input file $tmpfile\n";
    while (<IN>)
      {
      s/^1//;
      s/^0/\n /;
      print TEMP;
      }
    close(TEMP);
    close(IN);
    rename $tmpfile,$input;
#    unlink($tmpfile);
    }
  }

sub printusage {
    print <<USAGEDESC;

usage:
        $producer [-options ...] list

where options include:
    -help                        print out this message
    -current                     the program version
    -verbose                     verbose

list:
    with list you can use metacharacters and relative and absolute path name

If you want to know more about this tool, you might want
to read the docs. They came together with $producer!

USAGEDESC
    exit(1);
}
