]> git.saurik.com Git - apple/libc.git/blob - gen/wordexp.3
Libc-391.2.3.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 .Fn wordexp "const char * restrict words" "wordexp_t * restrict we" "int flags"
38 .Ft void
39 .Fn wordfree "wordexp_t *we"
40 .Sh DESCRIPTION
41 The
42 .Fn wordexp
43 function performs shell-style word expansion on
44 .Fa words
45 and places the list of words into the
46 .Va we_wordv
47 member of
48 .Fa we ,
49 and the number of words into
50 .Va we_wordc .
51 .Pp
52 The
53 .Fa flags
54 argument (see
55 .Sx BUGS )
56 is the bitwise inclusive OR of any of the following constants:
57 .Bl -tag -width ".Dv WRDE_SHOWERR"
58 .It Dv WRDE_APPEND
59 Append the words to those generated by a previous call to
60 .Fn wordexp .
61 .It Dv WRDE_DOOFS
62 As many
63 .Dv NULL
64 pointers as are specified by the
65 .Va we_offs
66 member of
67 .Fa we
68 are added to the front of
69 .Va we_wordv .
70 .It Dv WRDE_NOCMD
71 Disallow command substitution in
72 .Fa words .
73 See the note in
74 .Sx BUGS
75 before using this.
76 .It Dv WRDE_REUSE
77 The
78 .Fa we
79 argument was passed to a previous successful call to
80 .Fn wordexp
81 but has not been passed to
82 .Fn wordfree .
83 The implementation may reuse the space allocated to it.
84 .It Dv WRDE_SHOWERR
85 Do not redirect shell error messages to
86 .Pa /dev/null .
87 .It Dv WRDE_UNDEF
88 Report error on an attempt to expand an undefined shell variable.
89 .El
90 .Pp
91 The
92 .Vt wordexp_t
93 structure is defined in
94 .In wordexp.h
95 as:
96 .Bd -literal -offset indent
97 typedef struct {
98 size_t we_wordc; /* count of words matched */
99 char **we_wordv; /* pointer to list of words */
100 size_t we_offs; /* slots to reserve in we_wordv */
101 } wordexp_t;
102 .Ed
103 .Pp
104 The
105 .Fn wordfree
106 function frees the memory allocated by
107 .Fn wordexp .
108 .Sh RETURN VALUES
109 The
110 .Fn wordexp
111 function returns zero if successful, otherwise it returns one of the following
112 error codes:
113 .Bl -tag -width ".Dv WRDE_NOSPACE"
114 .It Dv WRDE_BADCHAR
115 The
116 .Fa words
117 argument contains one of the following unquoted characters:
118 .Aq newline ,
119 .Ql | ,
120 .Ql & ,
121 .Ql \&; ,
122 .Ql < ,
123 .Ql > ,
124 .Ql \&( ,
125 .Ql \&) ,
126 .Ql { ,
127 .Ql } .
128 .It Dv WRDE_BADVAL
129 An attempt was made to expand an undefined shell variable and
130 .Dv WRDE_UNDEF
131 is set in
132 .Fa flags .
133 .It Dv WRDE_CMDSUB
134 An attempt was made to use command substitution and
135 .Dv WRDE_NOCMD
136 is set in
137 .Fa flags .
138 .It Dv WRDE_NOSPACE
139 Not enough memory to store the result.
140 .It Dv WRDE_SYNTAX
141 Shell syntax error in
142 .Fa words .
143 .El
144 .Pp
145 The
146 .Fn wordfree
147 function returns no value.
148 .Sh EXAMPLES
149 Invoke the editor on all
150 .Pa .c
151 files in the current directory
152 and
153 .Pa /etc/motd
154 (error checking omitted):
155 .Bd -literal -offset indent
156 wordexp_t we;
157
158 wordexp("${EDITOR:-vi} *.c /etc/motd", &we, 0);
159 execvp(we->we_wordv[0], we->we_wordv);
160 .Ed
161 .Sh SEE ALSO
162 .Xr sh 1 ,
163 .Xr fnmatch 3 ,
164 .Xr glob 3 ,
165 .Xr popen 3 ,
166 .Xr system 3
167 .Sh BUGS
168 This version of
169 .Fn workexp
170 ignores the value of the
171 .Fa flags
172 argument.
173 .Sh COPYRIGHT
174 Copyright 1995-2002 University Corporation for Atmospheric Research/Unidata
175 .Pp
176 Portions of this software were developed by the Unidata Program at the
177 University Corporation for Atmospheric Research.