1139922Stjr/*- 2139922Stjr * Copyright (c) 2004-2005 Tim J. Robbins. 3139922Stjr * All rights reserved. 4139922Stjr * 5139922Stjr * Redistribution and use in source and binary forms, with or without 6139922Stjr * modification, are permitted provided that the following conditions 7139922Stjr * are met: 8139922Stjr * 1. Redistributions of source code must retain the above copyright 9139922Stjr * notice, this list of conditions and the following disclaimer. 10139922Stjr * 2. Redistributions in binary form must reproduce the above copyright 11139922Stjr * notice, this list of conditions and the following disclaimer in the 12139922Stjr * documentation and/or other materials provided with the distribution. 13139922Stjr * 14139922Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15139922Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16139922Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17139922Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18139922Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19139922Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20139922Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21139922Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22139922Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23139922Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24139922Stjr * SUCH DAMAGE. 25139922Stjr */ 26139922Stjr 27139922Stjr#include <sys/cdefs.h> 28139922Stjr__FBSDID("$FreeBSD: releng/10.2/lib/libc/locale/rpmatch.c 139922 2005-01-09 03:55:13Z tjr $"); 29139922Stjr 30139922Stjr#include <langinfo.h> 31139922Stjr#include <regex.h> 32139922Stjr#include <stdlib.h> 33139922Stjr 34139922Stjrint 35139922Stjrrpmatch(const char *response) 36139922Stjr{ 37139922Stjr regex_t yes, no; 38139922Stjr int ret; 39139922Stjr 40139922Stjr if (regcomp(&yes, nl_langinfo(YESEXPR), REG_EXTENDED|REG_NOSUB) != 0) 41139922Stjr return (-1); 42139922Stjr if (regcomp(&no, nl_langinfo(NOEXPR), REG_EXTENDED|REG_NOSUB) != 0) { 43139922Stjr regfree(&yes); 44139922Stjr return (-1); 45139922Stjr } 46139922Stjr if (regexec(&yes, response, 0, NULL, 0) == 0) 47139922Stjr ret = 1; 48139922Stjr else if (regexec(&no, response, 0, NULL, 0) == 0) 49139922Stjr ret = 0; 50139922Stjr else 51139922Stjr ret = -1; 52139922Stjr regfree(&yes); 53139922Stjr regfree(&no); 54139922Stjr return (ret); 55139922Stjr} 56