parsercmd/src/configpar.cxx
// ===========================================================================
// For an element like
//     <list separator=";" getenv="INCLUDE">-I"%"</list>
// get the environment variable and interpret it as a list using the given
// separator.  Expand the translation (-I"%") for each value in the list.
//
For an element like
-I"%"
get the environment variable and interpret it as a list using the given
separator.  Expand the translation (-I"%") for each value in the list.
For an element like - I " % " get the environment variable and interpret it as a list using the given separator . Expand the translation ( - I " % " ) for each value in the list .
bool expand_list(const string &env_variable, list<string> &translation,
		 const char separator, list<string> &expansion)
{
    const char *listval = getenv(env_variable.c_str());
    if (listval == NULL) {
	return false;
    }
    const char *begin = listval;
    const char *p;
    expansion.clear();
    for (p = begin; ; p += 1) {
	if (*p == '\0' || *p == separator) {
	    if (p != begin) {
		string listelem = string(begin, p - begin);
		bool found_bad = false;
		{
		    size_t i = 0;
		    size_t j = 0;
		    size_t elem_len = listelem.length();
		    size_t var_len = env_variable.length();
		    for (i = 0; i < elem_len; i += 1) {
			if (listelem.at(i) == '%' && i+1+var_len < elem_len
                                      && listelem.at(i + 1 + var_len) == '%') {
			    bool match_so_far = true;
			    for (j = 0; j < var_len; j += 1) {
				match_so_far = match_so_far &&
				    toupper(env_variable.at(j)) == toupper(listelem.at(i+1+j));
			    }
			    found_bad = found_bad || match_so_far;
			}
		    }
		}
		if (!found_bad) {
		    list<string>::iterator iter;
		    for (iter = translation.begin(); iter != translation.end(); ++iter) {
			expansion.push_back(*iter);
			substitute(expansion.back(), listelem);
		    }
		}
	    }
	    if (*p == '\0') {
		break;
	    }
	    else {
		begin = p + 1;
	    }
	}
    }
    return true;
}
bool expand_list ( const string & env_variable , list < string > & translation , const char separator , list < string > & expansion ) { const char * listval = getenv ( env_variable . c_str ( ) ) ; if ( listval == NULL ) { return false ; } const char * begin = listval ; const char * p ; expansion . clear ( ) ; for ( p = begin ; ; p += 1 ) { if ( * p == ' \0 ' || * p == separator ) { if ( p != begin ) { string listelem = string ( begin , p - begin ) ; bool found_bad = false ; { size_t i = 0 ; size_t j = 0 ; size_t elem_len = listelem . length ( ) ; size_t var_len = env_variable . length ( ) ; for ( i = 0 ; i < elem_len ; i += 1 ) { if ( listelem . at ( i ) == ' ' && i + 1 + var_len < elem_len && listelem . at ( i + 1 + var_len ) == ' ' ) { bool match_so_far = true ; for ( j = 0 ; j < var_len ; j += 1 ) { match_so_far = match_so_far && toupper ( env_variable . at ( j ) ) == toupper ( listelem . at ( i + 1 + j ) ) ; } found_bad = found_bad || match_so_far ; } } } if ( ! found_bad ) { list < string > :: iterator iter ; for ( iter = translation . begin ( ) ; iter != translation . end ( ) ; ++ iter ) { expansion . push_back ( * iter ) ; substitute ( expansion . back ( ) , listelem ) ; } } } if ( * p == ' \0 ' ) { break ; } else { begin = p + 1 ; } } } return true ; }
For an element like
<list separator=";" getenv="INCLUDE">-I"%"</list>
get the environment variable and interpret it as a list using the given
separator.
For an element like <list separator = " ; " getenv = " INCLUDE " > - I " % " < / list > get the environment variable and interpret it as a list using the given separator .
// Detect badness (infinite recursion) if listelem refers to env_variable.