From 7d8d30a0dc4e3e9812188025cabbb473f77e7f93 Mon Sep 17 00:00:00 2001 From: canacar Date: Tue, 22 Jul 2008 03:00:23 +0000 Subject: [PATCH] Add signed size printing functions, as requested by deraadt@. Just use print_fld_ssize() for signed values. Increase scale up to "Tera" while there. --- usr.bin/systat/engine.c | 66 ++++++++++++++++++++++++++++++++++++++++- usr.bin/systat/engine.h | 4 ++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/usr.bin/systat/engine.c b/usr.bin/systat/engine.c index 512e5def1d1..4c14c2fa8a0 100644 --- a/usr.bin/systat/engine.c +++ b/usr.bin/systat/engine.c @@ -1,4 +1,4 @@ -/* $Id: engine.c,v 1.3 2008/06/13 17:45:02 canacar Exp $ */ +/* $Id: engine.c,v 1.4 2008/07/22 03:00:23 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * @@ -691,6 +691,13 @@ print_fld_sdiv(field_def *fld, u_int64_t size, int div) size /= div; if (tbprintf("%lluG", size) <= len) goto ok; + if (size == 0) + goto err; + + tb_start(); + size /= div; + if (tbprintf("%lluT", size) <= len) + goto ok; err: print_fld_str(fld, "*"); @@ -707,6 +714,63 @@ print_fld_size(field_def *fld, u_int64_t size) print_fld_sdiv(fld, size, 1024); } +void +print_fld_ssdiv(field_def *fld, int64_t size, int div) +{ + int len; + + if (fld == NULL) + return; + + len = fld->width; + if (len < 1) + return; + + tb_start(); + if (tbprintf("%lld", size) <= len) + goto ok; + + tb_start(); + size /= div; + if (tbprintf("%lldK", size) <= len) + goto ok; + if (size == 0) + goto err; + + tb_start(); + size /= div; + if (tbprintf("%lldM", size) <= len) + goto ok; + if (size == 0) + goto err; + + tb_start(); + size /= div; + if (tbprintf("%lldG", size) <= len) + goto ok; + if (size == 0) + goto err; + + tb_start(); + size /= div; + if (tbprintf("%lldT", size) <= len) + goto ok; + +err: + print_fld_str(fld, "*"); + tb_end(); + return; + +ok: + print_fld_tb(fld); +} + +void +print_fld_ssize(field_def *fld, int64_t size) +{ + print_fld_ssdiv(fld, size, 1024); +} + void print_fld_rate(field_def *fld, double rate) { diff --git a/usr.bin/systat/engine.h b/usr.bin/systat/engine.h index fd3d7e91a01..86f00012b53 100644 --- a/usr.bin/systat/engine.h +++ b/usr.bin/systat/engine.h @@ -1,4 +1,4 @@ -/* $Id: engine.h,v 1.1 2008/06/12 22:26:01 canacar Exp $ */ +/* $Id: engine.h,v 1.2 2008/07/22 03:00:23 canacar Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * @@ -109,6 +109,8 @@ void print_fld_str(field_def *fld, const char *str); void print_fld_age(field_def *fld, unsigned int age); void print_fld_sdiv(field_def *fld, u_int64_t size, int div); void print_fld_size(field_def *fld, u_int64_t size); +void print_fld_ssdiv(field_def *fld, int64_t size, int div); +void print_fld_ssize(field_def *fld, int64_t size); void print_fld_bw(field_def *fld, double bw); void print_fld_rate(field_def *fld, double rate); void print_fld_uint(field_def *fld, unsigned int size); -- 2.20.1