|
#!/usr/bin/perl -w # # txgraf --crb3 02Jul06/20jan07/23mar07 # # quick text bargraph showing relative sizes of text chapters. # story chapters should be roughly the same size, other than # maybe short prolog and epilog chapters. call it an indicator of # where to focus the storyteller's eye. # # 20jan07: implement up-adjusted $szmax # 23mar07: redid non- -2 to a more compact format (more chapters) # use strict; # my $is2=0; if(substr($ARGV[0],0,1) eq '-'){ my $sw=shift(@ARGV); if(substr($sw,1,1) eq '2'){ $is2=1; } } die "no subdir specified\n" unless defined $ARGV[0]; my $sdir=$ARGV[0]; my $szmax=100E3; my @ls=`ls -l $sdir/*txt`; # ignore html files, dotfiles my ($ln,$fname,@lsln,%sizes,$sz); foreach $ln (@ls){ chomp $ln; (@lsln)=split(/\s+/,$ln); ($fname=$lsln[8]) =~ s/^.+\///; # shave path, leave filename.typ $sizes{$fname}=$sz=0+$lsln[4]; # coerce to numeric $szmax=$sz if $sz > $szmax; } undef @ls; undef @lsln; if($szmax > 100E3){ # pad up to one 10k-point higher my $rem = $szmax % 10E3; $szmax += (10E3 - $rem); } my(@names,$fl,@fsiz); (@names)=(sort keys %sizes); foreach $fl (@names){ push(@fsiz,$sizes{$fl}); } # # the longhand way of determining the chapter-number placement. # we are relying on the habit of naming chapters nearly thus: ficname.00.txt # ...we need to know if the firstly-numbered chapter is 00 or 01. # 00 is (potentially) used for a prolog. creep out an index to the spot # where the first two names don't match: that's our units digit. # my $na=$names[0]; my $nb=$names[1]; my $ni=0; while(substr($na,$ni,1) eq substr($nb,$ni,1)){ $ni++; } my $nbase = (substr($na,$ni,1) eq '0' ? 0 : 1); # # print the actual graph. # my($szvtxt,$cx,$t,$tt); my $szstepping= $szmax / 10E3; my $szstep=$szmax / $szstepping; my $szval=$szmax; while($szval >-1){ $szvtxt = sprintf("%3dk",$szval/1E3); print "$szvtxt |"; for($cx = 0;$cx <= $#fsiz;$cx++){ $t=($fsiz[$cx] > $szval ? '#' : ' '); $tt = ($is2 ? "$t " : ' '); print "$t$tt"; } print "\n"; $szval -= $szstep; } my($vx,$hl,$lbln,$lbln2,$xlbl); $vx = ($is2 ? 3 : 2); $hl= '-----+' . ($is2 ? '-' : '') . ('-' x (($vx * $#fsiz + 1))); print "$hl\n"; $lbln=$lbln2= "ch "; for($cx = 0;$cx <= $#fsiz;$cx++){ $xlbl=sprintf("%2.02d ",$nbase); $nbase++; if($is2){ $lbln .= $xlbl; }else{ $lbln .= substr($xlbl,0,1); $lbln2 .=substr($xlbl,1,1); $lbln .= ' '; $lbln2 .= ' '; } } if($is2){ print "$lbln\n"; }else{ print "$lbln\n$lbln2\n"; } |
Grab a gzipped copy here |
| Syntax highlighting using Syntax::Highlight::Engine::Kate |