gentex: misc. changes
authorMartin Perner <martin@perner.cc>
Tue, 26 Oct 2010 11:45:09 +0000 (13:45 +0200)
committerMartin Perner <martin@perner.cc>
Tue, 26 Oct 2010 13:07:28 +0000 (15:07 +0200)
1) should now work with every perl input
which includes function calls split over many lines
2) now runs with strict
3) put every instr. in a own subsubsection
4) added parameter for descripton
5) added parameter for flags
6) added parameter for example

2_isa/gentex.pl

index 0e71de358cbd91bcf63016e128d7ab5a93bb0ff6..b2751c84d51c257fce8d3cbca1f31273d93a8e35 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/perl
+use strict;
 
 sub ins {
        my $bits = $_[0];
@@ -10,9 +11,15 @@ sub ins {
        my $pvline;
        my @bitlist;
        my $tabular;
+       my $count = 0;
+       my @fields;
+       my $i;
+       my $x;
+       my @fieldnames;
+       my @flagnames = ('SF', 'CF', 'OF', 'ZF');
+
 
 
-       $count = 0;
        @fields = split(/\|/, $_[3]);
        foreach my $field (@fields) {
                #remove heading and trailing spaces
@@ -63,14 +70,15 @@ sub ins {
                #$tabular .= $fieldn.": ". $bits." \\\\";
                $count++;
        }
-       $bitlist = join("",@bitlist);
+       my $bitlist = join("",@bitlist);
 
        #$tabular .= "\\textbf{names:} @fieldnames \n";
        #$tabular .= "\\textbf{bitlist:} $bitlist \n";
 
        $count = $bits-1;
 
-       $tabular = "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
+       $tabular = "\\subsubsection{".$_[1]."}\n";
+       $tabular .= "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
        $tabular .= "\\begin{tabular}{|l|";
        for($i = $bits-1; $i >= 0; $i--) {
                #build table
@@ -122,28 +130,47 @@ sub ins {
        $tabular .= "\\cellcolor{title}Field &". $nline;
        $tabular .= "\\end{tabular}\n}\n \\end{center}\n";
 
+       if($_[5]) {
+               $tabular .= "\\paragraph{Description:}~\\\\ \n ".$_[5]. "\n";
+       }
+
+       if($_[6]) {
+               $count = 0;
+               my @flags = split(/\|/, $_[6]);
+
+               if(scalar(@flags) == scalar(@flagnames)) {
+                       $tabular .= "\\paragraph{Flags:} \n";
+
+                       foreach my $flag (@flags) {
+                               #remove heading and trailing spaces
+                               $flag =~ s/^\s+//;
+                               $flag =~ s/\s+$//;
+                               if(length($flag) > 0 ) {
+                                       $tabular .= "\\subparagraph{".$flagnames[$count].":} ".$flag." \n";
+                               }
+                               $count++;
+                       }
+               }
+
+       }
+
+       if($_[7]) {
+               $tabular .= "\\paragraph{Example:}~\\\\ \n \\begin{lstlisting} \n ".$_[7]. " \\end{lstlisting}\n";
+       }
 
-       return $tabular;
+       print $tabular;
 }
 
 if($#ARGV != 0) {
        die "Usage: gentex.pl <file.ptex>";
 }
 
-open(DATA, "<".$ARGV[0]) || die "Couldn't open file $ARGV[0] for read!";
-
-$output = $ARGV[0];
+my $output = $ARGV[0];
+my $input = $ARGV[0];
 
 $output =~ s/\.[^.]*$//;
 $output .= ".tex";
 
-open(OUTPUT, ">".$output) || die "Couldn't open file $output for output!";
-
-while(<DATA>)
-{
-       $res = eval "$_";
-       print OUTPUT $res;
-}
+open STDOUT, '>', $output or die "Can't redirect STDOUT: $!";
 
-close(DATA);
-close(OUTPUT);
+do $input;