First column of hreport results now dynamically resizes
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 1 Nov 2006 01:32:40 +0000 (01:32 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 1 Nov 2006 01:32:40 +0000 (01:32 +0000)
mmsoftware/mmstatd/src/mmstat.c

index ee5b8c1..bed0e54 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmstat.c,v 1.18 2004/05/22 17:44:01 mmondor Exp $ */
+/* $Id: mmstat.c,v 1.19 2006/11/01 01:32:40 mmondor Exp $ */
 
 /*
  * Copyright (C) 2002-2004, Matthew Mondor
@@ -52,7 +52,7 @@
 
 MMCOPYRIGHT("@(#) Copyright (c) 2002-2004\n\
 \tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mmstat.c,v 1.18 2004/05/22 17:44:01 mmondor Exp $");
+MMRCSID("$Id: mmstat.c,v 1.19 2006/11/01 01:32:40 mmondor Exp $");
 
 
 
@@ -240,12 +240,23 @@ int stat_hreport(int argc, char **argv)
                 */
                if ((index = malloc(sizeof(struct entnode *) *
                                (DLIST_NODES(&list) + 1))) != NULL) {
-                   register int i = 0;
+                   register int        i = 0;
+                   int64_t             max = 0;
+                   char                fmt[32];
 
-                   DLIST_FOREACH(&list, entnod)
+                   DLIST_FOREACH(&list, entnod) {
                        index[i++] = entnod;
+                       if (entnod->ent.value > max)
+                               max = entnod->ent.value;
+                       else if (-entnod->ent.value > max)
+                               max = -entnod->ent.value;
+                   }
                    index[i] = NULL;
 
+                   (void) snprintf(fmt, 31, "%lld", max);
+                   i = mm_strlen(fmt) + 1;
+                   (void) snprintf(fmt, 31, "%%%dlld %%s %%s\n", i);
+
                    qsort(index, DLIST_NODES(&list), sizeof(struct entnode *),
                            compar_entnode);
 
@@ -253,8 +264,7 @@ int stat_hreport(int argc, char **argv)
                        ent = &(index[i])->ent;
                        gmtime_r(&ent->modified, &modifiedt);
                        strftime(modified, 14, "%y%m%d.%H%M%S", &modifiedt);
-                       printf("%11lld %s %s\n", ent->value, modified,
-                               ent->key);
+                       (void) printf(fmt, ent->value, modified, ent->key);
                    }
 
                    free(index);