19 my @flagnames = ('SF', 'CF', 'OF', 'ZF');
23 @fields = split(/\|/, $_[3]);
24 foreach my $field (@fields) {
25 #remove heading and trailing spaces
30 #$tabular .= $field." \\\\";
34 return "Num of Fields not equal to Bits!";
37 @fieldnames = split(/\|/, $_[4]);
39 if(scalar(@fields) != scalar(@fieldnames)) {
40 return "Num of Fields != Num of Names";
44 foreach my $fieldn (@fieldnames) {
45 #remove heading and trailing spaces
49 if($fieldn =~ m/^[^\(.]*\(\s*([0-1]+)\s*\).*$/) {
50 if(length($1) == $fields[$count]) {
52 $fieldn =~ s/\s?\(\s*[0-1]+\s*\)//;
57 for($i = 1; $i <= $fields[$count]; $i++) {
65 for($i = 1; $i <= $fields[$count]; $i++) {
70 #$tabular .= $fieldn.": ". $bits." \\\\";
73 my $bitlist = join("",@bitlist);
75 #$tabular .= "\\textbf{names:} @fieldnames \n";
76 #$tabular .= "\\textbf{bitlist:} $bitlist \n";
80 $tabular = "\\subsubsection{".$_[1]."}\n";
81 $tabular .= "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
82 $tabular .= "\\begin{tabular}{|l|";
83 for($i = $bits-1; $i >= 0; $i--) {
93 $bline .= "\\\\ \\hline \n";
97 $vline .= substr($bitlist,($bits-1)-$i,1);
102 $vline .= "\\\\ \\hline \n";
106 #because of multicolumn we need to limit execution
108 $nline .= "\\multicolumn{@fields[0]}{>{\\columncolor{names}}c|}{@fieldnames[0]}";
111 $count -= @fields[0];
114 $nline .= "\\\\ \\hline \n";
124 $tabular .= "} \\hline \n";
125 $tabular .= "\\multicolumn{".($bits+1)."}{|>{\\columncolor{title}}c|}{\\textbf{".$_[1]."} (".$_[2].")} \\\\ \\hline \n";
126 $tabular .= "\\rowcolor{bit} \\cellcolor{title} &". $bline;
128 $tabular .= "\\rowcolor{bitval} \\cellcolor{title}Values &". $vline;
130 $tabular .= "\\cellcolor{title}Field &". $nline;
131 $tabular .= "\\end{tabular}\n}\n \\end{center}\n";
134 $tabular .= "\\paragraph{Description:}~\\\\ \n ".$_[5]. "\n";
139 my @flags = split(/\|/, $_[6]);
141 if(scalar(@flags) == scalar(@flagnames)) {
142 $tabular .= "\\paragraph{Flags:} \n";
144 foreach my $flag (@flags) {
145 #remove heading and trailing spaces
148 if(length($flag) > 0 ) {
149 $tabular .= "\\subparagraph{".$flagnames[$count].":} ".$flag." \n";
158 $tabular .= "\\paragraph{Example:}~\\\\ \n \\begin{lstlisting} \n ".$_[7]. " \\end{lstlisting}\n";
165 die "Usage: gentex.pl <file.ptex>";
168 my $output = $ARGV[0];
169 my $input = $ARGV[0];
171 $output =~ s/\.[^.]*$//;
174 open STDOUT, '>', $output or die "Can't redirect STDOUT: $!";