#!/usr/local/bin/perl -w
# MKINDEX DIR converts DIR/deepak to DIR/index
#
$fred = $ARGV[0];
$fred1 = $ARGV[0];
$old = "$fred/deepak";
$old = "$fred/gcf" unless( -e $old);
$old = "$fred/dirout" unless( -e $old);
unless(-e $old)	{
	$fred = '../../../04/hitachi/' .$fred1;
	$old = "$fred/dirout";
}
unless(-e $old)	{
	$fred = '../../../05/hitachi/' .$fred1;
	$old = "$fred/dirout";
}
$new = "$fred/index";
open(OLD,'<'. $old ) || die("\nSorry Could not open $old \n");
open(NEW,'>'. $new ) || die("\nSorry Could not open $new \n");
while( $line =<OLD> )	{
	chomp($line);
	$test = $line;
	next if($test =~ m%MPG% );
	$test =~ m%^([^:]*):%;
	unless( $test =~ m% %)	{
		print NEW $line,"\n";
		next;
	}
	my(@fields) = split(/\s+/, $line);
	$title ='';
	my($i)=6;
	while(defined($fields[$i]))	{
		$title .= ' ' . $fields[$i];
		++$i;
	}
	$title =~ s/^ *//;
	$date = $fields[3].','.$fields[4];
	$num= $fields[5];
	$title="No title yet for $num" unless($title);
	print NEW "$num:$title\{date=$date\}\n";
}
close(OLD);
close(NEW);
