From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 2 10:44:45 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 14F6B106566B for ; Fri, 2 Mar 2012 10:44:45 +0000 (UTC) (envelope-from gleb.kurtsou@gmail.com) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 7F0338FC13 for ; Fri, 2 Mar 2012 10:44:44 +0000 (UTC) Received: by lagv3 with SMTP id v3so2625224lag.13 for ; Fri, 02 Mar 2012 02:44:43 -0800 (PST) Received-SPF: pass (google.com: domain of gleb.kurtsou@gmail.com designates 10.112.102.68 as permitted sender) client-ip=10.112.102.68; Authentication-Results: mr.google.com; spf=pass (google.com: domain of gleb.kurtsou@gmail.com designates 10.112.102.68 as permitted sender) smtp.mail=gleb.kurtsou@gmail.com; dkim=pass header.i=gleb.kurtsou@gmail.com Received: from mr.google.com ([10.112.102.68]) by 10.112.102.68 with SMTP id fm4mr4262448lbb.7.1330685083316 (num_hops = 1); Fri, 02 Mar 2012 02:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=upr9QyFvpZr81chdPpYiWvj4rnJLCfKydbjF6tqHlWI=; b=WKxZpjM8p9pKfk/jyRVyVJVy0yeYZ+yM8VRt674agRfysXNqwmEXL36r1nFdAxXd6R qpFno9T2eMEtuHWbJeERqw2ubnRx1CPXAmEBFM0Grvvh/KM+hKBtgtlVlSo1PREoaNBa M/PHsHsJQlY3k2CWRefK57Sk62Myd6ZFhVJ4dgbjBEt5kyKwX5fVtkXqJn4VjoTxP46N I5CxCmIerm2hpIH+QAwmBJSplfv0ZBeOWH+xG1CxS5by/+KG9kB+EqAKpdl9nj/fa6XU IPr845WS2rKU1lUnWvCy6JE6OllzaKTnLxYa9CyPORpZ4/uTpgxphOwi1x+a2dEmxqXt bmZQ== Received: by 10.112.102.68 with SMTP id fm4mr3486367lbb.7.1330685083197; Fri, 02 Mar 2012 02:44:43 -0800 (PST) Received: from localhost ([78.157.92.5]) by mx.google.com with ESMTPS id w10sm7433971lbe.14.2012.03.02.02.44.41 (version=SSLv3 cipher=OTHER); Fri, 02 Mar 2012 02:44:42 -0800 (PST) Date: Fri, 2 Mar 2012 12:44:44 +0200 From: Gleb Kurtsou To: Alexander Best Message-ID: <20120302104444.GA19811@reks> References: <20120301233822.GA19709@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20120301233822.GA19709@freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org Subject: Re: small change to du, so it will accepts unit suffixes for negative thresholds X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Mar 2012 10:44:45 -0000 On (01/03/2012 23:38), Alexander Best wrote: > hi there, > > i just noticed that du will not accepts something like the following: > > du -t-500M > > whereas > > du -t500M > > will work. i've attached a patch, which makes unit suffixes in connection with > negative thresholds possible. Good catch, thanks. A few minor comments below. > > cheers. > alex > diff --git a/usr.bin/du/du.1 b/usr.bin/du/du.1 > index 3db1367..01d2ec1 100644 > --- a/usr.bin/du/du.1 > +++ b/usr.bin/du/du.1 > @@ -137,6 +137,10 @@ If > is negative, display only entries for which size is less than the absolute > value of > .Ar threshold . > +For both positive and negative values, > +.Ar threshold > +accepts unit suffixes > +.Po see Fl h Li option Pc . > .It Fl x > File system mount points are not traversed. > .El > diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c > index 7b47b71..51bfd07 100644 > --- a/usr.bin/du/du.c > +++ b/usr.bin/du/du.c > @@ -175,13 +175,18 @@ main(int argc, char *argv[]) > break; > case 'r': /* Compatibility. */ > break; > - case 't' : > + case 't': > + if (strncmp(optarg, "-", 1) == 0) { Why not optarg[0] == '-', it makes intent more clear. I think we should support "+500M" as well. Perhaps we'd better use temporal variable for string value instead of changing optarg. Or initialize threshold_sign with 0, set it either to 1 or -1 if optarg starts with '+' or '-' accordingly, and do expand_number(optarg + (threshold_sign != 0 ? 1 : 0), &threshold) > + optarg++; > + threshold_sign = -1; > + } > if (expand_number(optarg, &threshold) != 0 || > threshold == 0) { > warnx("invalid threshold: %s", optarg); optarg can differ from original value because of optarg++ above. > usage(); > - } else if (threshold < 0) > - threshold_sign = -1; > + } > + if (threshold_sign == -1) > + threshold = -threshold; > break; > case 'x': > ftsoptions |= FTS_XDEV; > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"