File size distribution: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed wording in the output section comments.)
m (→‎{{header|REXX}}: made the output more consistant looking, added whitespace to the output, used a more idiomatic programming style..)
Line 420:
fID=substr(path, 1 + lastpos('\', path) ) /* " the filename and the filetype.*/
parse var fID fn '.' /* " just the pure filename of pgm.*/
sw=max(79, linesize() - 1;) if sw<80 then sw=79 /* " terminal width (linesize) - 1.*/
dirOut= fn".OUT" /*filename for workfile output of DIR.*/
'DIR' ds '/s /-c /a-d >' dirOut /*do (DOS) DIR cmd for a data structure*/
call linein 0, 1 /*open output file, point to 1st record*/
maxL=0; @.=00; g=0 /*max len size; log array; # good /*maximum length of number of recordsrecs. */
@.$=000 /*stemmed$: total arraybytes toused holdby recordfiles countsfound. */
g=0 do while lines(dirOut) \== 0 /*numberprocess ofdata. good records found (so far)*/
$=0; do while lines(dirOut) \== 0 /*process data. */
_=linein(dirOUT); if left(_, 1)==' ' then iterate /*Not legit? Skip.*/
parse upper var _ . . sz . /*uppercase suffix*/
Line 438 ⟶ 437:
else L=length(sz) /*obtain the length of filesize number.*/
g=g + 1 /*bump the counter of # of good records*/
maxL=max(L, maxL) /*obtainget the maximummax length of filesize for alignment*/
@.L=@.L + 1 /*bump counter of categoryrecord ofsize rec sizecategory.*/
end /*j*/ /* [↑] categories: split by log ten.*/
 
if g==0 then do; say 'file not found: ' ds; exit 13; end /*no good records*/
say ' record size range count '
hdr= '══════════════════ ═══════════════════ '; say hdr; lenHdr= Lhdr=length(hdr)
mC=0 /*mC: the maximum count for any range.*/
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 /*1st pass? */
select
when k==0 then y= center(' zero', length( word(hdr, 1) ) ')
otherwise when k==1 then y= '10^'left(k-1,2) 1 "──► 10^"left(k,2) 9 '-1'
end when k==2 then y= ' 10 ──► 99 '/*select*/
say y || right( commas(@.k), 11) copies('─', max(1, when (@.k==3 / thenmC y=* 'sw % 1001) ──►- LHdr) 999 ')
when k==4 then y= ' 1000 ──► 9999 '
otherwise y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1'
end /*select*/
say y || right(commas(@.k), 10) copies('─', max(1, (@.k / mC * sw % 1) - lenHdr) )
end /*k*/
end /*y*/
say
trace off; 'ERASE' dirOut /*perform clean─up (erase a work file).*/
say commas(g) ' files detected, ' commas($) " total bytes."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do jcj#=length(_)-3 to 1 by -3; _=insert(',', _, jcj#); end; return _</lang>
This REXX program makes use of &nbsp; '''LINESIZE''' &nbsp; REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console) so as to maximize the width of the histogram.
<br>The &nbsp; '''LINESIZE.REX''' &nbsp; REXX program is included here &nbsp; ──► &nbsp; [[LINESIZE.REX]].<br>
Line 484 ⟶ 479:
10^9 ──► 10^10 -1 1 ─
 
55,539 files detected, 12,656,593,862 total bytes.
</pre>
 
Line 501 ⟶ 496:
10^7 ──► 10^8 -1 6 ─
 
20,385 files detected, 1,625,509,222 total bytes.
</pre>