-/* $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
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 $");
*/
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);
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);