#!/usr/local/bin/perl/perl
#
# Jerome C. Parks
# June 16, 1996
#
# This program takes in an all uppercase file and dumps it out as
# {filename}.BAK in sentence case.

if (!@ARGV) {
  print "Usage: sentencecase.pl \{filename\}\n\n";
  exit;
}

$temp = "Temp.txt";
$filename = @ARGV[0];
$newfile = "$filename.BAK";

open (IN,"$filename") || warn "Can't open $filename for read";
chop(@f=<IN>);
close $filename;

open (OUT,">$newfile") || warn "Can't open $newfile for write";
foreach $L (@f) {
  $L=~s/([\.\?\!])\s/$1\. /g;
  print OUT join("  ",map($_=ucfirst(lc($_)),split(/\.\s+/,$L))) . "\n";
}

close OUT;

open (IN,"$newfile") || warn "Can't open $newfile for read";
@f=<IN>;
close $newfile;

open(OUT,">$newfile") || warn "Can't open $newfile for write";
foreach $L (@f) {
  $L=~s/lord/Lord/g;
  $L=~s/god/God/g;
  $L=~s/jesus/Jesus/g;
  $L=~s/spirit/Spirit/g;
  $L=~s/holy/Holy/g;
  $L=~s/father/Father/g;
  $L=~s/i /I /g;
  $L=~s/i\'/I\'/g;
  $L=~s/dr\./Dr\./g;
  $L=~s/mr\./Mr\./g;
  $L=~s/mrs\./Mrs\./g;
  $L=~s/ms\./Ms\./g;
  
  $L=~s/john /John /g;
  $L=~s/matthew /Matthew /g;
  $L=~s/luke /Luke /g;
  $L=~s/mark /Mark /g;
  
  $L=~s/psalms /Psalms /g;
  
  print OUT $L;
}
exit;

