File size distribution: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl example) |
m (→{{header|REXX}}: added/changed whitespace and comments, simplified the inner DO loop by eliding the use of SELECT.) |
||
Line 457: | Line 457: | ||
parse arg ds . /*obtain optional argument from the CL.*/ |
parse arg ds . /*obtain optional argument from the CL.*/ |
||
parse source . . path . /* " the path of this REXX program.*/ |
parse source . . path . /* " the path of this REXX program.*/ |
||
fID=substr(path, 1 + lastpos('\', path) ) |
fID= substr(path, 1 + lastpos('\', path) ) /* " the filename and the filetype.*/ |
||
parse var fID fn '.' /* " just the pure filename of pgm.*/ |
parse var fID fn '.' /* " just the pure filename of pgm.*/ |
||
sw=max(79, linesize() - 1) /* " terminal width (linesize) - 1.*/ |
sw=max(79, linesize() - 1) /* " terminal width (linesize) - 1.*/ |
||
Line 463: | Line 463: | ||
'DIR' ds '/s /-c /a-d >' work /*do (DOS) DIR cmd for a data structure*/ |
'DIR' ds '/s /-c /a-d >' work /*do (DOS) DIR cmd for a data structure*/ |
||
call linein 0, 1 /*open output file, point to 1st record*/ |
call linein 0, 1 /*open output file, point to 1st record*/ |
||
maxL=0; |
maxL= 0; @.= 00; g= 0 /*max len size; log array; # good recs.*/ |
||
$=0 /*$: total bytes used by files found. */ |
$=0 /*$: total bytes used by files found. */ |
||
do while lines(work)\==0; _=linein(work) |
do while lines(work)\==0; _= linein(work) /*process the data in the DIR work file*/ |
||
if left(_, 1)==' ' then iterate /*Is the record not legitimate? Skip. */ |
if left(_, 1)==' ' then iterate /*Is the record not legitimate? Skip. */ |
||
parse upper var _ . . sz . /*uppercase suffix*/ |
parse upper var _ . . sz . /*uppercase suffix*/ |
||
if \datatype(sz,'W') then do; #=left(sz, length(sz) - 1) |
if \datatype(sz,'W') then do; #= left(sz, length(sz) - 1) /*SZ has a suffix?*/ |
||
if \datatype(#, |
if \datatype(#,'N') then iterate /*Meat ¬ numeric? */ |
||
sz= # * 1024 ** pos( right(sz, 1), 'KMGTPEZYXWVU') / 1 |
sz= # * 1024 ** pos( right(sz, 1), 'KMGTPEZYXWVU') / 1 |
||
end /* [↑] use suffix*/ |
end /* [↑] use suffix*/ |
||
$=$ + sz |
$= $ + sz /*keep a running total for the filesize*/ |
||
if sz==0 then L= |
if sz==0 then L= 0 /*handle special case for an empty file*/ |
||
else L=length(sz) |
else L= length(sz) /*obtain the length of filesize number.*/ |
||
g=g + 1 |
g= g + 1 /*bump the counter of # of good records*/ |
||
maxL=max(L, maxL) |
maxL= max(L, maxL) /*get max length filesize for alignment*/ |
||
@.L=@.L + 1 |
@.L= @.L + 1 /*bump counter of record size category.*/ |
||
end /*j*/ /* [↑] categories: split by log ten.*/ |
end /*j*/ /* [↑] categories: split by log ten.*/ |
||
Line 485: | Line 485: | ||
mC=0 /*mC: the maximum count for any range.*/ |
mC=0 /*mC: the maximum count for any range.*/ |
||
do t=1 to 2 /*T==1 is used to find the max count.*/ |
do t=1 to 2 /*T==1 is used to find the max count.*/ |
||
do k=0 to maxL; mC=max(mC, @.k); if t==1 then iterate |
do k=0 to maxL; mC= max(mC, @.k); if t==1 then iterate /*1st pass? */ |
||
if k==0 then y= center('zero', length( word(hdr, 1) ) ) |
|||
else y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1' |
|||
otherwise y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1' |
|||
end /*select*/ |
|||
say y || right( commas(@.k), 11) copies('─', max(1, (@.k / mC * sw % 1) - LHdr) ) |
say y || right( commas(@.k), 11) copies('─', max(1, (@.k / mC * sw % 1) - LHdr) ) |
||
end /*k*/ |
end /*k*/ |