123
|
|
|
|
|
|
|
The data is output as an HTML I, suitable for display through a I-client.
124
|
|
|
|
|
|
|
See L<"ShowHTMLTable">. Input can either be plain ASCII text, or text |
125
|
|
|
|
|
|
|
with embedded HTML elements, depending upon an argument or global parameter. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The subroutines which perform these displays are listed below. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 EXPORTED NAMES |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This module exports the following subroutines: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
ShowDatabases - show list of databases |
136
|
|
|
|
|
|
|
ShowTables - show list of tables |
137
|
|
|
|
|
|
|
ShowColumns - show table of column info |
138
|
|
|
|
|
|
|
ShowTable - show a table of data |
139
|
|
|
|
|
|
|
ShowRow - show a row from one or more columns |
140
|
|
|
|
|
|
|
ShowTableValue - show a single column's value |
141
|
|
|
|
|
|
|
ShowBoxTable - show a table of data in a box |
142
|
|
|
|
|
|
|
ShowListTable - show a table of data in a list |
143
|
|
|
|
|
|
|
ShowSimpleTable - show a table of data in a simple table |
144
|
|
|
|
|
|
|
ShowHTMLTable - show a table of data using HTML |
145
|
|
|
|
|
|
|
PlainText - convert HTML text into plain text |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
All of these subroutines, and others, are described in detail in the |
148
|
|
|
|
|
|
|
following sections. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
22
|
|
|
22
|
|
37626
|
use Exporter; |
|
22
|
|
|
|
|
51
|
|
|
22
|
|
|
|
|
4170
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
155
|
|
|
|
|
|
|
@EXPORT = qw( ShowDatabases |
156
|
|
|
|
|
|
|
ShowTables |
157
|
|
|
|
|
|
|
ShowColumns |
158
|
|
|
|
|
|
|
ShowTable |
159
|
|
|
|
|
|
|
ShowRow |
160
|
|
|
|
|
|
|
ShowBoxTable |
161
|
|
|
|
|
|
|
ShowHTMLTable |
162
|
|
|
|
|
|
|
ShowListTable |
163
|
|
|
|
|
|
|
ShowSimpleTable |
164
|
|
|
|
|
|
|
ShowTableValue |
165
|
|
|
|
|
|
|
Show_Mode |
166
|
|
|
|
|
|
|
PlainText |
167
|
|
|
|
|
|
|
URL_Keys |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
@EXPORT_OK = qw( Show_Mode |
171
|
|
|
|
|
|
|
URL_Keys |
172
|
|
|
|
|
|
|
Title_Formats |
173
|
|
|
|
|
|
|
Data_Formats |
174
|
|
|
|
|
|
|
); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Some control variables -- the user may set these |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
$Show_Mode = 'Box'; # one of: List, Table, Box, or HTML |
179
|
|
|
|
|
|
|
$List_Wrap_Margin = 10; # break words up to this long |
180
|
|
|
|
|
|
|
$Max_Table_Width = ''; # if defined, scale tables |
181
|
|
|
|
|
|
|
$Max_List_Width = $ENV{'COLUMNS'} || 80; |
182
|
|
|
|
|
|
|
$No_Escape = ''; # escape by default |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
%URL_Keys = (); |
185
|
|
|
|
|
|
|
@Title_Formats = (); # formats for HTML formatting |
186
|
|
|
|
|
|
|
@Data_Formats = (); |
187
|
|
|
|
|
|
|
|
188
|
22
|
|
|
22
|
|
278
|
use Carp; |
|
22
|
|
|
|
|
42
|
|
|
22
|
|
|
|
|
39722
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
unshift(@INC, '.'); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub ShowDatabases; |
193
|
|
|
|
|
|
|
sub ShowTables; |
194
|
|
|
|
|
|
|
sub ShowColumns; |
195
|
|
|
|
|
|
|
sub ShowTable; |
196
|
|
|
|
|
|
|
sub ShowRow; |
197
|
|
|
|
|
|
|
sub PlainText; |
198
|
|
|
|
|
|
|
sub htmltext; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub get_params; |
201
|
|
|
|
|
|
|
sub html_formats; |
202
|
|
|
|
|
|
|
sub center; |
203
|
|
|
|
|
|
|
sub max_length; |
204
|
|
|
|
|
|
|
sub max; |
205
|
|
|
|
|
|
|
sub out; |
206
|
|
|
|
|
|
|
sub put; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 MODULES |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 ShowTable |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Format and display the contents of one or more rows of data. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
S< >B { I => I, ... }; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
S< >B I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> |
217
|
|
|
|
|
|
|
[, I<\&fmt_sub> [, I<$max_width> ] [, I<$show_mode> ] ]; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
The B subroutine displays tabular data aligned in columns, |
220
|
|
|
|
|
|
|
with headers. B supports four I of display: B, B,
221
|
|
|
|
|
|
|
B, and B. Each mode is described separately below. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
The arguments to B may be given in one of two ways: as a |
224
|
|
|
|
|
|
|
hashed-array, or by a combination of fixed order arguments, and some |
225
|
|
|
|
|
|
|
package-global variable settings. The hash-array parameters correspond |
226
|
|
|
|
|
|
|
to the fixed arguments and the global-parameter settings. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
In the list below, both the hash-array parameter name and the |
229
|
|
|
|
|
|
|
fixed-order argument name is given as the value. In the case where |
230
|
|
|
|
|
|
|
there is no fixed-order argument for a given parameter-value pair, then |
231
|
|
|
|
|
|
|
the corresponding global variable name is given. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=over 10 |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item C => I<\@titles> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
A reference to an array of column names, or titles. If a particular column name |
238
|
|
|
|
|
|
|
is null, then the string C> is used by default. To have a column |
239
|
|
|
|
|
|
|
have no title, use the empty string. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item C => I<\@types> |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
A reference to an array of types, one for each column. These types are |
244
|
|
|
|
|
|
|
passed to the I for appropriate formatting. Also, if a column |
245
|
|
|
|
|
|
|
type matches the regexp "C", then the column |
246
|
|
|
|
|
|
|
alignment will be left-justified, otherwise it will be right-justified. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item C => I<\@widths> |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
A reference to an array of column widths, which may be given as an integer, or |
251
|
|
|
|
|
|
|
as a string of the form: "I.I". |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=item C => I<\&row_sub> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
A reference to a subroutine which successively returns rows of values in an array. |
256
|
|
|
|
|
|
|
It is called for two purposes, each described separately: |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
* To fetch successive rows of data: |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
@row = &$row_sub(0); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
When given a null, zero, or empty argument, the next row is returned. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
* To initialize or rewind the data traversal. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
$rewindable = &$row_sub(1); |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
When invoked with a non-null argument, the subroutine should rewind its |
269
|
|
|
|
|
|
|
row pointer to start at the first row of data. If the data which |
270
|
|
|
|
|
|
|
I is traversing is not rewindable, it must return zero or null. |
271
|
|
|
|
|
|
|
If the data is rewindable, a non-null, non-zero value should be returned. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
The I must expect to be invoked once with a non-null argument, |
274
|
|
|
|
|
|
|
in order to discover whether or not the data is rewindable. If the data |
275
|
|
|
|
|
|
|
cannot be rewound, I will thereafter only be called with a zero |
276
|
|
|
|
|
|
|
argument. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Specifically, I subroutine is used in this manner: |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
$rewindable = &$row_sub(1); |
281
|
|
|
|
|
|
|
if ($rewindable) { |
282
|
|
|
|
|
|
|
while ((@row = &$row_sub(0)), $#row >= 0) { |
283
|
|
|
|
|
|
|
# examine lengths for optimal formatting |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
&$row_sub(1); # rewind |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
while ((@row = &$row_sub(0)), $#row >= 0) { |
288
|
|
|
|
|
|
|
# format the data |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
The consequence of data that is not rewindable, a reasonably nice table |
292
|
|
|
|
|
|
|
will still be formatted, but it may contain fairly large amounts of |
293
|
|
|
|
|
|
|
whitespace for wide columns. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item C => I<\&fmt_sub> |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
A reference to a subroutine which formats a value, according to its |
298
|
|
|
|
|
|
|
type, width, precision, and the current column width. It is invoked |
299
|
|
|
|
|
|
|
either with a fixed list of arguments, or with a hash-array of parameter |
300
|
|
|
|
|
|
|
and value pairs. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
$string = &fmt_sub { I => I, ... }; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
$string = &fmt_sub($value, $type, $max_width, $width, $precision) |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
If I<\&fmt_sub> is omitted, then a default subroutine, B, |
307
|
|
|
|
|
|
|
will be used, which will use Perl's standard string formatting rules. |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
The arguments to I<\&fmt_sub>, either as values passed in a fixed |
310
|
|
|
|
|
|
|
order, or as part of the parameter value pair, are described in the |
311
|
|
|
|
|
|
|
section on L<"ShowTableValue> below. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item C => I, |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
The maximum table width, including the table formatting characters. If |
316
|
|
|
|
|
|
|
not given, defaults to the global variable B<$Max_Table_Width>; |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=item C => 'I', |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
The display mode of the output. One of five strings: C<'Box'>, |
321
|
|
|
|
|
|
|
C<'Table'>, C<'Simple'>, C<'List'>, and C<'HTML'>. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=back |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=cut |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
sub ShowTable { |
328
|
0
|
|
|
0
|
0
|
0
|
my @argv = @_; |
329
|
0
|
|
|
|
|
0
|
local ($_,$titles,$types,$widths,$row_sub,$fmt_sub, |
330
|
|
|
|
|
|
|
$max_width, $show_mode, $wrap_margin, $url_keys, |
331
|
|
|
|
|
|
|
$no_escape, $title_formats, $data_formats); |
332
|
0
|
|
|
|
|
0
|
my $args = |
333
|
|
|
|
|
|
|
get_params \@argv, |
334
|
|
|
|
|
|
|
{ titles => \$titles, |
335
|
|
|
|
|
|
|
types => \$types, |
336
|
|
|
|
|
|
|
widths => \$widths, |
337
|
|
|
|
|
|
|
row_sub => \$row_sub, |
338
|
|
|
|
|
|
|
fmt_sub => \$fmt_sub, |
339
|
|
|
|
|
|
|
max_width => \$max_width, |
340
|
|
|
|
|
|
|
show_mode => \$show_mode, |
341
|
|
|
|
|
|
|
}, |
342
|
|
|
|
|
|
|
[qw(titles types widths row_sub fmt_sub max_width show_mode)]; |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
# Default mode is from $Show_Mode global |
345
|
0
|
0
|
|
|
|
0
|
$show_mode = $args->{'show_mode'} = $Show_Mode unless $show_mode ne ''; |
346
|
0
|
|
|
|
|
0
|
$_ = $show_mode; |
347
|
0
|
0
|
|
|
|
0
|
if (/List/i) { &ShowListTable($args); } |
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
|
348
|
0
|
|
|
|
|
0
|
elsif (/HTML/i) { &ShowHTMLTable($args); } |
349
|
0
|
|
|
|
|
0
|
elsif (/Table/i) { &ShowSimpleTable($args); } |
350
|
0
|
|
|
|
|
0
|
else { &ShowBoxTable($args); } |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=head1 ShowDatabases |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
Show a list of database names. |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
S< >B I<\@dbnames>; |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
S< >B { 'data' => I<\@dbnames>, I => |
360
|
|
|
|
|
|
|
I, ...}; |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
B is intended to be used to display a list of database |
363
|
|
|
|
|
|
|
names, under the column heading of "Databases". It is a special case |
364
|
|
|
|
|
|
|
usage of B (and can thus be passed any parameter suitable |
365
|
|
|
|
|
|
|
for B. |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
The argument, I<\@dbnames>, is a reference to an array of strings, used |
368
|
|
|
|
|
|
|
as the values of the single column display. |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=cut |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub ShowDatabases { |
373
|
0
|
|
|
0
|
0
|
0
|
my @argv = @_; |
374
|
0
|
|
|
|
|
0
|
local $databases; |
375
|
0
|
|
|
|
|
0
|
my $args = get_params \@argv, {data => \$databases}, ['data']; |
376
|
0
|
0
|
|
|
|
0
|
$databases ne '' or croak "Missing array of databases.\n"; |
377
|
|
|
|
|
|
|
|
378
|
0
|
0
|
|
|
|
0
|
$args->{'titles'} = 'Databases' unless exists $args->{'titles'}; |
379
|
0
|
|
|
|
|
0
|
$args->{'types'} = [ 'char' ]; |
380
|
0
|
|
|
|
|
0
|
$args->{'width'} = max_length $databases; |
381
|
0
|
|
|
|
|
0
|
$args->{'lengths'} = $args->{'width'}; |
382
|
0
|
|
|
|
|
0
|
local( $current_row ) = 0; |
383
|
0
|
|
|
0
|
|
0
|
$args->{'row_sub'} = sub { &ShowRow( $_[0], \$current_row, $databases ); }; |
|
0
|
|
|
|
|
0
|
|
384
|
0
|
|
|
|
|
0
|
ShowTable $args; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=head1 ShowTables |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
Show an array of table names. |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
S< >B I<\@tblnames>; |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
S< >B { 'data' => I<\@tblnames>, I => I, ...}; |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
B is used to display a list of table names, under the column |
396
|
|
|
|
|
|
|
heading of "Tables". It is a special case usage of B, and can |
397
|
|
|
|
|
|
|
be passed any L<"ShowTable"> argument parameter. |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
=cut |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub ShowTables { |
402
|
0
|
|
|
0
|
0
|
0
|
my @argv = @_; |
403
|
0
|
|
|
|
|
0
|
local $tables; |
404
|
0
|
|
|
|
|
0
|
my $args = get_params \@argv, {data => \$tables}, ['data']; |
405
|
0
|
0
|
|
|
|
0
|
$tables ne '' or croak "Missing array of tables.\n"; |
406
|
|
|
|
|
|
|
|
407
|
0
|
0
|
|
|
|
0
|
$args->{'titles'} = 'Tables' unless exists $args->{'titles'}; |
408
|
0
|
|
|
|
|
0
|
$args->{'types'} = 'char'; |
409
|
0
|
|
|
|
|
0
|
$args->{'width'} = max_length $tables; |
410
|
0
|
|
|
|
|
0
|
$args->{'lengths'} = $args->{'width'}; |
411
|
0
|
|
|
|
|
0
|
local( $current_row ) = 0; |
412
|
0
|
|
|
0
|
|
0
|
$args->{'row_sub'} = sub { &ShowRow( $_[0], \$current_row, $tables ); }; |
|
0
|
|
|
|
|
0
|
|
413
|
0
|
|
|
|
|
0
|
ShowTable $args; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=head1 ShowColumns |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
Display a table of column names, types, and attributes. |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
S< >B { I => I, ... }; |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
S< >B I<\@columns>, I<\@col_types>, I<\@col_lengths>, I<\@col_attrs>; |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
The B subroutine displays a table of column names, types, lengths, |
425
|
|
|
|
|
|
|
and other attributes in a nicely formatted table. It is a special case usage |
426
|
|
|
|
|
|
|
of B, and can be passed any argument suitable for L<"ShowTable">; |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
The arguments are: |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
=over 10 |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=item C = I<\@columns> |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
An array of column names. This provides the value for the first column |
435
|
|
|
|
|
|
|
of the output. |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
=item C = I<\@col_types> |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
An array of column types names. This provides the value for the second |
440
|
|
|
|
|
|
|
column. |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
=item C = I<\@col_lengths> |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
An array of maximum lengths for corresponding columns. This provides |
445
|
|
|
|
|
|
|
the value for the third column of the output. |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=item C = I<\@col_attrs> |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
An array of column attributes array references (ie: an array of arrays). |
450
|
|
|
|
|
|
|
The attributes array for the first column are at "I<$col_attrs>-\>[0]". |
451
|
|
|
|
|
|
|
The first attribute of the second column is "I<$col_attrs>-\>[1][0]". |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=back |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
The columns, types, lengths, and attributes are displayed in a table |
456
|
|
|
|
|
|
|
with the column headings: "Column", "Type", "Length", and "Attributes". |
457
|
|
|
|
|
|
|
This is a special case usage of B, and can be passed |
458
|
|
|
|
|
|
|
additional arguments suitable for L<"ShowTable">. |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=cut |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
sub ShowColumns { |
463
|
0
|
|
|
0
|
0
|
0
|
my @argv = @_; |
464
|
0
|
|
|
|
|
0
|
local ($col_names, $col_types, $col_lengths, $col_attributes); |
465
|
0
|
|
|
|
|
0
|
my $args = |
466
|
|
|
|
|
|
|
get_params |
467
|
|
|
|
|
|
|
\@argv, |
468
|
|
|
|
|
|
|
{ col_names => \$col_names, |
469
|
|
|
|
|
|
|
col_types => \$col_types, |
470
|
|
|
|
|
|
|
col_lengths => \$col_lengths, |
471
|
|
|
|
|
|
|
col_attributes => \$col_attributes, |
472
|
|
|
|
|
|
|
},[qw(col_names col_types col_lengths col_attributes)]; |
473
|
|
|
|
|
|
|
|
474
|
0
|
0
|
|
|
|
0
|
$col_names ne '' or croak "Missing array of column names.\n"; |
475
|
0
|
0
|
|
|
|
0
|
$col_types ne '' or croak "Missing array of column types.\n"; |
476
|
0
|
0
|
|
|
|
0
|
$col_lengths ne '' or croak "Missing array of column lengths.\n"; |
477
|
0
|
0
|
|
|
|
0
|
$col_attributes ne '' or croak "Missing array of column attributes.\n"; |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# setup the descriptor arrays |
480
|
0
|
|
|
|
|
0
|
$args->{'titles'} = [ qw(Column Type Length Attributes) ]; |
481
|
0
|
|
|
|
|
0
|
$args->{'types'} = [ qw(varchar varchar int varchar) ]; |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
# Do some data conversions before displaying |
484
|
|
|
|
|
|
|
# Convert attribute array to a string of attributes |
485
|
0
|
|
|
|
|
0
|
local @col_attrs = (); |
486
|
0
|
|
|
|
|
0
|
my $i; |
487
|
0
|
|
|
|
|
0
|
for ($i = 0; $i <= $#{$col_attributes}; $i++) { |
|
0
|
|
|
|
|
0
|
|
488
|
0
|
|
|
|
|
0
|
$col_attrs[$i] = join(', ',@{$col_attributes->[$i]}); |
|
0
|
|
|
|
|
0
|
|
489
|
|
|
|
|
|
|
} |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
# count the widths, to setup the Column name column width |
492
|
0
|
|
|
|
|
0
|
$args->{'lengths'} = [ (max_length $col_names), (max_length $col_types), |
493
|
|
|
|
|
|
|
(max_length $col_lengths), (max_length \@col_attrs) ]; |
494
|
|
|
|
|
|
|
|
495
|
0
|
|
|
|
|
0
|
local($current_row) = 0; |
496
|
0
|
|
|
0
|
|
0
|
$args->{'row_sub'} = sub { &ShowRow($_[0], \$current_row, $col_names, |
497
|
0
|
|
|
|
|
0
|
$col_types, $col_lengths, \@col_attrs); }; |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
# Finally, show the darn thing |
500
|
0
|
|
|
|
|
0
|
ShowTable $args; |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=head1 ShowBoxTable |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
Show tabular data in a box. |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
S< >B { I = I, ... }; |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
S< >B I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> |
511
|
|
|
|
|
|
|
S< >[, [ I<\&fmt_sub> ] [, I<$max_width> ] ]; |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
The B displays tabular data in titled columns using a "box" |
514
|
|
|
|
|
|
|
of ASCII graphics, looking something like this: |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
+------------+----------+-----+----------+ |
518
|
|
|
|
|
|
|
| Column1 | Column2 | ... | ColumnN | |
519
|
|
|
|
|
|
|
+------------+----------+-----+----------+ |
520
|
|
|
|
|
|
|
| Value11 | Value12 | ... | Value 1M | |
521
|
|
|
|
|
|
|
| Value21 | Value22 | ... | Value 2M | |
522
|
|
|
|
|
|
|
| Value31 | Value32 | ... | Value 3M | |
523
|
|
|
|
|
|
|
| ... | ... | ... | ... | |
524
|
|
|
|
|
|
|
| ValueN1 | ValueN2 | ... | Value NM | |
525
|
|
|
|
|
|
|
+------------+----------+-----+----------+ |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
The arguments are the same as with L<"ShowTable">. If the I<@titles> array |
529
|
|
|
|
|
|
|
is empty, the header row is omitted. |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
=cut |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
sub ShowBoxTable { |
534
|
37
|
|
|
37
|
0
|
569167
|
my @argv = @_; |
535
|
37
|
|
|
|
|
510
|
local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width); |
536
|
37
|
|
|
|
|
1923
|
my $args = |
537
|
|
|
|
|
|
|
get_params |
538
|
|
|
|
|
|
|
\@argv, |
539
|
|
|
|
|
|
|
{ titles => \$titles, |
540
|
|
|
|
|
|
|
types => \$types, |
541
|
|
|
|
|
|
|
widths => \$col_widths, |
542
|
|
|
|
|
|
|
row_sub => \$row_sub, |
543
|
|
|
|
|
|
|
fmtsub => \$fmt_sub, |
544
|
|
|
|
|
|
|
max_width => \$max_width, |
545
|
|
|
|
|
|
|
}, |
546
|
|
|
|
|
|
|
[qw(titles types widths row_sub fmtsub max_width)]; |
547
|
|
|
|
|
|
|
|
548
|
37
|
50
|
|
|
|
258
|
$titles ne '' or croak "Missing column names array.\n"; |
549
|
37
|
50
|
|
|
|
311
|
$types ne '' or croak "Missing column types array.\n"; |
550
|
37
|
50
|
|
|
|
1102
|
$col_widths ne '' or croak "Missing column width array.\n"; |
551
|
37
|
50
|
|
|
|
147
|
$row_sub ne '' or croak "Missing row subroutine.\n"; |
552
|
37
|
100
|
100
|
|
|
560
|
$fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; |
553
|
37
|
100
|
100
|
|
|
405
|
$max_width = $Max_Table_Width if !defined($max_width) || $max_width eq ''; |
554
|
|
|
|
|
|
|
|
555
|
37
|
|
|
|
|
332
|
my $rewindable = &$row_sub(1); # see if data is rewindable |
556
|
|
|
|
|
|
|
|
557
|
37
|
|
|
|
|
582
|
my ($num_cols, $widths, $precision, $max_widths) = |
558
|
|
|
|
|
|
|
&calc_widths($col_widths, $titles, $rewindable, |
559
|
|
|
|
|
|
|
$row_sub, $fmt_sub, $types, 'box', $max_width); |
560
|
|
|
|
|
|
|
|
561
|
37
|
|
|
|
|
96
|
my $width = 1; |
562
|
37
|
|
|
|
|
111
|
my $dashes = ' +'; |
563
|
37
|
|
|
|
|
59
|
my $title_line = ' |'; |
564
|
37
|
|
|
|
|
50
|
my $title; |
565
|
37
|
|
|
|
|
721
|
my $fmt = ' |'; # initial format string |
566
|
37
|
|
|
|
|
59
|
my $c; |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
# Compose the box header |
569
|
37
|
|
|
|
|
132
|
for ($c = 0; $c < $num_cols; $c++) { |
570
|
170
|
|
|
|
|
264
|
$width = $max_widths->[$c]; # get previously calculated max col width |
571
|
170
|
|
|
|
|
288
|
$width += 2; # account for a blank on either |
572
|
|
|
|
|
|
|
# side of each value |
573
|
170
|
|
|
|
|
352
|
$dashes .= ('-' x $width); |
574
|
170
|
|
|
|
|
223
|
$dashes .= '+'; |
575
|
|
|
|
|
|
|
|
576
|
170
|
50
|
33
|
|
|
1328
|
$title = $#$titles >= 0 && defined($titles->[$c]) ? $titles->[$c] : |
577
|
|
|
|
|
|
|
sprintf("Field_%d", $c+1); |
578
|
170
|
|
|
|
|
454
|
$title_line .= center $title, $width; |
579
|
170
|
|
|
|
|
3122
|
$title_line .= '|'; |
580
|
|
|
|
|
|
|
} |
581
|
37
|
|
|
|
|
262
|
out $dashes; |
582
|
37
|
50
|
|
|
|
292
|
if ($#$titles >= 0) { |
583
|
37
|
|
|
|
|
167
|
out $title_line; |
584
|
37
|
|
|
|
|
99
|
out $dashes; |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
|
587
|
37
|
|
|
|
|
142
|
my @values; |
588
|
37
|
|
|
|
|
163
|
my @prefix = (" ", "<"); |
589
|
37
|
|
|
|
|
130
|
my @suffix = (" |", ">|"); |
590
|
37
|
|
|
|
|
63
|
my @cell; |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
# loop over the data, formatting it into cells, one row at a time. |
593
|
22
|
|
|
22
|
|
21946
|
while ((@values = &$row_sub(0)), $#values >= $[) { |
|
22
|
|
|
|
|
10006
|
|
|
22
|
|
|
|
|
91824
|
|
|
37
|
|
|
|
|
171
|
|
594
|
|
|
|
|
|
|
# first pass -- format each value into a string |
595
|
185
|
|
|
|
|
541
|
@cell = (); |
596
|
185
|
|
|
|
|
695
|
for ($c = 0; $c <= $#values; $c++) { |
597
|
850
|
|
|
|
|
3092
|
$cell[$c] = &$fmt_sub($values[$c], $types->[$c], $max_widths->[$c], |
598
|
|
|
|
|
|
|
$widths->[$c], $precision->[$c], 'box'); |
599
|
|
|
|
|
|
|
} |
600
|
|
|
|
|
|
|
# second pass -- output each cell, wrapping if necessary |
601
|
185
|
|
|
|
|
315
|
my $will_wrap; |
602
|
185
|
|
|
|
|
318
|
my $wrapped = 0; |
603
|
185
|
|
|
|
|
227
|
do { $will_wrap = 0; |
|
462
|
|
|
|
|
561
|
|
604
|
462
|
|
|
|
|
1324
|
put " |"; # start a line |
605
|
462
|
|
|
|
|
1625
|
for ($c = 0; $c <= $#cell; $c++) { |
606
|
2169
|
|
|
|
|
6752
|
$will_wrap |= &putcell(\@cell, $c, $max_widths->[$c], |
607
|
|
|
|
|
|
|
\@prefix, \@suffix, $wrapped); |
608
|
|
|
|
|
|
|
} |
609
|
462
|
|
|
|
|
972
|
out ""; |
610
|
462
|
|
|
|
|
2643
|
$wrapped++; |
611
|
|
|
|
|
|
|
} while ($will_wrap); |
612
|
|
|
|
|
|
|
} |
613
|
37
|
|
|
|
|
119
|
out $dashes; |
614
|
37
|
|
|
|
|
102
|
out ""; |
615
|
|
|
|
|
|
|
} |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
=head1 ShowSimpleTable |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
Display a table of data using a simple table format. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
S< >B I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> [, I<\&fmt_sub>]; |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
S< >B { I => I, ... }; |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
The B subroutine formats data into a simple table of |
627
|
|
|
|
|
|
|
aligned columns, in the following example: |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
Column1 Column2 Column3 |
630
|
|
|
|
|
|
|
------- ------- ------- |
631
|
|
|
|
|
|
|
Value1 Value2 Value3 |
632
|
|
|
|
|
|
|
Value12 Value22 Value32 |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
Columns are auto-sized by the data's widths, plus two spaces between columns. |
635
|
|
|
|
|
|
|
Values which are too long for the maximum colulmn width are wrapped within |
636
|
|
|
|
|
|
|
the column. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
=cut |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
sub ShowSimpleTable { |
641
|
37
|
|
|
37
|
0
|
449802
|
my @argv = @_; |
642
|
37
|
|
|
|
|
1443
|
local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width); |
643
|
37
|
|
|
|
|
1358
|
my $args = |
644
|
|
|
|
|
|
|
get_params |
645
|
|
|
|
|
|
|
\@argv, |
646
|
|
|
|
|
|
|
{ titles => \$titles, |
647
|
|
|
|
|
|
|
types => \$types, |
648
|
|
|
|
|
|
|
widths => \$col_widths, |
649
|
|
|
|
|
|
|
row_sub => \$row_sub, |
650
|
|
|
|
|
|
|
fmtsub => \$fmt_sub, |
651
|
|
|
|
|
|
|
max_width => \$max_width, |
652
|
|
|
|
|
|
|
}, |
653
|
|
|
|
|
|
|
[qw(titles types widths row_sub fmtsub max_width)]; |
654
|
|
|
|
|
|
|
|
655
|
37
|
50
|
|
|
|
411
|
$titles ne '' or croak "Missing column names array.\n"; |
656
|
37
|
50
|
|
|
|
202
|
$types ne '' or croak "Missing column types array.\n"; |
657
|
37
|
50
|
|
|
|
191
|
$col_widths ne '' or croak "Missing column width array.\n"; |
658
|
37
|
50
|
|
|
|
141
|
$row_sub ne '' or croak "Missing row sub array.\n"; |
659
|
37
|
100
|
100
|
|
|
348
|
$fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; |
660
|
37
|
100
|
100
|
|
|
429
|
$max_width = $Max_Table_Width if !defined($max_width) || $max_width eq ''; |
661
|
|
|
|
|
|
|
|
662
|
37
|
|
|
|
|
236
|
my $rewindable = &$row_sub(1); # see if data is rewindable |
663
|
|
|
|
|
|
|
|
664
|
37
|
|
|
|
|
435
|
my ($num_cols, $widths, $precision, $max_widths) = |
665
|
|
|
|
|
|
|
&calc_widths($col_widths, $titles, $rewindable, |
666
|
|
|
|
|
|
|
$row_sub, $fmt_sub, $types, 'table', $max_width); |
667
|
|
|
|
|
|
|
|
668
|
37
|
|
|
|
|
71
|
my $width = 1; |
669
|
37
|
|
|
|
|
82
|
my $dashes = ' '; |
670
|
37
|
|
|
|
|
71
|
my $title_line = ' '; |
671
|
37
|
|
|
|
|
54
|
my $title ; |
672
|
37
|
|
|
|
|
62
|
my $postfix = shift; |
673
|
37
|
|
|
|
|
474
|
my $c ; |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
# Calculate the maximum widths |
676
|
37
|
|
|
|
|
121
|
for ($c = 0; $c < $num_cols; $c++) { |
677
|
170
|
|
|
|
|
305
|
$width = $max_widths->[$c]; |
678
|
170
|
|
|
|
|
344
|
$dashes .= ('-' x $width); |
679
|
170
|
|
|
|
|
223
|
$dashes .= ' '; |
680
|
|
|
|
|
|
|
|
681
|
170
|
50
|
|
|
|
511
|
next if $#$titles < 0; |
682
|
170
|
|
|
|
|
648
|
$title = center $titles->[$c], $width; |
683
|
170
|
|
|
|
|
330
|
$title_line .= $title; |
684
|
170
|
|
|
|
|
446
|
$title_line .= ' '; |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
} |
687
|
37
|
50
|
|
|
|
329
|
out $title_line if $#$titles >= 0; |
688
|
37
|
|
|
|
|
210
|
out $dashes; |
689
|
|
|
|
|
|
|
|
690
|
37
|
|
|
|
|
259
|
my @values; |
691
|
37
|
|
|
|
|
661
|
my @prefix = (" ", "<"); |
692
|
37
|
|
|
|
|
216
|
my @suffix = (" ", ">"); |
693
|
|
|
|
|
|
|
|
694
|
37
|
|
|
|
|
185
|
while ((@values = &$row_sub(0)), $#values >= $[) { |
695
|
|
|
|
|
|
|
# first pass -- format each value into a string |
696
|
185
|
|
|
|
|
587
|
my @cell; |
697
|
185
|
|
|
|
|
547
|
for ($c = 0; $c <= $#values; $c++) { |
698
|
850
|
|
|
|
|
4435
|
$cell[$c] = &$fmt_sub($values[$c], $types->[$c], $max_widths->[$c], |
699
|
|
|
|
|
|
|
$widths->[$c], $precision->[$c], 'table'); |
700
|
|
|
|
|
|
|
} |
701
|
|
|
|
|
|
|
# second pass -- output each cell, wrapping if necessary |
702
|
185
|
|
|
|
|
246
|
my $will_wrap; |
703
|
185
|
|
|
|
|
301
|
my $wrapped = 0; |
704
|
185
|
|
|
|
|
229
|
do { $will_wrap = 0; |
|
391
|
|
|
|
|
481
|
|
705
|
391
|
|
|
|
|
968
|
for ($c = 0; $c <= $#cell; $c++) { |
706
|
1814
|
|
|
|
|
5716
|
$will_wrap |= &putcell(\@cell, $c, $max_widths->[$c], |
707
|
|
|
|
|
|
|
\@prefix, \@suffix, $wrapped); |
708
|
|
|
|
|
|
|
} |
709
|
391
|
|
|
|
|
911
|
out ""; |
710
|
391
|
|
|
|
|
2475
|
$wrapped++; |
711
|
|
|
|
|
|
|
} while ($will_wrap); |
712
|
|
|
|
|
|
|
} |
713
|
37
|
|
|
|
|
101
|
out ""; |
714
|
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
=head1 ShowHTMLTable |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
Display a table of data nicely using HTML tables. |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
S< >B { I => I, ... }; |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
S< >B I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> |
723
|
|
|
|
|
|
|
[, I<\&fmt_sub> [, I<$max_width> [, I<\%URL_Keys> [, I<$no_escape> |
724
|
|
|
|
|
|
|
[, I<\@title_formats> [, I<\@data_formats> [, I<$table_attrs> ] ] ] ] ] ] ]; |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
The B displays one or more rows of columns of data using |
727
|
|
|
|
|
|
|
the HTML C<\> feature. In addition to the usual parameter arguments
728
|
|
|
|
|
|
|
of L<"ShowTable">, the following parameter arguments are defined: |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
=over 10 |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
=item C => I<\%URL_Keys>, |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
This is a hash array of column names (titles) and corresponding base |
735
|
|
|
|
|
|
|
URLs. The values of any column names or indexes occuring as keys in |
736
|
|
|
|
|
|
|
the hash array will be generated as hypertext anchors using the |
737
|
|
|
|
|
|
|
associated I-like string as the base URL. Either the column name |
738
|
|
|
|
|
|
|
or the column index (beginning with 1) may be used as the hash key. |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
In the string value, these macros can be substituted: |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
"C<%K>" is replaced with the column name. |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
"C<%V>" is replaced with the column value; |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
"C<%I>" is replaced with the column index. |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
For example, if we define the array: |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
$base_url = "http://www.$domain/cgi/lookup?col=%K?val=%V"; |
751
|
|
|
|
|
|
|
%url_cols = ('Author' => $base_url, |
752
|
|
|
|
|
|
|
'Name' => $base_url); |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
Then, the values in the C column will be generated with the following |
755
|
|
|
|
|
|
|
HTML text: |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
and the values in the C column will be generated with the URL: |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
If this variable is not given, it will default to the global variable |
764
|
|
|
|
|
|
|
C<\%URL_Keys>. |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
=item C => I, |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
Unless B<$no_escape> is set, HTML-escaping is performed on the data |
769
|
|
|
|
|
|
|
values in order to properly display the special HTML formatting |
770
|
|
|
|
|
|
|
characters : '\<', '\>', and '&'. If you wish to display data with |
771
|
|
|
|
|
|
|
embedded HTML text, you must set B<$no_escape>. |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
Enabling embedded HTML, turns on certain heuristics which enable the |
774
|
|
|
|
|
|
|
user to more completely define appearance of the table. For instance, |
775
|
|
|
|
|
|
|
any C<\ | > tokens found embedded *anywhere* within a row of data will
776
|
|
|
|
|
|
|
be placed at the front of the row, within the generated C<\ | >.
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
Similarly, a row of data containing the C<\> or C<\ | >
779
|
|
|
|
|
|
|
tokens, and their closing counterparts, will begin and end, respectively |
780
|
|
|
|
|
|
|
a table header or footer data. |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
=item C => I<\@title_formats>, |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
=item C => I<\@title_formats>, |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
An array of HTML formatting elements for the column titles, one for each |
787
|
|
|
|
|
|
|
column. Each array element is a list of one or more HTML elements, |
788
|
|
|
|
|
|
|
given as C<\> or plainly, C, and separated by a comma |
789
|
|
|
|
|
|
|
C<','>, semi-colon C<';'>, or vertical bar C<'|'>. Each given HTML |
790
|
|
|
|
|
|
|
element is prepended to the corresponding column title, in the order |
791
|
|
|
|
|
|
|
given. The corresponding HTML closing elements are appended in the |
792
|
|
|
|
|
|
|
opposite order. |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
For example, if I<\@title_formats> contains the two elements: |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
[ 'FONT SIZE=+2,BOLD', 'FONT COLOR=red,EM' ] |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
then the text output for the title of the first column would be: |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
I |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
If C is omitted, the global variable B<@Title_Formats> |
803
|
|
|
|
|
|
|
is used by default. |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
=item C => I<\@data_formats>, |
806
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
=item C => I<\@data_formats>, |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
Similar to C, this array provides HTML formatting for |
810
|
|
|
|
|
|
|
the columns of each row of data. If C is omitted or |
811
|
|
|
|
|
|
|
null, then the global variable B<\@Data_Formats> is used by default. |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
=item C => I<$table_attrs>, |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
This variable defines a string of attributes to be inserted within the |
816
|
|
|
|
|
|
|
C<\> token. For example, if the user wishes to have no table
817
|
|
|
|
|
|
|
border: |
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
ShowHTMLTable { |
820
|
|
|
|
|
|
|
... |
821
|
|
|
|
|
|
|
table_attrs => 'BORDER=0', |
822
|
|
|
|
|
|
|
... |
823
|
|
|
|
|
|
|
}; |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
=back |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
=cut |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
sub ShowHTMLTable { |
830
|
49
|
|
|
49
|
0
|
833551
|
my @argv = @_; |
831
|
49
|
|
|
|
|
1431
|
local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width, |
832
|
|
|
|
|
|
|
$url_keys, $no_escape, $title_formats, $data_formats, |
833
|
|
|
|
|
|
|
$show_mode, $table_attrs); |
834
|
49
|
|
|
|
|
3115
|
my $args = |
835
|
|
|
|
|
|
|
get_params |
836
|
|
|
|
|
|
|
\@argv, |
837
|
|
|
|
|
|
|
{ titles => \$titles, |
838
|
|
|
|
|
|
|
types => \$types, |
839
|
|
|
|
|
|
|
widths => \$col_widths, |
840
|
|
|
|
|
|
|
row_sub => \$row_sub, |
841
|
|
|
|
|
|
|
fmtsub => \$fmt_sub, |
842
|
|
|
|
|
|
|
max_width => \$max_width, |
843
|
|
|
|
|
|
|
url_keys => \$url_keys, |
844
|
|
|
|
|
|
|
no_escape => \$no_escape, |
845
|
|
|
|
|
|
|
tformats => \$title_formats, |
846
|
|
|
|
|
|
|
dformats => \$data_formats, |
847
|
|
|
|
|
|
|
table_attrs => \$table_attrs, |
848
|
|
|
|
|
|
|
data_formats => 'tformats', |
849
|
|
|
|
|
|
|
title_formats => 'tformats', |
850
|
|
|
|
|
|
|
}, |
851
|
|
|
|
|
|
|
[qw(titles types widths row_sub fmtsub max_width |
852
|
|
|
|
|
|
|
url_keys no_escape title_formats data_formats |
853
|
|
|
|
|
|
|
table_attrs)]; |
854
|
|
|
|
|
|
|
|
855
|
49
|
50
|
|
|
|
445
|
$titles ne '' or croak "Missing column names array.\n"; |
856
|
49
|
50
|
|
|
|
1390
|
$types ne '' or croak "Missing column types array.\n"; |
857
|
49
|
50
|
|
|
|
178
|
$col_widths ne '' or croak "Missing column width array.\n"; |
858
|
49
|
50
|
|
|
|
373
|
$row_sub ne '' or croak "Missing row sub array.\n"; |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
# Defaults |
861
|
49
|
100
|
100
|
|
|
320
|
$fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; |
862
|
49
|
100
|
100
|
|
|
476
|
$max_width = $Max_Table_Width if !defined($max_width) || $max_width eq ''; |
863
|
49
|
100
|
100
|
|
|
300
|
$url_keys = \%URL_Keys if !defined($url_keys) || $url_keys eq ''; |
864
|
49
|
100
|
100
|
|
|
963
|
$title_formats = \@Title_Formats if !defined($title_formats) || $title_formats eq ''; |
865
|
49
|
100
|
66
|
|
|
257
|
$data_formats = \@Data_Formats if !defined($data_formats) || $data_formats eq ''; |
866
|
49
|
100
|
|
|
|
204
|
$no_escape = $No_Escape if !defined($no_escape); |
867
|
|
|
|
|
|
|
|
868
|
49
|
|
|
|
|
356
|
my $rewindable = &$row_sub(1); # see if rewindable |
869
|
|
|
|
|
|
|
|
870
|
49
|
|
|
|
|
525
|
my ($num_cols, $widths, $precision, $max_widths) = |
871
|
|
|
|
|
|
|
&calc_widths($col_widths, $titles, $rewindable, |
872
|
|
|
|
|
|
|
$row_sub, $fmt_sub, $types, 'html', $max_width); |
873
|
|
|
|
|
|
|
|
874
|
49
|
|
|
|
|
133
|
my $width = 1; |
875
|
49
|
|
|
|
|
73
|
my $total_width = 0; |
876
|
49
|
|
|
|
|
94
|
my $title_line = ''; |
877
|
49
|
|
|
|
|
62
|
my $title; |
878
|
49
|
|
|
|
|
62
|
my ($c,$x); |
879
|
0
|
|
|
|
|
0
|
my ($tprefixes,$tsuffixes,$dprefixes,$dsuffixes); |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
# prepare the HTML prefixes and suffixes, if any |
882
|
49
|
50
|
33
|
|
|
586
|
($tprefixes,$tsuffixes) = html_formats $title_formats |
883
|
|
|
|
|
|
|
if defined($title_formats) && $title_formats ne ''; |
884
|
49
|
50
|
33
|
|
|
411
|
($dprefixes,$dsuffixes) = html_formats $data_formats |
885
|
|
|
|
|
|
|
if defined($data_formats) && $data_formats ne ''; |
886
|
|
|
|
|
|
|
|
887
|
49
|
100
|
|
|
|
129
|
if ($table_attrs) { # any table attributes? |
888
|
4
|
|
|
|
|
19
|
local($_) = $table_attrs; |
889
|
4
|
100
|
|
|
|
50
|
$table_attrs .= ' BORDER=1' unless /\bBORDER=/i; |
890
|
4
|
100
|
|
|
|
56
|
$table_attrs .= ' CELLPADDING=1' unless /\bCELLPADDING=/i; |
891
|
4
|
100
|
|
|
|
25
|
$table_attrs .= ' CELLSPACING=1' unless /\bCELLSPACING=/i; |
892
|
|
|
|
|
|
|
} else { |
893
|
45
|
|
|
|
|
213
|
$table_attrs = 'BORDER=2 CELLPADDING=1 CELLSPACING=1'; |
894
|
|
|
|
|
|
|
} |
895
|
|
|
|
|
|
|
|
896
|
49
|
|
|
|
|
420
|
out "\n" ;
897
|
49
|
50
|
|
|
|
134
|
map { $total_width += defined($_) ? $_ : 0; } @$max_widths; |
|
230
|
|
|
|
|
498
|
|
898
|
49
|
|
|
|
|
320
|
for ($c = 0; $c < $num_cols; $c++) { |
899
|
|
|
|
|
|
|
# If the user specified a width, then use it. |
900
|
230
|
50
|
|
|
|
1720
|
$width = defined($widths->[$c]) ? $widths->[$c] : $max_widths->[$c]; |
901
|
230
|
|
|
|
|
570
|
my $pct_width = int(100 * $width/$total_width); |
902
|
230
|
|
|
|
|
583
|
$title_line .= " | ";
|
903
|
230
|
50
|
|
|
|
683
|
if ($#$titles >= 0) { |
904
|
230
|
100
|
|
|
|
638
|
if (($x = $#$tprefixes) >= 0) { |
905
|
10
|
100
|
|
|
|
35
|
$title_line .= $tprefixes->[$c > $x ? $x : $c]; |
906
|
|
|
|
|
|
|
} |
907
|
230
|
100
|
|
|
|
1132
|
$title_line .= $no_escape ? $titles->[$c] : &htmltext($titles->[$c]); |
908
|
230
|
100
|
|
|
|
552
|
if (($x = $#$tsuffixes) >= 0) { |
909
|
10
|
100
|
|
|
|
31
|
$title_line .= $tsuffixes->[$c > $x ? $x : $c]; |
910
|
|
|
|
|
|
|
} |
911
|
|
|
|
|
|
|
} |
912
|
230
|
|
|
|
|
1006
|
$title_line .= "\n"; |
913
|
|
|
|
|
|
|
} |
914
|
49
|
|
|
|
|
102
|
out $title_line; |
915
|
49
|
|
|
|
|
161
|
out " | ";
916
|
|
|
|
|
|
|
|
917
|
49
|
|
|
|
|
92
|
my ($href, $key, $val, $out); |
918
|
49
|
|
|
|
|
278
|
while ((@values = &$row_sub(0)), $#values >= $[) { |
919
|
245
|
|
|
|
|
1579
|
out " | ";
920
|
|
|
|
|
|
|
# Walk through the values |
921
|
245
|
|
|
|
|
5776
|
for ($c = 0; $c <= $#values; $c++) { |
922
|
1150
|
|
|
|
|
3161
|
$out = " |
|
923
|
1150
|
50
|
|
|
|
2385
|
if (defined($val = $values[$c])) { # only worry about defined values |
924
|
|
|
|
|
|
|
# In HTML mode, all CHAR, TEXT, SYMBOL, or STRING data should |
925
|
|
|
|
|
|
|
# be escaped to protect HTML syntax "<", ">", "\", and "&". |
926
|
1150
|
100
|
|
|
|
5652
|
if ($types->[$c] =~ /char|text|symbol|string/i) { |
927
|
710
|
100
|
|
|
|
3206
|
$val = &htmltext($val) unless $no_escape; |
928
|
710
|
|
|
|
|
5822
|
$out .= " ALIGN=LEFT"; |
929
|
|
|
|
|
|
|
} else { |
930
|
440
|
|
|
|
|
704
|
$out .= " ALIGN=RIGHT"; |
931
|
|
|
|
|
|
|
} |
932
|
1150
|
|
|
|
|
1308
|
$out .= ">"; |
933
|
|
|
|
|
|
|
# Discover if either the column name or column index |
934
|
|
|
|
|
|
|
# have been mapped to a URL. |
935
|
1150
|
|
|
|
|
1444
|
$href = ''; |
936
|
1150
|
|
33
|
|
|
4679
|
foreach $key ( $#$titles >= 0 && &PlainText($titles->[$c]), |
937
|
|
|
|
|
|
|
sprintf("%d", $c+1)) { |
938
|
2255
|
100
|
66
|
|
|
15193
|
next unless $key ne '' && defined($url_keys->{$key}); |
939
|
45
|
|
|
|
|
75
|
$href = $url_keys->{$key}; |
940
|
45
|
|
|
|
|
65
|
last; |
941
|
|
|
|
|
|
|
} |
942
|
1150
|
100
|
|
|
|
4214
|
if ($href ne '') { |
943
|
45
|
100
|
|
|
|
145
|
if ($href =~ /%K/) { |
944
|
30
|
|
|
|
|
73
|
my $s = &htmltext(&PlainText($titles->[$c]), 1); |
945
|
30
|
|
|
|
|
114
|
$href =~ s/%K/$s/g; |
946
|
|
|
|
|
|
|
} |
947
|
45
|
50
|
|
|
|
130
|
if ($href =~ /%V/) { |
948
|
45
|
|
|
|
|
80
|
my $s = &htmltext($val, 1); |
949
|
45
|
|
|
|
|
149
|
$href =~ s/%V/$s/g; |
950
|
|
|
|
|
|
|
} |
951
|
45
|
100
|
|
|
|
117
|
if ($href =~ /%I/) { |
952
|
20
|
|
|
|
|
56
|
my $s = sprintf("%d", $c+1); |
953
|
20
|
|
|
|
|
63
|
$href =~ s/%I/$s/g; |
954
|
|
|
|
|
|
|
} |
955
|
45
|
|
|
|
|
214
|
$out .= sprintf("",$href); |
956
|
|
|
|
|
|
|
} |
957
|
1150
|
|
|
|
|
4368
|
$val = &$fmt_sub($val, $types->[$c], 0, $widths->[$c], |
958
|
|
|
|
|
|
|
$precision->[$c], 'html'); |
959
|
1150
|
|
|
|
|
3935
|
$val =~ s/^\s+//; # don't try to align |
960
|
1150
|
|
|
|
|
4396
|
$val =~ s/\s+$//; |
961
|
|
|
|
|
|
|
|
962
|
1150
|
100
|
|
|
|
2805
|
if (($x = $#$dprefixes) >= 0) { |
963
|
125
|
100
|
|
|
|
296
|
$out .= $dprefixes->[$c > $x ? $x : $c]; |
964
|
|
|
|
|
|
|
} |
965
|
1150
|
|
|
|
|
1778
|
$out .= $val; |
966
|
1150
|
100
|
|
|
|
3121
|
if (($x = $#$dsuffixes) >= 0) { |
967
|
125
|
100
|
|
|
|
251
|
$out .= $dsuffixes->[$c > $x ? $x : $c]; |
968
|
|
|
|
|
|
|
} |
969
|
1150
|
100
|
|
|
|
2387
|
$out .= "" if $href; |
970
|
|
|
|
|
|
|
} else { |
971
|
0
|
|
|
|
|
0
|
$out .= ">"; |
972
|
|
|
|
|
|
|
} |
973
|
1150
|
|
|
|
|
5589
|
$out .= " | ";
974
|
1150
|
|
|
|
|
12546
|
out $out; |
975
|
|
|
|
|
|
|
} |
976
|
245
|
|
|
|
|
485
|
out " | ";
977
|
|
|
|
|
|
|
} |
978
|
49
|
|
|
|
|
127
|
out " | "; |
979
|
|
|
|
|
|
|
} |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
=head1 ShowListTable |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
Display a table of data using a list format. |
984
|
|
|
|
|
|
|
|
985
|
|
|
|
|
|
|
S< >B { I => I, ... }; |
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
S< >B I<\@titles>, I<\@types>, I<\@widths>, I<\&row_sub> |
988
|
|
|
|
|
|
|
[, I<\&fmt_sub> [, I<$max_width> [, I<$wrap_margin> ] ] ]; |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
The arguments for B are the same as for L<"ShowTable">, |
991
|
|
|
|
|
|
|
except for those described next. |
992
|
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
=over 10 |
994
|
|
|
|
|
|
|
|
995
|
|
|
|
|
|
|
=item C = I, |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
=item C = I, |
998
|
|
|
|
|
|
|
|
999
|
|
|
|
|
|
|
Lines are truncated, and wrapped when their length exceeds |
1000
|
|
|
|
|
|
|
I<$max_width>. Wrapping is done on a word-basis, unless the resulting |
1001
|
|
|
|
|
|
|
right margin exceeds I<$wrap_margin>, in which case the line is simply |
1002
|
|
|
|
|
|
|
truncated at the I<$max_width> limit. |
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
The I<$max_width> variable defaults to B<$Max_List_Width>. The |
1005
|
|
|
|
|
|
|
I<$wrap_margin> defaults to B<$List_Wrap_Margin>. |
1006
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
=back |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
In I mode, columns (called "fields" in List mode) are displayed |
1010
|
|
|
|
|
|
|
wth a field name and value pair per line, with records being one or |
1011
|
|
|
|
|
|
|
more fields . In other words, the output of a table would |
1012
|
|
|
|
|
|
|
look something like this: |
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
Field1_1: Value1_1 |
1015
|
|
|
|
|
|
|
Field1_2: Value1_2 |
1016
|
|
|
|
|
|
|
Field1_3: Value1_3 |
1017
|
|
|
|
|
|
|
... |
1018
|
|
|
|
|
|
|
Field1-N: Value1_M |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
Field2_1: Value2_1 |
1021
|
|
|
|
|
|
|
Field2_2: Value2_2 |
1022
|
|
|
|
|
|
|
Field2_3: Value2_3 |
1023
|
|
|
|
|
|
|
... |
1024
|
|
|
|
|
|
|
Field2_N: Value2_N |
1025
|
|
|
|
|
|
|
... |
1026
|
|
|
|
|
|
|
FieldM_1: ValueM_1 |
1027
|
|
|
|
|
|
|
FieldM_2: ValueM_2 |
1028
|
|
|
|
|
|
|
... |
1029
|
|
|
|
|
|
|
FieldM_N: ValueM_N |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
|
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
Characteristics of I mode: |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
=over 10 |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
=item * |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
two empty lines indicate the end of data. |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
=item * |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
An empty field (column) may be omitted, or may have a label, but no |
1044
|
|
|
|
|
|
|
data. |
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
=item * |
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
A long line can be continue by a null field (column): |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
Field2: blah blah blah |
1051
|
|
|
|
|
|
|
: blah blah blah |
1052
|
|
|
|
|
|
|
|
1053
|
|
|
|
|
|
|
=item * |
1054
|
|
|
|
|
|
|
|
1055
|
|
|
|
|
|
|
On a continuation, the null field is an arbitrary number of leading |
1056
|
|
|
|
|
|
|
white space, a colon ':', a single blank or tab, followed by the |
1057
|
|
|
|
|
|
|
continued text. |
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
=item * |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
Embedded newlines are indicated by the escape mechanism "\n". |
1062
|
|
|
|
|
|
|
Similarly, embedded tabs are indicated with "\t", returns with "\r". |
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
=item * |
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
If the I<@titles> array is empty, the field names "CI" are used |
1067
|
|
|
|
|
|
|
instead. |
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
=back |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
=cut |
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
sub ShowListTable { |
1074
|
37
|
|
|
37
|
0
|
535146
|
my @argv = @_; |
1075
|
37
|
|
|
|
|
998
|
local ($titles, $types, $col_widths, $row_sub, $fmt_sub, $max_width, |
1076
|
|
|
|
|
|
|
$wrap_margin); |
1077
|
37
|
|
|
|
|
1804
|
my $args = |
1078
|
|
|
|
|
|
|
get_params |
1079
|
|
|
|
|
|
|
\@argv, |
1080
|
|
|
|
|
|
|
{ titles => \$titles, |
1081
|
|
|
|
|
|
|
types => \$types, |
1082
|
|
|
|
|
|
|
widths => \$col_widths, |
1083
|
|
|
|
|
|
|
row_sub => \$row_sub, |
1084
|
|
|
|
|
|
|
fmtsub => \$fmt_sub, |
1085
|
|
|
|
|
|
|
max_width => \$max_width, |
1086
|
|
|
|
|
|
|
wrap_margin => \$wrap_margin, |
1087
|
|
|
|
|
|
|
}, |
1088
|
|
|
|
|
|
|
[qw(titles types widths row_sub fmt_sub max_width wrap_margin)]; |
1089
|
|
|
|
|
|
|
|
1090
|
37
|
50
|
33
|
|
|
545
|
defined($titles) && $titles ne '' or croak "Missing column names array.\n"; |
1091
|
37
|
50
|
33
|
|
|
956
|
defined($types) && $types ne '' or croak "Missing column types array.\n"; |
1092
|
37
|
50
|
33
|
|
|
456
|
defined($col_widths) && $col_widths ne '' or croak "Missing column width array.\n"; |
1093
|
37
|
50
|
33
|
|
|
302
|
defined($row_sub) && $row_sub ne '' or croak "Missing row sub array.\n"; |
1094
|
|
|
|
|
|
|
|
1095
|
37
|
50
|
33
|
|
|
276
|
$fmt_sub = \&ShowTableValue if !defined($fmt_sub) || $fmt_sub eq ''; |
1096
|
37
|
100
|
100
|
|
|
360
|
$max_width = $Max_List_Width if !defined($max_width) || $max_width eq ''; |
1097
|
37
|
50
|
66
|
|
|
160
|
$wrap_margin = $List_Wrap_Margin if !defined($wrap_margin) || $wrap_margin eq ''; |
1098
|
|
|
|
|
|
|
|
1099
|
37
|
|
|
|
|
266
|
my $rewindable = &$row_sub(1); # init the row pointer |
1100
|
|
|
|
|
|
|
|
1101
|
37
|
|
|
|
|
472
|
my ($num_cols, $widths, $precision, $max_widths) = |
1102
|
|
|
|
|
|
|
&calc_widths($col_widths, $titles, $rewindable, |
1103
|
|
|
|
|
|
|
$row_sub, $fmt_sub, $types, 'list', ''); |
1104
|
|
|
|
|
|
|
|
1105
|
37
|
50
|
|
|
|
281
|
my $fmt = sprintf("%%-%ds : %%s\n", ($#$titles >= 0 ? &max_length($titles) : 8)); |
1106
|
37
|
|
|
|
|
63
|
my @values; |
1107
|
37
|
|
|
|
|
49
|
my ($value, $c, $cut, $line); |
1108
|
37
|
|
|
|
|
80
|
my $col_limit = $max_width - 2; |
1109
|
|
|
|
|
|
|
|
1110
|
37
|
|
|
|
|
126
|
while ((@values = &$row_sub(0)), $#values >= $[) { |
1111
|
185
|
|
|
|
|
638
|
for ($c = 0; $c <= $#values; $c++) { |
1112
|
|
|
|
|
|
|
# get this column's title |
1113
|
850
|
50
|
|
|
|
2341
|
$title = $#$titles >= 0 ? $titles->[$c] : sprintf("Field_%d", $c+1); |
1114
|
850
|
|
|
|
|
1336
|
my $type = $types->[$c]; |
1115
|
850
|
|
|
|
|
991
|
my $width = 0; |
1116
|
850
|
|
|
|
|
1264
|
my $prec = $precision->[$c]; |
1117
|
850
|
|
|
|
|
2701
|
$value = &$fmt_sub($values[$c], $type, 0, $width, $prec, 'list'); |
1118
|
850
|
|
|
|
|
2101
|
while (length($value)) { |
1119
|
871
|
100
|
|
|
|
1791
|
if (length($value) > ($cut = $col_limit)) { |
1120
|
21
|
|
|
|
|
65
|
$line = substr($value, 0, $cut); |
1121
|
21
|
50
|
33
|
|
|
565
|
if ($line =~ m/([-,;? \t])([^-,;? \t]*)$/ && |
1122
|
|
|
|
|
|
|
length($2) <= $wrap_margin) { |
1123
|
21
|
|
|
|
|
50
|
$cut = $col_limit - length($2); |
1124
|
21
|
|
|
|
|
47
|
$line = substr($value, 0, $cut); |
1125
|
|
|
|
|
|
|
} |
1126
|
21
|
|
|
|
|
198
|
($value = substr($value, $cut)) =~ s/^\s+//; |
1127
|
|
|
|
|
|
|
} else { |
1128
|
850
|
|
|
|
|
1233
|
$line = $value; |
1129
|
850
|
|
|
|
|
1149
|
$value = ''; |
1130
|
|
|
|
|
|
|
} |
1131
|
871
|
|
|
|
|
1913
|
out $fmt, $title, $line; |
1132
|
871
|
|
|
|
|
5230
|
$title = ''; |
1133
|
|
|
|
|
|
|
} |
1134
|
|
|
|
|
|
|
} |
1135
|
185
|
|
|
|
|
491
|
out ""; |
1136
|
|
|
|
|
|
|
} |
1137
|
|
|
|
|
|
|
} |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
=head1 ShowRow |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
Fetch rows successively from one or more columns of data. |
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
S< >B I<$rewindflag>, I<\$index>, I<$col_array_1> [, I<$col_array_2>, ...;] |
1144
|
|
|
|
|
|
|
|
1145
|
|
|
|
|
|
|
The B subroutine returns a row of data from one or more |
1146
|
|
|
|
|
|
|
columns of data. It is designed to be used as a I routine, |
1147
|
|
|
|
|
|
|
within the B routine. It can be used to select elements |
1148
|
|
|
|
|
|
|
from one or more array reference arguments. |
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
If passed two or more array references as arguments, elements of the |
1151
|
|
|
|
|
|
|
arrays selected by I<$index> are returned as the "row" of data. |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
If a single array argument is passed, and each element of the array is |
1154
|
|
|
|
|
|
|
itself an array, the subarray is returned as the "row" of data. |
1155
|
|
|
|
|
|
|
|
1156
|
|
|
|
|
|
|
If the I<$rewindflag> flag is set, then the I<$index> pointer is reset |
1157
|
|
|
|
|
|
|
to zero, and "true" is returned (a scalar 1). This indicates that the |
1158
|
|
|
|
|
|
|
data is rewindable to the B routines. |
1159
|
|
|
|
|
|
|
|
1160
|
|
|
|
|
|
|
When the I<$rewindflag> is not set, then the current row of data, as |
1161
|
|
|
|
|
|
|
determined by I<$index> is returned, and I<$index> will |
1162
|
|
|
|
|
|
|
have been incremented. |
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
An actual invocation (from B) is: |
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
ShowTable \@titles, \@types, \@lengths, |
1167
|
|
|
|
|
|
|
sub { &ShowRow( $_[0], \$current_row, $col_names, $col_types, |
1168
|
|
|
|
|
|
|
$col_lengths, \@col_attrs); }; |
1169
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
In the example above, after each invocation, the I<$current_row> argument |
1171
|
|
|
|
|
|
|
will have been incremented. |
1172
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
=cut |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
sub ShowRow { |
1176
|
2044
|
|
|
2044
|
0
|
11840
|
my $rewind_flag = shift; |
1177
|
2044
|
|
|
|
|
3102
|
my $index_ref = shift; # an indirect index |
1178
|
2044
|
|
|
|
|
6928
|
my @columns = @_; # get rest of columns |
1179
|
2044
|
|
|
|
|
3171
|
my @row; # we're selecting a row |
1180
|
2044
|
100
|
|
|
|
5537
|
if ($rewind_flag) { |
1181
|
292
|
|
|
|
|
556
|
$$index_ref = 0; # reset the pointer |
1182
|
292
|
|
|
|
|
1184
|
return 1; |
1183
|
|
|
|
|
|
|
} |
1184
|
1752
|
100
|
|
|
|
5058
|
return () if $#{$columns[0]} < $$index_ref; |
|
1752
|
|
|
|
|
9244
|
|
1185
|
1460
|
50
|
|
|
|
3643
|
if ($#columns == 0) { # exactly one array ref argument |
1186
|
1460
|
|
|
|
|
3162
|
my $data = $columns[0]->[$$index_ref]; # get the current data |
1187
|
1460
|
50
|
|
|
|
5383
|
if (ref($data) eq 'ARRAY') { # if an array.. |
|
|
0
|
|
|
|
|
|
1188
|
1460
|
|
|
|
|
7962
|
@row = @$data; # ..return the array of data |
1189
|
|
|
|
|
|
|
} elsif (ref($data) eq 'HASH') {# if a hash.. |
1190
|
0
|
|
|
|
|
0
|
@row = values %$data; # ..return the values |
1191
|
|
|
|
|
|
|
} else { # otherwise.. |
1192
|
0
|
|
|
|
|
0
|
@row = ($data); # ..return the data element |
1193
|
|
|
|
|
|
|
} |
1194
|
|
|
|
|
|
|
} else { # with two or more array refs.. |
1195
|
0
|
|
|
|
|
0
|
my $col; # select elements from each |
1196
|
0
|
|
|
|
|
0
|
for ($col = 0; $col <= $#columns; $col++) { |
1197
|
0
|
|
|
|
|
0
|
push(@row, ${$columns[$col]}[$$index_ref]); |
|
0
|
|
|
|
|
0
|
|
1198
|
|
|
|
|
|
|
} |
1199
|
|
|
|
|
|
|
} |
1200
|
1460
|
|
|
|
|
2707
|
${$index_ref}++; # increment the index for the next call |
|
1460
|
|
|
|
|
2644
|
|
1201
|
1460
|
|
|
|
|
27593
|
@row; # return this row of data |
1202
|
|
|
|
|
|
|
} |
1203
|
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
=head1 ShowTableValue |
1205
|
|
|
|
|
|
|
|
1206
|
|
|
|
|
|
|
Prepare and return a formatted representation of a value. A value |
1207
|
|
|
|
|
|
|
argument, using its corresponding type, effective width, and precision |
1208
|
|
|
|
|
|
|
is formatted into a field of a given maximum width. |
1209
|
|
|
|
|
|
|
|
1210
|
|
|
|
|
|
|
S< >I<$fmt> = B I<$value>, I<$type>, I<$max_width>, I<$width>, I<$precision>, I<$showmode>; |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
=over 10 |
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
=item C => I<$width> |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
=item I<$width> |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
The width of the current value. If omittied, I<$max_width> is assumed. |
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
=item C => I<$precision> |
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
=item I<$precision> |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
The number of decimal digits; zero is assumed if omittied. |
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
=item C => I<$value> |
1227
|
|
|
|
|
|
|
|
1228
|
|
|
|
|
|
|
=item I<$value> |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
The value to be formatted. |
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
=item I<$type> |
1233
|
|
|
|
|
|
|
|
1234
|
|
|
|
|
|
|
The type name of the value; eg: C, C, C, etc. |
1235
|
|
|
|
|
|
|
|
1236
|
|
|
|
|
|
|
=item C => I<$max_width> |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
=item I<$max_width> |
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
The maximum width of any value in the current value's column. If I<$width> |
1241
|
|
|
|
|
|
|
is zero or null, I<$max_width> is used by default. I<$max_width> is also |
1242
|
|
|
|
|
|
|
used as a I width, in case I<$width> is a smaller value. |
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
=item I<$width> |
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
The default width of the value, obtained from the width specification of the |
1247
|
|
|
|
|
|
|
column in which this value occurs. |
1248
|
|
|
|
|
|
|
|
1249
|
|
|
|
|
|
|
=item I<$precision> |
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
The precision specification, if any, from the column width specification. |
1252
|
|
|
|
|
|
|
|
1253
|
|
|
|
|
|
|
=item I<$showmode> |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
The mode of the output: one of "table", "list", "box", or "html". Currently, |
1256
|
|
|
|
|
|
|
only the "html" mode is significant: it is used to avoid using HTML tokens |
1257
|
|
|
|
|
|
|
as part of the formatted text and length calculations. |
1258
|
|
|
|
|
|
|
|
1259
|
|
|
|
|
|
|
=back |
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
=cut |
1262
|
|
|
|
|
|
|
|
1263
|
|
|
|
|
|
|
sub ShowTableValue { |
1264
|
6760
|
|
|
6760
|
0
|
14686
|
my $value = shift; |
1265
|
6760
|
|
|
|
|
10076
|
my $type = shift; |
1266
|
6760
|
|
|
|
|
9823
|
my $max_width = shift; |
1267
|
6760
|
|
|
|
|
11081
|
my $width = shift; |
1268
|
6760
|
|
50
|
|
|
38009
|
my $prec = shift || 2; |
1269
|
6760
|
|
|
|
|
12684
|
my $showmode = shift; |
1270
|
6760
|
|
66
|
|
|
27015
|
my $fmt = ($Type2Format{lc($type)} || $Type2Format{'char'}); |
1271
|
6760
|
|
|
|
|
8964
|
my $str; |
1272
|
|
|
|
|
|
|
|
1273
|
6760
|
50
|
33
|
|
|
37870
|
$max_width = 0 if !defined($max_width) || $max_width eq ''; |
1274
|
6760
|
50
|
33
|
|
|
43510
|
$width = $max_width if !defined($width) || $width eq ''; |
1275
|
|
|
|
|
|
|
|
1276
|
6760
|
100
|
|
|
|
17870
|
$width = min($width, $max_width) if $max_width > 0; |
1277
|
6760
|
50
|
|
|
|
15963
|
if ($type =~ /money/i) { # money formatting is special |
1278
|
0
|
0
|
|
|
|
0
|
if (($str = $value) !~ /[\$,]/) { # not already formatted? |
1279
|
0
|
|
|
|
|
0
|
my ($d,$c) = split(/\./,$value,2); |
1280
|
|
|
|
|
|
|
# reverse the digits |
1281
|
0
|
|
|
|
|
0
|
$d = join('',reverse(split(//,abs($d)))); |
1282
|
|
|
|
|
|
|
# do the grouping from the rightmost to the left |
1283
|
0
|
|
|
|
|
0
|
$d =~ s/(...)(?=.)/$1,/g; |
1284
|
|
|
|
|
|
|
# reverse the digits and grouping char |
1285
|
0
|
|
|
|
|
0
|
$d = '$'.join('',reverse(split(//,$d))); |
1286
|
|
|
|
|
|
|
# If there is any precision, add on pennies (allow for > 2 precision) |
1287
|
0
|
0
|
|
|
|
0
|
$d .= sprintf($prec > 2 ? "%0${prec}d" : ".%02d",$c) if $prec > 0; |
|
|
0
|
|
|
|
|
|
1288
|
|
|
|
|
|
|
# Mark as negative with '(xxx)' |
1289
|
0
|
0
|
|
|
|
0
|
$d = '-'.$d if $value < 0; |
1290
|
0
|
|
|
|
|
0
|
$str = $d; |
1291
|
|
|
|
|
|
|
} |
1292
|
|
|
|
|
|
|
} else { |
1293
|
6760
|
|
|
|
|
20196
|
$fmt = sprintf ($fmt,$width,$prec); |
1294
|
|
|
|
|
|
|
|
1295
|
|
|
|
|
|
|
# If we are in HTML mode, and the value has any HTML tokens, |
1296
|
|
|
|
|
|
|
# then format it always as a string (even if it might |
1297
|
|
|
|
|
|
|
# be a decimal--this is a kluge but seems to work). |
1298
|
|
|
|
|
|
|
|
1299
|
6760
|
100
|
100
|
|
|
45840
|
if ($showmode =~ /html/i && $value =~ /<\/?($HTML_Elements)/) { |
1300
|
80
|
|
|
|
|
168
|
$fmt =~ s/[df]/s/; # convert to string sub |
1301
|
|
|
|
|
|
|
} |
1302
|
6760
|
|
|
|
|
18896
|
$str = sprintf($fmt,$value); |
1303
|
|
|
|
|
|
|
} |
1304
|
6760
|
100
|
|
|
|
15122
|
if ($width > length(&PlainText($str))) { |
1305
|
|
|
|
|
|
|
# right align the value if any kind of number |
1306
|
40
|
50
|
|
|
|
156
|
$str = sprintf("%${width}s", $str) |
1307
|
|
|
|
|
|
|
if $type =~ /int|float|pct|real|numeric|money/i; |
1308
|
|
|
|
|
|
|
} |
1309
|
6760
|
|
|
|
|
27322
|
$str; |
1310
|
|
|
|
|
|
|
} |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
%Type2Format = ( |
1313
|
|
|
|
|
|
|
'char' => '%%-%ds', |
1314
|
|
|
|
|
|
|
'varchar' => '%%-%ds', |
1315
|
|
|
|
|
|
|
'symbol' => '%%-%ds', |
1316
|
|
|
|
|
|
|
'tinyint' => '%%%dd', |
1317
|
|
|
|
|
|
|
'shortint' => '%%%dd', |
1318
|
|
|
|
|
|
|
'int' => '%%%dd', |
1319
|
|
|
|
|
|
|
'pct' => '%%%d.%df%%%%', |
1320
|
|
|
|
|
|
|
'real' => '%%%d.%df', |
1321
|
|
|
|
|
|
|
'float' => '%%%d.%df', |
1322
|
|
|
|
|
|
|
'numeric' => '%%%d.%df', |
1323
|
|
|
|
|
|
|
'text' => '%%-%ds', |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
# The money types do not actually need to be in this table, since |
1326
|
|
|
|
|
|
|
# ShowTableValue handle money formatting explicitly. However, some |
1327
|
|
|
|
|
|
|
# one else might use this table, so we treat them like right-aligned |
1328
|
|
|
|
|
|
|
# strings. |
1329
|
|
|
|
|
|
|
'money' => '%%%d.%df', |
1330
|
|
|
|
|
|
|
'smallmoney' => '%%%d.%df', |
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
); |
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
=head1 PlainText |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
S< >I<$plaintext> = B<&PlainText>(I<$htmltext>); |
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
S< >B<&PlainText> |
1339
|
|
|
|
|
|
|
|
1340
|
|
|
|
|
|
|
This function removes any HTML formatting sequences from the input argument, |
1341
|
|
|
|
|
|
|
or from C<$_> if no argument is given. The resulting plain text is returned |
1342
|
|
|
|
|
|
|
as the result. |
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
=cut |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
# $plaintext = &PlainText($htmltext); |
1347
|
|
|
|
|
|
|
# or: |
1348
|
|
|
|
|
|
|
# &PlainText; |
1349
|
|
|
|
|
|
|
# |
1350
|
|
|
|
|
|
|
# Convert the argument and return as a string, or convert $_. |
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
sub PlainText { |
1353
|
8153
|
50
|
|
8153
|
0
|
37391
|
local($_) = shift if $#_ >= 0; # set local $_ if there's an argument |
1354
|
|
|
|
|
|
|
# skip unless there's a sequence |
1355
|
8153
|
100
|
|
|
|
81592
|
return $_ unless m=?($HTML_Elements)=i; # HTML text? |
1356
|
80
|
|
|
|
|
1676
|
s{?(?:$HTML_Elements)# # match and remove any HTML token.. |
1357
|
|
|
|
|
|
|
(?:\ \w+# # ..then PARAM or PARAM=VALUE |
1358
|
|
|
|
|
|
|
(?:\=(?:"(?:[^"]|\\")*"|# # ...."STRING" or.. |
1359
|
|
|
|
|
|
|
[^"> ]+# # ....VALUE |
1360
|
|
|
|
|
|
|
)# |
1361
|
|
|
|
|
|
|
)?# # ..=VALUE is optional |
1362
|
|
|
|
|
|
|
)*# # zero or more PARAM or PARAM=VALUE |
1363
|
|
|
|
|
|
|
>}{}igx; # up to the closing '>' |
1364
|
80
|
|
|
|
|
431
|
$_; # return the result |
1365
|
|
|
|
|
|
|
} |
1366
|
|
|
|
|
|
|
|
1367
|
|
|
|
|
|
|
BEGIN { |
1368
|
|
|
|
|
|
|
|
1369
|
22
|
|
|
22
|
|
432
|
@HTML_Elements = qw( |
1370
|
|
|
|
|
|
|
A ABBREV ACRONYM ADDRESS APP APPLET AREA AU B BANNER BASE BASEFONT BDO |
1371
|
|
|
|
|
|
|
BGSOUND BIG BLINK BLOCKQUOTE BODY BQ BR CAPTION CENTER CITE CODE COL |
1372
|
|
|
|
|
|
|
COLGROUP CREDIT DD DEL DFN DIR DIV DL DT EM EMBED FN FIG FONT FORM FRAME |
1373
|
|
|
|
|
|
|
FRAMESET H1 H2 H3 H4 H5 H6 HEAD HP HR HTML I IMG INPUT INS ISINDEX KBD |
1374
|
|
|
|
|
|
|
LANG LH LI LINK LISTING MAP MARQUEE MENU META NEXTID NOBR NOEMBED |
1375
|
|
|
|
|
|
|
NOFRAMES NOTE OL OPTION OVERLAY P PARAM PERSON PLAINTEXT PRE Q S SAMP |
1376
|
|
|
|
|
|
|
SELECT SMALL SPAN STRIKE STRONG SUB SUP TAB TABLE TBODY TD TEXTAREA |
1377
|
|
|
|
|
|
|
TFOOT TH THEAD TITLE TR TT U UL VAR WBR XMP |
1378
|
|
|
|
|
|
|
); |
1379
|
|
|
|
|
|
|
|
1380
|
22
|
|
|
|
|
12665
|
$HTML_Elements = join("|",@HTML_Elements); |
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
} |
1383
|
|
|
|
|
|
|
|
1384
|
|
|
|
|
|
|
=head1 VARIABLES |
1385
|
|
|
|
|
|
|
|
1386
|
|
|
|
|
|
|
The following variables may be set by the user to affect the display (with |
1387
|
|
|
|
|
|
|
the defaults enclosed in square brackets [..]): |
1388
|
|
|
|
|
|
|
|
1389
|
|
|
|
|
|
|
=over 10 |
1390
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
=item B<$Show_Mode> [Box] |
1392
|
|
|
|
|
|
|
|
1393
|
|
|
|
|
|
|
This is the default display mode when using B. The |
1394
|
|
|
|
|
|
|
environment variable, C<$ENV{'SHOW_MODE'}>, is used when this variable is |
1395
|
|
|
|
|
|
|
null or the empty string. The possible values for this variable are: |
1396
|
|
|
|
|
|
|
C<"Box">, C<"List">, C<"Table">, and C<"HTML">. Case is insignificant. |
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
=item B<$List_Wrap_Margin> [2] |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
This variable's value determines how large a margin to keep before wrarpping a |
1401
|
|
|
|
|
|
|
long value's display in a column. This value is only used in "List" mode. |
1402
|
|
|
|
|
|
|
|
1403
|
|
|
|
|
|
|
=item B<$Max_List_Width> [80] |
1404
|
|
|
|
|
|
|
|
1405
|
|
|
|
|
|
|
This variable, used in "List" mode, is used to determine how long an output line |
1406
|
|
|
|
|
|
|
may be before wrapping it. The environment variable, C<$ENV{'COLUMNS'}>, is |
1407
|
|
|
|
|
|
|
used to define this value when it is null. |
1408
|
|
|
|
|
|
|
|
1409
|
|
|
|
|
|
|
=item B<$Max_Table_Width> [''] |
1410
|
|
|
|
|
|
|
|
1411
|
|
|
|
|
|
|
This variable, when set, causes all tables to have their columns scaled |
1412
|
|
|
|
|
|
|
such that their total combined width does not exceed this value. When |
1413
|
|
|
|
|
|
|
this variable is not set, which is the default case, there is no maximum |
1414
|
|
|
|
|
|
|
table width, and no scaling will be done. |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
=item B<$No_Escape> [''] |
1417
|
|
|
|
|
|
|
|
1418
|
|
|
|
|
|
|
If set, allows embedded HTML text to be included in the data displayed |
1419
|
|
|
|
|
|
|
in an HTML-formatted table. By default, the HTML formatting characters |
1420
|
|
|
|
|
|
|
("<", ">", and "&") occuring in values are escaped. |
1421
|
|
|
|
|
|
|
|
1422
|
|
|
|
|
|
|
=item B<%URL_Keys> |
1423
|
|
|
|
|
|
|
|
1424
|
|
|
|
|
|
|
In HTML mode, this variable is used to recognize which columns are to be |
1425
|
|
|
|
|
|
|
displayed with a corresponding hypertext anchor. See L<"ShowHTMLTable"> |
1426
|
|
|
|
|
|
|
for more details. |
1427
|
|
|
|
|
|
|
|
1428
|
|
|
|
|
|
|
=item B<@HTML_Elements> |
1429
|
|
|
|
|
|
|
|
1430
|
|
|
|
|
|
|
An array of HTML elements (as of HTML 3.0) used to recognize and strip for |
1431
|
|
|
|
|
|
|
width calculations. |
1432
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
=item B<$HTML_Elements> |
1434
|
|
|
|
|
|
|
|
1435
|
|
|
|
|
|
|
A regular expression string formed from the elements of B<@HTML_Elements>. |
1436
|
|
|
|
|
|
|
|
1437
|
|
|
|
|
|
|
=back |
1438
|
|
|
|
|
|
|
|
1439
|
|
|
|
|
|
|
=cut |
1440
|
|
|
|
|
|
|
|
1441
|
|
|
|
|
|
|
############################## |
1442
|
|
|
|
|
|
|
|
1443
|
|
|
|
|
|
|
=head1 INTERNAL SUBROUTINES |
1444
|
|
|
|
|
|
|
|
1445
|
|
|
|
|
|
|
=head1 get_params |
1446
|
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
S< >my I<$args> = B<&get_params> I<\@argv>, I<\%params>, I<\@arglist>; |
1448
|
|
|
|
|
|
|
|
1449
|
|
|
|
|
|
|
Given the I<@argv> originally passed to the calling sub, and the hash of |
1450
|
|
|
|
|
|
|
named parameters as I<%params>, and the array of parameter names in the |
1451
|
|
|
|
|
|
|
order expected for a pass-by-value invocation, set the values of each of |
1452
|
|
|
|
|
|
|
the variables named in I<@vars>. |
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
If the only element of the I<@argv> is a hash array, then set the |
1455
|
|
|
|
|
|
|
variables to the values of their corresponding parameters used as keys |
1456
|
|
|
|
|
|
|
to the hash array. If the parameter is not a key of the I<%params> |
1457
|
|
|
|
|
|
|
hash, and is not a key in the global hash B<%ShowTableParams>, then an |
1458
|
|
|
|
|
|
|
error is noted. |
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
When I<@argv> has multiple elements, or is not a hash array, set each |
1461
|
|
|
|
|
|
|
variable, in the order given within I<@arglist>, to the values from the |
1462
|
|
|
|
|
|
|
I<@argv>, setting the variables named by each value in I<%params>. |
1463
|
|
|
|
|
|
|
|
1464
|
|
|
|
|
|
|
Variables may given either by name or by reference. |
1465
|
|
|
|
|
|
|
|
1466
|
|
|
|
|
|
|
The result is a HASH array reference, either corresponding directly to |
1467
|
|
|
|
|
|
|
the HASH array passed as the single argument, or one created by |
1468
|
|
|
|
|
|
|
associating the resulting variable values to the parameter names |
1469
|
|
|
|
|
|
|
associated with the variable names. |
1470
|
|
|
|
|
|
|
|
1471
|
|
|
|
|
|
|
=cut |
1472
|
|
|
|
|
|
|
|
1473
|
|
|
|
|
|
|
sub get_params { |
1474
|
160
|
50
|
|
160
|
0
|
1468
|
my $argvref = shift or croak "Missing required argument.\n"; |
1475
|
160
|
50
|
|
|
|
814
|
my $params = shift or croak "Missing required parameters hash.\n"; |
1476
|
160
|
50
|
|
|
|
1546
|
my $arglist = shift or croak "Missing required arglist array.\n"; |
1477
|
160
|
|
|
|
|
458
|
my %args; |
1478
|
160
|
|
|
|
|
307
|
my ($param, $var); |
1479
|
160
|
100
|
66
|
|
|
2979
|
if ($#$argvref == 0 && ref($argvref->[0]) eq 'HASH') { |
1480
|
143
|
|
|
|
|
458
|
my $href = $argvref->[0]; |
1481
|
143
|
|
|
|
|
1702
|
%args = %$href; # initialize result with input hash |
1482
|
143
|
|
|
|
|
1062
|
foreach $param (keys %$href) { # for each named argument... |
1483
|
|
|
|
|
|
|
# Is this a known parameter? |
1484
|
674
|
100
|
|
|
|
2309
|
if (exists($params->{$param})) { |
1485
|
663
|
|
|
|
|
1183
|
$var = $params->{$param}; |
1486
|
663
|
|
33
|
|
|
6491
|
while ($var ne '' && ref($var) eq '') { # indirect refs? |
1487
|
0
|
|
|
|
|
0
|
$var = $params->{$param = $var}; |
1488
|
|
|
|
|
|
|
} |
1489
|
663
|
50
|
|
|
|
1901
|
if ($var ne '') { |
1490
|
663
|
|
|
|
|
1378
|
$$var = $href->{$param}; # assign the param's variable |
1491
|
663
|
|
|
|
|
1673
|
$args{$param} = $$var; # make sure canonical param gets defined |
1492
|
663
|
|
|
|
|
2401
|
next; # go to the next parameter |
1493
|
|
|
|
|
|
|
} |
1494
|
|
|
|
|
|
|
} |
1495
|
11
|
50
|
|
|
|
127
|
if (!exists($show_table_params{$param})) { |
1496
|
0
|
|
|
|
|
0
|
croak "Unknown parameter: \"$param\"\n"; |
1497
|
|
|
|
|
|
|
} |
1498
|
|
|
|
|
|
|
} |
1499
|
|
|
|
|
|
|
} else { # use args in the order given for variables |
1500
|
17
|
|
|
|
|
35
|
my $i; |
1501
|
17
|
|
|
|
|
80
|
for ($i = 0; $i <= $#$arglist; $i++) { |
1502
|
131
|
|
|
|
|
212
|
$param = $arglist->[$i]; # get the next argument |
1503
|
131
|
|
|
|
|
655
|
$var = $params->{$param}; # get it's variable |
1504
|
131
|
100
|
|
|
|
392
|
next unless defined($var); |
1505
|
127
|
|
66
|
|
|
911
|
while ($var ne '' && ref($var) eq '') { |
1506
|
10
|
|
|
|
|
59
|
$var = $params->{$param = $var}; |
1507
|
|
|
|
|
|
|
} |
1508
|
127
|
50
|
|
|
|
1050
|
if ($var ne '') { |
|
|
0
|
|
|
|
|
|
1509
|
127
|
100
|
|
|
|
386
|
$$var = $i <= $#$argvref ? $argvref->[$i] : ''; |
1510
|
127
|
|
|
|
|
481
|
$args{$param} = $$var; # assign to the hash |
1511
|
|
|
|
|
|
|
} elsif (!exists($show_table_params{$param})) { |
1512
|
0
|
|
|
|
|
0
|
croak "Unknown parameter: \"$param\" for argument $i.\n"; |
1513
|
|
|
|
|
|
|
} |
1514
|
|
|
|
|
|
|
} |
1515
|
|
|
|
|
|
|
} |
1516
|
|
|
|
|
|
|
# Now, make sure all variables get initialized |
1517
|
160
|
|
|
|
|
1476
|
foreach $param (keys %$params) { |
1518
|
1340
|
|
|
|
|
3622
|
$var = $params->{$param}; |
1519
|
1340
|
|
66
|
|
|
9986
|
while ($var ne '' && ref($var) eq '') { |
1520
|
98
|
|
|
|
|
585
|
$var = $params->{$param = $var}; |
1521
|
|
|
|
|
|
|
} |
1522
|
1340
|
100
|
66
|
|
|
7930
|
if ($var ne '' && !exists($args{$param})) { |
1523
|
457
|
|
|
|
|
1242
|
$$var = $args{$param} = undef; |
1524
|
|
|
|
|
|
|
} |
1525
|
|
|
|
|
|
|
} |
1526
|
160
|
|
|
|
|
1231
|
\%args; # return the HASH ref |
1527
|
|
|
|
|
|
|
} |
1528
|
|
|
|
|
|
|
|
1529
|
|
|
|
|
|
|
BEGIN { |
1530
|
|
|
|
|
|
|
|
1531
|
|
|
|
|
|
|
# A table of parameters used by all the external subroutines For |
1532
|
|
|
|
|
|
|
# example, in order for parameters applicable to ShowHTMLTable to be |
1533
|
|
|
|
|
|
|
# passed through ShowTable, they need to be defined in this table. |
1534
|
|
|
|
|
|
|
|
1535
|
22
|
|
|
22
|
|
125
|
@show_table_params = qw( |
1536
|
|
|
|
|
|
|
caption |
1537
|
|
|
|
|
|
|
col_attributes |
1538
|
|
|
|
|
|
|
col_lengths |
1539
|
|
|
|
|
|
|
col_names |
1540
|
|
|
|
|
|
|
col_types |
1541
|
|
|
|
|
|
|
data |
1542
|
|
|
|
|
|
|
data_formats |
1543
|
|
|
|
|
|
|
dformats |
1544
|
|
|
|
|
|
|
fmt_sub |
1545
|
|
|
|
|
|
|
fmtsub |
1546
|
|
|
|
|
|
|
max_width |
1547
|
|
|
|
|
|
|
no_escape |
1548
|
|
|
|
|
|
|
row_sub |
1549
|
|
|
|
|
|
|
show_mode |
1550
|
|
|
|
|
|
|
table_attrs |
1551
|
|
|
|
|
|
|
tformats |
1552
|
|
|
|
|
|
|
title_formats |
1553
|
|
|
|
|
|
|
titles |
1554
|
|
|
|
|
|
|
types |
1555
|
|
|
|
|
|
|
url_keys |
1556
|
|
|
|
|
|
|
widths |
1557
|
|
|
|
|
|
|
wrap_margin |
1558
|
|
|
|
|
|
|
); |
1559
|
22
|
|
|
|
|
394
|
@show_table_params{@show_table_params} = () x (1 + $#show_table_params); |
1560
|
22
|
|
|
|
|
51814
|
undef @show_table_params; |
1561
|
|
|
|
|
|
|
|
1562
|
|
|
|
|
|
|
} |
1563
|
|
|
|
|
|
|
|
1564
|
|
|
|
|
|
|
=head1 html_formats |
1565
|
|
|
|
|
|
|
|
1566
|
|
|
|
|
|
|
S< >(I<$prefixes>,I<$suffixes>) = B I<\@html_formats>; |
1567
|
|
|
|
|
|
|
|
1568
|
|
|
|
|
|
|
The B function takes an array reference of HTML formatting |
1569
|
|
|
|
|
|
|
elements I<\@html_formats>, and builds two arrays of strings: the first: |
1570
|
|
|
|
|
|
|
I<$prefixes>, is an array of prefixes containing the corresponding HTML |
1571
|
|
|
|
|
|
|
formatting elements from I<\@html_formats>, and the second, |
1572
|
|
|
|
|
|
|
I<$suffixes>, containing the appropriate HTML closing elements, in the |
1573
|
|
|
|
|
|
|
opposite order. |
1574
|
|
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
The result is designed to be used as prefixes and suffixes for the |
1576
|
|
|
|
|
|
|
corresponding titles and column values. |
1577
|
|
|
|
|
|
|
|
1578
|
|
|
|
|
|
|
The array I<\@html_formats> contains lists of HTML formatting elements, |
1579
|
|
|
|
|
|
|
one for each column (either title or data). Each array element is a |
1580
|
|
|
|
|
|
|
list of one or more HTML elements, either given in HTML syntax, or as a |
1581
|
|
|
|
|
|
|
"plain" name (ie: given as C<\> or plainly, C). |
1582
|
|
|
|
|
|
|
Multiple elements are separated by a comma C<','>. |
1583
|
|
|
|
|
|
|
|
1584
|
|
|
|
|
|
|
The resulting array of I<$prefixes> contains the corresponding opening |
1585
|
|
|
|
|
|
|
elements, in the order given, with the proper HTML element syntax. The |
1586
|
|
|
|
|
|
|
resulting array of I<$suffixes> contains the closing elements, in the |
1587
|
|
|
|
|
|
|
opposite order given, with the proper HTML element syntax. |
1588
|
|
|
|
|
|
|
|
1589
|
|
|
|
|
|
|
For example, if I<\@html_formats> contains the two elements: |
1590
|
|
|
|
|
|
|
|
1591
|
|
|
|
|
|
|
[ 'FONT SIZE=+2,BOLD', 'FONT COLOR=red,EM' ] |
1592
|
|
|
|
|
|
|
|
1593
|
|
|
|
|
|
|
then the resulting two arrays will be returned as: |
1594
|
|
|
|
|
|
|
|
1595
|
|
|
|
|
|
|
[ [ '', '' ], |
1596
|
|
|
|
|
|
|
[ '', '' ] ] |
1597
|
|
|
|
|
|
|
|
1598
|
|
|
|
|
|
|
=cut |
1599
|
|
|
|
|
|
|
|
1600
|
|
|
|
|
|
|
sub html_formats { |
1601
|
98
|
|
|
98
|
0
|
174
|
my $html_formats = shift; # array ref |
1602
|
98
|
|
|
|
|
108
|
my $i; |
1603
|
98
|
|
|
|
|
156
|
my (@prefixes, @suffixes); |
1604
|
0
|
|
|
|
|
0
|
my ($html, $elt, $html_list, @html_list); |
1605
|
0
|
|
|
|
|
0
|
my ($prefixes, $suffixes); |
1606
|
98
|
|
|
|
|
115
|
local($_); |
1607
|
|
|
|
|
|
|
|
1608
|
98
|
|
|
|
|
419
|
foreach $html_list (@$html_formats) { |
1609
|
9
|
|
|
|
|
43
|
@html_list = split(/,/,$html_list); |
1610
|
9
|
|
|
|
|
17
|
$prefixes = $suffixes = ''; # initialize the list |
1611
|
9
|
|
|
|
|
16
|
my %formats; # keep track of formats |
1612
|
9
|
|
|
|
|
19
|
foreach (@html_list) { |
1613
|
9
|
|
|
|
|
23
|
($html, $elt) = (); |
1614
|
9
|
50
|
|
|
|
94
|
if (($html, $elt) = /^(<)?\s*(\w+)/) {#
|
1615
|
9
|
50
|
|
|
|
119
|
next if $formats{$elt}++ > 0; # only do an element once |
1616
|
9
|
50
|
|
|
|
24
|
$html = '<' unless $html; |
1617
|
9
|
|
|
|
|
33
|
$prefixes .= $html.$elt.$'; |
1618
|
9
|
50
|
|
|
|
34
|
$prefixes .= '>' unless $prefixes =~ />$/; |
1619
|
9
|
|
|
|
|
35
|
$suffixes = $html.'/'.$elt.'>'.$suffixes; |
1620
|
|
|
|
|
|
|
} |
1621
|
|
|
|
|
|
|
} |
1622
|
9
|
|
|
|
|
22
|
push(@prefixes, $prefixes); # even push empty items |
1623
|
9
|
|
|
|
|
31
|
push(@suffixes, $suffixes); |
1624
|
|
|
|
|
|
|
} |
1625
|
98
|
|
|
|
|
340
|
( \@prefixes, \@suffixes ); |
1626
|
|
|
|
|
|
|
} |
1627
|
|
|
|
|
|
|
|
1628
|
|
|
|
|
|
|
|
1629
|
|
|
|
|
|
|
=head1 calc_widths |
1630
|
|
|
|
|
|
|
|
1631
|
|
|
|
|
|
|
S< >(I<$num_cols>, I<$widths>, I<$precision>, I<$max_widths>) = |
1632
|
|
|
|
|
|
|
S< >B<&calc_widths>( I<$widthspec>, I<$titles>, I<$rewindable>, |
1633
|
|
|
|
|
|
|
S< >I<$row_sub>, I<$fmt_sub>, I<$types>, I<$showmode>, |
1634
|
|
|
|
|
|
|
S< >I<$max_width>); |
1635
|
|
|
|
|
|
|
|
1636
|
|
|
|
|
|
|
=head2 B |
1637
|
|
|
|
|
|
|
|
1638
|
|
|
|
|
|
|
B is a generalized subroutine used by all the B |
1639
|
|
|
|
|
|
|
variant subroutines to setup internal variables prior to formatting for |
1640
|
|
|
|
|
|
|
display. B handles the column width and precision |
1641
|
|
|
|
|
|
|
analysis, including scanning the data (if rewindable) for appropriate |
1642
|
|
|
|
|
|
|
default values. |
1643
|
|
|
|
|
|
|
|
1644
|
|
|
|
|
|
|
The number of columns in the data is returned, as well as three arrays: |
1645
|
|
|
|
|
|
|
the declared column widths, the column precision values, and the maximum |
1646
|
|
|
|
|
|
|
column widths. |
1647
|
|
|
|
|
|
|
|
1648
|
|
|
|
|
|
|
=head2 B |
1649
|
|
|
|
|
|
|
|
1650
|
|
|
|
|
|
|
=over 10 |
1651
|
|
|
|
|
|
|
|
1652
|
|
|
|
|
|
|
=item I<$num_cols> |
1653
|
|
|
|
|
|
|
|
1654
|
|
|
|
|
|
|
is the number of columns in the data. If the data is not rewindable, |
1655
|
|
|
|
|
|
|
this is computed as the maximum of the number of elements in the |
1656
|
|
|
|
|
|
|
I<$widthspec> array and the number of elements in the I<$titles> |
1657
|
|
|
|
|
|
|
array. When the data is rewindable, this is the maximum of the number |
1658
|
|
|
|
|
|
|
of columns of each row of data. |
1659
|
|
|
|
|
|
|
|
1660
|
|
|
|
|
|
|
=item I<$widths> |
1661
|
|
|
|
|
|
|
|
1662
|
|
|
|
|
|
|
is the column widths array ref, without the precision specs (if any). |
1663
|
|
|
|
|
|
|
Each column's width value is determined by the original I<$widthspec> |
1664
|
|
|
|
|
|
|
value and/or the maximum length of the formatted data for the column. |
1665
|
|
|
|
|
|
|
|
1666
|
|
|
|
|
|
|
=item I<$precision> |
1667
|
|
|
|
|
|
|
|
1668
|
|
|
|
|
|
|
is the precision component (if any) of the original I<$widthspec> |
1669
|
|
|
|
|
|
|
array ref. If there was no original precision component from the I<$widthspec>, |
1670
|
|
|
|
|
|
|
and the data is rewindable, then the data is examined to determine the |
1671
|
|
|
|
|
|
|
maximum default precision. |
1672
|
|
|
|
|
|
|
|
1673
|
|
|
|
|
|
|
=item I<$max_widths> |
1674
|
|
|
|
|
|
|
|
1675
|
|
|
|
|
|
|
is the ref to the array of maximum widths for the given columns. |
1676
|
|
|
|
|
|
|
|
1677
|
|
|
|
|
|
|
=back |
1678
|
|
|
|
|
|
|
|
1679
|
|
|
|
|
|
|
=head2 B |
1680
|
|
|
|
|
|
|
|
1681
|
|
|
|
|
|
|
=over 10 |
1682
|
|
|
|
|
|
|
|
1683
|
|
|
|
|
|
|
=item I<$widthspec> |
1684
|
|
|
|
|
|
|
|
1685
|
|
|
|
|
|
|
A reference to an array of column width (or length) values, each given |
1686
|
|
|
|
|
|
|
as an integer, real number, or a string value of |
1687
|
|
|
|
|
|
|
"I.I". If a value is zero or null, the length of the |
1688
|
|
|
|
|
|
|
corresponding formatted data (if rewindable) and column title length are |
1689
|
|
|
|
|
|
|
used to determine a reasonable default. |
1690
|
|
|
|
|
|
|
|
1691
|
|
|
|
|
|
|
If a column's I portion is a positive, non-zero number, then the |
1692
|
|
|
|
|
|
|
column will be this wide, regardless of the values lengths of the data |
1693
|
|
|
|
|
|
|
in the column. |
1694
|
|
|
|
|
|
|
|
1695
|
|
|
|
|
|
|
If the column's I portion is given as a negative number, then the |
1696
|
|
|
|
|
|
|
positive value is used as a minimum column width, with no limit on the |
1697
|
|
|
|
|
|
|
maximum column width. In other words, the column will be at least |
1698
|
|
|
|
|
|
|
I characters wide. |
1699
|
|
|
|
|
|
|
|
1700
|
|
|
|
|
|
|
If the data is not rewindable, and a column's width value is null or |
1701
|
|
|
|
|
|
|
zero, then the length of the column title is used. This may cause severe |
1702
|
|
|
|
|
|
|
wrapping of data in the column, if the column data lengths are much |
1703
|
|
|
|
|
|
|
greater than the column title widths. |
1704
|
|
|
|
|
|
|
|
1705
|
|
|
|
|
|
|
=item I<$titles> |
1706
|
|
|
|
|
|
|
|
1707
|
|
|
|
|
|
|
The array ref to the column titles; used to determine the minimum |
1708
|
|
|
|
|
|
|
acceptable width, as well as the default number of columns. If the |
1709
|
|
|
|
|
|
|
C<$titles> array is empty, then the C<$widthspec> array is used to |
1710
|
|
|
|
|
|
|
determine the default number of columns. |
1711
|
|
|
|
|
|
|
|
1712
|
|
|
|
|
|
|
=item I<$rewindable> |
1713
|
|
|
|
|
|
|
|
1714
|
|
|
|
|
|
|
A flag indicating whether or not the data being formatted is rewindable. |
1715
|
|
|
|
|
|
|
If this is true, a pass over the data will be done in order to calculate |
1716
|
|
|
|
|
|
|
the maximum lengths of the actual formatted data, using I<$fmt_sub> |
1717
|
|
|
|
|
|
|
(below), rather than just rely on the declared column lengths. This |
1718
|
|
|
|
|
|
|
allows for optimal column width adjustments (ie: the actual column |
1719
|
|
|
|
|
|
|
widths may be less than the declared column widths). |
1720
|
|
|
|
|
|
|
|
1721
|
|
|
|
|
|
|
If it is not desired to have the column widths dynamically adjusted, |
1722
|
|
|
|
|
|
|
then set the I<$rewindable> argument to 0, even if the data is |
1723
|
|
|
|
|
|
|
rewindable. |
1724
|
|
|
|
|
|
|
|
1725
|
|
|
|
|
|
|
=item I<$row_sub> |
1726
|
|
|
|
|
|
|
|
1727
|
|
|
|
|
|
|
The code reference to the subroutine which returns the data; invoked |
1728
|
|
|
|
|
|
|
only if I<$rewindable> is non-null. |
1729
|
|
|
|
|
|
|
|
1730
|
|
|
|
|
|
|
=item I<$fmt_sub> |
1731
|
|
|
|
|
|
|
|
1732
|
|
|
|
|
|
|
The subroutine used to determine the length of the data when formatted; |
1733
|
|
|
|
|
|
|
if this is omitted or null, the length of the data is used by default. |
1734
|
|
|
|
|
|
|
The I<$fmt_sub> is used only when the data is rewindable. |
1735
|
|
|
|
|
|
|
|
1736
|
|
|
|
|
|
|
=item I<$types> |
1737
|
|
|
|
|
|
|
|
1738
|
|
|
|
|
|
|
An array reference to the types of each of the value columns; used only |
1739
|
|
|
|
|
|
|
when I<$fmt_sub> is invoked. |
1740
|
|
|
|
|
|
|
|
1741
|
|
|
|
|
|
|
=item I<$showmode> |
1742
|
|
|
|
|
|
|
|
1743
|
|
|
|
|
|
|
A string indicating the mode of the eventual display; one of four strings: |
1744
|
|
|
|
|
|
|
"C", "C", "C", and "C". Used to adjust widths
1745
|
|
|
|
|
|
|
for formatting requirements. |
1746
|
|
|
|
|
|
|
|
1747
|
|
|
|
|
|
|
=item I<$max_width> |
1748
|
|
|
|
|
|
|
|
1749
|
|
|
|
|
|
|
The maximum width of the table being formatted. If set, and the total |
1750
|
|
|
|
|
|
|
sum of the individual columns exceeds this value, the column widths are |
1751
|
|
|
|
|
|
|
scaled down uniformly. If not set (null), no column width scaling is done. |
1752
|
|
|
|
|
|
|
|
1753
|
|
|
|
|
|
|
=back |
1754
|
|
|
|
|
|
|
|
1755
|
|
|
|
|
|
|
=cut |
1756
|
|
|
|
|
|
|
|
1757
|
|
|
|
|
|
|
sub calc_widths { |
1758
|
160
|
|
|
160
|
0
|
424
|
my $widthspec = shift; |
1759
|
160
|
|
|
|
|
283
|
my $titles = shift; |
1760
|
160
|
|
|
|
|
315
|
my $rewindable = shift; |
1761
|
160
|
|
|
|
|
315
|
my $row_sub = shift; |
1762
|
160
|
|
|
|
|
280
|
my $fmt_sub = shift; |
1763
|
160
|
|
|
|
|
249
|
my $types = shift; |
1764
|
160
|
|
|
|
|
457
|
my $showmode = shift; |
1765
|
160
|
|
|
|
|
312
|
my $max_width = shift; |
1766
|
|
|
|
|
|
|
|
1767
|
160
|
|
|
|
|
383
|
my @precision; # array of precision values |
1768
|
|
|
|
|
|
|
my @setprec; # array of flags to set default precision |
1769
|
0
|
|
|
|
|
0
|
my @widths; # array of widths |
1770
|
0
|
|
|
|
|
0
|
my @max_widths; # array of max widths |
1771
|
0
|
|
|
|
|
0
|
my @expandable; # flag if widths expandable |
1772
|
0
|
|
|
|
|
0
|
my $num_cols; |
1773
|
0
|
|
|
|
|
0
|
my $c; |
1774
|
|
|
|
|
|
|
|
1775
|
160
|
100
|
|
|
|
791
|
if ($#$widthspec >= 0) { |
1776
|
144
|
|
|
|
|
739
|
@precision = @$widthspec; |
1777
|
144
|
50
|
|
|
|
1072
|
foreach (@precision) { s/^.*\.(\d+)/$1/ || ($_ = ''); } |
|
672
|
|
|
|
|
3527
|
|
1778
|
|
|
|
|
|
|
|
1779
|
|
|
|
|
|
|
# The setprec array indicates which columns need a default precision |
1780
|
144
|
|
|
|
|
1263
|
@setprec = map { !length } @precision; |
|
672
|
|
|
|
|
2607
|
|
1781
|
|
|
|
|
|
|
|
1782
|
|
|
|
|
|
|
# Get the integer portions |
1783
|
144
|
100
|
|
|
|
396
|
@widths = map { length($_) ? int : 0 } @$widthspec; |
|
672
|
|
|
|
|
1940
|
|
1784
|
|
|
|
|
|
|
|
1785
|
|
|
|
|
|
|
# Set @expandable if negative widths |
1786
|
144
|
|
|
|
|
364
|
@expandable = map { $_ < 0 } @widths; |
|
672
|
|
|
|
|
2772
|
|
1787
|
|
|
|
|
|
|
|
1788
|
|
|
|
|
|
|
# Convert widths to all positive values |
1789
|
144
|
|
|
|
|
930
|
@widths = map abs, @widths; |
1790
|
144
|
|
|
|
|
744
|
@max_widths = (0) x (1 + $#widths); # no maximums yet |
1791
|
144
|
|
|
|
|
438
|
$num_cols = 1 + $#widths; |
1792
|
|
|
|
|
|
|
} else { |
1793
|
|
|
|
|
|
|
# No widths given |
1794
|
16
|
|
|
|
|
373
|
@expandable = (1) x (1 + $#$titles); |
1795
|
16
|
|
|
|
|
180
|
@precision = ('') x (1 + $#$titles); |
1796
|
16
|
|
|
|
|
378
|
@setprec = @expandable; |
1797
|
16
|
|
|
|
|
328
|
@max_widths = map length, @$titles; # initialize maximums to title widths |
1798
|
16
|
|
|
|
|
85
|
$num_cols = 1 + $#$titles; |
1799
|
|
|
|
|
|
|
} |
1800
|
|
|
|
|
|
|
|
1801
|
|
|
|
|
|
|
# If the data is rewindable, scan and accumulate *actual* widths for |
1802
|
|
|
|
|
|
|
# each column, using the title lengths as a minimum. |
1803
|
160
|
100
|
|
|
|
530
|
if ($rewindable) { |
1804
|
132
|
|
|
|
|
407
|
my @values; |
1805
|
|
|
|
|
|
|
my @prectype; |
1806
|
132
|
50
|
|
|
|
685
|
if (ref($types) eq 'ARRAY') { |
1807
|
132
|
|
|
|
|
394
|
@prectype = map {/float|num(eric|ber)|money|dec|real|precision|double/i } @$types; |
|
612
|
|
|
|
|
4290
|
|
1808
|
|
|
|
|
|
|
} |
1809
|
|
|
|
|
|
|
|
1810
|
|
|
|
|
|
|
# Scan the values |
1811
|
132
|
|
|
|
|
560
|
while ((@values = &$row_sub(0)), $#values >= $[) { |
1812
|
|
|
|
|
|
|
# If the new row is larger than the number of titles, adjust |
1813
|
|
|
|
|
|
|
# the info arrays.. |
1814
|
660
|
50
|
|
|
|
3850
|
if ($num_cols < 1 + $#values) { # new column? |
1815
|
0
|
|
|
|
|
0
|
$num_cols = 1 + $#values; # new # of columns |
1816
|
0
|
|
|
|
|
0
|
for ($c = $#expandable + 1; $c <= $#values; $c++) { |
1817
|
0
|
|
|
|
|
0
|
$expandable[$c] = 1; |
1818
|
0
|
|
|
|
|
0
|
$precision[$c] = ''; |
1819
|
0
|
|
|
|
|
0
|
$setprec[$c] = 1; |
1820
|
0
|
|
|
|
|
0
|
$max_widths[$c] = 0; |
1821
|
|
|
|
|
|
|
} |
1822
|
|
|
|
|
|
|
} |
1823
|
660
|
|
|
|
|
1378
|
my $len; |
1824
|
|
|
|
|
|
|
my $value; |
1825
|
660
|
|
|
|
|
1937
|
for ($c = 0; $c < $num_cols; $c++) { |
1826
|
|
|
|
|
|
|
# Does this column's precision need setting? |
1827
|
3060
|
100
|
|
|
|
11054
|
if ($setprec[$c]) { |
1828
|
|
|
|
|
|
|
# Yes, is it a type of value which can use the precision? |
1829
|
612
|
50
|
|
|
|
1613
|
if ($prectype[$c]) { |
1830
|
|
|
|
|
|
|
# yes, how much is the current value's default precision? |
1831
|
0
|
0
|
|
|
|
0
|
if ($values[$c] =~ /\.(.*)$/) { |
1832
|
0
|
0
|
|
|
|
0
|
$precision[$c] = length($1) if length($1) > $precision[$c]; |
1833
|
|
|
|
|
|
|
} |
1834
|
|
|
|
|
|
|
} else { |
1835
|
|
|
|
|
|
|
# No, this column can't use the precision value -- don't |
1836
|
|
|
|
|
|
|
# do this check on this column again |
1837
|
612
|
|
|
|
|
1423
|
$precision[$c] = $setprec[$c] = 0; |
1838
|
|
|
|
|
|
|
} |
1839
|
|
|
|
|
|
|
} |
1840
|
|
|
|
|
|
|
|
1841
|
|
|
|
|
|
|
# Now, let's get the formatted value so we can guess the best |
1842
|
|
|
|
|
|
|
# default widths |
1843
|
|
|
|
|
|
|
$value = |
1844
|
|
|
|
|
|
|
# If a fmt_sub is available, use it to format the value |
1845
|
3060
|
0
|
|
|
|
11364
|
$fmt_sub ? |
|
|
50
|
|
|
|
|
|
1846
|
|
|
|
|
|
|
&$fmt_sub($values[$c], $types->[$c], 0, 0, $precision[$c], $showmode) |
1847
|
|
|
|
|
|
|
# If no fmt sub, then use Perl stringify |
1848
|
|
|
|
|
|
|
: length($showmode eq 'html' ? # in HTML mode? |
1849
|
|
|
|
|
|
|
&PlainText($values[$c]) # use plain text |
1850
|
|
|
|
|
|
|
: $values[$c]); # else, use raw text |
1851
|
3060
|
|
|
|
|
4377
|
$len = length($value); |
1852
|
|
|
|
|
|
|
|
1853
|
3060
|
100
|
66
|
|
|
34463
|
$max_widths[$c] = $len if |
1854
|
|
|
|
|
|
|
$c > $#max_widths || $len > $max_widths[$c]; |
1855
|
|
|
|
|
|
|
} |
1856
|
|
|
|
|
|
|
} |
1857
|
|
|
|
|
|
|
# okay -- maximums scanned. |
1858
|
|
|
|
|
|
|
# If the maximum table width set, scale the max_widths |
1859
|
132
|
100
|
66
|
|
|
2805
|
$max_width = 0 unless |
1860
|
|
|
|
|
|
|
defined($max_width) && $max_width ne ''; |
1861
|
132
|
100
|
|
|
|
407
|
if ($max_width > 0) { |
1862
|
|
|
|
|
|
|
# Start with the given maximum, but adjust it to account for |
1863
|
|
|
|
|
|
|
# the formatting and space characters. |
1864
|
50
|
|
|
|
|
300
|
my $max_width = $max_width; |
1865
|
50
|
100
|
|
|
|
541
|
$max_width -= $num_cols * 3 + 2 if $showmode eq 'box'; |
1866
|
50
|
100
|
|
|
|
202
|
$max_width -= $num_cols * 2 - 1 if $showmode eq 'table'; |
1867
|
50
|
|
|
|
|
94
|
my $total = 0; |
1868
|
|
|
|
|
|
|
# Calculate the total table width |
1869
|
50
|
|
|
|
|
1189
|
for ($c = 0; $c <= $#max_widths; $c++) { |
1870
|
250
|
|
|
|
|
607
|
$total += $max_widths[$c]; |
1871
|
|
|
|
|
|
|
} |
1872
|
50
|
100
|
|
|
|
505
|
if ($max_width < $total) { |
1873
|
|
|
|
|
|
|
# Now scale it to the adjusted maximum table width |
1874
|
44
|
|
|
|
|
187
|
for ($c = 0; $c <= $#max_widths; $c++) { |
1875
|
220
|
|
|
|
|
681
|
$max_widths[$c] = int($max_widths[$c] * |
1876
|
|
|
|
|
|
|
$max_width / $total); |
1877
|
|
|
|
|
|
|
} |
1878
|
|
|
|
|
|
|
} |
1879
|
|
|
|
|
|
|
} |
1880
|
|
|
|
|
|
|
|
1881
|
|
|
|
|
|
|
# If the column is expandable, allow the width to grow to the max_width. |
1882
|
|
|
|
|
|
|
# If the column is not expandable, allow the width to shrink to |
1883
|
|
|
|
|
|
|
# the max_width if it is smaller. |
1884
|
|
|
|
|
|
|
|
1885
|
132
|
100
|
|
|
|
518
|
if ($#widths < 0) { # were there any widths? |
1886
|
16
|
|
|
|
|
101
|
@widths = @max_widths; # nope, set them to the scanned values |
1887
|
|
|
|
|
|
|
} else { |
1888
|
116
|
50
|
|
|
|
3175
|
$num_cols = max($num_cols, 1 + $#widths) if $#widths >= 0; |
1889
|
116
|
|
|
|
|
281
|
my $len; |
1890
|
116
|
|
|
|
|
5712
|
for ($c = 0; $c < $num_cols; $c++) { |
1891
|
|
|
|
|
|
|
# provide defaults first |
1892
|
544
|
50
|
|
|
|
1428
|
$max_widths[$c] = 0 if !defined($max_widths[$c]); |
1893
|
544
|
50
|
33
|
|
|
3303
|
$widths[$c] = $max_widths[$c] |
1894
|
|
|
|
|
|
|
if $c > $#widths || !defined($widths[$c]); |
1895
|
|
|
|
|
|
|
# if the column can shrink, let it |
1896
|
544
|
100
|
100
|
|
|
5049
|
if ($max_widths[$c] < $widths[$c]) { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
1897
|
348
|
|
|
|
|
611
|
$widths[$c] = $max_widths[$c]; |
1898
|
|
|
|
|
|
|
} elsif ($expandable[$c] || !$widths[$c]) { |
1899
|
|
|
|
|
|
|
# allow the width to grow to the maximum width |
1900
|
44
|
100
|
|
|
|
276
|
$widths[$c] = $max_widths[$c] if $widths[$c] < $max_widths[$c]; |
1901
|
|
|
|
|
|
|
} elsif ($max_widths[$c] > $widths[$c] && $widths[$c] > 0) { |
1902
|
|
|
|
|
|
|
# not expandable -- set the max width to the width value |
1903
|
98
|
|
|
|
|
217
|
$max_widths[$c] = $widths[$c]; |
1904
|
|
|
|
|
|
|
} |
1905
|
|
|
|
|
|
|
# In either case, however, ensure that the widths are at |
1906
|
|
|
|
|
|
|
# least as long as the title length |
1907
|
544
|
50
|
|
|
|
1922
|
if ($c <= $#$titles) { |
1908
|
544
|
50
|
|
|
|
1777
|
if (defined($titles->[$c])) { |
1909
|
|
|
|
|
|
|
# If we're in HTML mode, get the length of the plaintext |
1910
|
544
|
100
|
|
|
|
1397
|
$len = length($showmode eq 'html' ? &PlainText($titles->[$c]) |
1911
|
|
|
|
|
|
|
# else, use raw text. |
1912
|
|
|
|
|
|
|
: $titles->[$c]); |
1913
|
|
|
|
|
|
|
} else { |
1914
|
0
|
|
|
|
|
0
|
$len = length("Field_$c"); |
1915
|
|
|
|
|
|
|
} |
1916
|
544
|
100
|
|
|
|
1661
|
$widths[$c] = $len |
1917
|
|
|
|
|
|
|
if $widths[$c] < $len; |
1918
|
544
|
100
|
|
|
|
2313
|
$max_widths[$c] = $len |
1919
|
|
|
|
|
|
|
if $max_widths[$c] < $len; |
1920
|
|
|
|
|
|
|
} |
1921
|
|
|
|
|
|
|
} |
1922
|
|
|
|
|
|
|
} |
1923
|
132
|
|
|
|
|
456
|
&$row_sub(1); # reset the pointer for the next scan |
1924
|
|
|
|
|
|
|
} else { |
1925
|
|
|
|
|
|
|
# Use title width as default if original width is null or zero |
1926
|
28
|
|
|
|
|
302
|
my $len; |
1927
|
28
|
|
|
|
|
1470
|
for ($c = 0; $c <= $#widths; $c++) { |
1928
|
128
|
50
|
|
|
|
714
|
next unless $c <= $#$titles; |
1929
|
|
|
|
|
|
|
# Get the length of the title (sans HTML text if in that mode) |
1930
|
128
|
100
|
|
|
|
1156
|
$len = length($showmode eq 'html' ? &PlainText($titles->[$c]) |
1931
|
|
|
|
|
|
|
: $titles->[$c]); |
1932
|
128
|
50
|
|
|
|
575
|
$widths[$c] = $len if $widths[$c] < $len; |
1933
|
|
|
|
|
|
|
} |
1934
|
|
|
|
|
|
|
# Can't scan the data, so the maximums can only be set by using the |
1935
|
|
|
|
|
|
|
# explicit widths. |
1936
|
28
|
|
|
|
|
144
|
@max_widths = @widths; |
1937
|
|
|
|
|
|
|
} |
1938
|
160
|
|
|
|
|
1334
|
($num_cols, \@widths, \@precision, \@max_widths); |
1939
|
|
|
|
|
|
|
} |
1940
|
|
|
|
|
|
|
|
1941
|
|
|
|
|
|
|
############################## |
1942
|
|
|
|
|
|
|
|
1943
|
|
|
|
|
|
|
=head1 putcell |
1944
|
|
|
|
|
|
|
|
1945
|
|
|
|
|
|
|
S< >I<$wrapped> = B<&putcell>( I<\@cells>, I<$c>, I<$cell_width>, I<\@prefix>, I<\@suffix>, I<$wrap_flag> ); |
1946
|
|
|
|
|
|
|
|
1947
|
|
|
|
|
|
|
Output the contents of an array cell at I<$cell>[I<$c>], causing text |
1948
|
|
|
|
|
|
|
longer than I<$cell_width> to be saved for output on subsequent calls. |
1949
|
|
|
|
|
|
|
Prefixing the output of each cell's value is a string from the |
1950
|
|
|
|
|
|
|
two-element array I<@prefix>. Suffixing each cell's value is a string |
1951
|
|
|
|
|
|
|
from the two-element array I<@suffix>. The first element of either |
1952
|
|
|
|
|
|
|
array is selected when I<$wrap_flag> is zero or null, or when there is |
1953
|
|
|
|
|
|
|
no more text in the current to be output. The second element |
1954
|
|
|
|
|
|
|
is selected when I<$wrap_flag> is non-zero, and when there is more text in |
1955
|
|
|
|
|
|
|
the current cell to be output. |
1956
|
|
|
|
|
|
|
|
1957
|
|
|
|
|
|
|
In the case of text longer than I<$cell_width>, a non-zero value is |
1958
|
|
|
|
|
|
|
returned. |
1959
|
|
|
|
|
|
|
|
1960
|
|
|
|
|
|
|
Cells with undefined data are not output, nor are the prefix or suffix |
1961
|
|
|
|
|
|
|
strings. |
1962
|
|
|
|
|
|
|
|
1963
|
|
|
|
|
|
|
=cut |
1964
|
|
|
|
|
|
|
|
1965
|
|
|
|
|
|
|
sub putcell { |
1966
|
3983
|
|
|
3983
|
0
|
6065
|
my $cells = shift; # ref to cell array |
1967
|
3983
|
|
|
|
|
5069
|
my $c = shift; # index |
1968
|
3983
|
|
|
|
|
4610
|
my $cell_width = shift; # maximum width of the cell |
1969
|
3983
|
|
|
|
|
5412
|
my $prefix = shift; # 2-elt array of prefix strings |
1970
|
3983
|
|
|
|
|
4983
|
my $suffix = shift; # 2-elt array of suffix strings |
1971
|
3983
|
|
|
|
|
4993
|
my $wrap_flag = shift; # non-zero for wrapped lines |
1972
|
3983
|
|
|
|
|
4288
|
my $more; |
1973
|
|
|
|
|
|
|
|
1974
|
3983
|
|
|
|
|
7950
|
my $v = $cells->[$c]; # get the data |
1975
|
3983
|
|
|
|
|
6676
|
my $px = 0; # prefix index |
1976
|
3983
|
|
|
|
|
4937
|
my $sx = 0; # suffix index |
1977
|
3983
|
50
|
|
|
|
10214
|
if (defined $v) { # not undef data? |
1978
|
3983
|
|
|
|
|
5429
|
my $text = $v; # save the text |
1979
|
3983
|
100
|
66
|
|
|
20011
|
$cell_width = 1 if !defined($cell_width) || $cell_width == 0; |
1980
|
3983
|
100
|
|
|
|
9372
|
if ($cell_width <= length($text)) { |
1981
|
2353
|
|
|
|
|
4973
|
$more = substr($text,$cell_width); |
1982
|
2353
|
|
|
|
|
5715
|
$v = substr($text,0,$cell_width); |
1983
|
|
|
|
|
|
|
} else { |
1984
|
1630
|
|
|
|
|
2042
|
$v = $text; $more = ''; |
|
1630
|
|
|
|
|
2576
|
|
1985
|
|
|
|
|
|
|
} |
1986
|
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
|
# wrapping? |
1988
|
3983
|
100
|
100
|
|
|
33037
|
if ($more ne '' && |
|
|
|
66
|
|
|
|
|
1989
|
|
|
|
|
|
|
|
1990
|
|
|
|
|
|
|
# See if we can wrap on a word boundary, instead of |
1991
|
|
|
|
|
|
|
# arbitrarily splitting one; note that we try to not |
1992
|
|
|
|
|
|
|
# split grouped numbers (1,345) or reals (1.234). |
1993
|
|
|
|
|
|
|
|
1994
|
|
|
|
|
|
|
$v =~ /([-,;? \t])([^-,;? \t0-9]*)$/ && |
1995
|
|
|
|
|
|
|
|
1996
|
|
|
|
|
|
|
# but also make sure that it is not too long |
1997
|
|
|
|
|
|
|
|
1998
|
|
|
|
|
|
|
length($2) <= $List_Wrap_Margin ) |
1999
|
|
|
|
|
|
|
{ |
2000
|
|
|
|
|
|
|
|
2001
|
|
|
|
|
|
|
# Okay, cut on the word boundary, leaving the break char |
2002
|
|
|
|
|
|
|
# on the tail end of the current output value |
2003
|
|
|
|
|
|
|
|
2004
|
548
|
|
|
|
|
1427
|
my $cut = $cell_width - length($2); |
2005
|
548
|
|
|
|
|
1095
|
$v = substr($text,0,$cut); # get new value |
2006
|
548
|
|
|
|
|
1023
|
$more = substr($text, $cut); # new remainder |
2007
|
|
|
|
|
|
|
} |
2008
|
3983
|
|
|
|
|
6988
|
$cells->[$c] = $more; # leave the rest for later |
2009
|
3983
|
|
100
|
|
|
15561
|
$px = $wrap_flag != 0 && length($v) > 0; |
2010
|
3983
|
|
|
|
|
7710
|
$sx = length($more) > 0; |
2011
|
|
|
|
|
|
|
} |
2012
|
3983
|
|
|
|
|
17444
|
my $fmt = sprintf("%%s%%-%ds%%s",$cell_width); |
2013
|
3983
|
|
|
|
|
10372
|
put $fmt,$prefix->[$px],$v,$suffix->[$sx]; # output something (could be blanks) |
2014
|
3983
|
|
|
|
|
35665
|
$sx; # leave wrapped flag |
2015
|
|
|
|
|
|
|
} |
2016
|
|
|
|
|
|
|
|
2017
|
|
|
|
|
|
|
############################## |
2018
|
|
|
|
|
|
|
|
2019
|
|
|
|
|
|
|
=head1 center |
2020
|
|
|
|
|
|
|
|
2021
|
|
|
|
|
|
|
Center a string within a given width. |
2022
|
|
|
|
|
|
|
|
2023
|
|
|
|
|
|
|
S< >I<$field> = B I<$string>, I<$width>; |
2024
|
|
|
|
|
|
|
|
2025
|
|
|
|
|
|
|
=cut |
2026
|
|
|
|
|
|
|
|
2027
|
|
|
|
|
|
|
sub center { |
2028
|
340
|
|
|
340
|
0
|
951
|
my($string,$width) = @_; |
2029
|
340
|
50
|
|
|
|
1703
|
$width = 0 if !defined($width); |
2030
|
340
|
100
|
|
|
|
895
|
return $string if length($string) >= $width; |
2031
|
280
|
|
|
|
|
675
|
my($pad) = int(($width - length($string))/2); # pad left half |
2032
|
280
|
|
|
|
|
9787
|
my($center) = (' ' x $pad) . $string; |
2033
|
280
|
|
|
|
|
377
|
$pad = $width - length($center); |
2034
|
280
|
|
|
|
|
625
|
$center .= ' ' x $pad; # pad right half |
2035
|
280
|
|
|
|
|
909
|
$center; # return with the centered string |
2036
|
|
|
|
|
|
|
} |
2037
|
|
|
|
|
|
|
|
2038
|
|
|
|
|
|
|
############################## |
2039
|
|
|
|
|
|
|
|
2040
|
|
|
|
|
|
|
=head1 max |
2041
|
|
|
|
|
|
|
|
2042
|
|
|
|
|
|
|
Compute the maximum value from a list of values. |
2043
|
|
|
|
|
|
|
|
2044
|
|
|
|
|
|
|
S< >I<$max> = B<&max>( I<@values> ); |
2045
|
|
|
|
|
|
|
|
2046
|
|
|
|
|
|
|
=cut |
2047
|
|
|
|
|
|
|
|
2048
|
|
|
|
|
|
|
sub max { |
2049
|
153
|
|
|
153
|
0
|
518
|
my ($max) = shift; |
2050
|
153
|
100
|
|
|
|
1391
|
foreach (@_) { $max = $_ if $max < $_; } |
|
249
|
|
|
|
|
2406
|
|
2051
|
153
|
|
|
|
|
551
|
$max; |
2052
|
|
|
|
|
|
|
} |
2053
|
|
|
|
|
|
|
|
2054
|
|
|
|
|
|
|
############################## |
2055
|
|
|
|
|
|
|
|
2056
|
|
|
|
|
|
|
=head1 min |
2057
|
|
|
|
|
|
|
|
2058
|
|
|
|
|
|
|
Compute the minum value from a list of values. |
2059
|
|
|
|
|
|
|
|
2060
|
|
|
|
|
|
|
S< >I<$min> = B<&min>( I<@values> ); |
2061
|
|
|
|
|
|
|
|
2062
|
|
|
|
|
|
|
=cut |
2063
|
|
|
|
|
|
|
|
2064
|
|
|
|
|
|
|
sub min { |
2065
|
1690
|
|
|
1690
|
0
|
7956
|
my ($min) = shift; |
2066
|
1690
|
50
|
|
|
|
3234
|
foreach (@_) { $min = $_ if $min > $_; } |
|
1690
|
|
|
|
|
8310
|
|
2067
|
1690
|
|
|
|
|
5964
|
$min; |
2068
|
|
|
|
|
|
|
} |
2069
|
|
|
|
|
|
|
|
2070
|
|
|
|
|
|
|
############################## |
2071
|
|
|
|
|
|
|
|
2072
|
|
|
|
|
|
|
=head1 max_length |
2073
|
|
|
|
|
|
|
|
2074
|
|
|
|
|
|
|
Compute the maximum length of a set of strings in an array reference. |
2075
|
|
|
|
|
|
|
|
2076
|
|
|
|
|
|
|
S< >I<$maxlength> = B<&max_length>( I<\@array_ref> ); |
2077
|
|
|
|
|
|
|
|
2078
|
|
|
|
|
|
|
=cut |
2079
|
|
|
|
|
|
|
|
2080
|
|
|
|
|
|
|
sub max_length { |
2081
|
37
|
|
|
37
|
0
|
140
|
my($aref) = shift; |
2082
|
37
|
|
|
|
|
101
|
my(@lens) = map { length } @$aref; |
|
170
|
|
|
|
|
472
|
|
2083
|
37
|
|
|
|
|
215
|
my($maxlen) = max( @lens ); |
2084
|
37
|
|
|
|
|
189
|
$maxlen; |
2085
|
|
|
|
|
|
|
} |
2086
|
|
|
|
|
|
|
|
2087
|
|
|
|
|
|
|
############################## |
2088
|
|
|
|
|
|
|
|
2089
|
|
|
|
|
|
|
=head1 htmltext |
2090
|
|
|
|
|
|
|
|
2091
|
|
|
|
|
|
|
Translate regular text for output into an HTML document. This means |
2092
|
|
|
|
|
|
|
certain characters, such as "&", ">", and "<" must be escaped. |
2093
|
|
|
|
|
|
|
|
2094
|
|
|
|
|
|
|
S< >I<$output> = B<&htmltext>( I<$input> [, I<$allflag> ] ); |
2095
|
|
|
|
|
|
|
|
2096
|
|
|
|
|
|
|
If I<$allflag> is non-zero, then all characters are escaped. Normally, |
2097
|
|
|
|
|
|
|
only the four HTML syntactic break characters are escaped. |
2098
|
|
|
|
|
|
|
|
2099
|
|
|
|
|
|
|
=cut |
2100
|
|
|
|
|
|
|
|
2101
|
|
|
|
|
|
|
# htmltext -- translate special text into HTML esacpes |
2102
|
|
|
|
|
|
|
sub htmltext { |
2103
|
935
|
|
|
935
|
0
|
2153
|
local($_) = shift; |
2104
|
935
|
|
|
|
|
1283
|
my $all = shift; |
2105
|
935
|
50
|
|
|
|
2897
|
return undef unless defined($_); |
2106
|
935
|
|
|
|
|
1535
|
s/&(?!(?:amp|quot|gt|lt|#\d+);)/&/g; |
2107
|
935
|
|
|
|
|
1133
|
s/\"/"/g; |
2108
|
935
|
|
|
|
|
1242
|
s/>/>/g; |
2109
|
935
|
|
|
|
|
1700
|
s/\</g; |
2110
|
935
|
100
|
|
|
|
1898
|
if ($all) { |
2111
|
75
|
|
|
|
|
161
|
s/ /\ /g; |
2112
|
75
|
|
|
|
|
111
|
s/\t/\ /g; |
2113
|
|
|
|
|
|
|
} |
2114
|
935
|
|
|
|
|
1828
|
$_; |
2115
|
|
|
|
|
|
|
} |
2116
|
|
|
|
|
|
|
|
2117
|
|
|
|
|
|
|
############################## |
2118
|
|
|
|
|
|
|
|
2119
|
|
|
|
|
|
|
=head1 out |
2120
|
|
|
|
|
|
|
|
2121
|
|
|
|
|
|
|
Print text followed by a newline. |
2122
|
|
|
|
|
|
|
|
2123
|
|
|
|
|
|
|
S< >B I<$fmt> [, I<@text> ]; |
2124
|
|
|
|
|
|
|
|
2125
|
|
|
|
|
|
|
=cut |
2126
|
|
|
|
|
|
|
|
2127
|
|
|
|
|
|
|
sub out { |
2128
|
4041
|
|
|
4041
|
0
|
7807
|
my $fmt = shift; |
2129
|
4041
|
100
|
|
|
|
14108
|
$fmt .= "\n" unless $fmt =~ /\n$/; |
2130
|
4041
|
|
|
|
|
116426
|
printf STDOUT $fmt, @_; |
2131
|
|
|
|
|
|
|
} |
2132
|
|
|
|
|
|
|
|
2133
|
|
|
|
|
|
|
############################## |
2134
|
|
|
|
|
|
|
|
2135
|
|
|
|
|
|
|
=head1 put |
2136
|
|
|
|
|
|
|
|
2137
|
|
|
|
|
|
|
Print text (without a trailing newline). |
2138
|
|
|
|
|
|
|
|
2139
|
|
|
|
|
|
|
S< >B I<$fmt> [, I<@text> ]; |
2140
|
|
|
|
|
|
|
|
2141
|
|
|
|
|
|
|
=cut |
2142
|
|
|
|
|
|
|
|
2143
|
|
|
|
|
|
|
sub put { |
2144
|
4445
|
|
|
4445
|
0
|
91780
|
printf STDOUT @_; |
2145
|
|
|
|
|
|
|
} |
2146
|
|
|
|
|
|
|
|
2147
|
|
|
|
|
|
|
############################## |
2148
|
|
|
|
|
|
|
|
2149
|
|
|
|
|
|
|
=head1 AUTHOR |
2150
|
|
|
|
|
|
|
|
2151
|
|
|
|
|
|
|
Alan K. Stebbens |
2152
|
|
|
|
|
|
|
|
2153
|
|
|
|
|
|
|
=cut |
2154
|
|
|
|
|
|
|
|
2155
|
|
|
|
|
|
|
=head1 BUGS |
2156
|
|
|
|
|
|
|
|
2157
|
|
|
|
|
|
|
=over 10 |
2158
|
|
|
|
|
|
|
|
2159
|
|
|
|
|
|
|
=item * |
2160
|
|
|
|
|
|
|
|
2161
|
|
|
|
|
|
|
Embedded HTML is how the user can insert formatting overrides. However, |
2162
|
|
|
|
|
|
|
the HTML formatting techniques have not been given much consideration -- |
2163
|
|
|
|
|
|
|
feel free to provide constructive feedback. |
2164
|
|
|
|
|
|
|
|
2165
|
|
|
|
|
|
|
=back |
2166
|
|
|
|
|
|
|
|
2167
|
|
|
|
|
|
|
=cut |
2168
|
|
|
|
|
|
|
|
2169
|
|
|
|
|
|
|
# |
2170
|
|
|
|
|
|
|
1; |
| | | | |