]> git.saurik.com Git - apple/libc.git/blob - gen/wordexp.3
Libc-594.1.4.tar.gz
[apple/libc.git] / gen / wordexp.3
1 .\"
2 .\" Copyright (c) 2002 Tim J. Robbins
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD: src/lib/libc/gen/wordexp.3,v 1.6 2003/09/08 19:57:14 ru Exp $
27 .\"
28 .Dd December 27, 2002
29 .Dt WORDEXP 3
30 .Os
31 .Sh NAME
32 .Nm wordexp
33 .Nd "perform shell-style word expansions"
34 .Sh SYNOPSIS
35 .In wordexp.h
36 .Ft int
37 .Fo wordexp
38 .Fa "const char *restrict words"
39 .Fa "wordexp_t *restrict pwordexp"
40 .Fa "int flags"
41 .Fc
42 .Ft void
43 .Fo wordfree
44 .Fa "wordexp_t *pwordexp"
45 .Fc
46 .Sh DESCRIPTION
47 The
48 .Fn wordexp
49 function performs shell-style word expansion on
50 .Fa words .
51 It places the list of words into the
52 .Va we_wordv
53 member of
54 .Fa pwordexp
55 and the number of words into
56 .Va we_wordc .
57 .Pp
58 The
59 .Fa flags
60 argument (see
61 .Sx BUGS )
62 is the bitwise inclusive OR of any of the following constants:
63 .Bl -tag -width ".Dv WRDE_SHOWERR"
64 .It Dv WRDE_APPEND
65 Append the words to those generated by a previous call to
66 .Fn wordexp .
67 .It Dv WRDE_DOOFS
68 As many
69 .Dv NULL
70 pointers as are specified by the
71 .Va we_offs
72 member of
73 .Fa pwordexp
74 are added to the front of
75 .Va we_wordv .
76 .It Dv WRDE_NOCMD
77 Disallow command substitution in
78 .Fa words .
79 See the note in
80 .Sx BUGS
81 before using this.
82 .It Dv WRDE_REUSE
83 The
84 .Fa pwordexp
85 argument was passed to a previous successful call to
86 .Fn wordexp
87 but has not been passed to
88 .Fn wordfree .
89 The implementation may reuse the space allocated to it.
90 .It Dv WRDE_SHOWERR
91 Do not redirect shell error messages to
92 .Pa /dev/null .
93 .It Dv WRDE_UNDEF
94 Report error on an attempt to expand an undefined shell variable.
95 .El
96 .Pp
97 The
98 .Vt wordexp_t
99 structure is defined in
100 .In wordexp.h
101 as:
102 .Bd -literal -offset indent
103 typedef struct {
104 size_t we_wordc; /* count of words matched */
105 char **we_wordv; /* pointer to list of words */
106 size_t we_offs; /* slots to reserve in we_wordv */
107 } wordexp_t;
108 .Ed
109 .Pp
110 The
111 .Fn wordfree
112 function frees the memory allocated by
113 .Fn wordexp .
114 .Sh RETURN VALUES
115 The
116 .Fn wordexp
117 function returns zero if successful, otherwise it returns one of the following
118 error codes:
119 .Bl -tag -width ".Dv WRDE_NOSPACE"
120 .It Dv WRDE_BADCHAR
121 The
122 .Fa words
123 argument contains one of the following unquoted characters:
124 .Aq newline ,
125 .Ql | ,
126 .Ql & ,
127 .Ql \&; ,
128 .Ql < ,
129 .Ql > ,
130 .Ql \&( ,
131 .Ql \&) ,
132 .Ql { ,
133 .Ql } .
134 .It Dv WRDE_BADVAL
135 An attempt was made to expand an undefined shell variable and
136 .Dv WRDE_UNDEF
137 is set in
138 .Fa flags .
139 .It Dv WRDE_CMDSUB
140 An attempt was made to use command substitution and
141 .Dv WRDE_NOCMD
142 is set in
143 .Fa flags .
144 .It Dv WRDE_NOSPACE
145 Not enough memory to store the result.
146 .It Dv WRDE_SYNTAX
147 Shell syntax error in
148 .Fa words .
149 .El
150 .Pp
151 The
152 .Fn wordfree
153 function returns no value.
154 .Sh EXAMPLES
155 Invoke the editor on all
156 .Pa .c
157 files in the current directory
158 and
159 .Pa /etc/motd
160 (error checking omitted):
161 .Bd -literal -offset indent
162 wordexp_t pwordexp;
163
164 wordexp("${EDITOR:-vi} *.c /etc/motd", &pwordexp, 0);
165 execvp(pwordexp->we_wordv[0], pwordexp->we_wordv);
166 .Ed
167 .Sh SEE ALSO
168 .Xr sh 1 ,
169 .Xr fnmatch 3 ,
170 .Xr glob 3 ,
171 .Xr popen 3 ,
172 .Xr system 3
173 .Sh BUGS
174 This version of
175 .Fn wordexp
176 ignores the value of the
177 .Fa flags
178 argument.
179 .Sh COPYRIGHT
180 Copyright 1995-2002 University Corporation for Atmospheric Research/Unidata
181 .Pp
182 Portions of this software were developed by the Unidata Program at the
183 University Corporation for Atmospheric Research.