.\" Part of publib. .\" .\" Copyright (c) 1994-2006 Lars Wirzenius. 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. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. .\" .\" part of publib .\" "@(#)publib-strutil:$Id: strvars.3,v 1.2 1995/06/17 10:47:23 wirzeniu Exp $" .\" .TH STRVARS 3pub "C Programmer's Manual" Publib "C Programmer's Manual" .SH NAME strvars \- expand variables in string .SH SYNOPSIS .nf #include int \fBstrvars\fR(char **\fIres\fR, const char *\fIstr\fR, char *(*\fIexpand\fR)(const char *)); .SH DESCRIPTION \fIstrvars\fR will replaces references to variables in the string \fIstr\fR with the values of the variables. A reference to a variable is of the form \fI$(foo)\fR or \fI$x\fR (where \fIx\fR is a single character, but not \fI$\fR). A dollar sign is expressed in the string as \fI$$\fR, and will be converted to \fI$\fR in the output. Memory for the expanded string is allocated dynamically, and \fI*res\fR is set to point to it. .PP The values of the variables are fetched using the function \fIexpand\fR. It is given the name of the variable as its argument, and must return a pointer to the value, or NULL if that variable doesn't exist. .SH "RETURN VALUE" \fIstrvars\fR will return 0 if successful, or NULL if an error occurred (malformed input string, result too big, or unknown variable). .SH EXAMPLE To replace references to environment variables, one would the following. .sp 1 .nf .in +5 #include #include char line[1024]; char *res; if (strvars(&res, line, getenv) == NULL) errormsg(1, 0, "strvars failed"); printf("res = <%s>\\n", res); .in -5 .SH "SEE ALSO" publib(3), getenv(3) .SH AUTHOR Lars Wirzenius (lars.wirzenius@helsinki.fi)