Jim Meyering wrote:
> Akim Demaille wrote:
>
>> Also, FWIW, in Bison there are many more strcmp, but they do not
>> conform to the sc pattern.
>>
>> src/ielr.c:    if (0 == strcmp (type, "lalr"))
>> src/ielr.c:    else if (0 == strcmp (type, "ielr"))
>> src/ielr.c:    else if (0 == strcmp (type, "canonical-lr"))
>
> How about this?
>
> diff --git a/top/maint.mk b/top/maint.mk
> index 1dd6493..2841773 100644
> --- a/top/maint.mk
> +++ b/top/maint.mk
> @@ -303,8 +303,10 @@ sc_prohibit_atoi_atof:
>         $(_sc_search_regexp)
>
>  # Use STREQ rather than comparing strcmp == 0, or != 0.
> +s_ = str''cmp
> +sp_ = $(s_) *\(.+\)
>  sc_prohibit_strcmp:
> -     @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]='   \
> +     @grep -nE '! *$(s_) *\(|\<$(sp_) *[!=]=|[!=]= *$(sp_)'          \
>           $$($(VC_LIST_EXCEPT))                                       \
>         | grep -vE ':# *define STRN?EQ\(' &&                          \
>         { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \

Here's a complete patch, with the additional tweak of replacing
the other occurrence of str''cmp with $(s_).

If Bruno opts to rename the STREQ macro in streq.h, then it would be
superfluous to include the actual STREQ definition in this diagnostic.

>From e51eecc1f8374e6d86f50eba17716e82f8286478 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@redhat.com>
Date: Fri, 24 Feb 2012 09:45:54 +0100
Subject: [PATCH] maint.mk: tell sc_prohibit_strcmp to ding "0 == strcmp
 (...)", too

* top/maint.mk (sc_prohibit_strcmp): Also prohibit uses of strcmp
uses with "==" *before* the call, e.g., 0 == strcmp (...)
Suggested by Akim Demaille.
---
 ChangeLog    |    7 +++++++
 top/maint.mk |    6 ++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 444422e..0a1f0d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-02-24  Jim Meyering  <meyer...@redhat.com>
+
+       maint.mk: tell sc_prohibit_strcmp to ding "0 == strcmp (...)", too
+       * top/maint.mk (sc_prohibit_strcmp): Also prohibit uses of strcmp
+       uses with "==" *before* the call, e.g., 0 == strcmp (...)
+       Suggested by Akim Demaille.
+
 2012-02-20  Paul Eggert  <egg...@cs.ucla.edu>

        regex: fix typo in definition of MIN
diff --git a/top/maint.mk b/top/maint.mk
index 1dd6493..50d8f9e 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -303,11 +303,13 @@ sc_prohibit_atoi_atof:
          $(_sc_search_regexp)

 # Use STREQ rather than comparing strcmp == 0, or != 0.
+s_ = str''cmp
+sp_ = $(s_) *\(.+\)
 sc_prohibit_strcmp:
-       @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]='   \
+       @grep -nE '! *$(s_) *\(|\<$(sp_) *[!=]=|[!=]= *$(sp_)'          \
            $$($(VC_LIST_EXCEPT))                                       \
          | grep -vE ':# *define STRN?EQ\(' &&                          \
-         { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \
+         { echo '$(ME): replace $(s_) calls above with STREQ/STRNEQ'   \
                1>&2; exit 1; } || :

 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
--
1.7.9.2.235.g1d0cd

Reply via email to