summaryrefslogtreecommitdiff
path: root/lib/rpmatch.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-07-21 22:46:39 +0000
committerJim Meyering <jim@meyering.net>1996-07-21 22:46:39 +0000
commit08ffff561586c8609e429a559d6af938c5094b8f (patch)
tree240003401f432be40e3193ddfebec1331caf7896 /lib/rpmatch.c
parent16efa02b7724c19a0e4a74120c38c690501ae6fd (diff)
downloadcoreutils-08ffff561586c8609e429a559d6af938c5094b8f.tar.xz
[STDC_HEADERS]: Guard inclusion of stdlib.h.
(_) [!_]: Define it. (try): Add RESPONSE parameter. (rpmatch): Update caller. Change the regular expressions to be ^[yY] and ^[nN].
Diffstat (limited to 'lib/rpmatch.c')
-rw-r--r--lib/rpmatch.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/rpmatch.c b/lib/rpmatch.c
index b3fd4a091..a57a0478f 100644
--- a/lib/rpmatch.c
+++ b/lib/rpmatch.c
@@ -20,12 +20,19 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
# include <config.h>
#endif
-#include <stdlib.h>
+#if STDC_HEADERS || _LIBC
+# include <stdlib.h>
+#endif
+
#include <regex.h>
+#ifndef _
+# define _(String) String
+#endif
static int
-try (tag, match, nomatch, lastp, re)
+try (response, pattern, match, nomatch, lastp, re)
+ const char *response;
const char *pattern;
const int match;
const int nomatch;
@@ -47,7 +54,7 @@ try (tag, match, nomatch, lastp, re)
*lastp = pattern;
}
- /* Try the pattern. */
+ /* See if the regular expression matches RESPONSE. */
return regexec (re, response, 0, NULL, 0) == 0 ? match : nomatch;
}
@@ -64,7 +71,8 @@ rpmatch (response)
static regex_t yesre, nore;
int result;
- return ((result = try (_("[yY][[:alpha:]]"), 1, 0, &yesexpr, &yesre))
+ return ((result = try (response, _("^[yY]"), 1, 0,
+ &yesexpr, &yesre))
? result
- : try (_("[nN][[:alpha:]]"), 0, -1, &noexpr, &nore));
+ : try (response, _("^[nN]"), 0, -1, &noexpr, &nore));
}