bug-gnulib
[Top][All Lists]
Advanced

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

Re: maint: avoid usage(1)


From: Eric Blake
Subject: Re: maint: avoid usage(1)
Date: Thu, 29 Oct 2009 07:31:03 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Jim Meyering on 10/29/2009 6:50 AM:
> Eric Blake wrote:
>> I noticed this during my audit for stderr vs. exec.  We've made previous
>> cleanups along these lines, but usages have crept back in.  OK to commit?
> ...
>> Subject: [PATCH] maint: avoid exiting with magic number
>>
>> * cfg.mk (sc_prohibit_magic_number_exit)
>> (sc_prohibit_error_success): New rules.
>>
>> +# Pass EXIT_*, not number, to usage, exit, and error
>> +sc_prohibit_magic_number_exit:
>> +    @re='\<(usage|exit) \([0-9]|\<error \([1-9][0-9]*,'             \
> 
> Please allow 0 or one space between the function name
> and the opening parenthesis, so this rule will also be useful
> to projects with different code formatting conventions.

But many other rules in maint.mk are hardcoded to require the space.
Well, that can be a later cleanup, if we want it.

> 
>> +    msg='use EXIT_* values rather than magic number'                \
>> +      $(_prohibit_regexp)
>> +
>> +# error (0) is preferred over error (EXIT_SUCCESS), since it does not exit
>> +sc_prohibit_error_success:
>> +    @re='\<error \(EXIT_SUCCESS,'                                   \
> 
> same here
> 
>> +    msg='use error(0) rather than error(EXIT_SUCCESS)'              \
> 
> which means you'll want to obfuscate the above, e.g., to
> 
>       msg='use error''(0) rather than error(EXIT_SUCCESS)'            \
> 
> These seem generally useful enough for gnulib's maint.mk.

Done as follows.  I should have looked there first; sc_error_exit_success
already existed, so only sc_prohibit_magic_number_exit is new.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrpmRcACgkQ84KuGfSFAYCE1gCguGvurqkjUUpd3c8911J3hsOI
PacAoIWjpeZu6y54+6aqboftUiYvZ29d
=doEj
-----END PGP SIGNATURE-----
>From 975243c9fb21ec51e9cc59db68626a800be78abd Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 07:29:26 -0600
Subject: [PATCH] maint: detect usage(1) and other suspicious exits

* top/maint.mk (sc_prohibit_magic_number_exit): New rule.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog    |    5 +++++
 top/maint.mk |    6 ++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b2073ee..b0c83b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-29  Eric Blake  <address@hidden>
+
+       maint: detect usage(1) and other suspicious exits
+       * top/maint.mk (sc_prohibit_magic_number_exit): New rule.
+
 2009-10-29  Jim Meyering  <address@hidden>

        timespec: long-to-int truncation could make timespec_cmp malfunction
diff --git a/top/maint.mk b/top/maint.mk
index 68bd8f9..996344a 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -156,6 +156,12 @@ sc_prohibit_strcmp:
          { echo '$(ME): use STREQ in place of the above uses of str''cmp' \
                1>&2; exit 1; } || :

+# Pass EXIT_*, not number, to usage, exit, and error (when exiting)
+sc_prohibit_magic_number_exit:
+       @re='\<(usage|exit) ?\([0-9]|\<error ?\([1-9][0-9]*,'           \
+       msg='use EXIT_* values rather than magic number'                \
+         $(_prohibit_regexp)
+
 # Using EXIT_SUCCESS as the first argument to error is misleading,
 # since when that parameter is 0, error does not exit.  Use `0' instead.
 sc_error_exit_success:
-- 
1.6.5.rc1


reply via email to

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