diff options
Diffstat (limited to 'usr.bin/top/top.c')
-rw-r--r-- | usr.bin/top/top.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 856ad838dc1c..f0458a4037af 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -252,7 +252,7 @@ main(int argc, const char *argv[]) char no_command = 1; struct timeval timeout; char *order_name = NULL; - int order_index = 0; + const struct sort_info *sort_info = NULL; fd_set readfds; char *nptr; @@ -505,21 +505,18 @@ main(int argc, const char *argv[]) /* determine sorting order index, if necessary */ if (order_name != NULL) { - if ((order_index = string_index(order_name, statics.order_names)) == -1) - { - const char * const *pp; - + if ((sort_info = get_sort_info(order_name)) == NULL) { warnx("'%s' is not a recognized sorting order.", order_name); fprintf(stderr, "\tTry one of these:"); - pp = statics.order_names; - while (*pp != NULL) - { - fprintf(stderr, " %s", *pp++); - } + dump_sort_names(stderr); fputc('\n', stderr); exit(1); } } + else + { + sort_info = get_sort_info(NULL); + } /* initialize termcap */ init_termcap(interactive); @@ -602,17 +599,13 @@ restart: while ((displays == -1) || (displays-- > 0)) { - int (*compare)(const void * const, const void * const); - /* get the current stats */ get_system_info(&system_info); - compare = compares[order_index]; - /* get the current set of processes */ processes = - get_process_info(&system_info, &ps, compare); + get_process_info(&system_info, &ps, sort_info); /* display the load averages */ (*d_loadave)(system_info.last_pid, @@ -1047,7 +1040,9 @@ restart: "Order to sort: "); if (readline(tempbuf2, sizeof(tempbuf2), false) > 0) { - if ((i = string_index(tempbuf2, statics.order_names)) == -1) + const struct sort_info *new_sort_info; + + if ((new_sort_info = get_sort_info(tempbuf2)) == NULL) { new_message(MT_standout, " %s: unrecognized sorting order", tempbuf2); @@ -1055,7 +1050,7 @@ restart: } else { - order_index = i; + sort_info = new_sort_info; } putchar('\r'); } |