Blame man3/rpmatch.3

Packit 7cfc04
.\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(PERMISSIVE_MISC)
Packit 7cfc04
.\" Permission is hereby granted, free of charge, to any person obtaining
Packit 7cfc04
.\" a copy of this software and associated documentation files (the
Packit 7cfc04
.\" "Software"), to deal in the Software without restriction, including
Packit 7cfc04
.\" without limitation the rights to use, copy, modify, merge, publish,
Packit 7cfc04
.\" distribute, sublicense, and/or sell copies of the Software, and to
Packit 7cfc04
.\" permit persons to whom the Software is furnished to do so, subject to
Packit 7cfc04
.\" the following conditions:
Packit 7cfc04
.\"
Packit 7cfc04
.\" The above copyright notice and this permission notice shall be
Packit 7cfc04
.\" included in all copies or substantial portions of the Software.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 7cfc04
.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 7cfc04
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit 7cfc04
.\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Packit 7cfc04
.\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Packit 7cfc04
.\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Packit 7cfc04
.\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" References:
Packit 7cfc04
.\"   glibc manual and source
Packit 7cfc04
.\"
Packit 7cfc04
.\" 2006-05-19, mtk, various edits and example program
Packit 7cfc04
.\"
Packit 7cfc04
.TH RPMATCH 3 2017-09-15 "GNU" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
rpmatch \- determine if the answer to a question is affirmative or negative
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <stdlib.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int rpmatch(const char *" response );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.BR rpmatch ():
Packit 7cfc04
    Since glibc 2.19:
Packit 7cfc04
        _DEFAULT_SOURCE
Packit 7cfc04
    Glibc 2.19 and earlier:
Packit 7cfc04
        _SVID_SOURCE
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
handles a user response to yes or no questions, with
Packit 7cfc04
support for internationalization.
Packit 7cfc04
.PP
Packit 7cfc04
.I response
Packit 7cfc04
should be a null-terminated string containing a
Packit 7cfc04
user-supplied response, perhaps obtained with
Packit 7cfc04
.BR fgets (3)
Packit 7cfc04
or
Packit 7cfc04
.BR getline (3).
Packit 7cfc04
.PP
Packit 7cfc04
The user's language preference is taken into account per the
Packit 7cfc04
environment variables
Packit 7cfc04
.BR LANG ,
Packit 7cfc04
.BR LC_MESSAGES ,
Packit 7cfc04
and
Packit 7cfc04
.BR LC_ALL ,
Packit 7cfc04
if the program has called
Packit 7cfc04
.BR setlocale (3)
Packit 7cfc04
to effect their changes.
Packit 7cfc04
.PP
Packit 7cfc04
Regardless of the locale, responses matching
Packit 7cfc04
.B ^[Yy]
Packit 7cfc04
are always accepted as affirmative, and those matching
Packit 7cfc04
.B ^[Nn]
Packit 7cfc04
are always accepted as negative.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
After examining
Packit 7cfc04
.IR response ,
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
returns 0 for a recognized negative response ("no"), 1
Packit 7cfc04
for a recognized positive response ("yes"), and \-1 when the value
Packit 7cfc04
of
Packit 7cfc04
.I response
Packit 7cfc04
is unrecognized.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
A return value of \-1 may indicate either an invalid input, or some
Packit 7cfc04
other error.
Packit 7cfc04
It is incorrect to only test if the return value is nonzero.
Packit 7cfc04
.PP
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
can fail for any of the reasons that
Packit 7cfc04
.BR regcomp (3)
Packit 7cfc04
or
Packit 7cfc04
.BR regexec (3)
Packit 7cfc04
can fail; the cause of the error
Packit 7cfc04
is not available from
Packit 7cfc04
.I errno
Packit 7cfc04
or anywhere else, but indicates a
Packit 7cfc04
failure of the regex engine (but this case is indistinguishable from
Packit 7cfc04
that of an unrecognized value of
Packit 7cfc04
.IR response ).
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lb lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
T}	Thread safety	MT-Safe locale
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
is not required by any standard, but
Packit 7cfc04
is available on a few other systems.
Packit 7cfc04
.\" It is available on at least AIX 5.1 and FreeBSD 6.0.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
The
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
implementation looks at only the first character
Packit 7cfc04
of
Packit 7cfc04
.IR response .
Packit 7cfc04
As a consequence, "nyes" returns 0, and
Packit 7cfc04
"ynever; not in a million years" returns 1.
Packit 7cfc04
It would be preferable to accept input strings much more
Packit 7cfc04
strictly, for example (using the extended regular
Packit 7cfc04
expression notation described in
Packit 7cfc04
.BR regex (7)):
Packit 7cfc04
.B ^([yY]|yes|YES)$
Packit 7cfc04
and
Packit 7cfc04
.BR ^([nN]|no|NO)$ .
Packit 7cfc04
.SH EXAMPLE
Packit 7cfc04
The following program displays the results when
Packit 7cfc04
.BR rpmatch ()
Packit 7cfc04
is applied to the string given in the program's command-line argument.
Packit 7cfc04
.PP
Packit 7cfc04
.EX
Packit 7cfc04
#define _SVID_SOURCE
Packit 7cfc04
#include <locale.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <string.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
Packit 7cfc04
int
Packit 7cfc04
main(int argc, char *argv[])
Packit 7cfc04
{
Packit 7cfc04
    if (argc != 2 || strcmp(argv[1], "\-\-help") == 0) {
Packit 7cfc04
        fprintf(stderr, "%s response\\n", argv[0]);
Packit 7cfc04
        exit(EXIT_FAILURE);
Packit 7cfc04
    }
Packit 7cfc04
Packit 7cfc04
    setlocale(LC_ALL, "");
Packit 7cfc04
    printf("rpmatch() returns: %d\\n", rpmatch(argv[1]));
Packit 7cfc04
    exit(EXIT_SUCCESS);
Packit 7cfc04
}
Packit 7cfc04
.EE
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR fgets (3),
Packit 7cfc04
.BR getline (3),
Packit 7cfc04
.BR nl_langinfo (3),
Packit 7cfc04
.BR regcomp (3),
Packit 7cfc04
.BR setlocale (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.