mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 18:23:03 +00:00
avoid direct strncmp calls.
Before this change, bison would accept either .tab and _tab equivalently,
whatever the current platform. Besides, it was not obeying everywhere
to the possible definition of TAB_EXT to something else than .tab.
For consistency, handle only TAB_EXT (".tab" on non DJGPP platforms).
Support for "_tab" is neither documented, nor tested.
* src/system.h (STRNCMP_LIT): New.
From Jim Meyering.
(STRPREFIX_LIT): New.
* src/files.c, src/getargs.c: Use it.
This commit is contained in:
@@ -215,10 +215,9 @@ file_name_split (const char *file_name,
|
|||||||
if (*ext)
|
if (*ext)
|
||||||
{
|
{
|
||||||
size_t baselen = *ext - *base;
|
size_t baselen = *ext - *base;
|
||||||
size_t dottablen = 4;
|
size_t dottablen = sizeof (TAB_EXT) - 1;
|
||||||
if (dottablen < baselen
|
if (dottablen < baselen
|
||||||
&& (strncmp (*ext - dottablen, ".tab", dottablen) == 0
|
&& STRPREFIX_LIT (TAB_EXT, *ext - dottablen))
|
||||||
|| strncmp (*ext - dottablen, "_tab", dottablen) == 0))
|
|
||||||
*tab = *ext - dottablen;
|
*tab = *ext - dottablen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ flags_argmatch (const char *option,
|
|||||||
args = strtok (args, ",");
|
args = strtok (args, ",");
|
||||||
while (args)
|
while (args)
|
||||||
{
|
{
|
||||||
int no = strncmp (args, "no-", 3) == 0 ? 3 : 0;
|
int no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
|
||||||
int value = XARGMATCH (option, args + no, keys, values);
|
int value = XARGMATCH (option, args + no, keys, values);
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,6 +42,15 @@
|
|||||||
#define STREQ(L, R) (strcmp(L, R) == 0)
|
#define STREQ(L, R) (strcmp(L, R) == 0)
|
||||||
#define STRNEQ(L, R) (!STREQ(L, R))
|
#define STRNEQ(L, R) (!STREQ(L, R))
|
||||||
|
|
||||||
|
/* Just like strncmp, but the second argument must be a literal string
|
||||||
|
and you don't specify the length. */
|
||||||
|
#define STRNCMP_LIT(S, Literal) \
|
||||||
|
strncmp (S, "" Literal "", sizeof (Literal) - 1)
|
||||||
|
|
||||||
|
/* Whether Literal is a prefix of S. */
|
||||||
|
#define STRPREFIX_LIT(Literal, S) \
|
||||||
|
(STRNCMP_LIT (S, Literal) == 0)
|
||||||
|
|
||||||
#if HAVE_SYS_TYPES_H
|
#if HAVE_SYS_TYPES_H
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user