From owner-svn-src-head@freebsd.org Wed Jun 13 08:52:07 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A64DE101505D; Wed, 13 Jun 2018 08:52:07 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7A428751D2; Wed, 13 Jun 2018 08:52:07 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4384B172CF; Wed, 13 Jun 2018 08:52:07 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5D8q7dA093577; Wed, 13 Jun 2018 08:52:07 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5D8q7tV093576; Wed, 13 Jun 2018 08:52:07 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806130852.w5D8q7tV093576@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Wed, 13 Jun 2018 08:52:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335037 - head/usr.bin/top X-SVN-Group: head X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: head/usr.bin/top X-SVN-Commit-Revision: 335037 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2018 08:52:07 -0000 Author: eadler Date: Wed Jun 13 08:52:06 2018 New Revision: 335037 URL: https://svnweb.freebsd.org/changeset/base/335037 Log: top(1): format help more nicely For entries that are duplicates present them nicely rather than showing two identical help entries. For ' ' present it as SPC Modified: head/usr.bin/top/commands.c Modified: head/usr.bin/top/commands.c ============================================================================== --- head/usr.bin/top/commands.c Wed Jun 13 08:52:04 2018 (r335036) +++ head/usr.bin/top/commands.c Wed Jun 13 08:52:06 2018 (r335037) @@ -57,16 +57,16 @@ const struct command all_commands[] = {'e', "list errors generated by last \"kill\" or \"renice\" command", false, CMD_errors}, {'H', "toggle the displaying of threads", false, CMD_thrtog}, {'h', "show this help text", true, CMD_help}, - {'?', "show this help text", true, CMD_help}, + {'?', NULL, true, CMD_help}, {'i', "toggle the displaying of idle processes", false, CMD_idletog}, - {'I', "toggle the displaying of idle processes", false, CMD_idletog}, + {'I', NULL, false, CMD_idletog}, {'j', "toggle the displaying of jail ID", false, CMD_jidtog}, {'J', "display processes for only one jail (+ selects all jails)", false, CMD_jail}, {'k', "kill processes; send a signal to a list of processes", false, CMD_kill}, {'q', "quit" , true, CMD_quit}, {'m', "toggle the display between 'cpu' and 'io' modes", false, CMD_viewtog}, {'n', "change number of processes to display", false, CMD_number}, - {'#', "change number of processes to display", false, CMD_number}, + {'#', NULL, false, CMD_number}, {'o', "specify the sort order", false, CMD_order}, {'p', "display one process (+ selects all processes)", false, CMD_pid}, {'P', "toggle the displaying of per-CPU statistics", false, CMD_pcputog}, @@ -86,7 +86,9 @@ const struct command all_commands[] = void show_help(void) { - const struct command *curcmd; + const struct command *curcmd, *nextcmd; + char keys[8] = ""; + _Static_assert(sizeof(keys) >= sizeof("a or b"), "keys right size"); printf("Top version FreeBSD, %s\n", copyright); curcmd = all_commands; @@ -95,7 +97,22 @@ show_help(void) ++curcmd; continue; } - printf("%c\t- %s\n", curcmd->c, curcmd->desc); + if (curcmd->desc == NULL) { + /* we already printed this */ + ++curcmd; + continue; + } + nextcmd = curcmd + 1; + if (nextcmd->desc == NULL && nextcmd->c != '\0') { + sprintf(keys, "%c or %c", curcmd->c, nextcmd->c); + } else if (curcmd->c == ' '){ + /* special case space rather than introducing a "display string" to + * the struct */ + sprintf(keys, "SPC"); + } else { + sprintf(keys, "%c", curcmd->c); + } + printf("%s\t- %s\n", keys, curcmd->desc); ++curcmd; } if (overstrike)