summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-20 10:09:44 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:32:34 -0700
commit4fad56112022d60688e52fa75261785b51213831 (patch)
tree539839c462dcf498d541bc6f5c10fb0cda6d77e1 /tools
parentabcd53ddce872e3f331d8a6d7c1ff44c070b91b0 (diff)
format stuff in columns
Diffstat (limited to 'tools')
-rwxr-xr-xtools/columns33
-rw-r--r--tools/greylist.c19
2 files changed, 46 insertions, 6 deletions
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();
}