Buf_AddInterval(buf, start, p);
Buf_Addi(buf, start, p);
Var_SubstVar(buf, str, var, val)    Buffer	buf;    const char	*str;		/* The string in which to substitute */    const char	*var;		/* Named variable */    const char	*val;		/* Its value */{    assert(*var != '\0');    for (;;) {	const char *start;	/* Copy uninteresting stuff */	for (start = str; *str != '\0' && *str != '$'; str++)	    ;	Buf_AddInterval(buf, start, str);	start = str;	if (*str++ == '\0')	    break;	str++;	/* and escaped dollars */	if (start[1] == '$') {	    Buf_AddInterval(buf, start, start+2);	    continue;	}	/* Simple variable, if it's not us, copy.  */	if (start[1] != '(' && start[1] != '{') {	    if (start[1] != *var || var[1] != '\0') {		Buf_AddChars(buf, 2, start);		continue;	    }	} else {	    const char *p;	    char endc;	    if (start[1] == '(')		endc = ')';	    else		endc = '}';	    /* Find the end of the variable specification.  */	    p = str;	    while (*p != '\0' && *p != ':' && *p != endc && *p != '$')		p++;	    /* A variable inside the variable.	We don't know how to	     * expand the external variable at this point, so we try	     * again with the nested variable.	*/	    if (*p == '$') {		Buf_AddInterval(buf, start, p);		str = p;		continue;	    }	    if (strncmp(var, str, p - str) != 0 ||		var[p - str] != '\0') {		/* Not the variable we want to expand.	*/		Buf_AddInterval(buf, start, p);		str = p;		continue;	    }	    if (*p == ':') {		size_t	length; 	/* Length of the variable invocation */		Boolean doFree; 	/* Set true if val should be freed */		char	*newval;	/* Value substituted for a variable */		struct Name name;		length = p - str + 1;		doFree = FALSE;		name.s = var;		name.e = var + (p-str);		/* val won't be freed since doFree == FALSE, but		 * VarModifiers_Apply doesn't know that, hence the cast. */		newval = VarModifiers_Apply((char *)val, &name, NULL, FALSE,		    &doFree, p, endc, &length);		Buf_AddString(buf, newval);		if (doFree)		    free(newval);		str += length;		continue;	    } else		str = p+1;	}	Buf_AddString(buf, val);    }}