This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Simplify S_parse_body() by calling S_usage() and S_minus_v() directly.
authorNicholas Clark <nick@ccl4.org>
Thu, 24 Nov 2011 21:34:43 +0000 (22:34 +0100)
committerNicholas Clark <nick@ccl4.org>
Sun, 4 Dec 2011 12:01:52 +0000 (13:01 +0100)
Previously the code for "--help" and "--version" set a local variable to a
string corresponding to the single character option ("h" or "v"
respectively), then restarted the option parsing code, which would then call
into Perl_moreswitches(), which would then use a switch statement to
dispatch to the final code.

This is not as clear as it could be.

perl.c

diff --git a/perl.c b/perl.c
index 1219e99..66860ed 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1938,15 +1938,12 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
                argc--,argv++;
                goto switch_end;
            }
-           /* catch use of gnu style long options */
-           if (strEQ(s, "version")) {
-               s = (char *)"v";
-               goto reswitch;
-           }
-           if (strEQ(s, "help")) {
-               s = (char *)"h";
-               goto reswitch;
-           }
+           /* catch use of gnu style long options.
+              Both of these exit immediately.  */
+           if (strEQ(s, "version"))
+               minus_v();
+           if (strEQ(s, "help"))
+               usage();
            s--;
            /* FALL THROUGH */
        default: