#!/bin/perl -w $start_run=`date`; $fileTNS=$ARGV[0]; open(TNS, "< $fileTNS"); open(TMP01, "> ${fileTNS}.tmp.01"); open(TMP02, "> ${fileTNS}.tmp.02"); # ----------------------------------------------------------------------- # - Remove commented lines and blank line # ----------------------------------------------------------------------- while () { next if /^#/; # skip lines starting with comments next if /^$/; # blank lines print TMP01 $_; # This is the line that we wanted } close TMP01; # ----------------------------------------------------------------------- # - Search for lines that begins with alpha characters # - This is where we get the range of lines for each entry # ----------------------------------------------------------------------- $tns=""; $switch=0; $count=0; $start=0; $end=0; open(TMP01, "< ${fileTNS}.tmp.01"); while () { $count++; if ( /^[a-z]/i ) { #print $_; if ( $switch eq 0 ) { $start=${count}; $tns=$_; $switch=1; } elsif ( $switch eq 1 ) { $end=${count}-1; print TMP02 "${start},${end},$tns"; ${start}=${count}; $tns=$_; } } else { next; } } print TMP02 "${start},${count},${tns}"; close TMP02; close TMP01; # ----------------------------------------------------------------------- # - Now READ each range of lines and check if we have the # - same number of opening and closing braces # ----------------------------------------------------------------------- open(TMP02, "< ${fileTNS}.tmp.02"); open(MAL, "> ${fileTNS}.tmp.malformed"); while () { chomp($_); my @tns_info = split(',', $_); $start_line=$tns_info[0]; $end_line=$tns_info[1]; $tns_line=$tns_info[2]; my @tns = split('\.', $tns_line); # ------------------------------------------------------------------------- # - Print the range of lines that we want, i.e. $start_line TO $end_line # ------------------------------------------------------------------------- $count=0; open(TMP01, "< ${fileTNS}.tmp.01"); open(TMP03, "> ${fileTNS}.tmp.03.$tns[0]"); while () { $count++; if ( ( ${count} >= ${start_line} ) && ( ${count} <= ${end_line} ) ) { print TMP03 $_; } last if ${count} > ${end_line}; } close TMP01; close TMP03; my $count_open_brace; my $count_close_brace; my $count_open_brace_total; my $count_close_brace_total; open(TMP03, "< ${fileTNS}.tmp.03.$tns[0]"); while () { $count_open_brace = ( $_ =~ tr/\(// ); $count_close_brace = ( $_ =~ tr/\)// ); $count_open_brace_total += $count_open_brace; $count_close_brace_total += $count_close_brace; } close TMP03; if ( ${count_open_brace_total} == ${count_close_brace_total} ) { print "Checking -> START = $start_line :: END = $end_line :: TNS = ${tns_line} = OKAY \n"; } else { print "Checking -> START = $start_line :: END = $end_line :: TNS = ${tns_line} = MALFORMed !!! \n"; print MAL $tns_line . "\n"; } } close MAL; close TMP02; print "START = ${start_run}"; print "FINISH = " . `date`; exit(0); ########### # THE END # ###########