File: getsubopt.3

package info (click to toggle)
manpages-ja 0.5.0.0.20100315-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 21,156 kB
  • ctags: 1
  • sloc: sh: 13,935; perl: 157; makefile: 114
file content (219 lines) | stat: -rw-r--r-- 6,034 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
.\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
.\" and Copyright (C) 2007 Justin Pryzby <pryzbyj@justinpryzby.com>
.\"
.\" Permission is hereby granted, free of charge, to any person obtaining
.\" a copy of this software and associated documentation files (the
.\" "Software"), to deal in the Software without restriction, including
.\" without limitation the rights to use, copy, modify, merge, publish,
.\" distribute, sublicense, and/or sell copies of the Software, and to
.\" permit persons to whom the Software is furnished to do so, subject to
.\" the following conditions:
.\"
.\" The above copyright notice and this permission notice shall be
.\" included in all copies or substantial portions of the Software.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
.\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
.\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
.\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
.\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
.\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
.\"
.\" Japanese Version Copyright (c) 2007  Akihiro MOTOKI
.\"         all rights reserved.
.\" Translated 2007-06-02, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" 
.TH GETSUBOPT 3 2008-05-29 "GNU" "Linux Programmer's Manual"
.SH ̾
getsubopt \- ʸΥ֥ץβԤ
.SH 
.B #define _XOPEN_SOURCE 500
.br
.B #include <stdlib.h>

.BI "int getsubopt(char **"optionp ", char * const *" tokens \
", char **" valuep );
.SH 
.BR getsubopt ()
ϡ
.I optionp
Ϳ줿޶ڤΥ֥ץ󡦥ꥹȤϤ롣
(Τ褦ʥ֥ץ󡦥ꥹȤ
.BR getopt (3)
Ȥäƥޥɥ饤ᤷ˸뤳Ȥ¿
㤨С
.BR mount (8)
 \fI-o\fP ץ򸫤Ȥ褤)
줾Υ֥ץˤбͤꤹ뤳ȤǤ롣
֥ץ̾бͤ (\(aq=\(aq) Ƕڤ롣
㤨СʲΤ褦ʸ
.I optionp
ϤȤǤ롣
.sp
.in +4n
.B ro,name=xyz
.in

.I tokens
ϥȡΥꥹȤؤΥݥ󥿤ǡꥹȤ NULL ǽü롣
.BR getsubopt ()
ϤΥȡ
.I optionp
õ
줾ΥȡϡNULL ü줿 1ʸʾʸǡ
¾Υȡȶ̤Ǥɬפ롣
ޤȥޤޤǤϤʤʤ

.BR getsubopt ()
ϸƤӽФ뤿Ӥˡ
.I optionp
μ̤Υ֥ץξ֤
֥ץ椬ä硢ǽ
Υ֥ץ̾ͤζڤȲᤵ롣
ڤ꤫鼡Υ (ǸΥ֥ץξ硢ʸ)
ޤǤ֥ץͤȤʤ롣
֥ץ̾
.I tokens
̾Ȱפͤɽʸ󤬸Ĥä硢
.BR getsubopt ()

.I *valuep
ͤɽʸΥɥ쥹ꤹ롣
.I optionp
κǽΥޤϥ̥ХȤǾ񤭤롣Τᡢ
.I *valuep
ϤΥ֥ץΡͤʸפΤΤȤʤ롣

֥ץǧ줿ͤɽʸ󤬸Ĥʤä硢
.RI * valuep
 NULL ꤵ롣

.BR getsubopt ()
֤
.I optionp
ϼΥ֥ץؤƤ롣
礦ɺǸΥ֥ץ󤬽줿ϡ
ʸΥ̥ʸؤƤ롣
.SH ֤
.I optionp
ǥ֥ץ󤬸Ĥä硢
.BR getsubopt ()
ϺǽΥ֥ץ˥ޥå
.I tokens
Ǥź֤
Ĥʤä硢\-1 ֤ξ硢
.I *valuep

.IB name [= value ]
ʸΤȤʤ롣

.I *optionp
ѹΤǡ
.BR getsubopt ()
ƤӽФκǽΥ֥ץ
.BR getsubopt ()
ƤӽФΥ֥ץɬƱȤϸ¤ʤ
.SH 
POSIX.1-2001.
.SH 

.BR getsubopt ()
ϡʸ
.RI * optionp
˸Ĥޤ񤭤Τǡʸ
.I *optionp
Ͻ񤭹߲ǽǤʤФʤ餺
ʸˤ뤳ȤϤǤʤ
.SH 
ʲΥץ "\-o" ץ³ƥ֥ץ󤬤뤳Ȥ
ԤƤ롣

.nf
#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    enum {
        RO_OPT = 0,
        RW_OPT,
        NAME_OPT
    };
    char *const token[] = {
        [RO_OPT]   = "ro",
        [RW_OPT]   = "rw",
        [NAME_OPT] = "name",
        NULL
    };
    char *subopts;
    char *value;
    int opt;

    int readonly = 0;
    int readwrite = 0;
    char *name = NULL;
    int errfnd = 0;

    while ((opt = getopt(argc, argv, "o:")) != \-1) {
        switch (opt) {
        case \(aqo\(aq:
            subopts = optarg;
            while (*subopts != \(aq\\0\(aq && !errfnd) {

            switch (getsubopt(&subopts, token, &value)) {
            case RO_OPT:
                readonly = 1;
                break;

            case RW_OPT:
                readwrite = 1;
                break;

            case NAME_OPT:
                if (value == NULL) {
                    fprintf(stderr, "Missing value for "
                            "suboption \(aq%s\(aq\\n", token[NAME_OPT]);
                    errfnd = 1;
                    continue;
                }

                name = value;
                break;

            default:
                fprintf(stderr, "No match found "
                        "for token: /%s/\\n", value);
                errfnd = 1;
                break;
            }
        }
        if (readwrite && readonly) {
            fprintf(stderr, "Only one of \(aq%s\(aq and \(aq%s\(aq can be "
                    "specified\\n", token[RO_OPT], token[RW_OPT]);
            errfnd = 1;
        }
        break;

        default:
            errfnd = 1;
        }
    }

    if (errfnd || argc == 1) {
        fprintf(stderr, "\\nUsage: %s \-o <suboptstring>\\n", argv[0]);
        fprintf(stderr, "suboptions are \(aqro\(aq, \(aqrw\(aq, "
                "and \(aqname=<value>\(aq\\n");
        exit(EXIT_FAILURE);
    }

    /* Remainder of program... */

    exit(EXIT_SUCCESS);
}
.fi
.SH Ϣ
.BR getopt (3),
.BR feature_test_macros (7)