#!/usr/um/bin/perl

$file = shift;
$is_shk = 0;
$is_bsq = 0;
$need_cut = 0;
$s_blank = 0;
$blank = 0;
$s_lines = 0;
$lines = 0;

open (in, "<$file");
while (!eof(in) && $is_shk==0)
{
$line = <in>;
$lines=$lines+1;
$s_lines=$s_lines+1;
$_ = $line;
if (/^ / || /^$/) { $cut = $cut+1; $s_cut=$s_cut+1};
if ($lines == 1 && /^\116\365\106\351\154\345/) { print "SHK!\n"; $is_shk = 1;}
if ($line eq "FiLeStArTfIlEsTaRt\n")
  {
   if ($s_lines==$s_cut) {print "File may need haircut.. (section $bsq)\n"; $s_lines = 0 ; $s_cut = 0;};
   $is_bsq = is_bsq + 1;
  };
}


close (fd);

if (($lines == $cut)&& !$is_bsq) { print "File needs Haircut, but it's not bsq..\n" }
if (($lines == $cut)&&$is_bsq)
  {
   print "Haircut time..\n";
   open (in, "<$file");
   open (out, ">temp.pl");
   while (!eof(in))
    {
     $line = <in>;
     $_ = $line;
     $line =~ s/^ //;
     print out "$line";
    }
   close (out); close (in);
   rename ($file, "old.$file");
   rename ("temp.pl", $file);
  }
