aboutsummaryrefslogblamecommitdiff
path: root/ja_JP.eucJP/man/man3/getsubopt.3
blob: 9a75ceb131d818df2bbbb18e3d22d447887e3be2 (plain) (tree)
































                                                                              
             
























































































































                                                                          
.\" Copyright (c) 1990, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)getsubopt.3	8.1 (Berkeley) 6/9/93
.\"
.\" $FreeBSD$
.Dd June 9, 1993
.Dt GETSUBOPT 3
.Os
.Sh 名称
.Nm getsubopt
.Nd 引数からサブオプションを取得
.Sh 書式
.Fd #include <stdlib.h>
.Vt extern char *suboptarg
.Ft int
.Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep"
.Sh 解説
.Fn getsubopt
関数は、
1 つまたは複数のタブ、スペースまたはコンマ
.Pq Ql \&,
キャラクタによって区切られた、トークンが含まれるストリングを解析します。
ユーティリティコマンドラインの一部として提供される、オプション引数グループ
の解析に使用するのが目的です。
.Pp
引数
.Fa optionp
は、ストリングのポインタを示すポインタです。引数
.Fa tokens
は、
ストリングのポインタの
.Dv NULL
で終わる配列を示すポインタです。
.Pp
.Fn getsubopt
関数は、ストリングの最初のトークンに適合するストリングを、
参照するポインタのゼロベースオフセットを返します。ストリングにトークンが
一切含まれない、または
.Fa tokens
に適合するストリングか含まれない場合には、
\-1 を返します。
.Pp
トークンの形式が
``name=value''
である場合、
.Fa valuep
で参照される位置は、トークンの
``値''
部分の開始を示すように設定されます。
.Pp
.Fn getsubopt
からの戻りでは、
.Fa optionp
がストリングの次のトークンの開始を
示すように設定されます。または、それ以上のストリングがない場合には、
ストリングの終わりに
null
を示します。外部変数
.Fa suboptarg
は、現在のトークン
の開始を示すように設定されます。トークンがなかった場合は、
.Dv NULL
を示します。
引数
.Fa valuep
は、トークンの
``値''
部分を示すように設定されます。または、
``値''
部分がなかった場合は
.Dv NULL
を示します。
.Sh 例
.Bd -literal -compact
char *tokens[] = {
	#define ONE	0
		"one",
	#define TWO	1
		"two",
	NULL
};

\&...

extern char *optarg, *suboptarg;
char *option, *value;

while ((ch = getopt(argc, argv, "ab:")) != -1) {
	switch(ch) {
	case 'a':
		/*  ``a'' オプションを処理 */
		break;
	case 'b':
		option = optarg;
		while (*option) {
			switch(getsubopt(&option, tokens, &value)) {
			case ONE:
				/* ``one'' サブオプションを処理 */
				break;
			case TWO:
				/* ``two'' サブオプションを処理 */
				if (!value)
					error("no value for two");
				i = atoi(value);
				break;
			case \-1:
				if (suboptarg)
					error("illegal sub option %s",
					  suboptarg);
				else
					error("missing sub option");
				break;
		}
		break;
	}

.Ed
.Sh 関連項目
.Xr getopt 3
、
.Xr strsep 3
.Sh 歴史
.Fn getsubopt
関数は
.Bx 4.4
で最初に取り入れられました。