/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
/* 0 = both upper and lower case */
/* 1 = initial lower case only (build variables) */
/* 2 = initial upper case only (install variables) */
/*
* For next and last functions below, values indicate whether resolution
* was possible.
*
* 0 = all OK - the variable resolved within the established parameters
* or it wasn't time for the variable to bind.
* 1 = parameter did not resolve because there was no value in the
* environment or because it was a build variable at install
* time.
*/
/*
* This gets a raw path which may contain shell variables and returns in path
* a pathname with all appropriate parameters resolved. If it comes in
* relative, it goes out relative.
*/
int
{
char *token;
int retvalue = 0;
/*
* For each "/" separated token. If the token contains an environment
* variable, then evaluate the variable and insert it into path.
*/
/*
* If this is a token and it's an environment variable
* properly situated in the path...
*/
/* ... and it's the right time to evaluate it... */
/* replace the parameter with its value. */
/* void */)
*pt2 = '\0';
/*
* At this point EVERY token should evaluate
* to a value. If it doesn't, there's an
* error.
*/
/* copy in parameter value */
while (*token)
} else {
retvalue = 1;
}
/*
* If evaluate time is wrong, determine of this is an
* error.
*/
} else {
/*
* ALL variables MUST evaluate at
* install time.
*/
retvalue = 1;
/*
* All build-time variables must
* evaluate at build time.
*/
retvalue = 1;
} else /* no problem. */
}
/*
* If it's a separator, copy it over to the target buffer and
* move to the start of the next token.
*/
} else if (*pt == '/') {
pt++;
break;
/*
* If we're in the middle of a non-parametric token, copy
* that character over and try the next character.
*/
} else
}
*copy = '\0';
return (retvalue);
}
/*
* This function resolves the path into an absolute path referred to
* an install root of ir.
*/
void
{
/* For a relative path, prepend the basedir */
if (*path != '/') {
while (*ir)
path--;
}
*path++ = '/';
while (*basedir)
path--;
}
*path++ = '/';
/* For an absolute path, just prepend the install root */
} else {
while (*ir)
path--;
}
}
}
/*
* Evaluate varname and return with environment variables resolved.
* NOTE: This assumes that varname is a buffer long enough to hold the
* evaluated string.
*/
int
{
char *token;
int retvalue = 0;
/* If its a parametric entry beginning with an alpha character. */
/* ...and it's the right time to evaluate it... */
/*
* then it MUST be possible to evaluate it. If not,
* there's an error.
*/
*token) {
/* copy token into varname */
while (*token)
*varname = '\0';
} else
retvalue = 1;
} else {
/*
* ALL variables MUST evaluate at install
* time.
*/
retvalue = 1;
/*
* all build-time variables must evaluate at
* build time.
*/
retvalue = 1;
}
}
return (retvalue);
}