diff options
Diffstat (limited to 'backomp')
-rwxr-xr-x | backomp | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -6,13 +6,16 @@ set -e function flr(n, s) { return int(n / s) * s } BEGIN { - split("h d w m", buckets) - for (i in buckets) { - if (match(retain, "([*0-9]+)" buckets[i], md) && md[1]) - ret[buckets[i]] = md[1] + split("h d w m", arr) + for (i = 1; i <= length(arr); ++i) { + b = arr[i] - if (index(replace, buckets[i])) - repl[buckets[i]] = 1 + if (!match(retain, "([*0-9]+)" b, md)) + continue + ret[b] = md[1] + buckets[++n_buckets] = b + + repl[b] = !!index(replace, b) } } @@ -25,14 +28,22 @@ BEGIN { bt["m"] = mktime(strftime("%Y %m", t, 1) " 01 00 00 00", 1) bt["w"] = bt["m"] + flr(t - bt["m"], 7*24*60*60) - for (i = 1; i <= length(buckets); ++i) { + for (i = 1; i <= n_buckets; ++i) { b = buckets[i] - if (!ret[b] || (b in repl && (b, bt[b]) in bkeep)) - continue + if (skip = (repl[b] && bt[b] == last[b, b])) { + for (j = 1; j < i; ++j) { + skip = (bt[buckets[j]] != last[b, buckets[j]]) + if (!skip) break + } + if (skip) next + } if ((b, bt[b]) in bkeep || ret[b] == "*" || bc[b]++ < ret[b]) bkeep[b, bt[b]] = $1 + + for (j in buckets) + last[b, buckets[j]] = bt[buckets[j]] } } |