GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
STRVARS(3) C Programmer's Manual STRVARS(3)

strvars - expand variables in string

#include <publib.h>
int strvars(char **res, const char *str, char *(*expand)(const char *));

strvars will replaces references to variables in the string str with the values of the variables. A reference to a variable is of the form $(foo) or $x (where x is a single character, but not $). A dollar sign is expressed in the string as $$, and will be converted to $ in the output. Memory for the expanded string is allocated dynamically, and *res is set to point to it.

The values of the variables are fetched using the function expand. 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.

strvars will return 0 if successful, or NULL if an error occured (malformed input string, result too big, or unknown variable).

To replace references to environment variables, one would the following.


#include <publib.h> #include <stdlib.h> char line[1024]; char *res; if (strvars(&res, line, getenv) == NULL) errormsg(1, 0, "strvars failed"); printf("res = <%s>\n", res);

publib(3), getenv(3)

Lars Wirzenius (lars.wirzenius@helsinki.fi)
C Programmer's Manual Publib

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.