src/gedlib/lloptions.c
/*==========================================
 * expand_variables -- do any variable substitutions
 *  (variables are option properties starting & ending with %
 * Created: 2002/10/21, Perry Rapp
 *========================================*/
- do any variable substitutions
(variables are option properties starting & ending with %
Created: 2002/10/21, Perry Rapp
- do any variable substitutions ( variables are option properties starting & ending with % Created : 2002 / 10 / 21 Perry Rapp
static void
expand_variables (STRING valbuf, INT max)
{
	STRING start, end;
	STRING ptr; 
	ptr = valbuf;
	while ((start=strchr(ptr, '%')) && (end=strchr(start+1, '%'))) {
		STRING name = allocsubbytes(start, 0, end-start+1);
		STRING value = valueof_str(f_global, name);
		if (!value)
			value = valueof_str(f_predef, name);
		if (value) {
			INT newlen = strlen(valbuf)-(end-start+1)+strlen(value);
			if (newlen < max) {
				STRING copy = strdup(valbuf);
				if (start>valbuf)
					strncpy(valbuf, copy, start-valbuf);
				strcpy(start, value);
				strcpy(start+strlen(value), copy+(end-valbuf+1));
				stdfree(copy);
			}
		}
		stdfree(name);
		ptr = end+1;
	}
}
static void expand_variables ( STRING valbuf , INT max ) { STRING start , end ; STRING ptr ; ptr = valbuf ; while ( ( start = strchr ( ptr , ' ' ) ) && ( end = strchr ( start + 1 , ' ' ) ) ) { STRING name = allocsubbytes ( start , 0 , end - start + 1 ) ; STRING value = valueof_str ( f_global , name ) ; if ( ! value ) value = valueof_str ( f_predef , name ) ; if ( value ) { INT newlen = strlen ( valbuf ) - ( end - start + 1 ) + strlen ( value ) ; if ( newlen < max ) { STRING copy = strdup ( valbuf ) ; if ( start > valbuf ) strncpy ( valbuf , copy , start - valbuf ) ; strcpy ( start , value ) ; strcpy ( start + strlen ( value ) , copy + ( end - valbuf + 1 ) ) ; stdfree ( copy ) ; } } stdfree ( name ) ; ptr = end + 1 ; } }
expand_variables -- do any variable substitutions
  (variables are option properties starting & ending with %
 Created: 2002/10/21, Perry Rapp
expand_variables -- do any variable substitutions ( variables are option properties starting & ending with % Created : 2002 / 10 / 21 Perry Rapp
/* remainder of valbuf to check */