~vcs-imports/nano/master

« back to all changes in this revision

Viewing changes to src/nano.c

  • Committer: Benno Schulenberg
  • Author(s): Mateusz Kazimierczuk
  • Date: 2023-07-31 05:40:07 UTC
  • Revision ID: git-v1:e65b0ba6542b03a76fa6fecabdea56c04c2792b5
options: add -? as a synonym of -h (--help)

The short option '-?' was removed nine years ago in commit 43019189,
then restored six years later in 5bd92d4c, and then removed again two
months later in 743100fe due to getopt() returning '?' for options
that aren't recognized, preventing the use of '-?' as a valid option.

However, getopt() provides a way to check for unrecognized options
via the 'optopt' variable, which gets set only for invalid options.

Signed-off-by: Mateusz Kazimierczuk <mataha+savannah@protonmail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>

Show diffs side-by-side

added added

removed removed

Lines of Context:
607
607
#if defined(ENABLE_BROWSER) || defined(ENABLE_HELP)
608
608
        print_opt("-g", "--showcursor", N_("Show cursor in file browser & help text"));
609
609
#endif
610
 
        print_opt("-h", "--help", N_("Show this help text and exit"));
 
610
        print_opt("-h, -?", "--help", N_("Show this help text and exit"));
611
611
#ifndef NANO_TINY
612
612
        print_opt("-i", "--autoindent", N_("Automatically indent new lines"));
613
613
        print_opt("-j", "--jumpyscrolling", N_("Scroll per half-screen, not per line"));
1849
1849
                SET(RESTRICTED);
1850
1850
 
1851
1851
        while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNOPQ:RS$T:UVWX:Y:Z"
1852
 
                                "abcdef:ghijklmno:pqr:s:tuvwxy!%_0", long_options, NULL)) != -1) {
 
1852
                                "abcdef:gh?ijklmno:pqr:s:tuvwxy!%_0", long_options, NULL)) != -1) {
1853
1853
                switch (optchr) {
1854
1854
#ifndef NANO_TINY
1855
1855
                        case 'A':
1999
1999
                                SET(SHOW_CURSOR);
2000
2000
                                break;
2001
2001
#endif
2002
 
                        case 'h':
2003
 
                                usage();
2004
 
                                exit(0);
2005
2002
#ifndef NANO_TINY
2006
2003
                        case 'i':
2007
2004
                                SET(AUTOINDENT);
2098
2095
                                SET(ZERO);
2099
2096
                                break;
2100
2097
#endif
2101
 
                        default:
 
2098
                        case 'h':
 
2099
                        case '?':
 
2100
                                /* If the option is valid, print the help text and exit. */
 
2101
                                if (!optopt) {
 
2102
                                        usage();
 
2103
                                        exit(0);
 
2104
                                }
2102
2105
                                printf(_("Type '%s -h' for a list of available options.\n"), argv[0]);
2103
2106
                                exit(1);
2104
2107
                }