OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / getsubopt.3
1 .\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2007 Justin Pryzby <pryzbyj@justinpryzby.com>
3 .\"
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 .\"
23 .\" Japanese Version Copyright (c) 2007  Akihiro MOTOKI
24 .\"         all rights reserved.
25 .\" Translated 2007-06-02, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
26 .\" 
27 .TH GETSUBOPT 3 2008-05-29 "GNU" "Linux Programmer's Manual"
28 .\"O .SH NAME
29 .SH Ì¾Á°
30 .\"O getsubopt \- parse suboption arguments from a string
31 getsubopt \- Ê¸»úÎóÃæ¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó°ú¤­¿ô¤Î²ò¼á¤ò¹Ô¤¦
32 .\"O .SH SYNOPSIS
33 .SH ½ñ¼°
34 .B #define _XOPEN_SOURCE 500
35 .br
36 .B #include <stdlib.h>
37
38 .BI "int getsubopt(char **"optionp ", char * const *" tokens \
39 ", char **" valuep );
40 .\"O .SH DESCRIPTION
41 .SH ÀâÌÀ
42 .\"O .BR getsubopt ()
43 .\"O parses the list of comma-separated suboptions provided in
44 .\"O .IR optionp .
45 .\"O (Such a suboption list is typically produced when
46 .\"O .BR getopt (3)
47 .\"O is used to parse a command line;
48 .\"O see for example the \fI-o\fP option of
49 .\"O .BR mount (8).)
50 .\"O Each suboption may include an associated value,
51 .\"O which is separated from the suboption name by an equal sign.
52 .\"O The following is an example of the kind of string
53 .\"O that might be passed in
54 .\"O .IR optionp :
55 .BR getsubopt ()
56 ¤Ï¡¢
57 .I optionp
58 ¤ÇÍ¿¤¨¤é¤ì¤¿¥«¥ó¥Þ¶èÀÚ¤ê¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¡¦¥ê¥¹¥È¤ò²òÀϤ¹¤ë¡£
59 (¤³¤Î¤è¤¦¤Ê¥µ¥Ö¥ª¥×¥·¥ç¥ó¡¦¥ê¥¹¥È¤Ï
60 .BR getopt (3)
61 ¤ò»È¤Ã¤Æ¥³¥Þ¥ó¥É¥é¥¤¥ó¤ò²ò¼á¤·¤¿¾ì¹ç¤Ë¸½¤ì¤ë¤³¤È¤¬Â¿¤¤¡£
62 Î㤨¤Ð¡¢
63 .BR mount (8)
64 ¤Î \fI-o\fP ¥ª¥×¥·¥ç¥ó¤ò¸«¤ë¤È¤è¤¤¡£)
65 ¤½¤ì¤¾¤ì¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Ë¤ÏÂбþ¤¹¤ëÃͤò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
66 ¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Î̾Á°¤ÈÂбþ¤¹¤ëÃͤÏÅù¹æ (\(aq=\(aq) ¤Ç¶èÀÚ¤é¤ì¤ë¡£
67 Î㤨¤Ð¡¢°Ê²¼¤Î¤è¤¦¤Êʸ»úÎó¤ò
68 .I optionp
69 ¤ËÅϤ¹¤³¤È¤¬¤Ç¤­¤ë¡£
70 .sp
71 .in +4n
72 .B ro,name=xyz
73 .in
74
75 .\"O The
76 .\"O .I tokens
77 .\"O argument is a pointer to a NULL-terminated list of the tokens that
78 .\"O .BR getsubopt ()
79 .\"O will look for in
80 .\"O .IR optionp .
81 .\"O The tokens should be distinct, null-terminated strings containing at
82 .\"O least one character, with no embedded equal signs or commas.
83 .I tokens
84 °ú¤­¿ô¤Ï¥È¡¼¥¯¥ó¤Î¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¡¢¥ê¥¹¥È¤Ï NULL ¤Ç½ªÃ¼¤µ¤ì¤ë¡£
85 .BR getsubopt ()
86 ¤Ï¤³¤Î¥È¡¼¥¯¥ó¤ò
87 .I optionp
88 Æâ¤Çõ¤¹¡£
89 ¤½¤ì¤¾¤ì¤Î¥È¡¼¥¯¥ó¤Ï¡¢NULL ½ªÃ¼¤µ¤ì¤¿ 1ʸ»ú°Ê¾å¤Îʸ»úÎó¤Ç¡¢
90 ¾¤Î¥È¡¼¥¯¥ó¤È¶èÊ̤Ǥ­¤ëɬÍפ¬¤¢¤ë¡£
91 ¤Þ¤¿¡¢Åù¹æ¤È¥«¥ó¥Þ¤ò´Þ¤ó¤Ç¤Ï¤Ê¤é¤Ê¤¤¡£
92
93 .\"O Each call to
94 .\"O .BR getsubopt ()
95 .\"O returns information about the next unprocessed suboption in
96 .\"O .IR optionp .
97 .BR getsubopt ()
98 ¤Ï¸Æ¤Ó½Ð¤µ¤ì¤ë¤¿¤Ó¤Ë¡¢
99 .I optionp
100 Ãæ¤Î¼¡¤Î̤½èÍý¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Î¾ðÊó¤òÊÖ¤¹¡£
101 .\"O The first equal sign in a suboption (if any) is interpreted as a
102 .\"O separator between the name and the value of that suboption.
103 .\"O The value extends to the next comma,
104 .\"O or (for the last suboption) to the end of the string.
105 ¥µ¥Ö¥ª¥×¥·¥ç¥óÆâ¤ËÅù¹æ¤¬¤¢¤Ã¤¿¾ì¹ç¡¢ºÇ½é¤ÎÅù¹æ¤Ï
106 ¤½¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Î̾Á°¤ÈÃͤζèÀÚ¤ê¤È²ò¼á¤µ¤ì¤ë¡£
107 ¶èÀڤ꤫¤é¼¡¤Î¥«¥ó¥Þ (ºÇ¸å¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Î¾ì¹ç¡¢Ê¸»úÎó¤ÎËöÈø)
108 ¤Þ¤Ç¤¬¡¢¥µ¥Ö¥ª¥×¥·¥ç¥ó¤ÎÃͤȤʤ롣
109 .\"O If the name of the suboption matches a known name from
110 .\"O .IR tokens ,
111 .\"O and a value string was found,
112 .\"O .BR getsubopt ()
113 .\"O sets
114 .\"O .I *valuep
115 .\"O to the address of that string.
116 ¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Î̾Á°¤¬
117 .I tokens
118 Æâ¤Î̾Á°¤È°ìÃפ·¡¢Ãͤòɽ¤¹Ê¸»úÎ󤬸«¤Ä¤«¤Ã¤¿¾ì¹ç¡¢
119 .BR getsubopt ()
120 ¤Ï
121 .I *valuep
122 ¤òÃͤòɽ¤¹Ê¸»úÎó¤Î¥¢¥É¥ì¥¹¤ËÀßÄꤹ¤ë¡£
123 .\"O The first comma in
124 .\"O .I optionp
125 .\"O is overwritten with a null byte, so
126 .\"O .I *valuep
127 .\"O is precisely the "value string" for that suboption.
128 .I optionp
129 Ãæ¤ÎºÇ½é¤Î¥«¥ó¥Þ¤Ï¥Ì¥ë¥Ð¥¤¥È¤Ç¾å½ñ¤­¤µ¤ì¤ë¡£¤½¤Î¤¿¤á¡¢
130 .I *valuep
131 ¤Ï¤½¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Î¡ÖÃͤÎʸ»úÎó¡×¤½¤Î¤â¤Î¤È¤Ê¤ë¡£
132
133 .\"O If the suboption is recognized, but no value string was found,
134 .\"O .RI * valuep
135 .\"O is set to NULL.
136 ¥µ¥Ö¥ª¥×¥·¥ç¥ó¤¬Ç§¼±¤µ¤ì¤¿¤¬¡¢Ãͤòɽ¤¹Ê¸»úÎ󤬸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
137 .RI * valuep
138 ¤Ï NULL ¤ËÀßÄꤵ¤ì¤ë¡£
139
140 .\"O When
141 .\"O .BR getsubopt ()
142 .\"O returns,
143 .\"O .I optionp
144 .\"O points to the next suboption, or to the null character at the end of the
145 .\"O string if the last suboption was just processed.
146 .BR getsubopt ()
147 ¤¬ÊÖ¤ë»þ¡¢
148 .I optionp
149 ¤Ï¼¡¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤ò»Ø¤·¤Æ¤¤¤ë¡£
150 ¤Á¤ç¤¦¤ÉºÇ¸å¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤¬½èÍý¤µ¤ì¤¿¾ì¹ç¤Ï¡¢
151 ʸ»úÎóËöÈø¤Î¥Ì¥ëʸ»ú¤ò»Ø¤·¤Æ¤¤¤ë¡£
152 .\"O .SH RETURN VALUE
153 .SH ÊÖ¤êÃÍ
154 .\"O If the first suboption in
155 .\"O .I optionp
156 .\"O is recognized,
157 .\"O .BR getsubopt ()
158 .\"O returns the index of the matching suboption element in
159 .\"O .IR tokens .
160 .\"O Otherwise, \-1 is returned and
161 .\"O .I *valuep
162 .\"O is the entire
163 .\"O .IB name [= value ]
164 .\"O string.
165 .I optionp
166 Æâ¤Ç¥µ¥Ö¥ª¥×¥·¥ç¥ó¤¬¸«¤Ä¤«¤Ã¤¿¾ì¹ç¡¢
167 .BR getsubopt ()
168 ¤ÏºÇ½é¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Ë¥Þ¥Ã¥Á¤¹¤ë
169 .I tokens
170 ¤ÎÍ×ÁǤÎź»ú¤òÊÖ¤¹¡£
171 ¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¾ì¹ç¡¢\-1 ¤òÊÖ¤¹¡£¤³¤Î¾ì¹ç¡¢
172 .I *valuep
173 ¤Ï
174 .IB name [= value ]
175 ¤Îʸ»úÎóÁ´ÂΤȤʤ롣
176
177 .\"O Since
178 .\"O .I *optionp
179 .\"O is changed, the first suboption before the call to
180 .\"O .BR getsubopt ()
181 .\"O is not (necessarily) the same as the first suboption after
182 .\"O .BR getsubopt ().
183 .I *optionp
184 ¤ÏÊѹ¹¤µ¤ì¤ë¤Î¤Ç¡¢
185 .BR getsubopt ()
186 ¤ò¸Æ¤Ó½Ð¤¹Á°¤ÎºÇ½é¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Ï
187 .BR getsubopt ()
188 ¤ò¸Æ¤Ó½Ð¤·¸å¤Î¥µ¥Ö¥ª¥×¥·¥ç¥ó¤Èɬ¤º¤·¤âƱ¤¸¤È¤Ï¸Â¤é¤Ê¤¤¡£
189 .\"O .SH CONFORMING TO
190 .SH ½àµò
191 POSIX.1-2001.
192 .\"O .SH NOTES
193 .SH Ãí°Õ
194
195 .\"O Since
196 .\"O .BR getsubopt ()
197 .\"O overwrites any commas it finds in the string
198 .\"O .I *optionp ,
199 .\"O that string must be writable; it cannot be a string constant.
200 .BR getsubopt ()
201 ¤Ï¡¢Ê¸»úÎó
202 .RI * optionp
203 Ãæ¤Ë¸«¤Ä¤±¤¿¥«¥ó¥Þ¤ò¾å½ñ¤­¤¹¤ë¤Î¤Ç¡¢Ê¸»úÎó
204 .I *optionp
205 ¤Ï½ñ¤­¹þ¤ß²Äǽ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤º¡¢
206 ʸ»úÎóÄê¿ô¤Ë¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£
207 .\"O .SH EXAMPLE
208 .SH Îã
209 .\"O The following program expects suboptions following a "\-o" option.
210 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï "\-o" ¥ª¥×¥·¥ç¥ó¤Ë³¤¤¤Æ¥µ¥Ö¥ª¥×¥·¥ç¥ó¤¬¤¢¤ë¤³¤È¤ò
211 ´üÂÔ¤·¤Æ¤¤¤ë¡£
212
213 .nf
214 #define _XOPEN_SOURCE 500
215 #include <stdlib.h>
216 #include <assert.h>
217 #include <stdio.h>
218
219 int main(int argc, char **argv)
220 {
221     enum {
222         RO_OPT = 0,
223         RW_OPT,
224         NAME_OPT
225     };
226     char *const token[] = {
227         [RO_OPT]   = "ro",
228         [RW_OPT]   = "rw",
229         [NAME_OPT] = "name",
230         NULL
231     };
232     char *subopts;
233     char *value;
234     int opt;
235
236     int readonly = 0;
237     int readwrite = 0;
238     char *name = NULL;
239     int errfnd = 0;
240
241     while ((opt = getopt(argc, argv, "o:")) != \-1) {
242         switch (opt) {
243         case \(aqo\(aq:
244             subopts = optarg;
245             while (*subopts != \(aq\\0\(aq && !errfnd) {
246
247             switch (getsubopt(&subopts, token, &value)) {
248             case RO_OPT:
249                 readonly = 1;
250                 break;
251
252             case RW_OPT:
253                 readwrite = 1;
254                 break;
255
256             case NAME_OPT:
257                 if (value == NULL) {
258                     fprintf(stderr, "Missing value for "
259                             "suboption \(aq%s\(aq\\n", token[NAME_OPT]);
260                     errfnd = 1;
261                     continue;
262                 }
263
264                 name = value;
265                 break;
266
267             default:
268                 fprintf(stderr, "No match found "
269                         "for token: /%s/\\n", value);
270                 errfnd = 1;
271                 break;
272             }
273         }
274         if (readwrite && readonly) {
275             fprintf(stderr, "Only one of \(aq%s\(aq and \(aq%s\(aq can be "
276                     "specified\\n", token[RO_OPT], token[RW_OPT]);
277             errfnd = 1;
278         }
279         break;
280
281         default:
282             errfnd = 1;
283         }
284     }
285
286     if (errfnd || argc == 1) {
287         fprintf(stderr, "\\nUsage: %s \-o <suboptstring>\\n", argv[0]);
288         fprintf(stderr, "suboptions are \(aqro\(aq, \(aqrw\(aq, "
289                 "and \(aqname=<value>\(aq\\n");
290         exit(EXIT_FAILURE);
291     }
292
293     /* Remainder of program... */
294
295     exit(EXIT_SUCCESS);
296 }
297 .fi
298 .\"O .SH SEE ALSO
299 .SH ´ØÏ¢¹àÌÜ
300 .BR getopt (3),
301 .BR feature_test_macros (7)