Add signed size printing functions, as requested by deraadt@.
authorcanacar <canacar@openbsd.org>
Tue, 22 Jul 2008 03:00:23 +0000 (03:00 +0000)
committercanacar <canacar@openbsd.org>
Tue, 22 Jul 2008 03:00:23 +0000 (03:00 +0000)
Just use print_fld_ssize() for signed values.
Increase scale up to "Tera" while there.

usr.bin/systat/engine.c
usr.bin/systat/engine.h

index 512e5de..4c14c2f 100644 (file)
@@ -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 <canacar@openbsd.org>
  *
@@ -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)
 {
index fd3d7e9..86f0001 100644 (file)
@@ -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 <canacar@openbsd.org>
  *
@@ -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);