version 1.15, 1999/11/11 11:35:17 |
version 1.16, 1999/12/06 22:24:32 |
|
|
|
|
typedef struct { |
typedef struct { |
char *lhs; /* String to match */ |
char *lhs; /* String to match */ |
int leftLen; /* Length of string */ |
size_t leftLen; /* Length of string */ |
char *rhs; /* Replacement string (w/ &'s removed) */ |
char *rhs; /* Replacement string (w/ &'s removed) */ |
int rightLen; /* Length of replacement */ |
size_t rightLen; /* Length of replacement */ |
int flags; |
int flags; |
} VarPattern; |
} VarPattern; |
|
|
|
|
static Boolean VarRESubstitute __P((char *, Boolean, Buffer, ClientData)); |
static Boolean VarRESubstitute __P((char *, Boolean, Buffer, ClientData)); |
#endif |
#endif |
static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData)); |
static Boolean VarSubstitute __P((char *, Boolean, Buffer, ClientData)); |
static char *VarGetPattern __P((GNode *, int, char **, int, int *, int *, |
static char *VarGetPattern __P((GNode *, int, char **, int, int *, size_t *, |
VarPattern *)); |
VarPattern *)); |
static char *VarQuote __P((char *)); |
static char *VarQuote __P((char *)); |
static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer, |
static char *VarModify __P((char *, Boolean (*)(char *, Boolean, Buffer, |
|
|
char *env; |
char *env; |
|
|
if ((env = getenv (name)) != NULL) { |
if ((env = getenv (name)) != NULL) { |
int len; |
size_t len; |
|
|
v = (Var *) emalloc(sizeof(Var)); |
v = (Var *) emalloc(sizeof(Var)); |
v->name = estrdup(name); |
v->name = estrdup(name); |
|
|
len = strlen(env); |
len = strlen(env); |
|
|
v->val = Buf_Init(len); |
v->val = Buf_Init(len); |
Buf_AddBytes(v->val, len, (Byte *)env); |
Buf_AddChars(v->val, len, env); |
|
|
v->flags = VAR_FROM_ENV; |
v->flags = VAR_FROM_ENV; |
return (v); |
return (v); |
|
|
|
|
len = val ? strlen(val) : 0; |
len = val ? strlen(val) : 0; |
v->val = Buf_Init(len+1); |
v->val = Buf_Init(len+1); |
Buf_AddBytes(v->val, len, (Byte *)val); |
Buf_AddChars(v->val, len, val); |
|
|
v->flags = 0; |
v->flags = 0; |
|
|
|
|
VarAdd (name, val, ctxt); |
VarAdd (name, val, ctxt); |
} else { |
} else { |
Buf_Discard(v->val, Buf_Size(v->val)); |
Buf_Discard(v->val, Buf_Size(v->val)); |
Buf_AddBytes(v->val, strlen(val), (Byte *)val); |
Buf_AddChars(v->val, strlen(val), val); |
|
|
if (DEBUG(VAR)) { |
if (DEBUG(VAR)) { |
printf("%s:%s = %s\n", ctxt->name, name, val); |
printf("%s:%s = %s\n", ctxt->name, name, val); |
|
|
if (v == (Var *) NIL) { |
if (v == (Var *) NIL) { |
VarAdd (name, val, ctxt); |
VarAdd (name, val, ctxt); |
} else { |
} else { |
Buf_AddByte(v->val, (Byte)' '); |
Buf_AddChar(v->val, ' '); |
Buf_AddBytes(v->val, strlen(val), (Byte *)val); |
Buf_AddChars(v->val, strlen(val), val); |
|
|
if (DEBUG(VAR)) { |
if (DEBUG(VAR)) { |
printf("%s:%s = %s\n", ctxt->name, name, |
printf("%s:%s = %s\n", ctxt->name, name, |
(char *) Buf_GetAll(v->val, (int *)NULL)); |
Buf_GetAll(v->val, NULL)); |
} |
} |
|
|
if (v->flags & VAR_FROM_ENV) { |
if (v->flags & VAR_FROM_ENV) { |
|
|
v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); |
v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); |
*frp = NULL; |
*frp = NULL; |
if (v != (Var *) NIL) { |
if (v != (Var *) NIL) { |
char *p = ((char *)Buf_GetAll(v->val, (int *)NULL)); |
char *p = Buf_GetAll(v->val, NULL); |
if (v->flags & VAR_FROM_ENV) { |
if (v->flags & VAR_FROM_ENV) { |
Buf_Destroy(v->val, FALSE); |
Buf_Destroy(v->val, FALSE); |
free((Address) v); |
free((Address) v); |
|
|
size_t len = strlen(word); |
size_t len = strlen(word); |
|
|
if (addSpace) { |
if (addSpace) { |
Buf_AddByte (buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
|
|
while (len--) { |
while (len--) { |
Buf_AddByte (buf, toupper(*word++)); |
Buf_AddChar(buf, toupper(*word++)); |
} |
} |
return (TRUE); |
return (TRUE); |
} |
} |
|
|
size_t len = strlen(word); |
size_t len = strlen(word); |
|
|
if (addSpace) { |
if (addSpace) { |
Buf_AddByte (buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
|
|
while (len--) { |
while (len--) { |
Buf_AddByte (buf, tolower(*word++)); |
Buf_AddChar(buf, tolower(*word++)); |
} |
} |
return (TRUE); |
return (TRUE); |
} |
} |
|
|
slash = strrchr (word, '/'); |
slash = strrchr (word, '/'); |
if (slash != (char *)NULL) { |
if (slash != (char *)NULL) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte (buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
*slash = '\0'; |
*slash = '\0'; |
Buf_AddBytes (buf, strlen (word), (Byte *)word); |
Buf_AddChars(buf, strlen(word), word); |
*slash = '/'; |
*slash = '/'; |
return (TRUE); |
return (TRUE); |
} else { |
} else { |
|
|
* If no directory part, give . (q.v. the POSIX standard) |
* If no directory part, give . (q.v. the POSIX standard) |
*/ |
*/ |
if (addSpace) { |
if (addSpace) { |
Buf_AddBytes(buf, 2, (Byte *)" ."); |
Buf_AddChars(buf, 2, " ."); |
} else { |
} else { |
Buf_AddByte(buf, (Byte)'.'); |
Buf_AddChar(buf, '.'); |
} |
} |
} |
} |
return(dummy ? TRUE : TRUE); |
return(dummy ? TRUE : TRUE); |
|
|
register char *slash; |
register char *slash; |
|
|
if (addSpace) { |
if (addSpace) { |
Buf_AddByte (buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
|
|
slash = strrchr (word, '/'); |
slash = strrchr (word, '/'); |
if (slash != (char *)NULL) { |
if (slash != (char *)NULL) { |
*slash++ = '\0'; |
*slash++ = '\0'; |
Buf_AddBytes (buf, strlen(slash), (Byte *)slash); |
Buf_AddChars(buf, strlen(slash), slash); |
slash[-1] = '/'; |
slash[-1] = '/'; |
} else { |
} else { |
Buf_AddBytes (buf, strlen(word), (Byte *)word); |
Buf_AddChars(buf, strlen(word), word); |
} |
} |
return (dummy ? TRUE : TRUE); |
return (dummy ? TRUE : TRUE); |
} |
} |
|
|
dot = strrchr (word, '.'); |
dot = strrchr (word, '.'); |
if (dot != (char *)NULL) { |
if (dot != (char *)NULL) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte (buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
*dot++ = '\0'; |
*dot++ = '\0'; |
Buf_AddBytes (buf, strlen (dot), (Byte *)dot); |
Buf_AddChars(buf, strlen(dot), dot); |
dot[-1] = '.'; |
dot[-1] = '.'; |
addSpace = TRUE; |
addSpace = TRUE; |
} |
} |
|
|
register char *dot; |
register char *dot; |
|
|
if (addSpace) { |
if (addSpace) { |
Buf_AddByte (buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
|
|
dot = strrchr (word, '.'); |
dot = strrchr (word, '.'); |
if (dot != (char *)NULL) { |
if (dot != (char *)NULL) { |
*dot = '\0'; |
*dot = '\0'; |
Buf_AddBytes (buf, strlen (word), (Byte *)word); |
Buf_AddChars(buf, strlen(word), word); |
*dot = '.'; |
*dot = '.'; |
} else { |
} else { |
Buf_AddBytes (buf, strlen(word), (Byte *)word); |
Buf_AddChars(buf, strlen(word), word); |
} |
} |
return (dummy ? TRUE : TRUE); |
return (dummy ? TRUE : TRUE); |
} |
} |
|
|
{ |
{ |
if (Str_Match(word, (char *) pattern)) { |
if (Str_Match(word, (char *) pattern)) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
addSpace = TRUE; |
addSpace = TRUE; |
Buf_AddBytes(buf, strlen(word), (Byte *)word); |
Buf_AddChars(buf, strlen(word), word); |
} |
} |
return(addSpace); |
return(addSpace); |
} |
} |
|
|
|
|
if (*word) { |
if (*word) { |
if (addSpace) |
if (addSpace) |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
|
|
addSpace = TRUE; |
addSpace = TRUE; |
|
|
if ((ptr = Str_SYSVMatch(word, pat->lhs, &len)) != NULL) |
if ((ptr = Str_SYSVMatch(word, pat->lhs, &len)) != NULL) |
Str_SYSVSubst(buf, pat->rhs, ptr, len); |
Str_SYSVSubst(buf, pat->rhs, ptr, len); |
else |
else |
Buf_AddBytes(buf, strlen(word), (Byte *) word); |
Buf_AddChars(buf, strlen(word), word); |
} |
} |
return(addSpace); |
return(addSpace); |
} |
} |
|
|
{ |
{ |
if (!Str_Match(word, (char *) pattern)) { |
if (!Str_Match(word, (char *) pattern)) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
addSpace = TRUE; |
addSpace = TRUE; |
Buf_AddBytes(buf, strlen(word), (Byte *)word); |
Buf_AddChars(buf, strlen(word), word); |
} |
} |
return(addSpace); |
return(addSpace); |
} |
} |
|
|
Buffer buf; /* Buffer for result */ |
Buffer buf; /* Buffer for result */ |
ClientData patternp; /* Pattern for substitution */ |
ClientData patternp; /* Pattern for substitution */ |
{ |
{ |
register int wordLen; /* Length of word */ |
register size_t wordLen; /* Length of word */ |
register char *cp; /* General pointer */ |
register char *cp; /* General pointer */ |
VarPattern *pattern = (VarPattern *) patternp; |
VarPattern *pattern = (VarPattern *) patternp; |
|
|
|
|
*/ |
*/ |
if (pattern->rightLen != 0) { |
if (pattern->rightLen != 0) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
addSpace = TRUE; |
addSpace = TRUE; |
Buf_AddBytes(buf, pattern->rightLen, |
Buf_AddChars(buf, pattern->rightLen, pattern->rhs); |
(Byte *)pattern->rhs); |
|
} |
} |
pattern->flags |= VAR_SUB_MATCHED; |
pattern->flags |= VAR_SUB_MATCHED; |
} else if (pattern->flags & VAR_MATCH_END) { |
} else if (pattern->flags & VAR_MATCH_END) { |
|
|
*/ |
*/ |
if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){ |
if ((pattern->rightLen + wordLen - pattern->leftLen) != 0){ |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
addSpace = TRUE; |
addSpace = TRUE; |
} |
} |
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs); |
Buf_AddChars(buf, pattern->rightLen, pattern->rhs); |
Buf_AddBytes(buf, wordLen - pattern->leftLen, |
Buf_AddChars(buf, wordLen - pattern->leftLen, |
(Byte *)(word + pattern->leftLen)); |
word + pattern->leftLen); |
pattern->flags |= VAR_SUB_MATCHED; |
pattern->flags |= VAR_SUB_MATCHED; |
} |
} |
} else if (pattern->flags & VAR_MATCH_START) { |
} else if (pattern->flags & VAR_MATCH_START) { |
|
|
*/ |
*/ |
if (((cp - word) + pattern->rightLen) != 0) { |
if (((cp - word) + pattern->rightLen) != 0) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
addSpace = TRUE; |
addSpace = TRUE; |
} |
} |
Buf_AddBytes(buf, cp - word, (Byte *)word); |
Buf_AddChars(buf, cp - word, word); |
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs); |
Buf_AddChars(buf, pattern->rightLen, pattern->rhs); |
pattern->flags |= VAR_SUB_MATCHED; |
pattern->flags |= VAR_SUB_MATCHED; |
} else { |
} else { |
/* |
/* |
|
|
* buffer. |
* buffer. |
*/ |
*/ |
register Boolean done; |
register Boolean done; |
int origSize; |
size_t origSize; |
|
|
done = FALSE; |
done = FALSE; |
origSize = Buf_Size(buf); |
origSize = Buf_Size(buf); |
|
|
cp = strstr(word, pattern->lhs); |
cp = strstr(word, pattern->lhs); |
if (cp != (char *)NULL) { |
if (cp != (char *)NULL) { |
if (addSpace && (((cp - word) + pattern->rightLen) != 0)){ |
if (addSpace && (((cp - word) + pattern->rightLen) != 0)){ |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
addSpace = FALSE; |
addSpace = FALSE; |
} |
} |
Buf_AddBytes(buf, cp-word, (Byte *)word); |
Buf_AddChars(buf, cp-word, word); |
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs); |
Buf_AddChars(buf, pattern->rightLen, pattern->rhs); |
wordLen -= (cp - word) + pattern->leftLen; |
wordLen -= (cp - word) + pattern->leftLen; |
word = cp + pattern->leftLen; |
word = cp + pattern->leftLen; |
if (wordLen == 0 || (pattern->flags & VAR_SUB_GLOBAL) == 0){ |
if (wordLen == 0 || (pattern->flags & VAR_SUB_GLOBAL) == 0){ |
|
|
} |
} |
if (wordLen != 0) { |
if (wordLen != 0) { |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
Buf_AddBytes(buf, wordLen, (Byte *)word); |
Buf_AddChars(buf, wordLen, word); |
} |
} |
/* |
/* |
* If added characters to the buffer, need to add a space |
* If added characters to the buffer, need to add a space |
* before we add any more. If we didn't add any, just return |
* before we add any more. If we didn't add any, just return |
* the previous value of addSpace. |
* the previous value of addSpace. |
*/ |
*/ |
return ((Buf_Size(buf) != origSize) || addSpace); |
return (Buf_Size(buf) != origSize || addSpace); |
} |
} |
return (addSpace); |
return (addSpace); |
} |
} |
nosub: |
nosub: |
if (addSpace) { |
if (addSpace) { |
Buf_AddByte(buf, (Byte)' '); |
Buf_AddChar(buf, ' '); |
} |
} |
Buf_AddBytes(buf, wordLen, (Byte *)word); |
Buf_AddChars(buf, wordLen, word); |
return(TRUE); |
return(TRUE); |
} |
} |
|
|
|
|
|
|
#define MAYBE_ADD_SPACE() \ |
#define MAYBE_ADD_SPACE() \ |
if (addSpace && !added) \ |
if (addSpace && !added) \ |
Buf_AddByte(buf, ' '); \ |
Buf_AddChar(buf, ' '); \ |
added = 1 |
added = 1 |
|
|
added = 0; |
added = 0; |
|
|
pat->flags |= VAR_SUB_MATCHED; |
pat->flags |= VAR_SUB_MATCHED; |
if (pat->matches[0].rm_so > 0) { |
if (pat->matches[0].rm_so > 0) { |
MAYBE_ADD_SPACE(); |
MAYBE_ADD_SPACE(); |
Buf_AddBytes(buf, pat->matches[0].rm_so, wp); |
Buf_AddChars(buf, pat->matches[0].rm_so, wp); |
} |
} |
|
|
for (rp = pat->replace; *rp; rp++) { |
for (rp = pat->replace; *rp; rp++) { |
if ((*rp == '\\') && ((rp[1] == '&') || (rp[1] == '\\'))) { |
if ((*rp == '\\') && ((rp[1] == '&') || (rp[1] == '\\'))) { |
MAYBE_ADD_SPACE(); |
MAYBE_ADD_SPACE(); |
Buf_AddByte(buf,rp[1]); |
Buf_AddChar(buf, rp[1]); |
rp++; |
rp++; |
} |
} |
else if ((*rp == '&') || ((*rp == '\\') && isdigit(rp[1]))) { |
else if ((*rp == '&') || ((*rp == '\\') && isdigit(rp[1]))) { |
|
|
|
|
if (sublen > 0) { |
if (sublen > 0) { |
MAYBE_ADD_SPACE(); |
MAYBE_ADD_SPACE(); |
Buf_AddBytes(buf, sublen, subbuf); |
Buf_AddChars(buf, sublen, subbuf); |
} |
} |
} else { |
} else { |
MAYBE_ADD_SPACE(); |
MAYBE_ADD_SPACE(); |
Buf_AddByte(buf, *rp); |
Buf_AddChar(buf, *rp); |
} |
} |
} |
} |
wp += pat->matches[0].rm_eo; |
wp += pat->matches[0].rm_eo; |
|
|
goto tryagain; |
goto tryagain; |
if (*wp) { |
if (*wp) { |
MAYBE_ADD_SPACE(); |
MAYBE_ADD_SPACE(); |
Buf_AddBytes(buf, strlen(wp), wp); |
Buf_AddChars(buf, strlen(wp), wp); |
} |
} |
break; |
break; |
default: |
default: |
|
|
case REG_NOMATCH: |
case REG_NOMATCH: |
if (*wp) { |
if (*wp) { |
MAYBE_ADD_SPACE(); |
MAYBE_ADD_SPACE(); |
Buf_AddBytes(buf,strlen(wp),wp); |
Buf_AddChars(buf, strlen(wp), wp); |
} |
} |
break; |
break; |
} |
} |
|
|
char *as; /* word list memory */ |
char *as; /* word list memory */ |
int ac, i; |
int ac, i; |
|
|
buf = Buf_Init (0); |
buf = Buf_Init(0); |
addSpace = FALSE; |
addSpace = FALSE; |
|
|
av = brk_string(str, &ac, FALSE, &as); |
av = brk_string(str, &ac, FALSE, &as); |
|
|
|
|
free(as); |
free(as); |
free(av); |
free(av); |
Buf_AddByte (buf, '\0'); |
Buf_AddChar(buf, '\0'); |
str = (char *)Buf_GetAll (buf, (int *)NULL); |
str = Buf_GetAll(buf, NULL); |
Buf_Destroy (buf, FALSE); |
Buf_Destroy(buf, FALSE); |
return (str); |
return (str); |
} |
} |
|
|
|
|
char **tstr; |
char **tstr; |
int delim; |
int delim; |
int *flags; |
int *flags; |
int *length; |
size_t *length; |
VarPattern *pattern; |
VarPattern *pattern; |
{ |
{ |
char *cp; |
char *cp; |
|
|
*/ |
*/ |
for (cp = *tstr; *cp && (*cp != delim); cp++) { |
for (cp = *tstr; *cp && (*cp != delim); cp++) { |
if (IS_A_MATCH(cp, delim)) { |
if (IS_A_MATCH(cp, delim)) { |
Buf_AddByte(buf, (Byte) cp[1]); |
Buf_AddChar(buf, cp[1]); |
cp++; |
cp++; |
} else if (*cp == '$') { |
} else if (*cp == '$') { |
if (cp[1] == delim) { |
if (cp[1] == delim) { |
if (flags == NULL) |
if (flags == NULL) |
Buf_AddByte(buf, (Byte) *cp); |
Buf_AddChar(buf, *cp); |
else |
else |
/* |
/* |
* Unescaped $ at end of pattern => anchor |
* Unescaped $ at end of pattern => anchor |
|
|
* substitution and recurse. |
* substitution and recurse. |
*/ |
*/ |
cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); |
cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); |
Buf_AddBytes(buf, strlen(cp2), (Byte *) cp2); |
Buf_AddChars(buf, strlen(cp2), cp2); |
if (freeIt) |
if (freeIt) |
free(cp2); |
free(cp2); |
cp += len - 1; |
cp += len - 1; |
} |
} |
} |
} |
else if (pattern && *cp == '&') |
else if (pattern && *cp == '&') |
Buf_AddBytes(buf, pattern->leftLen, (Byte *)pattern->lhs); |
Buf_AddChars(buf, pattern->leftLen, pattern->lhs); |
else |
else |
Buf_AddByte(buf, (Byte) *cp); |
Buf_AddChar(buf, *cp); |
} |
} |
|
|
Buf_AddByte(buf, (Byte) '\0'); |
Buf_AddChar(buf, '\0'); |
|
|
if (*cp != delim) { |
if (*cp != delim) { |
*tstr = cp; |
*tstr = cp; |
|
|
} |
} |
else { |
else { |
*tstr = ++cp; |
*tstr = ++cp; |
cp = (char *) Buf_GetAll(buf, length); |
cp = Buf_GetAll(buf, length); |
*length -= 1; /* Don't count the NULL */ |
*length -= 1; /* Don't count the NULL */ |
Buf_Destroy(buf, FALSE); |
Buf_Destroy(buf, FALSE); |
return cp; |
return cp; |
|
|
/* This should cover most shells :-( */ |
/* This should cover most shells :-( */ |
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; |
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; |
|
|
buf = Buf_Init (MAKE_BSIZE); |
buf = Buf_Init(MAKE_BSIZE); |
for (; *str; str++) { |
for (; *str; str++) { |
if (strchr(meta, *str) != NULL) |
if (strchr(meta, *str) != NULL) |
Buf_AddByte(buf, (Byte)'\\'); |
Buf_AddChar(buf, '\\'); |
Buf_AddByte(buf, (Byte)*str); |
Buf_AddChar(buf, *str); |
} |
} |
Buf_AddByte(buf, (Byte) '\0'); |
Buf_AddChar(buf, '\0'); |
str = (char *)Buf_GetAll (buf, (int *)NULL); |
str = Buf_GetAll(buf, NULL); |
Buf_Destroy (buf, FALSE); |
Buf_Destroy(buf, FALSE); |
return str; |
return str; |
} |
} |
|
|
|
|
* the only one who sets these things and we sure don't |
* the only one who sets these things and we sure don't |
* but nested invocations in them... |
* but nested invocations in them... |
*/ |
*/ |
val = (char *)Buf_GetAll(v->val, (int *)NULL); |
val = Buf_GetAll(v->val, NULL); |
|
|
if (str[3] == 'D') { |
if (str[3] == 'D') { |
val = VarModify(val, VarHead, (ClientData)0); |
val = VarModify(val, VarHead, (ClientData)0); |
|
|
* been dynamically-allocated, so it will need freeing when we |
* been dynamically-allocated, so it will need freeing when we |
* return. |
* return. |
*/ |
*/ |
str = (char *)Buf_GetAll(v->val, (int *)NULL); |
str = Buf_GetAll(v->val, NULL); |
if (strchr (str, '$') != (char *)NULL) { |
if (strchr (str, '$') != (char *)NULL) { |
str = Var_Subst(NULL, str, ctxt, err); |
str = Var_Subst(NULL, str, ctxt, err); |
*freePtr = TRUE; |
*freePtr = TRUE; |
|
|
if (v->flags & VAR_FROM_ENV) { |
if (v->flags & VAR_FROM_ENV) { |
Boolean destroy = FALSE; |
Boolean destroy = FALSE; |
|
|
if (str != (char *)Buf_GetAll(v->val, (int *)NULL)) { |
if (str != Buf_GetAll(v->val, NULL)) { |
destroy = TRUE; |
destroy = TRUE; |
} else { |
} else { |
/* |
/* |
|
|
* been reported to prevent a plethora |
* been reported to prevent a plethora |
* of messages when recursing */ |
* of messages when recursing */ |
|
|
buf = Buf_Init (MAKE_BSIZE); |
buf = Buf_Init(MAKE_BSIZE); |
errorReported = FALSE; |
errorReported = FALSE; |
|
|
while (*str) { |
while (*str) { |
|
|
* dollar sign into the buffer directly. |
* dollar sign into the buffer directly. |
*/ |
*/ |
str++; |
str++; |
Buf_AddByte(buf, (Byte)*str); |
Buf_AddChar(buf, *str); |
str++; |
str++; |
} else if (*str != '$') { |
} else if (*str != '$') { |
/* |
/* |
|
|
|
|
for (cp = str++; *str != '$' && *str != '\0'; str++) |
for (cp = str++; *str != '$' && *str != '\0'; str++) |
continue; |
continue; |
Buf_AddBytes(buf, str - cp, (Byte *)cp); |
Buf_AddChars(buf, str - cp, cp); |
} else { |
} else { |
if (var != NULL) { |
if (var != NULL) { |
int expand; |
int expand; |
for (;;) { |
for (;;) { |
if (str[1] != '(' && str[1] != '{') { |
if (str[1] != '(' && str[1] != '{') { |
if (str[1] != *var || var[1] != '\0') { |
if (str[1] != *var || var[1] != '\0') { |
Buf_AddBytes(buf, 2, (Byte *) str); |
Buf_AddChars(buf, 2, str); |
str += 2; |
str += 2; |
expand = FALSE; |
expand = FALSE; |
} |
} |
|
|
* the nested one |
* the nested one |
*/ |
*/ |
if (*p == '$') { |
if (*p == '$') { |
Buf_AddBytes(buf, p - str, (Byte *) str); |
Buf_AddChars(buf, p - str, str); |
str = p; |
str = p; |
continue; |
continue; |
} |
} |
|
|
*/ |
*/ |
for (;*p != '$' && *p != '\0'; p++) |
for (;*p != '$' && *p != '\0'; p++) |
continue; |
continue; |
Buf_AddBytes(buf, p - str, (Byte *) str); |
Buf_AddChars(buf, p - str, str); |
str = p; |
str = p; |
expand = FALSE; |
expand = FALSE; |
} |
} |
|
|
str += length; |
str += length; |
errorReported = TRUE; |
errorReported = TRUE; |
} else { |
} else { |
Buf_AddByte (buf, (Byte)*str); |
Buf_AddChar(buf, *str); |
str += 1; |
str += 1; |
} |
} |
} else { |
} else { |
|
|
* Copy all the characters from the variable value straight |
* Copy all the characters from the variable value straight |
* into the new string. |
* into the new string. |
*/ |
*/ |
Buf_AddBytes (buf, strlen (val), (Byte *)val); |
Buf_AddChars(buf, strlen(val), val); |
if (doFree) { |
if (doFree) { |
free ((Address)val); |
free ((Address)val); |
} |
} |
|
|
} |
} |
} |
} |
|
|
Buf_AddByte (buf, '\0'); |
Buf_AddChar(buf, '\0'); |
str = (char *)Buf_GetAll (buf, (int *)NULL); |
str = Buf_GetAll(buf, NULL); |
Buf_Destroy (buf, FALSE); |
Buf_Destroy(buf, FALSE); |
return (str); |
return (str); |
} |
} |
|
|
|
|
ClientData dummy; |
ClientData dummy; |
{ |
{ |
Var *v = (Var *) vp; |
Var *v = (Var *) vp; |
printf ("%-16s = %s\n", v->name, (char *) Buf_GetAll(v->val, (int *)NULL)); |
printf ("%-16s = %s\n", v->name, Buf_GetAll(v->val, NULL)); |
return (dummy ? 0 : 0); |
return (dummy ? 0 : 0); |
} |
} |
|
|