roll.sh: small cleanup and whitespace fixes - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit db76fd2dd16f1507593ead4c4f470645b6725813
 (DIR) parent 760ab4feb548764ecf6a66a6e07d4875f2cfed95
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 22 Jun 2025 11:27:48 +0200
       
       roll.sh: small cleanup and whitespace fixes
       
       Diffstat:
         M roll.sh                             |      24 +++++++++---------------
       
       1 file changed, 9 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/roll.sh b/roll.sh
       @@ -2,10 +2,6 @@
        # rolling sum and percentage.
        # input should be sorted descending by value.
        
       -# TODO: add and skip header column?
       -# TODO: rolling sum per group vs group total.
       -# TODO: simplify
       -
        # usage(argv0)
        usage() {
                printf "Usage:   %s [-k columns] [-v value]\n" "$1" >&2
       @@ -24,11 +20,10 @@ do
                        kflag=1
                        kval="$OPTARG"
                        ;; # key columns
       -        v)  
       +        v)
                        vflag=1
                        vval="$OPTARG"
                        ;; # value column
       -        
                ?)
                        usage "$0"
                        ;;
       @@ -50,20 +45,20 @@ BEGIN {
        {
                line[i] = $0;
                i++;
       -        
       +
                # config key column(s), if non-empty then it is grouped.
                k = '"$kexpr"';
       -        
       +
                # value field.
                value = '"$vexpr"' + 0.0; # config value column.
                if (value <= 0.0)
                        value = 0.0;
       -        
       +
                values[i] = value;
                # total per group
                if (k != "") {
                        gtotal[k] += (value+0.0);
       -                
       +
                        keys[i] = k;
                        if (!ukeycount[k]) {
                                ukeycount[k] = 1;
       @@ -71,7 +66,7 @@ BEGIN {
                                kk++;
                        }
                }
       -                
       +
                # total
                total += (value+0.0);
        }
       @@ -82,14 +77,14 @@ END {
        
                        value = values[j];
                        sum += value;
       -                
       +
                        print l;
                        print OFS;
                        printf("%.5f", sum);
                        print OFS;
                        if (total > 0)
                                printf("%.5f", ((sum / total)*100.0));
       -                
       +
                        k = keys[j];
                        if (k != "") {
                                print "\t";
       @@ -105,11 +100,10 @@ END {
                                # percentage of the group total.
                                if (gt > 0)
                                        printf("%.5f", ((value / gt) * 100.0));
       -                        
                        }
                        print "\n";
                }
       -        
       +
                # summary / totals (per group).
                #for (j = 0; j < kk; j++) {
                #        k = uniqkeys[j];