From f518dbaf46eb28bd39695474de6118683d905e5f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 23 Feb 2012 18:51:51 +0100 Subject: [PATCH] maint: use STREQ/STRNEQ. * doc/bison.texinfo: Space change. * src/system.h (STREQ, STRNEQ): New. * src/files.c, src/ielr.c, src/lalr.c, src/muscle-tab.c, * src/output.c, src/print.c, src/print_graph.c, * src/reader.c, src/scan-skel.l, src/tables.c, * src/uniqstr.c: Use them. * src/scan-gram.l: Do not use streq.h, use system.h's STREQ. * cfg.mk: The documentation is an exception. --- cfg.mk | 5 ++--- doc/bison.texinfo | 2 +- src/files.c | 6 +++--- src/ielr.c | 6 +++--- src/lalr.c | 3 +-- src/muscle-tab.c | 10 +++++----- src/output.c | 2 +- src/print.c | 4 ++-- src/print_graph.c | 2 +- src/reader.c | 2 +- src/scan-gram.l | 3 +-- src/scan-skel.l | 16 ++++++++-------- src/system.h | 3 +++ src/tables.c | 2 +- src/uniqstr.c | 2 +- 15 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cfg.mk b/cfg.mk index 5f8958b0..ce755393 100644 --- a/cfg.mk +++ b/cfg.mk @@ -35,9 +35,7 @@ url_dir_list = \ # Tests not to run as part of "make distcheck". local-checks-to-skip = \ sc_immutable_NEWS \ - sc_prohibit_always_true_header_tests \ - sc_prohibit_atoi_atof \ - sc_prohibit_strcmp + sc_prohibit_atoi_atof # The local directory containing the checked-out copy of gnulib used in # this release. Used solely to get a date for the "announcement" target. @@ -61,6 +59,7 @@ $(call exclude, \ prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \ prohibit_always-defined_macros+=?|^tests/regression.at$$ \ prohibit_empty_lines_at_EOF=^src/parse-gram.h$$ \ + prohibit_strcmp=^doc/bison\.texinfo$$ \ require_config_h_first=^(lib/yyerror|data/(glr|yacc))\.c$$ \ space_tab=^tests/(input|c\+\+)\.at$$ \ unmarked_diagnostics=^djgpp/ \ diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 79dd3311..d24d0c66 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -2569,7 +2569,7 @@ getsym (char const *sym_name) symrec *ptr; for (ptr = sym_table; ptr != (symrec *) 0; ptr = (symrec *)ptr->next) - if (strcmp (ptr->name,sym_name) == 0) + if (strcmp (ptr->name, sym_name) == 0) return ptr; return 0; @} diff --git a/src/files.c b/src/files.c index 208634cd..ceb0489a 100644 --- a/src/files.c +++ b/src/files.c @@ -142,7 +142,7 @@ xfclose (FILE *ptr) static void compute_exts_from_gf (const char *ext) { - if (strcmp (ext, ".y") == 0) + if (STREQ (ext, ".y")) { src_extension = xstrdup (language->src_extension); header_extension = xstrdup (language->header_extension); @@ -347,7 +347,7 @@ void output_file_name_check (char **file_name) { bool conflict = false; - if (0 == strcmp (*file_name, grammar_file)) + if (STREQ (*file_name, grammar_file)) { complain (_("refusing to overwrite the input file %s"), quote (*file_name)); @@ -357,7 +357,7 @@ output_file_name_check (char **file_name) { int i; for (i = 0; i < file_names_count; i++) - if (0 == strcmp (file_names[i], *file_name)) + if (STREQ (file_names[i], *file_name)) { warn (_("conflicting outputs to file %s"), quote (*file_name)); diff --git a/src/ielr.c b/src/ielr.c index cde2baaf..39e9cb66 100644 --- a/src/ielr.c +++ b/src/ielr.c @@ -1095,11 +1095,11 @@ ielr (void) /* Examine user options. */ { char *type = muscle_percent_define_get ("lr.type"); - if (0 == strcmp (type, "lalr")) + if (STREQ (type, "lalr")) lr_type = LR_TYPE__LALR; - else if (0 == strcmp (type, "ielr")) + else if (STREQ (type, "ielr")) lr_type = LR_TYPE__IELR; - else if (0 == strcmp (type, "canonical-lr")) + else if (STREQ (type, "canonical-lr")) lr_type = LR_TYPE__CANONICAL_LR; else aver (false); diff --git a/src/lalr.c b/src/lalr.c index f86bde1c..1ceda002 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -372,8 +372,7 @@ initialize_LA (void) { char *default_reductions = muscle_percent_define_get ("lr.default-reductions"); - default_reduction_only_for_accept = - 0 == strcmp (default_reductions, "accepting"); + default_reduction_only_for_accept = STREQ (default_reductions, "accepting"); free (default_reductions); } diff --git a/src/muscle-tab.c b/src/muscle-tab.c index bc1aa1fc..57050d05 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -50,7 +50,7 @@ hash_compare_muscles (void const *x, void const *y) { muscle_entry const *m1 = x; muscle_entry const *m2 = y; - return strcmp (m1->key, m2->key) == 0; + return STREQ (m1->key, m2->key); } static size_t @@ -407,7 +407,7 @@ muscle_percent_variable_update (char const *variable) }; int i; for (i = 0; i < sizeof conversion / sizeof *conversion; ++i) - if (!strcmp (conversion[i].obsolete, variable)) + if (STREQ (conversion[i].obsolete, variable)) return conversion[i].updated; return variable; } @@ -555,9 +555,9 @@ muscle_percent_define_flag_if (char const *variable) if (muscle_percent_define_ifdef (variable)) { char *value = muscle_percent_define_get (variable); - if (value[0] == '\0' || 0 == strcmp (value, "true")) + if (value[0] == '\0' || STREQ (value, "true")) result = true; - else if (0 == strcmp (value, "false")) + else if (STREQ (value, "false")) result = false; else if (!muscle_find_const (invalid_boolean_name)) { @@ -614,7 +614,7 @@ muscle_percent_define_check_values (char const * const *values) { for (++values; *values; ++values) { - if (0 == strcmp (value, *values)) + if (STREQ (value, *values)) break; } if (!*values) diff --git a/src/output.c b/src/output.c index 64a14c52..08922bc2 100644 --- a/src/output.c +++ b/src/output.c @@ -689,7 +689,7 @@ prepare (void) bool use_push_for_pull_flag = false; if (use_push_for_pull_env != NULL && use_push_for_pull_env[0] != '\0' - && 0 != strcmp (use_push_for_pull_env, "0")) + && STRNEQ (use_push_for_pull_env, "0")) use_push_for_pull_flag = true; /* Flags. */ diff --git a/src/print.c b/src/print.c index 58a9016a..e3795a94 100644 --- a/src/print.c +++ b/src/print.c @@ -336,8 +336,8 @@ print_reductions (FILE *out, state *s) char *default_reductions = muscle_percent_define_get ("lr.default-reductions"); print_reduction (out, width, _("$default"), default_reduction, true); - aver (0 == strcmp (default_reductions, "most") - || (0 == strcmp (default_reductions, "consistent") + aver (STREQ (default_reductions, "most") + || (STREQ (default_reductions, "consistent") && default_reduction_only) || (reds->num == 1 && reds->rules[0]->number == 0)); free (default_reductions); diff --git a/src/print_graph.c b/src/print_graph.c index 8dd8db43..61d36512 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -133,7 +133,7 @@ print_actions (state const *s, FILE *fgraph) : "dashed"); if (TRANSITION_IS_ERROR (trans, i) - && strcmp (symbols[sym]->tag, "error") != 0) + && STRNEQ (symbols[sym]->tag, "error")) abort (); output_edge (s->number, s1->number, TRANSITION_IS_ERROR (trans, i) ? NULL : symbols[sym]->tag, diff --git a/src/reader.c b/src/reader.c index 85f686ef..2e0aa5ee 100644 --- a/src/reader.c +++ b/src/reader.c @@ -638,7 +638,7 @@ prepare_percent_define_front_end_variables (void) default. */ muscle_percent_define_default ("lr.type", "lalr"); lr_type = muscle_percent_define_get ("lr.type"); - if (0 != strcmp (lr_type, "canonical-lr")) + if (STRNEQ (lr_type, "canonical-lr")) muscle_percent_define_default ("lr.default-reductions", "most"); else muscle_percent_define_default ("lr.default-reductions", "accepting"); diff --git a/src/scan-gram.l b/src/scan-gram.l index e2e08f9a..fa200d64 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -39,7 +39,6 @@ #include #include #include -#include #include @@ -968,7 +967,7 @@ unexpected_end (boundary start, char const *msgid, char const *token_end) loc.end = scanner_cursor; token_end = quote (token_end); // Instead of '\'', display "'". - if (STREQ (token_end, "'\\''", '\'', '\\', '\'', '\'', 0,0,0,0,0)) + if (STREQ (token_end, "'\\''")) token_end = "\"'\""; complain_at (loc, _(msgid), token_end); } diff --git a/src/scan-skel.l b/src/scan-skel.l index 33c264a1..e15294a1 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -179,15 +179,15 @@ at_directive_perform (int at_directive_argc, char *at_directive_argv[], char **outnamep, int *out_linenop) { - if (0 == strcmp (at_directive_argv[0], "@basename")) + if (STREQ (at_directive_argv[0], "@basename")) { if (at_directive_argc > 2) fail_for_at_directive_too_many_args (at_directive_argv[0]); fputs (last_component (at_directive_argv[1]), yyout); } - else if (0 == strcmp (at_directive_argv[0], "@warn") - || 0 == strcmp (at_directive_argv[0], "@complain") - || 0 == strcmp (at_directive_argv[0], "@fatal")) + else if (STREQ (at_directive_argv[0], "@warn") + || STREQ (at_directive_argv[0], "@complain") + || STREQ (at_directive_argv[0], "@fatal")) { void (*func)(char const *, ...); switch (at_directive_argv[0][1]) @@ -223,9 +223,9 @@ at_directive_perform (int at_directive_argc, break; } } - else if (0 == strcmp (at_directive_argv[0], "@warn_at") - || 0 == strcmp (at_directive_argv[0], "@complain_at") - || 0 == strcmp (at_directive_argv[0], "@fatal_at")) + else if (STREQ (at_directive_argv[0], "@warn_at") + || STREQ (at_directive_argv[0], "@complain_at") + || STREQ (at_directive_argv[0], "@fatal_at")) { void (*func)(location, char const *, ...); location loc; @@ -266,7 +266,7 @@ at_directive_perform (int at_directive_argc, break; } } - else if (0 == strcmp (at_directive_argv[0], "@output")) + else if (STREQ (at_directive_argv[0], "@output")) { if (at_directive_argc > 2) fail_for_at_directive_too_many_args (at_directive_argv[0]); diff --git a/src/system.h b/src/system.h index 24151bba..7aa2c9fa 100644 --- a/src/system.h +++ b/src/system.h @@ -39,6 +39,9 @@ #include #include +#define STREQ(L, R) (strcmp(L, R) == 0) +#define STRNEQ(L, R) (!STREQ(L, R)) + #if HAVE_SYS_TYPES_H # include #endif diff --git a/src/tables.c b/src/tables.c index f22ec9aa..96354b1a 100644 --- a/src/tables.c +++ b/src/tables.c @@ -309,7 +309,7 @@ action_row (state *s) { char *default_reductions = muscle_percent_define_get ("lr.default-reductions"); - if (0 != strcmp (default_reductions, "most") && !s->consistent) + if (STRNEQ (default_reductions, "most") && !s->consistent) nodefault = true; free (default_reductions); } diff --git a/src/uniqstr.c b/src/uniqstr.c index 7b2bb205..f2954443 100644 --- a/src/uniqstr.c +++ b/src/uniqstr.c @@ -111,7 +111,7 @@ uniqstr_print_processor (void *ustr, void *null ATTRIBUTE_UNUSED) static bool hash_compare_uniqstr (void const *m1, void const *m2) { - return strcmp (m1, m2) == 0; + return STREQ (m1, m2); } static size_t -- 2.47.2