OSDN Git Service

2a8bba9b6ef7a32f17f668e0b7350873fcb87299
[linuxjm/LDP_man-pages.git] / release / man3 / rpmatch.3
1 .\" Copyright (C) 2006 Justin Pryzby <pryzbyj@justinpryzby.com>
2 .\"
3 .\" Permission is hereby granted, free of charge, to any person obtaining
4 .\" a copy of this software and associated documentation files (the
5 .\" "Software"), to deal in the Software without restriction, including
6 .\" without limitation the rights to use, copy, modify, merge, publish,
7 .\" distribute, sublicense, and/or sell copies of the Software, and to
8 .\" permit persons to whom the Software is furnished to do so, subject to
9 .\" the following conditions:
10 .\"
11 .\" The above copyright notice and this permission notice shall be
12 .\" included in all copies or substantial portions of the Software.
13 .\"
14 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 .\"
22 .\" References:
23 .\"   glibc manual and source
24 .\"
25 .\" 2006-05-19, mtk, various edits and example program
26 .\"
27 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
28 .\" Translated 2006-07-31, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
29 .\"
30 .TH RPMATCH 3 2007-07-26 "GNU" "Linux Programmer's Manual"
31 .SH 名前
32 rpmatch \- 質問への応答が肯定か否定かを判定する
33 .SH 書式
34 .nf
35 .B #include <stdlib.h>
36
37 .BI "int rpmatch(const char *" response );
38 .fi
39 .sp
40 .in -4n
41 glibc 向けの機能検査マクロの要件
42 .RB ( feature_test_macros (7)
43 参照):
44 .in
45 .sp
46 .BR rpmatch ():
47 _SVID_SOURCE
48 .SH 説明
49 .BR  rpmatch ()
50 は yes/no の質問に対するユーザからの応答を処理する。
51 国際化 (I18N) に対応している。
52
53 .I response
54 にはユーザからの応答を格納した NULL 終端文字列が入っている必要がある。
55 たいていは、
56 .BR fgets (3)
57
58 .BR getline (3)
59 で取り込んだものであろう。
60
61 プログラムが
62 .BR setlocale (3)
63 を呼び出して環境変数の変更を有効にした場合、
64 環境変数 \fBLANG\fP, \fBLC_MESSAGES\fP, \fBLC_ALL\fP が
65 ユーザの言語設定として考慮される。
66
67 ロケールに関わらず、\fB^[Yy]\fP にマッチする応答は常に肯定だと解釈され、
68 \fB^[Nn]\fP にマッチする応答は常に否定だと解釈される。
69 .SH 返り値
70 .I response
71 を検査した後、
72 .BR rpmatch ()
73 は否定的な応答 ("no") と認識した場合は 0 を返し、
74 肯定的な応答 ("yes") と認識した場合は 1 を返す。
75 .I response
76 の値を解釈できなかった場合は \-1 を返す。
77 .SH エラー
78 返り値 \-1 が返った場合、入力が不正であったか、他の何らかのエラーが
79 あったことを意味する。返り値が 0 以外かどうかを確認するだけでは
80 十分ではない。
81
82 .BR rpmatch ()
83 は、
84 .BR regcomp (3)
85
86 .BR regexec (3)
87 が失敗する理由のどれかで失敗することがある。
88 エラーの原因を
89 .I errno
90 や他の何かで知ることはできないが、
91 .I errno
92 は正規表現エンジンの失敗の原因を示している
93 (但し、このケースと
94 .I response
95 の値を認識できずに失敗した場合を区別することはできない)。
96 .SH 準拠
97 .BR rpmatch ()
98 はどの標準でも必須となっていないが、
99 Linux 以外にも利用できるシステムもいくつかは存在する。
100 .\" 少なくとも AIX 5.1 と FreeBSD 6.0 では利用できる。
101 .SH バグ
102 .BR rpmatch ()
103 の実装は
104 .I response
105 の最初の 1 文字だけを見ているようである。その結果、
106 "nyes" は 0 を返し、
107 "ynever; not in a million years" は 1 を返すことになる。
108 入力文字列をもっと厳密に解釈した方がよいだろう。
109 例えば、
110 .RB ( regex (7)
111 で説明されている拡張正規表現を使って)
112 .BR ^([yY]|yes|YES)$ " や " ^([nN]|no|NO)$
113 で解釈するなど。
114 .SH 例
115 以下のプログラムは、コマンドライン引き数で
116 指定された文字列を
117 .BR rpmatch ()
118 に渡した場合の結果を表示する。
119 .nf
120
121 #define _SVID_SOURCE
122 #include <locale.h>
123 #include <stdlib.h>
124 #include <string.h>
125 #include <stdio.h>
126
127 int
128 main(int argc, char *argv[])
129 {
130     if (argc != 2 || strcmp(argv[1], "\-\-help") == 0) {
131         fprintf(stderr, "%s response\\n", argv[0]);
132         exit(EXIT_FAILURE);
133     }
134
135     setlocale(LC_ALL, "");
136     printf("rpmatch() returns: %d\\n", rpmatch(argv[1]));
137     exit(EXIT_SUCCESS);
138 }
139 .fi
140 .SH 関連項目
141 .BR fgets (3),
142 .BR getline (3),
143 .BR nl_langinfo (3),
144 .BR regcomp (3),
145 .BR setlocale (3)