#!/cygdrive/c/strawberry/perl/bin/perl -d
# Program to cycle through the text directories and 
# check to make sure that each file is valid.  In other words,
# make sure that the bird or place is in in_class.  I want to make 
# sure that I haven't misspelled a text file.
#
# I ignore any files that end in ~ and I only check file that end
# in .txt
#
$class_data = "in_class";
$root_dir = "/cygdrive/c/htdocs/birds/";		# root dir
#@dir = ("text", "text_class", "text_place", "text_title", "Tongue",
#"feet");
@dir = ("text", "text_class", "text_place", "text_title");


{
			# first read in in_class and process all the
			# relevant lines into hash arrays
   open CLASS, $class_data or die "Cannont open in_class\n";
   while ( <CLASS> ) {
	   chomp;
	   s/\s+//g;
	   s/'//;g;
	   s/\.//g;
	   s/,//g;
	   s/&//g;
	   s,/,,g;
	   @line = split /:/;
	   if ($line[0] =~ m/title/i) {
		   $title{$line[1]} = 1;
	   }elsif ($line[0] =~ m/ptitle/i) {
		   $title{$line[1]} = 1;
	   }elsif ($line[0] =~ m/bird/i) {
		   $bird{$line[1]} = 1;
	   }elsif ($line[0] =~ m/place/i) {
		   $place{$line[1]} = 1;
	   }elsif ($line[0] =~ m/header/i) {
		   $class{$line[1]} = 1;
	   }
   }
   while ($subd = pop (@dir)) {
	   $dir1 = $root_dir . $subd;
	   @files = `ls $dir1`;
	   foreach (@files) {
		   chomp;
		   next if /~/;
		   s/.jpg//;
		   s/.JPG//;
		   s/.txt//;
		   if ($subd eq "text_title") {
			if (! exists $title{$_}) {
					print "title: $_ file not in in_class \n";
			}
		   }
		   if ($subd eq "text") {
			if (! exists $bird{$_}) {
					print "bird: $_ file not in in_class \n";
			}
		   }
		   if ($subd eq "text_class") {
			if (! exists $class{$_}) {
					print "header: $_ file not in in_class \n";
			}
		   }
		   if ($subd eq "text_place") {
			if (! exists $place{$_}) {
					print "place: $_ file not in in_class \n";
			}
		   }
	   }
   }

}
