File: format-table

package info (click to toggle)
firehol 3.1.7%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,768 kB
  • sloc: sh: 20,852; makefile: 827; perl: 554; sed: 12
file content (35 lines) | stat: -rwxr-xr-x 879 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl -w

my $table_wanted = shift @ARGV;

my @cols = qw/54 24 40 150/;
my @bars = map { "-" x $_ } @cols;

sub padfields {
  my @results = ();
  foreach (@_) {
    die "Too big: $_" if (length($_) > $cols[@results]);
    push @results, sprintf "%-*.*s", $cols[@results], $cols[@results], $_;
  }
  return @results;
}

my @fields =

print join('--', @bars) . "\n"; # Start table

my @titles = padfields("command", "  4/6/46", "forbidden params", "description");
print join('  ', @titles) . "\n";
print join('  ', @bars); # Field headings

while (<>) {
  chomp;
  next unless (/^contents-table:/);
  my ($ct, $table, $keyword, $manual, $has46, $noparm, $desc) = split /:/;
  next unless $table eq $table_wanted;

  my @row = padfields("[$keyword][$manual]", $has46, $noparm, $desc);
  print "\n" . join('  ', @row) . "\n";
}

print join('--', @bars) . "\n"; # End table