OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / rpmatch.3
1 .\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
2 .\"
3 .\" %%%LICENSE_START(PERMISSIVE_MISC)
4 .\" Permission is hereby granted, free of charge, to any person obtaining
5 .\" a copy of this software and associated documentation files (the
6 .\" "Software"), to deal in the Software without restriction, including
7 .\" without limitation the rights to use, copy, modify, merge, publish,
8 .\" distribute, sublicense, and/or sell copies of the Software, and to
9 .\" permit persons to whom the Software is furnished to do so, subject to
10 .\" the following conditions:
11 .\"
12 .\" The above copyright notice and this permission notice shall be
13 .\" included in all copies or substantial portions of the Software.
14 .\"
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 .\" %%%LICENSE_END
23 .\"
24 .\" References:
25 .\"   glibc manual and source
26 .\"
27 .\" 2006-05-19, mtk, various edits and example program
28 .\"
29 .TH RPMATCH 3 2007-07-26 "GNU" "Linux Programmer's Manual"
30 .SH NAME
31 rpmatch \- determine if the answer to a question is affirmative or negative
32 .SH SYNOPSIS
33 .nf
34 .B #include <stdlib.h>
35
36 .BI "int rpmatch(const char *" response );
37 .fi
38 .sp
39 .in -4n
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
42 .in
43 .sp
44 .BR rpmatch ():
45 _SVID_SOURCE
46 .SH DESCRIPTION
47 .BR rpmatch ()
48 handles a user response to yes or no questions, with
49 support for internationalization.
50
51 .I response
52 should be a null-terminated string containing a
53 user-supplied response, perhaps obtained with
54 .BR fgets (3)
55 or
56 .BR getline (3).
57
58 The user's language preference is taken into account per the
59 environment variables
60 .BR LANG ,
61 .BR LC_MESSAGES ,
62 and
63 .BR LC_ALL ,
64 if the program has called
65 .BR setlocale (3)
66 to effect their changes.
67
68 Regardless of the locale, responses matching
69 .B ^[Yy]
70 are always accepted as affirmative, and those matching
71 .B ^[Nn]
72 are always accepted as negative.
73 .SH RETURN VALUE
74 After examining
75 .IR response ,
76 .BR rpmatch ()
77 returns 0 for a recognized negative response ("no"), 1
78 for a recognized positive response ("yes"), and \-1 when the value
79 of
80 .I response
81 is unrecognized.
82 .SH ERRORS
83 A return value of \-1 may indicate either an invalid input, or some
84 other error.
85 It is incorrect to only test if the return value is nonzero.
86
87 .BR rpmatch ()
88 can fail for any of the reasons that
89 .BR regcomp (3)
90 or
91 .BR regexec (3)
92 can fail; the cause of the error
93 is not available from
94 .I errno
95 or anywhere else, but indicates a
96 failure of the regex engine (but this case is indistinguishable from
97 that of an unrecognized value of
98 .IR response ).
99 .SH CONFORMING TO
100 .BR rpmatch ()
101 is not required by any standard, but
102 is available on a few other systems.
103 .\" It is available on at least AIX 5.1 and FreeBSD 6.0.
104 .SH BUGS
105 The
106 .BR rpmatch ()
107 implementation looks at only the first character
108 of
109 .IR response .
110 As a consequence, "nyes" returns 0, and
111 "ynever; not in a million years" returns 1.
112 It would be preferable to accept input strings much more
113 strictly, for example (using the extended regular
114 expression notation described in
115 .BR regex (7)):
116 .B ^([yY]|yes|YES)$
117 and
118 .BR ^([nN]|no|NO)$ .
119 .SH EXAMPLE
120 The following program displays the results when
121 .BR rpmatch ()
122 is applied to the string given in the program's command-line argument.
123 .nf
124
125 #define _SVID_SOURCE
126 #include <locale.h>
127 #include <stdlib.h>
128 #include <string.h>
129 #include <stdio.h>
130
131 int
132 main(int argc, char *argv[])
133 {
134     if (argc != 2 || strcmp(argv[1], "\-\-help") == 0) {
135         fprintf(stderr, "%s response\\n", argv[0]);
136         exit(EXIT_FAILURE);
137     }
138
139     setlocale(LC_ALL, "");
140     printf("rpmatch() returns: %d\\n", rpmatch(argv[1]));
141     exit(EXIT_SUCCESS);
142 }
143 .fi
144 .SH SEE ALSO
145 .BR fgets (3),
146 .BR getline (3),
147 .BR nl_langinfo (3),
148 .BR regcomp (3),
149 .BR setlocale (3)
150 .SH COLOPHON
151 This page is part of release 3.79 of the Linux
152 .I man-pages
153 project.
154 A description of the project,
155 information about reporting bugs,
156 and the latest version of this page,
157 can be found at
158 \%http://www.kernel.org/doc/man\-pages/.