From owner-svn-src-head@FreeBSD.ORG Thu Sep 16 22:47:50 2010 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 6F83A1065673; Thu, 16 Sep 2010 22:47:50 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 302C58FC08; Thu, 16 Sep 2010 22:47:50 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id C3D5535A825; Fri, 17 Sep 2010 00:47:48 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id AEA0D172A0; Fri, 17 Sep 2010 00:47:48 +0200 (CEST) Date: Fri, 17 Sep 2010 00:47:48 +0200 From: Jilles Tjoelker To: Juli Mallett Message-ID: <20100916224748.GA60291@stack.nl> References: <201009091927.o89JReXm022426@svn.freebsd.org> <20100916084442.GB21622@dragon.NUXI.org> <20100916212043.N724@delplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, David O'Brien , Bruce Evans Subject: Re: svn commit: r212374 - head/usr.bin/printf 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: Thu, 16 Sep 2010 22:47:50 -0000 On Thu, Sep 16, 2010 at 01:10:33PM -0700, Juli Mallett wrote: > On Thu, Sep 16, 2010 at 04:36, Bruce Evans wrote: > > WHat about the lesser burder on a character or two for putting -- in the > > synopsis where it is more visible: > >        printf [--] format [arguments ...] > Right, that's what I've been thinking about. For that matter, does > printf(1) need to use getopt(3) at all? It seems like simply checking > for "--" could be sufficient. Does POSIX require that it exit with an > error if it's given any options? It does not: implementations may add options as an extension and future versions of POSIX may add options. So while it would be a valid extension to allow format strings starting with "-" without "--" protection (other than "--" itself), I think it would be unwise. Most implementations of printf(1), other than the zsh builtin, require "--" protection for format strings starting with "-". Some of them also accept a few options: ksh93's builtin and GNU coreutils accept common options like --help, bash's builtin has a -v option to write the output directly into a variable (which seems bad to me by the way; I think printf(1) should usually be a builtin but it should be possible to use an external version with only performance and ARG_MAX as downsides). It is preferable if attempts to use such options fail loudly rather than silently writing garbage. I do not like "frivolous" extensions either, extensions that cause scripts written for FreeBSD to break on other systems without a good reason. Also note that the strict treatment of "-" is possible because printf(1) has historically recognized and required "--". Utilities that have not historically recognized "--" such as most of the special builtins may need a weaker approach. For example, in -current I have changed . and exec to treat "--" specially but not any other string starting with "-". The strict approach is cleaner but may cause compatibility problems in those cases. > At the very least, it seems like it would be more productive to have > printf(1) give unusually-helpful error messages (perhaps merely > changing its usage output to match that synopsis) if it encounters a > string beginning with '-' other than "--". That would be acceptable. -- Jilles Tjoelker