From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#63733: 28.3; error ("Unknown option =?UTF-8?Q?=E2=80=98--batch=E2=80=99?=") Date: Fri, 26 May 2023 12:10:21 +0300 Message-ID: <83h6rzlapu.fsf@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40136"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63733@debbugs.gnu.org To: Ulrich =?UTF-8?Q?M=C3=BCller?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 26 11:10:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q2TSq-000AF9-Td for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 26 May 2023 11:10:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2TSb-0006MY-9s; Fri, 26 May 2023 05:10:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2TSV-00068f-ST for bug-gnu-emacs@gnu.org; Fri, 26 May 2023 05:10:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2TSU-0000tk-Ri for bug-gnu-emacs@gnu.org; Fri, 26 May 2023 05:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q2TSU-0003NV-2o for bug-gnu-emacs@gnu.org; Fri, 26 May 2023 05:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 26 May 2023 09:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63733 X-GNU-PR-Package: emacs Original-Received: via spool by 63733-submit@debbugs.gnu.org id=B63733.168509219912972 (code B ref 63733); Fri, 26 May 2023 09:10:02 +0000 Original-Received: (at 63733) by debbugs.gnu.org; 26 May 2023 09:09:59 +0000 Original-Received: from localhost ([127.0.0.1]:48799 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2TSR-0003NA-7C for submit@debbugs.gnu.org; Fri, 26 May 2023 05:09:59 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60874) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2TSO-0003Mr-QP for 63733@debbugs.gnu.org; Fri, 26 May 2023 05:09:57 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2TSJ-0000q7-8T; Fri, 26 May 2023 05:09:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=Qxgk7O8AMIXjhw+Ott8/0c2TKE4atms/qjOh6HsOwr4=; b=HNZPM8R2B8ZzOMa+Lfxu ZOWf6Kmqq7L0KvyqBjCLIa68FWuvr9D7aHhftgM6kXuRns5fnUttB3Yd8T1rV50enL7an2NnO6ay+ AQ7UR3YcJm+kTEfII8/7BqM5qjgoF+0rHfrZxXfCcHHpeJg80luqhxgT+IGSud00JOlpoSzwadVrs zTHVCi7IOSnheDsxIjCon+DJ7jKPnqOLddgq4TgxjnUCWfFfBG3SIwcnD5mr3FxoDsI1SYcn4gfMJ P7G7b1VCVMeEh6KRTxZru6AhGeoJ1TGkNhkCotbwr4lf02oZjk2qMMNkocOE3w/C2yjJ3e/I/cQrt p8QHICQGqpxwNA==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2TSI-0006qZ-ND; Fri, 26 May 2023 05:09:51 -0400 In-Reply-To: (message from Ulrich =?UTF-8?Q?M=C3=BCller?= on Fri, 26 May 2023 09:43:40 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:262415 Archived-At: > From: Ulrich Müller > Date: Fri, 26 May 2023 09:43:40 +0200 > > Something is strange with option parsing: > > $ emacs -Q -batch -batch --eval '(message "hello, world")' > hello, world > $ emacs -Q --batch --batch --eval '(message "hello, world")' > hello, world > $ emacs -Q -batch --batch --eval '(message "hello, world")' > Debugger entered--Lisp error: (error "Unknown option ‘--batch’") > signal(error ("Unknown option ‘--batch’")) > error("Unknown option `%s'" "--batch") > command-line-1(("--batch" "-Q" "--eval" "(message \"hello, world\")")) > command-line() > normal-top-level() > > $ emacs -Q --batch -batch --eval '(message "hello, world")' > Debugger entered--Lisp error: (error "Unknown option ‘-batch’") > signal(error ("Unknown option ‘-batch’")) > error("Unknown option `%s'" "-batch") > command-line-1(("-batch" "-Q" "--eval" "(message \"hello, world\")")) > command-line() > normal-top-level() > > > I would expect -batch/--batch to be idempotent in all four combinations > above. They are not idempotent. Emacs doesn't use getopt, it uses its own custom code for parsing the command-line options, because our situation is complex: we only process part of the command-line options in C, the rest are processed in Lisp. What happens here is that, when you use identical "-batch" or "--batch" options several times, the code in sort_args removes the identical copies, and we are left with a single option to process. But if you use both "-batch" and "--batch", the extra option is not removed, and they both appear in the sorted argv[]. Then one of them is processed by 'main', the other is left for command-line-1, which doesn't know what to do with it. I'm not sure we want to support this use case. It certainly doesn't make sense to complicate our command-line parsing for its sake. Perhaps if a simple and safe solution can be found for removing such "duplicates" in sort_args, we could install such a change, but definitely not on the emacs-29 release branch. Thanks.