blib/lib/Text/NumericData/App/txdfromtcad.pm untested

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 110 SCAR 54.8
CC
15
Cov
0%
process_line
210.0
add_datasets
6.0
new
2.0
CRAP 240.0
1 package Text::NumericData::App::txdfromtcad;
2  
3 use Text::NumericData::App;
4  
5 use strict;
6  
7 # This is just a placeholder because of a past build system bug.
8 # The one and only version for Text::NumericData is kept in
9 # the Text::NumericData module itself.
10 our $VERSION = '1';
11 $VERSION = eval $VERSION;
12  
13 my $infostring = 'Hacky tool to convert DF-ISE xyplot data to usual text data. Filters STDIN to STDOUT. The parser is not very smart, it is modelled exactly after the format that TCAD produces.';
14  
15 our @ISA = ('Text::NumericData::App');
16  
17 sub new
18 {
19 my $class = shift;
20 my @pars =
21 (
22 'title', 'some TCAD data', 't',
23 'Provide a title for the data set.'
24 );
25  
26 return $class->SUPER::new
27 ({
28 parconf =>
29 {
30 info=>$infostring # default version
31 # default author
32 # default copyright
33 }
34 ,pardef => \@pars
35 ,pipemode => 1
36 ,pipe_begin => \&init
37 ,pipe_line => \&process_line
38 });
39 }
40  
41  
42 my $void = 0;
43 my $info = 1;
44 my $data = 2;
45 my $past = 3;
46  
47 sub init
48 {
49 my $self = shift;
50 $self->{place} = $void;
51 $self->{gottype} = 0;
52 $self->{indatasets} = 0;
53 $self->{cols} = 0;
54 $self->{data} = [];
55 }
56  
57 sub process_line
58 {
59 my $self = shift;
60  
61 if($self->{place} == $void)
62 {
63 if($_[0] =~ /^Info\s*\{$/){ $self->{place} = $info; }
64 elsif($_[0] =~ /^Data\s*\{$/){ $self->{place} = $data; }
65  
66 $_[0] = '';
67 return;
68 }
69 if($self->{place} == $info)
70 {
71 if($_[0] =~ /^\s*type\s*=\s*xyplot$/){ $self->{gottype} = 1; }
72 elsif($_[0] =~ /^\s*datasets\s*=\s*\[(.*)$/)
73 {
74 $self->add_datasets($1);
75 }
76 elsif($self->{indatasets})
77 {
78 $self->add_datasets($_[0]);
79 }
80 elsif($_[0] =~ /\}/)
81 {
82 $_[0] = ${$self->{txd}->CommentLine(\$self->{param}{title})};
83 $_[0] .= ${$self->{txd}->TitleLine()};
84 $self->{cols} = @{$self->{txd}->{titles}};
85 $self->{place} = $void;
86 print STDERR "Did not find the proper file type (wanted xyplot)!\n" unless $self->{gottype};
87 print STDERR "Need some columns!\n" unless $self->{cols} > 0;
88 }
89 }
90 elsif($self->{place} == $data)
91 {
92 $_[0] =~ s/[\012\015]+$//;
93 $_[0] =~ s/^\s*//;
94  
95 if($_[0] =~ /^\}$/)
96 {
97 # This should be the end.
98 $self->{place} = $past;
99 $_[0] = '';
100 print STDERR "There is data left! (@{$self->{data}})\n"
101 if(@{$self->{data}});
102 return;
103 }
104  
105 # Got a data line, add.
106 push(@{$self->{data}}, split(/\s+/, $_[0]));
107  
108 # Write out full blocks.
109 $_[0] = '';
110 while(@{$self->{data}} >= $self->{cols})
111 {
112 my @linedata = splice(@{$self->{data}}, 0, $self->{cols});
113 $_[0] .= ${$self->{txd}->data_line(\@linedata)};
114 }
115 }
116 }
117  
118 sub add_datasets
119 {
120 my $self = shift;
121  
122 $_[0] =~ s/[\012\015]+$//;
123  
124 if($_[0] =~ /^\s*(|.*\S)\s*\]$/){ $_[0] = $1; $self->{indatasets} = 0; }
125 else{ $self->{indatasets} = 1; }
126 # Hack!
127 $_[0] =~ s:^\s*"::;
128 $_[0] =~ s:"\s*$::;
129 push(@{$self->{txd}->{titles}}, split(/"\s+"/, $_[0]));
130 }