annotate lib/rpmatch.c @ 17361:8c32877a40e6

copy-file, rpmatch: fix problems found by cppcheck Reported by Arno Onken in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00069.html>. * lib/rpmatch.c (try): Fix memory leak. * lib/copy-file.c: Include "ignore-value.h". (qcopy_file_preserving): Ignore chown value. * modules/copy-file (Depends-on): Add ignore-value.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:30:58 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
882
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
1 /* Determine whether string value is affirmation or negative response
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
2 according to current locale's data.
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
3
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
4 Copyright (C) 1996, 1998, 2000, 2002-2003, 2006-2013 Free Software
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
5 Foundation, Inc.
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
6
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
7 This program is free software: you can redistribute it and/or modify
882
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
8 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
10 (at your option) any later version.
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11
882
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
12 This program is distributed in the hope that it will be useful,
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
15 GNU General Public License for more details.
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
16
882
43308e6073b6 libitize
Jim Meyering <jim@meyering.net>
parents: 722
diff changeset
17 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
19
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
20 #include <config.h>
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
21
10001
facc928673d7 Declare rpmatch.
Bruno Haible <bruno@clisp.org>
parents: 10000
diff changeset
22 /* Specification. */
facc928673d7 Declare rpmatch.
Bruno Haible <bruno@clisp.org>
parents: 10000
diff changeset
23 #include <stdlib.h>
facc928673d7 Declare rpmatch.
Bruno Haible <bruno@clisp.org>
parents: 10000
diff changeset
24
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
25 #include <stdbool.h>
4333
fcd34d3861a4 in lib:
Paul Eggert <eggert@cs.ucla.edu>
parents: 3966
diff changeset
26 #include <stddef.h>
665
724b81f1f93a [STDC_HEADERS]: Guard inclusion of stdlib.h.
Jim Meyering <jim@meyering.net>
parents: 662
diff changeset
27
681
c952aa1385fd (ENABLE_NLS): Include libintl.h and define _ to gettext.
Jim Meyering <jim@meyering.net>
parents: 667
diff changeset
28 #if ENABLE_NLS
1558
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
29 # include <sys/types.h>
4333
fcd34d3861a4 in lib:
Paul Eggert <eggert@cs.ucla.edu>
parents: 3966
diff changeset
30 # include <limits.h>
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
31 # include <string.h>
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
32 # if HAVE_LANGINFO_YESEXPR
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
33 # include <langinfo.h>
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
34 # endif
1558
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
35 # include <regex.h>
3966
22d3032f0239 Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents: 2444
diff changeset
36 # include "gettext.h"
22d3032f0239 Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents: 2444
diff changeset
37 # define _(msgid) gettext (msgid)
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
38 # define N_(msgid) gettext_noop (msgid)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
39
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
40 # if HAVE_LANGINFO_YESEXPR
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
41 /* Return the localized regular expression pattern corresponding to
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
42 ENGLISH_PATTERN. NL_INDEX can be used with nl_langinfo.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
43 The resulting string may only be used until the next nl_langinfo call. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
44 static const char *
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
45 localized_pattern (const char *english_pattern, nl_item nl_index,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
46 bool posixly_correct)
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
47 {
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
48 const char *translated_pattern;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
49
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
50 /* We prefer to get the patterns from a PO file. It would be possible to
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
51 always use nl_langinfo (YESEXPR) instead of _("^[yY]"), and
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
52 nl_langinfo (NOEXPR) instead of _("^[nN]"), if we could assume that the
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
53 system's locale support is good. But this is not the case e.g. on Cygwin.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
54 The localizations of gnulib.pot are of better quality in general.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
55 Also, if we use locale info from non-free systems that don't have a
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
56 'localedef' command, we deprive the users of the freedom to localize
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
57 this pattern for their preferred language.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
58 But some programs, such as 'cp', 'mv', 'rm', 'find', 'xargs', are
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
59 specified by POSIX to use nl_langinfo (YESEXPR). We implement this
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
60 behaviour if POSIXLY_CORRECT is set, for the sake of these programs. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
61
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
62 /* If the user wants strict POSIX compliance, use nl_langinfo. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
63 if (posixly_correct)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
64 {
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
65 translated_pattern = nl_langinfo (nl_index);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
66 /* Check against a broken system return value. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
67 if (translated_pattern != NULL && translated_pattern[0] != '\0')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
68 return translated_pattern;
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
69 }
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
70
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
71 /* Look in the gnulib message catalog. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
72 translated_pattern = _(english_pattern);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
73 if (translated_pattern == english_pattern)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
74 {
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
75 /* The gnulib message catalog provides no translation.
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
76 Try the system's message catalog. */
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
77 translated_pattern = nl_langinfo (nl_index);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
78 /* Check against a broken system return value. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
79 if (translated_pattern != NULL && translated_pattern[0] != '\0')
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
80 return translated_pattern;
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
81 /* Fall back to English. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
82 translated_pattern = english_pattern;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
83 }
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
84 return translated_pattern;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
85 }
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
86 # else
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
87 # define localized_pattern(english_pattern,nl_index,posixly_correct) \
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
88 _(english_pattern)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
89 # endif
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
90
Jim Meyering <jim@meyering.net>
parents:
diff changeset
91 static int
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
92 try (const char *response, const char *pattern, char **lastp, regex_t *re)
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
93 {
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
94 if (*lastp == NULL || strcmp (pattern, *lastp) != 0)
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
95 {
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
96 char *safe_pattern;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
97
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
98 /* The pattern has changed. */
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
99 if (*lastp != NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
100 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
101 /* Free the old compiled pattern. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
102 regfree (re);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
103 free (*lastp);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
104 *lastp = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
105 }
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
106 /* Put the PATTERN into safe memory before calling regcomp.
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
107 (regcomp may call nl_langinfo, overwriting PATTERN's storage. */
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
108 safe_pattern = strdup (pattern);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
109 if (safe_pattern == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
110 return -1;
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
111 /* Compile the pattern and cache it for future runs. */
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
112 if (regcomp (re, safe_pattern, REG_EXTENDED) != 0)
17361
8c32877a40e6 copy-file, rpmatch: fix problems found by cppcheck
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
113 {
8c32877a40e6 copy-file, rpmatch: fix problems found by cppcheck
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
114 free (safe_pattern);
8c32877a40e6 copy-file, rpmatch: fix problems found by cppcheck
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
115 return -1;
8c32877a40e6 copy-file, rpmatch: fix problems found by cppcheck
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
116 }
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
117 *lastp = safe_pattern;
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
118 }
Jim Meyering <jim@meyering.net>
parents:
diff changeset
119
665
724b81f1f93a [STDC_HEADERS]: Guard inclusion of stdlib.h.
Jim Meyering <jim@meyering.net>
parents: 662
diff changeset
120 /* See if the regular expression matches RESPONSE. */
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
121 return regexec (re, response, 0, NULL, 0) == 0;
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
122 }
1558
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
123 #endif
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
124
Jim Meyering <jim@meyering.net>
parents:
diff changeset
125
Jim Meyering <jim@meyering.net>
parents:
diff changeset
126 int
1557
38fd8f5d359d ansideclify
Jim Meyering <jim@meyering.net>
parents: 1417
diff changeset
127 rpmatch (const char *response)
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
128 {
1558
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
129 #if ENABLE_NLS
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
130 /* Match against one of the response patterns, compiling the pattern
Jim Meyering <jim@meyering.net>
parents:
diff changeset
131 first if necessary. */
Jim Meyering <jim@meyering.net>
parents:
diff changeset
132
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
133 /* We cache the response patterns and compiled regexps here. */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
134 static char *last_yesexpr, *last_noexpr;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
135 static regex_t cached_yesre, cached_nore;
9989
2bff2d33e74d Add some comments.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
136
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
137 # if HAVE_LANGINFO_YESEXPR
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
138 bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
139 # endif
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
140
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
141 const char *yesexpr, *noexpr;
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
142 int result;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
143
10000
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
144 /* TRANSLATORS: A regular expression testing for an affirmative answer
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
145 (english: "yes"). Testing the first character may be sufficient.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
146 Take care to consider upper and lower case.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
147 To enquire the regular expression that your system uses for this
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
148 purpose, you can use the command
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
149 locale -k LC_MESSAGES | grep '^yesexpr=' */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
150 yesexpr = localized_pattern (N_("^[yY]"), YESEXPR, posixly_correct);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
151 result = try (response, yesexpr, &last_yesexpr, &cached_yesre);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
152 if (result < 0)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
153 return -1;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
154 if (result)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
155 return 1;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
156
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
157 /* TRANSLATORS: A regular expression testing for a negative answer
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
158 (english: "no"). Testing the first character may be sufficient.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
159 Take care to consider upper and lower case.
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
160 To enquire the regular expression that your system uses for this
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
161 purpose, you can use the command
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
162 locale -k LC_MESSAGES | grep '^noexpr=' */
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
163 noexpr = localized_pattern (N_("^[nN]"), NOEXPR, posixly_correct);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
164 result = try (response, noexpr, &last_noexpr, &cached_nore);
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
165 if (result < 0)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
166 return -1;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
167 if (result)
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
168 return 0;
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
169
8095c13f76df Change rpmatch to use nl_langinfo when appropriate.
Bruno Haible <bruno@clisp.org>
parents: 9989
diff changeset
170 return -1;
1558
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
171 #else
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
172 /* Test against "^[yY]" and "^[nN]", hardcoded to avoid requiring regex */
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
173 return (*response == 'y' || *response == 'Y' ? 1
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10001
diff changeset
174 : *response == 'n' || *response == 'N' ? 0 : -1);
1558
db3dc1c514e1 (rpmatch) [!ENABLE_NLS]: Hard-code tests to use `^[yY]' and `^[nN]'.
Jim Meyering <jim@meyering.net>
parents: 1557
diff changeset
175 #endif
662
Jim Meyering <jim@meyering.net>
parents:
diff changeset
176 }