#!/usr/local/bin/perl
##-------------------------------------------------------------------------
## 
## splitc78 -- 
## 
## Author          : Jaccard Pierre
## Created On      : 1999/11/09 15:59:38
## Last Modified By: Jaccard Pierre
## Last Modified On: 1999/11/09 16:17:22
## Update Count    : 1
## Directory       : /dataOS/jaccard/codas/codas3c/gfi/bin/perl/
## Version         : 0.0
## Status          : Unknown
## --------------------------------------------------------------------- ++
## DESCRIPTION: 
## 
##    See separate documentation.
## 
## --------------------------------------------------------------------- ++
## REVISIONS: 
## --------------------------------------------------------------------- ++
## CHANGES: 
##-------------------------------------------------------------------------

use strict;
use IO::File;

#------------------------------------------------------------------.
# File Variables:
#------------------------------------------------------------------

#------------------------------------------------------------------
# MAIN
#------------------------------------------------------------------
{

  my($s, $if, $of, $ih, $oh);

  #--- Start suffix:
  $s = $oh = $of = 0;
  

  #--- Loop through input files:
  foreach $if (@ARGV){

    $ih = new IO::File "< $if";
    die("\nOpening input C78 file $if\n") unless(defined $ih);
    
    #--- Loop through input lines:
    while(<$ih>){
      chomp;
      next if(/^\s*$/);
      
      #--- Check for file changes:
      if(/^\*\s+MASTER\s+CARD\s+RECORD/){

        #--- Close previous output file:
        if(ref($oh) =~ /IO\:\:File/){
          close($oh) || die("\nClosing output C78 file $of\n");
        }
        
        $s++;
        die("\nSuffix number exceeded: $s\n") if($s > 999);
        $of = "ssr." . (sprintf "%03d", $s);

        #--- Open new output file:
        $oh = new IO::File "> $of";
        die("\nOpening output file $of\n") unless(defined $oh);
        
        #--- Messages:
        print "$if: $of\n";
      }

      print $oh "$_\n" if(ref($oh) =~ /IO\:\:File/);
    }
    
    close($oh) || die("\nClosing output file $of\n");
    close($ih) || die("\nClosing input file $if\n");
    
  }

}

exit(0);


    
    

      
          
        
        



