Path: blob/master/modules/features2d/doc/read_file_nondiff32.pl
16356 views
#!/usr/bin/perl1use strict;2use warnings;3use autodie; # die if problem reading or writing a file45my $filein = "./agast.txt";6my $fileout = "./agast_new.txt";7my $i1=1;8my $i2=1;9my $i3=1;10my $tmp;11my $ifcount0=0;12my $ifcount1=0;13my $ifcount2=0;14my $ifcount3=0;15my $ifcount4=0;16my $elsecount;17my $myfirstline = $ARGV[0];18my $mylastline = $ARGV[1];19my $tablename = $ARGV[2];20my @array0 = ();21my @array1 = ();22my @array2 = ();23my @array3 = ();24my $homogeneous;25my $success_homogeneous;26my $structured;27my $success_structured;2829open(my $in1, "<", $filein) or die "Can't open $filein: $!";30open(my $out, ">", $fileout) or die "Can't open $fileout: $!";313233$array0[0] = 0;34$i1=1;35while (my $line1 = <$in1>)36{37chomp $line1;38$array0[$i1] = 0;39if (($i1>=$myfirstline)&&($i1<=$mylastline))40{41if($line1=~/if\(ptr\[offset(\d+)/)42{43if($line1=~/if\(ptr\[offset(\d+).*\>.*cb/)44{45$tmp=$1;46}47else48{49if($line1=~/if\(ptr\[offset(\d+).*\<.*c\_b/)50{51$tmp=$1+128;52}53else54{55die "invalid array index!"56}57}58$array1[$ifcount1] = $tmp;59$array0[$ifcount1] = $i1;60$ifcount1++;61}62else63{64}65}66$i1++;67}68$homogeneous=$ifcount1;69$success_homogeneous=$ifcount1+1;70$structured=$ifcount1+2;71$success_structured=$ifcount1+3;7273close $in1 or die "Can't close $filein: $!";7475open($in1, "<", $filein) or die "Can't open $filein: $!";767778$i1=1;79while (my $line1 = <$in1>)80{81chomp $line1;82if (($i1>=$myfirstline)&&($i1<=$mylastline))83{84if ($array0[$ifcount2] == $i1)85{86$array2[$ifcount2]=0;87$array3[$ifcount2]=0;88if ($array0[$ifcount2+1] == ($i1+1))89{90$array2[$ifcount2]=($ifcount2+1);91}92else93{94open(my $in2, "<", $filein) or die "Can't open $filein: $!";95$i2=1;96while (my $line2 = <$in2>)97{98chomp $line2;99if ($i2 == $i1)100{101last;102}103$i2++;104}105my $line2 = <$in2>;106chomp $line2;107if ($line2=~/goto (\w+)/)108{109$tmp=$1;110if ($tmp eq "homogeneous")111{112$array2[$ifcount2]=$homogeneous;113}114if ($tmp eq "success_homogeneous")115{116$array2[$ifcount2]=$success_homogeneous;117}118if ($tmp eq "structured")119{120$array2[$ifcount2]=$structured;121}122if ($tmp eq "success_structured")123{124$array2[$ifcount2]=$success_structured;125}126}127else128{129die "goto expected: $!";130}131close $in2 or die "Can't close $filein: $!";132}133#find next else and interpret it134open(my $in3, "<", $filein) or die "Can't open $filein: $!";135$i3=1;136$ifcount3=0;137$elsecount=0;138while (my $line3 = <$in3>)139{140chomp $line3;141$i3++;142if ($i3 == $i1)143{144last;145}146}147while (my $line3 = <$in3>)148{149chomp $line3;150$ifcount3++;151if (($elsecount==0)&&($i3>$i1))152{153if ($line3=~/goto (\w+)/)154{155$tmp=$1;156if ($tmp eq "homogeneous")157{158$array3[$ifcount2]=$homogeneous;159}160if ($tmp eq "success_homogeneous")161{162$array3[$ifcount2]=$success_homogeneous;163}164if ($tmp eq "structured")165{166$array3[$ifcount2]=$structured;167}168if ($tmp eq "success_structured")169{170$array3[$ifcount2]=$success_structured;171}172}173else174{175if ($line3=~/if\(ptr\[offset/)176{177$ifcount4=0;178while ($array0[$ifcount4]!=$i3)179{180$ifcount4++;181if ($ifcount4==$ifcount1)182{183die "if else match expected: $!";184}185$array3[$ifcount2]=$ifcount4;186}187}188else189{190die "elseif or elsegoto match expected: $!";191}192}193last;194}195else196{197if ($line3=~/if\(ptr\[offset/)198{199$elsecount++;200}201else202{203if ($line3=~/else/)204{205$elsecount--;206}207}208}209$i3++;210}211printf("%3d [%3d][0x%08x]\n", $array0[$ifcount2], $ifcount2, (($array1[$ifcount2]&15)<<28)|($array2[$ifcount2]<<16)|(($array1[$ifcount2]&128)<<5)|($array3[$ifcount2]));212close $in3 or die "Can't close $filein: $!";213$ifcount2++;214}215else216{217}218}219$i1++;220}221222printf(" [%3d][0x%08x]\n", $homogeneous, 252);223printf(" [%3d][0x%08x]\n", $success_homogeneous, 253);224printf(" [%3d][0x%08x]\n", $structured, 254);225printf(" [%3d][0x%08x]\n", $success_structured, 255);226227close $in1 or die "Can't close $filein: $!";228229$ifcount0=0;230$ifcount2=0;231printf $out " static const unsigned long %s[] = {\n ", $tablename;232while ($ifcount0 < $ifcount1)233{234printf $out "0x%08x, ", (($array1[$ifcount0]&15)<<28)|($array2[$ifcount0]<<16)|(($array1[$ifcount0]&128)<<5)|($array3[$ifcount0]);235236$ifcount0++;237$ifcount2++;238if ($ifcount2==8)239{240$ifcount2=0;241printf $out "\n";242printf $out " ";243}244245}246printf $out "0x%08x, ", 252;247$ifcount0++;248$ifcount2++;249if ($ifcount2==8)250{251$ifcount2=0;252printf $out "\n";253printf $out " ";254}255printf $out "0x%08x, ", 253;256$ifcount0++;257$ifcount2++;258if ($ifcount2==8)259{260$ifcount2=0;261printf $out "\n";262printf $out " ";263}264printf $out "0x%08x, ", 254;265$ifcount0++;266$ifcount2++;267if ($ifcount2==8)268{269$ifcount2=0;270printf $out "\n";271printf $out " ";272}273printf $out "0x%08x\n", 255;274$ifcount0++;275$ifcount2++;276printf $out " };\n\n";277278$#array0 = -1;279$#array1 = -1;280$#array2 = -1;281$#array3 = -1;282283close $out or die "Can't close $fileout: $!";284285286