bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk error status problem


From: Aharon Robbins
Subject: Re: gawk error status problem
Date: Tue, 06 Oct 2009 21:11:22 +0200

Hi Ulrich.

> Date: Mon, 21 Sep 2009 19:55:04 -0700
> From: Ulrich Drepper <address@hidden>
> To: Aharon Robbins <address@hidden>
> Subject: gawk error status problem
>
> One test suite I used recently complained about this:
>
> $ echo '{ print $0}' > f
> $ echo hello | gawk -f f -v; echo $?
> gawk: option requires an argument -- v
> hello
> 0
>
> Since there was an error during the awk run the exit status should be
> >0.  I tested it with version 3.1.6a.
>
> Thanks,
>
> - --
>  Ulrich Drepper  Red Hat, Inc. 444 Castro St  Mountain View, CA 

Here's the patch.

Tue Oct  6 21:07:23 2009  Arnold D. Robbins  <address@hidden>

        * main.c (main): When an option requires an argument and we print a
        message, call `usage' and exit.

        Fix all calls to `usage' to use EXIT_FAILURE and EXIT_SUCCESS
        instead of 1 and 0.

Index: main.c
===================================================================
RCS file: /d/mongo/cvsrep/gawk-stable/main.c,v
retrieving revision 1.25
diff -u -r1.25 main.c
--- main.c      4 Oct 2009 19:51:25 -0000       1.25
+++ main.c      6 Oct 2009 19:09:29 -0000
@@ -313,7 +313,7 @@
                version_string += 4;
 
        if (argc < 2)
-               usage(1, stderr);
+               usage(EXIT_FAILURE, stderr);
 
        /* Robustness: check that file descriptors 0, 1, 2 are open */
        init_fds();
@@ -435,7 +435,7 @@
                        break;
 
                case 'u':
-                       usage(0, stdout);       /* per coding stds */
+                       usage(EXIT_SUCCESS, stdout);    /* per coding stds */
                        break;
 
                case 'V':
@@ -480,11 +480,13 @@
                                optind = old_optind;
                                stopped_early = TRUE;
                                goto out;
-                       } else if (optopt != '\0')
+                       } else if (optopt != '\0') {
                                /* Use 1003.2 required message format */
                                fprintf(stderr,
                                        _("%s: option requires an argument -- 
%c\n"),
                                        myname, optopt);
+                               usage(EXIT_FAILURE, stderr);
+                       }
                        /* else
                                let getopt print error message for us */
                        break;
@@ -580,7 +582,7 @@
        /* No -f or --source options, use next arg */
        if (numfiles == -1) {
                if (optind > argc - 1 || stopped_early) /* no args left or no 
program */
-                       usage(1, stderr);
+                       usage(EXIT_FAILURE, stderr);
                srcfiles_add(CMDLINE, argv[optind]);
                optind++;
        }
@@ -1117,7 +1119,7 @@
                fprintf(stderr,
                        _("%s: `%s' argument to `-v' not in `var=value' 
form\n\n"),
                        myname, arg);
-               usage(1, stderr);
+               usage(EXIT_FAILURE, stderr);
        }
 
        *cp++ = '\0';




reply via email to

[Prev in Thread] Current Thread [Next in Thread]