@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!/usr/local/bin/perl
#line 15

#=========================================================
# Perl script
#=========================================================

#!/usr/bin/perl

use strict;

use lib 'd:/Programs/Perl/lib';
use Utils;
use JFile;

my $Dir = ($ARGV[0])? $ARGV[0] : '';
while($Dir eq '' or !-d $Dir) {
	print "Input source data folder>>";
	$Dir = <>;
	Utils::DelSpace($Dir);
	last if(-d $Dir);
	print "  Error: [$Dir] is not a folder\n";
}

my $fmask = '^\d{14}\.txt$';
my @files = sort glob("$Dir/*.txt");

for(my $i = 0 ; $i < @files ; $i++) {
	print "$i: $files[$i]\n";
	my $NewFileName = &GetNewFileName($files[$i]);
	Utils::CopyFile($files[$i], $NewFileName);
#last;
}

exit;

sub GetNewFileName
{
	my ($fname) = @_;
	
print "File: [$fname]\n";
	my $in = new JFile($fname, "r");
	if(!$in) {
		print "Error: Can not read [$fname]\n";
		return 0;
	}
	
	$in->SkipTo("\\[Info 1\]");
	my $RegionName = &GetKeyVal($in, "Region Name");
print "  Region: [$RegionName]\n";
	my $SampleName = &GetKeyVal($in, "Sample");
print "  Sample: [$SampleName]\n";
	my $Comments = &GetKeyVal($in, "Comments");
print "  Comments: [$Comments]\n";
	$in->Close();

	my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($fname);
	my $NewFileNameBody = "$filebody-$SampleName-$RegionName";
	$NewFileNameBody =~ s/\s/_/g;
	my $NewFileName;
	for(my $c = 1 ; $c < 1000 ; $c++) {
		$NewFileName = sprintf("$NewFileNameBody-%d.txt", $c);
		last if(!-e $NewFileName);
	}
print "  New filename: $NewFileName\n";
	
	return $NewFileName;
}

sub GetKeyVal
{
	my ($in, $key) = @_;
#print "key [$key]\n";
	my $line = $in->SkipTo("$key=");
#print "l: $line";
	my ($key, $val) = ($line =~ /^(.*?)=(.*)\s*$/);
	return $val;
}

=head1 NAME

widget - Demonstration of Perl/Tk widgets

=head1 SYNOPSYS

  widget [ directory ]

=head1 DESCRIPTION

This script demonstrates the various widgets provided by Tk, along with
many of the features of the Tk toolkit.  This file only contains code to
generate the main window for the application, which invokes individual
demonstrations.  The code for the actual demonstrations is contained in
separate ".pl" files in the "widget_lib" directory, which are autoloaded
by this script as needed.

widget looks in the directory specified on the command line to load user
contributed demonstrations.  If no directory name is specified when widget is
invoked and the environment variable WIDTRIB is defined then demonstrations
are loaded from the WIDTRIB directory. If WIDTRIB is undefined then widget
defaults to the released user contributed directory, "widtrib".

=head2 History

 #
 # Stephen O. Lidie, LUCC, 96/03/11.  lusol@Lehigh.EDU
 # Stephen O. Lidie, LUCC, 97/01/01.  lusol@Lehigh.EDU
 # Stephen O. Lidie, LUCC, 97/02/11.  lusol@Lehigh.EDU
 # Stephen O. Lidie, LUCC, 97/06/07.  lusol@Lehigh.EDU
 #     Update for Tk402.00x.  Total revamp:  WidgetDemo, Scrolled, released
 #     composites, -menuitems, qw//, etcetera.  Perl 5.004 required.
 # Stephen O. Lidie, LUCC, 98/03/10.  lusol@Lehigh.EDU
 #     Update for Tk8.
 # Stephen O. Lidie, LUCC, 98/06/26.  Stephen.O.Lidie@Lehigh.EDU
 #     Add Common Dialogs for Tk800.007.
 # Stephen.O.Lidie@Lehigh.EDU, 1999/11/29, Lehigh University.
 #     Demo some "dash patch" changes.
 # Stephen.O.Lidie@Lehigh.EDU, 2000/01/11, Lehigh University.
 #     Update menubar to Tk 8, fix color palette Menubutton demo.
 # Stephen.O.Lidie@Lehigh.EDU, 2000/07/06, Lehigh University.
 #     Remove inswt() from widget and styles.pl to show the proper Perl/Tk
 #     idiom for inserting Text tags.  Various and sundry cleanups.
 # sol0@lehigh.edu, 2003/07/29, Lehigh University Computing Center.
 #     Update for Tk 8.4.4.

=head1 AUTHOR

Steve Lidie <sol0@Lehigh.EDU>

=cut

__END__

:endofperl
