#!/usr/bin/perl # # Or perhaps: /usr/local/bin/perl # # # $Id$ # undef $/; if($#ARGV<$[) {die "No Files\n";} open(tagfile,">TAGS") || die "Couldn't open TAGS: $!\n"; while(<>) { print "Tagging $ARGV\n"; $a=$_; $cp=1; $lp=1; $tagstring=""; while(1) { # ---- Get the next statement starting on a newline ---- if($a=~/^[ \t\n]*\(\*/) { while($a=~/^\s*\(\*/) { $d=1; $a=$'; $cp+=length $&; $lp+=(($wombat=$&)=~tr/\n/\n/); while($d>0 && $a=~/\(\*|\*\)/) { $a=$'; $cp+=2+length $`; $lp+=(($wombat=$`)=~tr/\n/\n/); if($& eq "(*") {$d++} else {$d--}; } if($d!=0) {die "Unbalanced Comment?";} } } if($cp>1 && $a=~/.*\n/) {$a=$'; $cp+=length $&; $lp++;} while($a=~/^\n/) {$cp++;$lp++;$a=$'} if($a=~/^[^\.]*\./) { $stmt=$&; $newa=$'; $newcp=$cp+length $&; $newlp=$lp+(($wombat=$&)=~tr/\n/\n/); } else { last;} # ---- The above embarrasses itself if there are semicolons inside comments # ---- inside commands. Could do better. # print "----- (",$lp,",",$cp,")\n", $stmt, "\n"; if($stmt=~/^([ \t]*((Fact)|(Goal)|(Lemma)|(Remark)|(Theorem))\s+([\w\']+))\s*:/) { $tagstring.=$1."\177".$8."\001".$lp.",".$cp."\n"; } elsif($stmt=~/^([ \t]*((Axiom)|(Hypothesis)|(Parameter)|(Variable))\s+[\w\']+)/) { do adddecs($stmt,$1) } elsif($stmt=~/^([ \t]*((Definition)|(Fixpoint)|(Inductive))\s+[\w\']+)/) { $tagstring.=$1."\177".$6."\001".$lp.",".$cp."\n"; } $cp=$newcp; $lp=$newlp; $a=$newa; } print tagfile "\f\n".$ARGV.",".(length $tagstring)."\n".$tagstring; } close tagfile; sub adddecs { $wk=$_[0]; $tag=$_[1]; $sep=","; while($tst=($wk=~/\s*([\w\']+)\s*([,:\[])/) && $sep eq ",") { $sep=$2; $tagstring.=$tag."\177".$1."\001".$lp.",".$cp."\n"; $wk=$'; } 0; }