From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12147 invoked by alias); 9 Jan 2018 22:48:26 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42249 Received: (qmail 532 invoked by uid 1010); 9 Jan 2018 22:48:25 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f54.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.54):SA:0(-2.6/5.0):. Processed in 2.299483 secs); 09 Jan 2018 22:48:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=O0Dosq3Ss6xkl8y1ncbfnXGXQoiG0sTfkusG18YQrdA=; b=Qa1YeP3wR4h81eiULzSnPdYlQhejPwxmucvy0mXTHuZLtvkjHSnGN6E7nOlskgmBCY vqdpxqzlQX3qZhikADy4Qdr5bbkfGMbCck79S3sx2lq8z08vwIY3CDOEhQSqLgsFFQFa xTOWA+bv7bwaaOQZGi8EzEjDtawcomYSfgBc+yGahusLtcTREomwyGnaBuc1iK0nbSF2 Yh2EU3LR7SUKBZbBmr+cOHlwjtbUa/U1zjvdNssYmiBqpwGcYUQ4jVqQRs2TyscMaFKF eonPysUP53G0w1kOgaOfhtcqim62ujVtAAQSjTgrCZYTmU9TOF5nbv3u9F+Cp0Em0+na aPlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=O0Dosq3Ss6xkl8y1ncbfnXGXQoiG0sTfkusG18YQrdA=; b=VSvzPDYnL5fhGdIeJMDJWX8Wom1wooSLHn4ESKfej7JOy3SdDadrXmEZWCF0V6ldnZ o/Q0NUysoE8QkSpDhok3R8x4MlmUi+mouDbwZpKnCag4zvDNNHkDpbDq5d9Uha0DLF49 stGSKQLDYEjb4x9vJQbbree50xNPSadsJrNtsWj0Z+tNPza7zIaDenffVFs9pTFRKrcT d8donmEa8kVXR7eXfIsKZecI7pc7kB124BkZq4RJdDoxJ3dzuF3uojrAv03CY6HPD5DA creH6m+lOlO7MC4doXlPwQQvqrJN4CacUtSoXyPNZWTBPklCW5EoQNtpzHxheLUCaHUd YGyA== X-Gm-Message-State: AKGB3mICnorymg+v6WOnEfziW3IGKr2/oUlTYfEMbkvk7HZX5j+Ek43K vjTv6cgSFrlNs+Uu8oU+t8ZKvIB5D60= X-Google-Smtp-Source: ACJfBovfAYLQWsNZ+06W0T6VXf9xQWAQxTxK/usFhkl0HTuiH7/TlpCsj1uiB51vvh0ErbqXxY1x/g== X-Received: by 10.36.157.203 with SMTP id f194mr17132911itd.53.1515538100694; Tue, 09 Jan 2018 14:48:20 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [BUG] getopts OPTIND From: dana In-Reply-To: Date: Tue, 9 Jan 2018 16:48:17 -0600 Cc: zsh-workers@zsh.org Content-Transfer-Encoding: quoted-printable Message-Id: <0877C4E8-4CA3-453F-A16B-99E576F60E8D@dana.is> References: To: franciscodezuviria@gmail.com X-Mailer: Apple Mail (2.3273) On 9 Jan 2018, at 10:22, Francisco de Zuvir=C3=ADa Allende = wrote: >Execution in bash: ... OPTIND is 5, next -a >execution in zsh: ... OPTIND is 4, next -r I think this fixes it? At least, zsh gives the same output as bash and = dash when i do this. Peter's left an ominous warning about changes to this = function that deserves recognition though... dana diff --git a/Src/builtin.c b/Src/builtin.c index 0211f2721..2550b29f2 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5437,6 +5437,9 @@ bin_getopts(UNUSED(char *name), char **argv, = UNUSED(Options ops), UNUSED(int fun if(opch =3D=3D ':' || !(p =3D memchr(optstr, opch, lenoptstr))) { p =3D "?"; err: + /* Keep OPTIND correct if the user doesn't return after the = error */ + optcind =3D 0; + zoptind++; zsfree(zoptarg); setsparam(var, ztrdup(p)); if(quiet) { diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst index 7eba5a4b1..f6977accb 100644 --- a/Test/B10getopts.ztst +++ b/Test/B10getopts.ztst @@ -79,3 +79,20 @@ test_getopts +x 1:one illegal option, + variant >test_getopts:3: bad option: +x + + t() { local o; repeat $1 { getopts a: o "${@:2}" 2>&1 }; print -r = $OPTIND } + t 4 -a -w -e -r -a + t 5 -a -w -e -a -w -e + t 5 -a -w -e -r -ax -a +0:OPTIND calculation after error (workers/42248) +*>*: bad option: -e +*>*: bad option: -r +*>*: argument expected after -a option +>6 +*>*: bad option: -e +*>*: bad option: -e +>7 +*>*: bad option: -e +*>*: bad option: -r +*>*: argument expected after -a option +>7