/* Determine whether string value is affirmation or negative response
according to current locale's data.
- Copyright (C) 1996, 1998, 2000, 2002, 2003, 2006-2008 Free Software
+ Copyright (C) 1996, 1998, 2000, 2002-2003, 2006-2013 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify
#include <config.h>
+/* Specification. */
+#include <stdlib.h>
+
#include <stdbool.h>
#include <stddef.h>
-#include <stdlib.h>
#if ENABLE_NLS
# include <sys/types.h>
The resulting string may only be used until the next nl_langinfo call. */
static const char *
localized_pattern (const char *english_pattern, nl_item nl_index,
- bool posixly_correct)
+ bool posixly_correct)
{
const char *translated_pattern;
translated_pattern = nl_langinfo (nl_index);
/* Check against a broken system return value. */
if (translated_pattern != NULL && translated_pattern[0] != '\0')
- return translated_pattern;
+ return translated_pattern;
}
/* Look in the gnulib message catalog. */
if (translated_pattern == english_pattern)
{
/* The gnulib message catalog provides no translation.
- Try the system's message catalog. */
+ Try the system's message catalog. */
translated_pattern = nl_langinfo (nl_index);
/* Check against a broken system return value. */
if (translated_pattern != NULL && translated_pattern[0] != '\0')
- return translated_pattern;
+ return translated_pattern;
/* Fall back to English. */
translated_pattern = english_pattern;
}
/* The pattern has changed. */
if (*lastp != NULL)
- {
- /* Free the old compiled pattern. */
- regfree (re);
- free (*lastp);
- *lastp = NULL;
- }
+ {
+ /* Free the old compiled pattern. */
+ regfree (re);
+ free (*lastp);
+ *lastp = NULL;
+ }
/* Put the PATTERN into safe memory before calling regcomp.
- (regcomp may call nl_langinfo, overwriting PATTERN's storage. */
+ (regcomp may call nl_langinfo, overwriting PATTERN's storage. */
safe_pattern = strdup (pattern);
if (safe_pattern == NULL)
- return -1;
+ return -1;
/* Compile the pattern and cache it for future runs. */
if (regcomp (re, safe_pattern, REG_EXTENDED) != 0)
- return -1;
+ {
+ free (safe_pattern);
+ return -1;
+ }
*lastp = safe_pattern;
}
#endif
-/* Test a user response to a question.
- Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
-
int
rpmatch (const char *response)
{
#else
/* Test against "^[yY]" and "^[nN]", hardcoded to avoid requiring regex */
return (*response == 'y' || *response == 'Y' ? 1
- : *response == 'n' || *response == 'N' ? 0 : -1);
+ : *response == 'n' || *response == 'N' ? 0 : -1);
#endif
}