117ebe400STim J. Robbins /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3d915a14eSPedro F. Giffuni *
417ebe400STim J. Robbins * Copyright (c) 2004-2005 Tim J. Robbins.
517ebe400STim J. Robbins * All rights reserved.
617ebe400STim J. Robbins *
717ebe400STim J. Robbins * Redistribution and use in source and binary forms, with or without
817ebe400STim J. Robbins * modification, are permitted provided that the following conditions
917ebe400STim J. Robbins * are met:
1017ebe400STim J. Robbins * 1. Redistributions of source code must retain the above copyright
1117ebe400STim J. Robbins * notice, this list of conditions and the following disclaimer.
1217ebe400STim J. Robbins * 2. Redistributions in binary form must reproduce the above copyright
1317ebe400STim J. Robbins * notice, this list of conditions and the following disclaimer in the
1417ebe400STim J. Robbins * documentation and/or other materials provided with the distribution.
1517ebe400STim J. Robbins *
1617ebe400STim J. Robbins * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1717ebe400STim J. Robbins * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1817ebe400STim J. Robbins * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1917ebe400STim J. Robbins * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2017ebe400STim J. Robbins * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2117ebe400STim J. Robbins * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2217ebe400STim J. Robbins * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2317ebe400STim J. Robbins * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2417ebe400STim J. Robbins * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2517ebe400STim J. Robbins * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2617ebe400STim J. Robbins * SUCH DAMAGE.
2717ebe400STim J. Robbins */
2817ebe400STim J. Robbins
2917ebe400STim J. Robbins #include <langinfo.h>
3017ebe400STim J. Robbins #include <regex.h>
3117ebe400STim J. Robbins #include <stdlib.h>
3217ebe400STim J. Robbins
3317ebe400STim J. Robbins int
rpmatch(const char * response)3417ebe400STim J. Robbins rpmatch(const char *response)
3517ebe400STim J. Robbins {
3617ebe400STim J. Robbins regex_t yes, no;
3717ebe400STim J. Robbins int ret;
3817ebe400STim J. Robbins
3917ebe400STim J. Robbins if (regcomp(&yes, nl_langinfo(YESEXPR), REG_EXTENDED|REG_NOSUB) != 0)
4017ebe400STim J. Robbins return (-1);
4117ebe400STim J. Robbins if (regcomp(&no, nl_langinfo(NOEXPR), REG_EXTENDED|REG_NOSUB) != 0) {
4217ebe400STim J. Robbins regfree(&yes);
4317ebe400STim J. Robbins return (-1);
4417ebe400STim J. Robbins }
4517ebe400STim J. Robbins if (regexec(&yes, response, 0, NULL, 0) == 0)
4617ebe400STim J. Robbins ret = 1;
4717ebe400STim J. Robbins else if (regexec(&no, response, 0, NULL, 0) == 0)
4817ebe400STim J. Robbins ret = 0;
4917ebe400STim J. Robbins else
5017ebe400STim J. Robbins ret = -1;
5117ebe400STim J. Robbins regfree(&yes);
5217ebe400STim J. Robbins regfree(&no);
5317ebe400STim J. Robbins return (ret);
5417ebe400STim J. Robbins }
55