1RPMATCH(3)                 Library Functions Manual                 RPMATCH(3)
2
3
4

NAME

6       rpmatch - determine if the answer to a question is affirmative or nega‐
7       tive
8

SYNOPSIS

10       #define _SVID_SOURCE
11       #include <stdlib.h>
12
13       int rpmatch (const char *response);
14

DESCRIPTION

16       rpmatch() handles a user response to yes or no questions, with  support
17       for internationalization.
18
19       response  should be a null-terminated string containing a user-supplied
20       response, perhaps obtained with fgets(3) or getline(3).
21
22       The user's language preference is taken into account per  the  environ‐
23       ment variables LANG, LC_MESSAGES, and LC_ALL, if the program has called
24       setlocale() to effect their changes.
25
26       Regardless of the locale, responses matching ^[Yy] are always  accepted
27       as  affirmative,  and those matching ^[Nn] are always accepted as nega‐
28       tive.
29

RETURN VALUE

31       After examining response, rpmatch() returns 0 for a recognized negative
32       response  ("no"),  1 for a recognized positive response ("yes"), and -1
33       when the value of response is unrecognized.
34

ERRORS

36       A return value of -1 may indicate either  an  invalid  input,  or  some
37       other  error.   It  is  incorrect  to  only test if the return value is
38       nonzero.
39
40       rpmatch() can fail for any of the reasons that regcomp(3) or regexec(3)
41       can  fail;  the  cause of the error is not available from errno or any‐
42       where else, but indicates a failure of the regex engine (but this  case
43       is indistinguishable from that of an unrecognized value of response).
44

CONFORMING TO

46       rpmatch()  is  not  required by any standard, but is available on a few
47       other systems.
48

BUGS

50       The rpmatch() implementation looks  at  only  the  first  character  of
51       response.   As  a  consequence, "nyes" returns 0, and "ynever; not in a
52       million years" returns 1.  It  would  be  preferable  to  accept  input
53       strings  much  more  strictly,  for example (using the extended regular
54       expression  notation  described  in  regex(7)):  ^([yY]|yes|YES)$   and
55       ^([nN]|no|NO)$.
56

EXAMPLE

58       The following program displays the results when rpmatch() is applied to
59       the string given in the program's command-line argument.
60
61       #define _SVID_SOURCE
62       #include <locale.h>
63       #include <stdlib.h>
64       #include <string.h>
65       #include <stdio.h>
66
67       int
68       main(int argc, char *argv[])
69       {
70           if (argc != 2 || strcmp(argv[1], "--help") == 0) {
71               fprintf(stderr, "%s response\n", argv[0]);
72               exit(EXIT_FAILURE);
73           }
74
75           setlocale(LC_ALL, "");
76           printf("rpmatch() returns: %d\n", rpmatch(argv[1]));
77           exit(EXIT_SUCCESS);
78       }
79

SEE ALSO

81       regcomp(3), fgets(3), getline(3),  nl_langinfo(3),  setlocale(3),  fea‐
82       ture_test_macros(7)
83
84
85
86GNU                               2006-05-17                        RPMATCH(3)
Impressum