From owner-svn-src-head@FreeBSD.ORG Tue Nov 8 11:36:47 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 868EA1065670; Tue, 8 Nov 2011 11:36:47 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 326C08FC1B; Tue, 8 Nov 2011 11:36:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pA8BalMQ029617; Tue, 8 Nov 2011 11:36:47 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pA8Balsp029615; Tue, 8 Nov 2011 11:36:47 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201111081136.pA8Balsp029615@svn.freebsd.org> From: Ed Schouten Date: Tue, 8 Nov 2011 11:36:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r227335 - head/usr.bin/du X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 08 Nov 2011 11:36:47 -0000 Author: ed Date: Tue Nov 8 11:36:46 2011 New Revision: 227335 URL: http://svn.freebsd.org/changeset/base/227335 Log: Simplify getopt switch parsing. Only one of these flags can be set. Just add them together and check the value. Also, get rid of the listall variable. The code is already filled with direct *flag-comparisons. Obtained from: Alexander Best (though modified) Modified: head/usr.bin/du/du.c Modified: head/usr.bin/du/du.c ============================================================================== --- head/usr.bin/du/du.c Tue Nov 8 11:08:40 2011 (r227334) +++ head/usr.bin/du/du.c Tue Nov 8 11:36:46 2011 (r227335) @@ -88,7 +88,6 @@ main(int argc, char *argv[]) off_t savednumber, curblocks; off_t threshold, threshold_sign; int ftsoptions; - int listall; int depth; int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag; int hflag, lflag, ch, notused, rval; @@ -229,17 +228,10 @@ main(int argc, char *argv[]) if (!Aflag && (cblocksize % DEV_BSIZE) != 0) cblocksize = howmany(cblocksize, DEV_BSIZE) * DEV_BSIZE; - listall = 0; - - if (aflag) { - if (sflag || dflag) - usage(); - listall = 1; - } else if (sflag) { - if (dflag) - usage(); + if (aflag + dflag + sflag > 1) + usage(); + if (sflag) depth = 0; - } if (!*argv) { argv = save; @@ -320,7 +312,7 @@ main(int argc, char *argv[]) howmany(p->fts_statp->st_size, cblocksize) : howmany(p->fts_statp->st_blocks, cblocksize); - if (listall || p->fts_level == 0) { + if (aflag || p->fts_level == 0) { if (hflag) { prthumanval(curblocks); (void)printf("\t%s\n", p->fts_path);