patchGNU nano - Patches: patch #10374, options: add -? as a synonym of -h...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #10374: options: add -? as a synonym of -h (--help)

Submitter:  mataha <mataha>
Submitted:  Thu 27 Jul 2023 12:26:22 AM UTC
   
 
Priority:  3 - Low Status:  Wont Do
Privacy:  Public Assigned to:  bens
Open/Closed:  Closed Release:  None

Mon 18 Mar 2024 09:18:05 AM UTC, comment #5: 

The change was reverted because of the unwanted effect for the ambiguous options --back and --word:

  https://git.savannah.gnu.org/cgit/nano.git/commit/?id=75b312de

Benno Schulenberg <bens>
Group administrator
Thu 03 Aug 2023 07:55:42 AM UTC, comment #4: 

Oh darn.  Getopt_long() should have put just something into optopt -- probably  the 'val' corresponding to the first possible match, or otherwise -1.

One could replace 'if (!optopt)' with

if (optchr == 'h' || strstr(argv[1], "-?"))

but that accepts '-?' only when it's the first option, unlike '-h'.

Benno Schulenberg <bens>
Group administrator
Tue 01 Aug 2023 04:26:30 PM UTC, comment #3: 

Apologies for the late reply.

comment #1:

> Thanks for the patch.  That works nicely.  Are you okay with the attached, somewhat modified version of the patch?
>
> (file #54990)


I would... though I've noticed an issue. Consider the following command:

    nano --ba

Because '--ba' is a valid abbreviation, getopt_long() will return '?' and set 'optopt' to 0[1], resulting in printing the help text when usage string should be shown instead (as '--ba' is ambiguous).

The worst part is I can't think of any easy way out; all my ideas involve reparsing 'argv' which is hardly elegant and prone to bugs...

[1]: https://www.gnu.org/software/libc/manual/html_node/Getopt-Long-Options.html

mataha <mataha>
Mon 31 Jul 2023 05:46:22 AM UTC, comment #2: 

A slightly more modified patch has been pushed to master, commit e65b0ba6.  Thanks.

Benno Schulenberg <bens>
Group administrator
Fri 28 Jul 2023 09:22:19 AM UTC, comment #1: 

Thanks for the patch.  That works nicely.  Are you okay with the attached, somewhat modified version of the patch?

(file #54990)

Benno Schulenberg <bens>
Group administrator
Thu 27 Jul 2023 12:26:22 AM UTC, original submission:  

That option was restored in 5bd92d4c (previously deleted in 43019189) and later removed in 743100fe due to getopt() returning '?' for options that were not recognized, preventing the use of '-?' as a valid option. However, getopt() provides a way to check for unrecognized options via the optopt variable, solving this problem in one if-statement away.

mataha <mataha>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #54975:  0001-options-add-as-a-synonym-of-h-help.patch added by mataha (3KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Updated the item)
  • -email is unavailable- added by mataha (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-18 bens StatusDone Wont Do
        Open/ClosedOpen Closed
    2023-07-31 bens StatusIn Progress Done
    2023-07-28 bens Attached File- Added 0001-options-add-as-a-synonym-of-h-help.patch, #54990
        StatusNone In Progress
        Assigned toNone bens
    2023-07-27 mataha Attached File- Added 0001-options-add-as-a-synonym-of-h-help.patch, #54975

    Back to the top

    Powered by Savane 3.14-31c1.
    Corresponding source code