my $opt;
+$opt->{style} = "altgray";
+
Getopt::Long::Configure(qw(gnu_getopt));
GetOptions(
'help|h' => \$opt->{help},
'entity|e=s' => \$opt->{entity},
'output|o=s' => \$opt->{output},
'pdf' => \$opt->{pdf},
+ 'style=s' => \$opt->{style},
'standalone' => \$opt->{standalone}
);
printHelpMessage() unless $opt->{entity} && $opt->{group};
-my $me = this->new();
+my $self = this->new();
+
+$self->{opt} = $opt; # assimilate options
-$me->setEntity($opt->{entity});
-# $me->{entityFile} = "/home/micha/mnt/55local1/htdocs/daqtools/xml-db/cache/CbController.entity";
-$me->{group} = $opt->{group};
-$me->{table}->{label} = $opt->{label}||"tab:".$opt->{group};
-$me->{table}->{caption} = $opt->{caption}||"Registers in group ".$opt->{group};
-$me->produceTable();
+$self->setEntity($opt->{entity});
+# $self->{entityFile} = "/home/micha/mnt/55local1/htdocs/daqtools/xml-db/cache/CbController.entity";
+$self->{group} = $opt->{group};
+$self->{table}->{label} = $opt->{label}||"tab:".$opt->{group};
+$self->{table}->{caption} = $opt->{caption}||"Registers in group ".$opt->{group};
+$self->produceTable();
-$me->writeTexFile($opt->{output}, $opt->{standalone} );
+$self->writeTexFile($opt->{output}, $opt->{standalone} );
if ($opt->{pdf}){
if ($opt->{output}){
- $me->pdflatex($opt->{output});
+ $self->pdflatex($opt->{output});
} else {
die "\n\ncannot make pdf!\nno output file specified, use the -o <file.tex> argument!\n";
}
-c, --caption caption of the table
-l, --label latex label of the table
+ --style hline : separate registers by
+ horizontal lines
+ altgray : separate registers with
+ alternating gray and white boxes
+ (default)
+
--standalone generate standalone compilable latex file
--pdf compile directly to pdf
# default formatting of the table
$self->{table}->{dataKeys} = [ 'name', 'addr', 'bits', 'description' ];
- $self->{table}->{header} = [ 'register', 'addr', 'bits', 'description' ];
- $self->{table}->{format} = '@{} l l l p{8cm} @{}';
+ $self->{table}->{header} = [ 'Register', 'Addr', 'Bits', 'Description' ];
+# $self->{table}->{format} = '@{} l l l p{8cm} @{}';
+ $self->{table}->{format} = ' l l c p{8cm} ';
$self = {
%$self,
my $type = $node->{type};
my $repeat = $node->{repeat} || 1;
my $stepsize = $node->{stepsize}||0;
- my $bits = "";
+ my $bits = " ";
if ($type ne 'register'){
my $start = $node->{start};
my $stop = $node->{start}+$node->{bits}-1;
$hexaddr = ''; # don't print addr it's already in the register
}
- push(@{$data},{%$node, name => $name_, addr => $hexaddr, bits => $bits, addr_uint => $addr_});
+ push(@{$data},{
+ %$node,
+ name => $name_,
+ addr => $hexaddr,
+ bits => $bits,
+ addr_uint => $addr_
+ });
}
}
- @$data = sort { $a->{bits} cmp $b->{bits} } @$data; # bit fields in ascending order
+ @$data = sort {
+ # sort numerically by first number in the bits string
+ my $aa=-1;
+ my $bb=-1;
+ if($a->{bits} =~ m/^(\d+)/){
+ $aa=$1;
+ }
+ if($b->{bits} =~ m/^(\d+)/){
+ $bb=$1;
+ }
+ return $aa <=> $bb;
+ } @$data; # bit fields in ascending order
+
@$data = sort { $a->{addr_uint} cmp $b->{addr_uint} } @$data; # addresses in ascending order
+ # some more formatting
+
my $last_addr;
+ my $addr_counter=0;
for my $item (@$data){
+
# make hline at each new register
my $cur_addr = $item->{addr_uint};
if($last_addr){
if($last_addr != $cur_addr){
- $self->{table}->addData(plain_code => '\hline');
+ if($self->{opt}->{style} eq "hline"){
+ $self->{table}->addData(plain_code => '\hline');
+ }
+ $addr_counter++;
+ }
+ }
+
+
+# if($item->{type} eq 'register' || $item->{type} eq 'registerfield'){
+# $self->{table}->addData(plain_code => '\rowcolor{lightgray}');
+# }
+ if($self->{opt}->{style} eq "altgray"){
+ if($addr_counter % 2){
+ $self->{table}->addData(plain_code => '\rowcolor{light-gray}');
}
}
$self->{table}->addData(%$item); # fill it with the sorted data
\usepackage{longtable}
\usepackage{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=3cm,rmargin=3cm}
+ \usepackage[table]{xcolor}
+
+ \definecolor{light-gray}{gray}{0.90}
\begin{document}
%;
}
sub pdflatex{
my $self = shift;
- my $output = shift||$me->{group};
+ my $output = shift||$self->{group};
my $here = qx("pwd");
$here =~ s/\n//g;
my $directory = "/dev/shm/xml-db2tex".rand();
unless(-e $directory or mkdir $directory) {
die "Unable to create $directory\n";
}
- my $texfile = $me->{group}.".tex";
- my $pdffile = $me->{group}.".pdf";
+ my $texfile = $self->{group}.".tex";
+ my $pdffile = $self->{group}.".pdf";
$output =~ s/\.(tex|pdf)//;
$output.= ".pdf";
chdir $directory;
- $me->writeTexFile($texfile, "standalone");
+ $self->writeTexFile($texfile, "standalone");
system("pdflatex $texfile");
system("pdflatex $texfile");
copy("$directory/$pdffile","$here/$output");
sub generateString {
my $self = shift;
my $str = '% remember to include the following latex packages:
- % booktabs
- % longtable'."\n";
+%\usepackage{booktabs}
+%\usepackage{longtable}
+%\usepackage[table]{xcolor}
+%\definecolor{light-gray}{gray}{0.90}
+ '."\n";
my $header;
$header= " ".join(" & ",map { '\textbf{'.$_.'}' } @{$self->{dataKeys}}).' \\\\'."\n";
}
+
$str .= '\begin{longtable}'."\n";
$str .="{".($self->{format}||"")."}\n";