[Toybox] [PATCH] top: use human_readable for the header lines too.
Rob Landley
rob at landley.net
Wed Feb 13 19:07:57 PST 2019
On 2/13/19 5:16 PM, enh via Toybox wrote:
> @@ -1564,13 +1566,21 @@ static void top_common(
> "\nBuffers:","\nCached:","\nSwapTotal:","\nSwapFree:"}[i]);
> run[i] = pos ? atol(pos) : 0;
> }
> - sprintf(toybuf,
> - "Mem:%10ldk total,%9ldk used,%9ldk free,%9ldk buffers",
> - run[0], run[0]-run[1], run[1], run[2]);
> +
> + human_readable(hr0, 1024*run[0], 0);
> + human_readable(hr1, 1024*(run[0]-run[1]), 0);
> + human_readable(hr2, 1024*run[1], 0);
> + human_readable(hr3, 1024*run[2], 0);
> + sprintf(toybuf, " Mem: %9s total, %9s used, %9s free,
> %9s buffers",
> + hr0, hr1, hr2, hr3);
> lines = header_line(lines, 0);
> - sprintf(toybuf,
> - "Swap:%9ldk total,%9ldk used,%9ldk free,%9ldk cached",
> - run[4], run[4]-run[5], run[5], run[3]);
> +
> + human_readable(hr0, 1024*run[4], 0);
> + human_readable(hr1, 1024*(run[4]-run[5]), 0);
> + human_readable(hr2, 1024*run[5], 0);
> + human_readable(hr3, 1024*run[3], 0);
> + sprintf(toybuf, " Swap: %9s total, %9s used, %9s free, %9s cached",
> + hr0, hr1, hr2, hr3);
> lines = header_line(lines, 0);
> }
Darn it, if that second one ended in 6 instead of 3 it'd be reusable code. Grrr.
Rob
More information about the Toybox
mailing list