- do environment variable substitutions on any strings in the .bochsrc

This commit is contained in:
Bryce Denney 2001-11-11 05:44:40 +00:00
parent 7c92e20272
commit fa88fc2083

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.77 2001-11-06 15:41:34 fries Exp $
// $Id: main.cc,v 1.78 2001-11-11 05:44:40 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -1155,16 +1155,37 @@ parse_line_unformatted(char *context, char *line)
for (i=0; i<strlen(ptr); i++) {
if (ptr[i] == '"')
inquotes = !inquotes;
else
else {
#if BX_HAVE_GETENV
// substitute environment variables.
if (ptr[i] == '$') {
char varname[512];
char *pv = varname;
char *value;
*pv = 0;
i++;
while (isalpha(ptr[i]) || ptr[i]=='_') {
*pv = ptr[i]; pv++; i++;
}
*pv = 0;
if (strlen(varname)<1 || !(value = getenv(varname))) {
BX_PANIC (("could not look up environment variable '%s'\n", varname));
} else {
// append value to the string
for (pv=value; *pv; pv++)
string[string_i++] = *pv;
}
}
#endif
if (!isspace(ptr[i]) || inquotes) {
string[string_i++] = ptr[i];
}
string[string_i++] = ptr[i];
}
}
string[string_i] = '\0';
strcpy(ptr, string);
params[num_params++] = ptr;
ptr = strtok(NULL, ",");
}
string[string_i] = '\0';
params[num_params++] = strdup (string);
ptr = strtok(NULL, ",");
}
parse_line_formatted(context, num_params, &params[0]);
}