3 <<rpmatch>>---determine whether response to question is affirmative or negative
10 int rpmatch(const char *<[response]>);
13 The <<rpmatch>> function determines whether <[response]> is an affirmative
14 or negative response to a question according to the current locale.
17 <<rpmatch>> returns 1 if <[response]> is affirmative, 0 if negative, or -1
18 if not recognized as either.
21 <<rpmatch>> is a BSD extension also found in glibc.
24 No supporting OS subroutines are required.
27 /* This code is originally taken from FreeBSD. */
29 * Copyright (c) 2004-2005 Tim J. Robbins.
30 * All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 #include <sys/cdefs.h>
55 #include <sys/types.h>
62 rpmatch (const char *response
)
67 if (regcomp(&yes
, nl_langinfo(YESEXPR
), REG_EXTENDED
|REG_NOSUB
) != 0)
69 if (regcomp(&no
, nl_langinfo(NOEXPR
), REG_EXTENDED
|REG_NOSUB
) != 0) {
73 if (regexec(&yes
, response
, 0, NULL
, 0) == 0)
75 else if (regexec(&no
, response
, 0, NULL
, 0) == 0)