line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# dbcoldefine.pm |
5
|
|
|
|
|
|
|
# Copyright (C) 1991-2016 by John Heidemann |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This program is distributed under terms of the GNU general |
8
|
|
|
|
|
|
|
# public license, version 2. See the file COPYING |
9
|
|
|
|
|
|
|
# in $dblibdir for details. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Fsdb::Filter::dbcoldefine; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
dbcoldefine - define the columns of a plain text file to make it an Fsdb file |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
dbcoldefine [-F x] [column...] |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This program writes a new header before the data with the specified column |
25
|
|
|
|
|
|
|
names. It does I do any validation of the data contents; |
26
|
|
|
|
|
|
|
it is up to the user to verify that, other than the header, |
27
|
|
|
|
|
|
|
the input datastream is a correctly formatted Fsdb file. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 OPTIONS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item B<-F> or B<--fs> or B<--fieldseparator> s |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Specify the field separator. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item B<--header> H |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Give the columns and field separator as a full Fsdb header |
40
|
|
|
|
|
|
|
(including C<#fsdb>). |
41
|
|
|
|
|
|
|
Can only be used alone, not with other specifications. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=back |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=for comment |
46
|
|
|
|
|
|
|
begin_standard_fsdb_options |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This module also supports the standard fsdb options: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=over 4 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item B<-d> |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Enable debugging output. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item B<-i> or B<--input> InputSource |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Read from InputSource, typically a file name, or C<-> for standard input, |
59
|
|
|
|
|
|
|
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item B<-o> or B<--output> OutputDestination |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Write to OutputDestination, typically a file name, or C<-> for standard output, |
64
|
|
|
|
|
|
|
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item B<--autorun> or B<--noautorun> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
By default, programs process automatically, |
69
|
|
|
|
|
|
|
but Fsdb::Filter objects in Perl do not run until you invoke |
70
|
|
|
|
|
|
|
the run() method. |
71
|
|
|
|
|
|
|
The C<--(no)autorun> option controls that behavior within Perl. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item B<--help> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Show help. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item B<--man> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Show full manual. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=for comment |
84
|
|
|
|
|
|
|
end_standard_fsdb_options |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SAMPLE USAGE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 Input: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
102400 4937974.964736 |
92
|
|
|
|
|
|
|
102400 4585247.875904 |
93
|
|
|
|
|
|
|
102400 5098141.207123 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 Command: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
cat DATA/http_bandwidth | dbcoldefine size bw |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 Output: |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#fsdb size bw |
102
|
|
|
|
|
|
|
102400 4937974.964736 |
103
|
|
|
|
|
|
|
102400 4585247.875904 |
104
|
|
|
|
|
|
|
102400 5098141.207123 |
105
|
|
|
|
|
|
|
# | dbcoldefine size bw |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L. |
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 CLASS FUNCTIONS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
@ISA = qw(Fsdb::Filter); |
117
|
|
|
|
|
|
|
($VERSION) = 2.0; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
1
|
|
5401
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
120
|
1
|
|
|
1
|
|
8
|
use Pod::Usage; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
107
|
|
121
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
78
|
|
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
1
|
|
9
|
use Fsdb::Filter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
124
|
1
|
|
|
1
|
|
8
|
use Fsdb::IO::Writer; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
823
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 new |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$filter = new Fsdb::Filter::dbcoldefine(@arguments); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Create a new dbcoldefine object, taking command-line arguments. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub new ($@) { |
136
|
0
|
|
|
0
|
1
|
|
my $class = shift @_; |
137
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
138
|
0
|
|
|
|
|
|
bless $self, $class; |
139
|
0
|
|
|
|
|
|
$self->set_defaults; |
140
|
0
|
|
|
|
|
|
$self->parse_options(@_); |
141
|
0
|
|
|
|
|
|
$self->SUPER::post_new(); |
142
|
0
|
|
|
|
|
|
return $self; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 set_defaults |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$filter->set_defaults(); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Internal: set up defaults. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub set_defaults ($) { |
155
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
156
|
0
|
|
|
|
|
|
$self->SUPER::set_defaults(); |
157
|
0
|
|
|
|
|
|
$self->{_fscode} = 'D'; |
158
|
0
|
|
|
|
|
|
$self->{_cols} = []; |
159
|
0
|
|
|
|
|
|
$self->{_header} = undef; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 parse_options |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$filter->parse_options(@ARGV); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Internal: parse command-line arguments. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub parse_options ($@) { |
171
|
0
|
|
|
0
|
1
|
|
my $self = shift @_; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my(@argv) = @_; |
174
|
|
|
|
|
|
|
$self->get_options( |
175
|
|
|
|
|
|
|
\@argv, |
176
|
0
|
|
|
0
|
|
|
'help|?' => sub { pod2usage(1); }, |
177
|
0
|
|
|
0
|
|
|
'man' => sub { pod2usage(-verbose => 2); }, |
178
|
|
|
|
|
|
|
'autorun!' => \$self->{_autorun}, |
179
|
|
|
|
|
|
|
'close!' => \$self->{_close}, |
180
|
|
|
|
|
|
|
'd|debug+' => \$self->{_debug}, |
181
|
|
|
|
|
|
|
'F|fs|fieldseparator|columnseparator=s' => \$self->{_fscode}, |
182
|
|
|
|
|
|
|
'header=s' => \$self->{_header}, |
183
|
0
|
|
|
0
|
|
|
'i|input=s' => sub { $self->parse_io_option('input', @_); }, |
184
|
|
|
|
|
|
|
'log!' => \$self->{_logprog}, |
185
|
0
|
|
|
0
|
|
|
'o|output=s' => sub { $self->parse_io_option('output', @_); }, |
186
|
0
|
0
|
|
|
|
|
) or pod2usage(2); |
187
|
0
|
|
|
|
|
|
push (@{$self->{_cols}}, @argv); |
|
0
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 setup |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
$filter->setup(); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Internal: setup, parse headers. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub setup ($) { |
199
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
my(@finish_args) = (-comment_handler => $self->create_pass_comments_sub); |
202
|
0
|
0
|
0
|
|
|
|
if (!defined($self->{_header}) && $#{$self->{_cols}} == -1) { |
|
0
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
203
|
0
|
|
|
|
|
|
croak $self->{_prog} . ": must specify either --header or columns.\n"; |
204
|
0
|
|
|
|
|
|
} elsif (defined($self->{_header}) && $#{$self->{_cols}} == -1) { |
205
|
0
|
|
|
|
|
|
push(@finish_args, -header => $self->{_header}); |
206
|
0
|
|
|
|
|
|
} elsif (!defined($self->{_header}) && $#{$self->{_cols}} > -1) { |
207
|
0
|
|
|
|
|
|
push(@finish_args, -fscode => $self->{_fscode}, -cols => $self->{_cols}); |
208
|
|
|
|
|
|
|
} else { |
209
|
0
|
|
|
|
|
|
croak $self->{_prog} . ": cannot specific both --header and columns.\n"; |
210
|
|
|
|
|
|
|
}; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# all the hard work is on the next line where we force the right codes |
214
|
0
|
|
|
|
|
|
$self->finish_io_option('input', @finish_args); |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
$self->finish_io_option('output', -clone => $self->{_in}); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 run |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
$filter->run(); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Internal: run over each rows. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
226
|
|
|
|
|
|
|
sub run ($) { |
227
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
228
|
|
|
|
|
|
|
# can't get any easier than this |
229
|
0
|
|
|
|
|
|
my $read_fastpath_sub = $self->{_in}->fastpath_sub(); |
230
|
0
|
|
|
|
|
|
my $write_fastpath_sub = $self->{_out}->fastpath_sub(); |
231
|
0
|
|
|
|
|
|
my $fref; |
232
|
0
|
|
|
|
|
|
while ($fref = &$read_fastpath_sub()) { |
233
|
0
|
|
|
|
|
|
&$write_fastpath_sub($fref); |
234
|
|
|
|
|
|
|
}; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 AUTHOR and COPYRIGHT |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Copyright (C) 1991-2016 by John Heidemann |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This program is distributed under terms of the GNU general |
242
|
|
|
|
|
|
|
public license, version 2. See the file COPYING |
243
|
|
|
|
|
|
|
with the distribution for details. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |