#!/usr/bin/perl
#if use ps2epsi, then 1 else 0
$use_ps2epsi=1;


$graphic=0;
$i=0;
while(<>){
  if(/\%\%BeginDocument:(.*)/){
    $graphic=1;
    $i++;
    if($1){
      $filename = $1;
      if($filename =~ m|/*([^\s/]+)$|){
	$filename=$1;
      }

    }else{
      $filename=$i.".ps";
    }
    print "$filename\n";
    if( -e $filename){
      $filename = $i.$filename;
      $i++;
    }
    open FILE, ">$filename";
  }elsif(/\%\%EndDocument/){
    print FILE $_;
    $graphic=0;
    close FILE;
    if($use_ps2epsi){
      system("ps2epsi $filename");
#      unlink($filename);
    }
  }

  if($graphic){
    print FILE $_;
  }
}

# $Log: pscut.pl,v $
# Revision 1.1.1.1  2001/07/09 16:37:39  kenstar
# start
#
# Revision 1.3  2001/05/04 16:43:09  kenstar
# avoid same filename.
#
# Revision 1.2  2001/05/04 16:27:51  kenstar
# Use ps2epsi
#
