OSDN Git Service

1e57e3b8ff9df6ba0cd565fefbc1f17431a5316e
[linuxjm/LDP_man-pages.git] / draft / man3 / wordexp.3
1 .\" Copyright (c) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .\"
24 .\"*******************************************************************
25 .\"
26 .\" This file was generated with po4a. Translate the source file.
27 .\"
28 .\"*******************************************************************
29 .TH WORDEXP 3 2008\-07\-14 "" "Linux Programmer's Manual"
30 .SH 名前
31 wordexp, wordfree \- posix シェルのように単語の展開を行う
32 .SH 書式
33 \fB#include <wordexp.h>\fP
34 .sp
35 \fBint wordexp(const char *\fP\fIs\fP\fB, wordexp_t *\fP\fIp\fP\fB, int \fP\fIflags\fP\fB);\fP
36 .sp
37 \fBvoid wordfree(wordexp_t *\fP\fIp\fP\fB);\fP
38 .sp
39 .in -4n
40 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
41 .in
42 .sp
43 \fBwordexp\fP(), \fBwordfree\fP(): _XOPEN_SOURCE
44 .SH 説明
45 The function \fBwordexp\fP()  performs a shell\-like expansion of the string
46 \fIs\fP and returns the result in the structure pointed to by \fIp\fP.  The data
47 type \fIwordexp_t\fP is a structure that at least has the fields \fIwe_wordc\fP,
48 \fIwe_wordv\fP, and \fIwe_offs\fP.  The field \fIwe_wordc\fP is a \fIsize_t\fP that
49 gives the number of words in the expansion of \fIs\fP.  The field \fIwe_wordv\fP
50 is a \fIchar\ **\fP that points to the array of words found.  The field
51 \fIwe_offs\fP of type \fIsize_t\fP is sometimes (depending on \fIflags\fP, see below)
52 used to indicate the number of initial elements in the \fIwe_wordv\fP array
53 that should be filled with NULLs.
54 .LP
55 関数 \fBwordfree\fP()  は割り当てたメモリを再度解放する。 より正確にいうと、この関数はその引き数を解放するのではなく、 配列
56 \fIwe_wordv\fP とそれが指し示す文字列を解放する。
57 .SS 文字列引き数
58 この展開はシェルによるコマンドのパラメータの展開 (\fBsh\fP(1)  を参照) と同じであるので、文字列 \fIs\fP
59 はシェルコマンドパラメータで不正とされる文字を含んではならない。 特にエスケープされていない改行、|, &, ;, <, >, (,
60 ), {, } 文字を コマンド置換やパラメータ置換の場面以外に含めてはならない。
61 .LP
62 引き数 \fIs\fP にクォートしていないコメント文字 # で始まる単語が含まれている場合には、 その単語とそれ以降の単語が無視されるか、 それとも #
63 がコメント文字として扱わないかは、規定されていない。
64 .SS 展開
65 実行される展開は、以下の段階で構成される: チルダ展開 (~user を user のホームディレクトリに置き換える)、 変数展開 ($FOO
66 を環境変数 FOO の値に置き換える)、 コマンド展開 ($(command) または \`command\` を command
67 の出力で置き換える)、 算術展開、フィールド分割、ワイルドカード展開、クォートの除去。
68 .LP
69 特殊なパラメータ ($@, $*, $#, $?, $\-, $$, $!, $0) の 展開結果は規定されていない。
70 .LP
71 フィールド分割は環境変数 $IFS を用いて行われる。 この環境変数が設定されていない場合、 フィールド区切り文字はスペース・タブ・改行である。
72 .SS 出力される配列
73 配列 \fIwe_wordv\fP は見つかった単語をを含み、最後に NULL が続く。
74 .SS "flags 引き数"
75 \fIflags\fP 引き数は以下の値のビット包含的 OR である:
76 .TP 
77 \fBWRDE_APPEND\fP
78 見つかった単語を前回の呼び出し結果の配列に追加する。
79 .TP 
80 \fBWRDE_DOOFFS\fP
81 初期状態である \fIwe_offs\fP 個の NULL を配列 \fIwe_wordv\fP に挿入する (これらは返される \fIwe_wordc\fP
82 にはカウントされない)。
83 .TP 
84 \fBWRDE_NOCMD\fP
85 コマンド置換を行わない。
86 .TP 
87 \fBWRDE_REUSE\fP
88 引き数 \fIp\fP は前回の \fBwordexp\fP()  の呼び出し結果であり、 \fBwordfree\fP()  が (まだ) 呼び出されない。
89 割り当てられた領域を再利用する。
90 .TP 
91 \fBWRDE_SHOWERR\fP
92 通常はコマンド置換のときに \fIstderr\fP が \fI/dev/null\fP にリダイレクトされる。 このフラグは \fIstderr\fP
93 をリダイレクトしないように指定する。
94 .TP 
95 \fBWRDE_UNDEF\fP
96 未定義のシェル変数を展開しようとした場合に、エラーとして扱う。
97 .SH 返り値
98 成功した場合は 0 が返される。 エラーの場合は以下の 5 つの値のうちの 1 つが返される。
99 .TP 
100 \fBWRDE_BADCHAR\fP
101 改行または |, &, ;, <, >, (, ), {, } のうちの 1 つが不正に出現した。
102 .TP 
103 \fBWRDE_BADVAL\fP
104 未定義のシェル変数が参照され、かつ \fBWRDE_UNDEF\fP フラグでこれをエラーとして扱うように指示されている。
105 .TP 
106 \fBWRDE_CMDSUB\fP
107 コマンド置換が起こり、かつ \fBWRDE_NOCMD\fP フラグでこれをエラーとして扱うように指示されている。
108 .TP 
109 \fBWRDE_NOSPACE\fP
110 メモリが足りない。
111 .TP 
112 \fBWRDE_SYNTAX\fP
113 対応する括弧がない、クォートが合致しないといった、 シェルの書式エラー。
114 .SH バージョン
115 \fBwordexp\fP()  と \fBwordfree\fP()  は、バージョン 2.1 以降の glibc で提供されている。
116 .SH 準拠
117 POSIX.1\-2001.
118 .SH 例
119 以下のサンプルプログラムの出力はだいたい "ls [a\-c]*.c" と同じになる。
120 .LP
121 .nf
122 #include <stdio.h>
123 #include <stdlib.h>
124 #include <wordexp.h>
125
126 int
127 main(int argc, char **argv)
128 {
129     wordexp_t p;
130     char **w;
131     int i;
132
133     wordexp("[a\-c]*.c", &p, 0);
134     w = p.we_wordv;
135     for (i = 0; i < p.we_wordc; i++)
136         printf("%s\en", w[i]);
137     wordfree(&p);
138     exit(EXIT_SUCCESS);
139 }
140 .fi
141 .SH 関連項目
142 \fBfnmatch\fP(3), \fBglob\fP(3)
143 .SH この文書について
144 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
145 である。プロジェクトの説明とバグ報告に関する情報は
146 http://www.kernel.org/doc/man\-pages/ に書かれている。