From 4fad56112022d60688e52fa75261785b51213831 Mon Sep 17 00:00:00 2001 From: John Denker Date: Fri, 20 Jul 2012 10:09:44 -0700 Subject: format stuff in columns --- tools/columns | 33 +++++++++++++++++++++++++++++++++ tools/greylist.c | 19 +++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100755 tools/columns (limited to 'tools') diff --git a/tools/columns b/tools/columns new file mode 100755 index 0000000..dcc934f --- /dev/null +++ b/tools/columns @@ -0,0 +1,33 @@ +#! /usr/bin/perl -w + +## not very scalable; stores entire document in memory + +use strict; +use List::Util qw[min max]; + +main:{ +## leftmost column is column ZERO + my @cwid = (); # width of column + + my @store = (); + + while (my $line = <>){ + chomp $line; + my @stuff = split(' ', $line); + for (my $ii = 0; $ii < 0+@stuff; $ii++){ + my $old = $cwid[$ii] || 0; + $cwid[$ii] = max(length($stuff[$ii]), $old); + } + push @store, \@stuff; + } + foreach my $line (@store) { + my @stuff = @$line; + for (my $ii = 0; $ii < 0+@stuff; $ii++){ + if ($ii) { + print " "; + } + printf("\%-$cwid[$ii]s", $stuff[$ii]); + } + print "\n"; + } +} \ No newline at end of file diff --git a/tools/greylist.c b/tools/greylist.c index 910b40c..1745b32 100644 --- a/tools/greylist.c +++ b/tools/greylist.c @@ -111,7 +111,7 @@ string time_out(const int ttt){ return foo.str(); } -void scan(const string p){ +void scan(const string p, const int copies=1){ timeval now; gettimeofday(&now, NULL); using namespace boost::filesystem; @@ -119,7 +119,8 @@ void scan(const string p){ if (is_directory(p)) { for (directory_iterator itr(p); itr!=directory_iterator(); ++itr) { string basename = itr->path().filename(); - cout << setw(20) << basename << ' '; // display filename only + for (int ii = 0; ii < copies; ii++) + cout << setw(20) << left << basename << ' '; // display filename only if (is_regular_file(itr->status())) { // cout << " [" << file_size(itr->path()) << ']'; struct stat mystat; @@ -177,17 +178,23 @@ int main(int _argc, char** _argv){ char** argv(_argv); const string dirname("/var/qmail/greylist"); whatsit foo(argv[0], dirname); argc--; argv++; + int scanmode(0); + int copies(1); while (argc > 0) { string arg = argv[0]; argc--; argv++; if (arg == "-scan") { - scan(dirname); - return 0; - } - else { + scanmode++; + } else if (arg == "-copy") { + copies++; + } else { cerr << "Unrecognized arg: " << arg << endl; exeunt(sa_syserr); } } + if (scanmode) { + scan(dirname, copies); + return 0; + } return foo.doit(); } -- cgit v1.2.3