scandsp/src/dspparser.cxx
// ===========================================================================
// Substitutes in s based on the user's environment variables.
// The argument 'sup' is a list of environment variables to suppress,
// because expansion is recursive, but we want to prevent runaways.
//
Substitutes in s based on the user's environment variables.
The argument 'sup' is a list of environment variables to suppress,
because expansion is recursive, but we want to prevent runaways.
Substitutes in s based on the user ' s environment variables . The argument ' sup ' is a list of environment variables to suppress because expansion is recursive but we want to prevent runaways .
void DSPParser::substituteEnvVars(string &s, void *sup)
{
    var_name_list *suppress = (var_name_list *)sup;
    const char *p = s.c_str();
    if (strchr(p, '%') != NULL) {
	string result;
	string var;
	bool in_var = false;
	for (;; p += 1) {
	    char ch = *p;
	    if (ch == '\0') {
		if (in_var) {
		    result.append("%");
		    result.append(var);
		}
		break;
	    }
	    if (in_var) {
		if (ch == '%') {
                    if (is_on_list(var, suppress)) {
		    }
		    else {
			const char *val = getenv(var.c_str());
			if (val == NULL) {
			    result.append("%");
			    result.append(var);
			    result.append("%");
			}
			else {
			    string v(val);
			    var_name_list to_suppress = { &var, suppress };
			    substituteEnvVars(v, &to_suppress);
			    result.append(v);
			}
		    }
		    in_var = false;
		}
		else {
		    var.append(1, ch);
		}
	    }
	    else {
		if (ch == '%') {
		    in_var = true;
		    var = "";
		}
		else {
		    result.append(1, ch);
		}
	    }
	}
	s = result;
    }
}
void DSPParser :: substituteEnvVars ( string & s , void * sup ) { var_name_list * suppress = ( var_name_list * ) sup ; const char * p = s . c_str ( ) ; if ( strchr ( p , ' ' ) != NULL ) { string result ; string var ; bool in_var = false ; for ( ; ; p += 1 ) { char ch = * p ; if ( ch == ' \0 ' ) { if ( in_var ) { result . append ( " " ) ; result . append ( var ) ; } break ; } if ( in_var ) { if ( ch == ' ' ) { if ( is_on_list ( var , suppress ) ) { } else { const char * val = getenv ( var . c_str ( ) ) ; if ( val == NULL ) { result . append ( " " ) ; result . append ( var ) ; result . append ( " " ) ; } else { string v ( val ) ; var_name_list to_suppress = { & var , suppress } ; substituteEnvVars ( v , & to_suppress ) ; result . append ( v ) ; } } in_var = false ; } else { var . append ( 1 , ch ) ; } } else { if ( ch == ' ' ) { in_var = true ; var = " " ; } else { result . append ( 1 , ch ) ; } } } s = result ; } }
Substitutes in s based on the user's environment variables.
Substitutes in s based on the user ' s environment variables .
// Substitute some more, in case the // expansion refers to other env vars.