Lst_ForEach(gn->children, SuffExpandChildren, (ClientData)gn);
Lst_ForEach(gn->children, SuffExpandChildren, gn);
SuffFindNormalDeps(gn, slst)    GNode   	*gn;	    /* Node for which to find sources */    Lst		slst;{    char    	*eoname;    /* End of name */    char    	*sopref;    /* Start of prefix */    LstNode 	ln; 	    /* Next suffix node to check */    Lst	    	srcs;	    /* List of sources at which to look */    Lst	    	targs;	    /* List of targets to which things can be			     * transformed. They all have the same file,			     * but different suff and pref fields */    Src	    	*bottom;    /* Start of found transformation path */    Src 	*src;	    /* General Src pointer */    char    	*pref;	    /* Prefix to use */    Src	    	*targ;	    /* General Src target pointer */    eoname = gn->name + strlen(gn->name);    sopref = gn->name;    /*     * Begin at the beginning...     */    ln = Lst_First(sufflist);    srcs = Lst_Init();    targs = Lst_Init();    /*     * We're caught in a catch-22 here. On the one hand, we want to use any     * transformation implied by the target's sources, but we can't examine     * the sources until we've expanded any variables/wildcards they may hold,     * and we can't do that until we've set up the target's local variables     * and we can't do that until we know what the proper suffix for the     * target is (in case there are two suffixes one of which is a suffix of     * the other) and we can't know that until we've found its implied     * source, which we may not want to use if there's an existing source     * that implies a different transformation.     *     * In an attempt to get around this, which may not work all the time,     * but should work most of the time, we look for implied sources first,     * checking transformations to all possible suffixes of the target,     * use what we find to set the target's local variables, expand the     * children, then look for any overriding transformations they imply.     * Should we find one, we discard the one we found before.     */    while (ln != NULL) {	/*	 * Look for next possible suffix...	 */	ln = Lst_FindFrom(ln, SuffSuffIsSuffixP, eoname);	if (ln != NULL) {	    int	    prefLen;	    /* Length of the prefix */	    Src	    *targ;	    /*	     * Allocate a Src structure to which things can be transformed	     */	    targ = (Src *)emalloc(sizeof (Src));	    targ->file = estrdup(gn->name);	    targ->suff = (Suff *)Lst_Datum(ln);	    targ->node = gn;	    targ->parent = (Src *)NULL;	    targ->children = 0;#ifdef DEBUG_SRC	    targ->cp = Lst_Init();#endif	    /*	     * Allocate room for the prefix, whose end is found by subtracting	     * the length of the suffix from the end of the name.	     */	    prefLen = (eoname - targ->suff->nameLen) - sopref;	    targ->pref = emalloc(prefLen + 1);	    memcpy(targ->pref, sopref, prefLen);	    targ->pref[prefLen] = '\0';	    /*	     * Add nodes from which the target can be made	     */	    SuffAddLevel(srcs, targ);	    /*	     * Record the target so we can nuke it	     */	    Lst_AtEnd(targs, (ClientData)targ);	    /*	     * Search from this suffix's successor...	     */	    ln = Lst_Succ(ln);	}    }    /*     * Handle target of unknown suffix...     */    if (Lst_IsEmpty(targs) && suffNull != NULL) {	if (DEBUG(SUFF)) {	    printf("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);	}	targ = (Src *)emalloc(sizeof (Src));	targ->file = estrdup(gn->name);	targ->suff = suffNull;	targ->node = gn;	targ->parent = (Src *)NULL;	targ->children = 0;	targ->pref = estrdup(sopref);#ifdef DEBUG_SRC	targ->cp = Lst_Init();#endif	/*	 * Only use the default suffix rules if we don't have commands	 * or dependencies defined for this gnode	 */	if (Lst_IsEmpty(gn->commands) && Lst_IsEmpty(gn->children))	    SuffAddLevel(srcs, targ);	else {	    if (DEBUG(SUFF))		printf("not ");	}	if (DEBUG(SUFF))	    printf("adding suffix rules\n");	Lst_AtEnd(targs, (ClientData)targ);    }    /*     * Using the list of possible sources built up from the target suffix(es),     * try and find an existing file/target that matches.     */    bottom = SuffFindThem(srcs, slst);    if (bottom == (Src *)NULL) {	/*	 * No known transformations -- use the first suffix found for setting	 * the local variables.	 */	if (!Lst_IsEmpty(targs)) {	    targ = (Src *)Lst_Datum(Lst_First(targs));	} else {	    targ = (Src *)NULL;	}    } else {	/*	 * Work up the transformation path to find the suffix of the	 * target to which the transformation was made.	 */	for (targ = bottom; targ->parent != NULL; targ = targ->parent)	    continue;    }    /*     * The .TARGET variable we always set to be the name at this point,     * since it's only set to the path if the thing is only a source and     * if it's only a source, it doesn't matter what we put here as far     * as expanding sources is concerned, since it has none...     */    Var_Set(TARGET, gn->name, gn);    pref = (targ != NULL) ? targ->pref : gn->name;    Var_Set(PREFIX, pref, gn);    /*     * Now we've got the important local variables set, expand any sources     * that still contain variables or wildcards in their names.     */    Lst_ForEach(gn->children, SuffExpandChildren, (ClientData)gn);    if (targ == NULL) {	if (DEBUG(SUFF)) {	    printf("\tNo valid suffix on %s\n", gn->name);	}sfnd_abort:	/*	 * Deal with finding the thing on the default search path if the	 * node is only a source (not on the lhs of a dependency operator	 * or [XXX] it has neither children or commands).	 */	if (OP_NOP(gn->type) ||	    (Lst_IsEmpty(gn->children) && Lst_IsEmpty(gn->commands)))	{	    gn->path = Dir_FindFile(gn->name,				    (targ == NULL ? dirSearchPath :				     targ->suff->searchPath));	    if (gn->path != NULL) {		char *ptr;		Var_Set(TARGET, gn->path, gn);		if (targ != NULL) {		    /*		     * Suffix known for the thing -- trim the suffix off		     * the path to form the proper .PREFIX variable.		     */		    int		savep = strlen(gn->path) - targ->suff->nameLen;		    char	savec;		    gn->suffix = targ->suff;		    savec = gn->path[savep];		    gn->path[savep] = '\0';		    if ((ptr = strrchr(gn->path, '/')) != NULL)			ptr++;		    else			ptr = gn->path;		    Var_Set(PREFIX, ptr, gn);		    gn->path[savep] = savec;		} else {		    /*		     * The .PREFIX gets the full path if the target has		     * no known suffix.		     */		    gn->suffix = NULL;		    if ((ptr = strrchr(gn->path, '/')) != NULL)			ptr++;		    else			ptr = gn->path;		    Var_Set(PREFIX, ptr, gn);		}	    }	} else {	    /*	     * Not appropriate to search for the thing -- set the	     * path to be the name so Dir_MTime won't go grovelling for	     * it.	     */	    gn->suffix = (targ == NULL) ? NULL : targ->suff;	    efree(gn->path);	    gn->path = estrdup(gn->name);	}	goto sfnd_return;    }    /*     * If the suffix indicates that the target is a library, mark that in     * the node's type field.     */    if (targ->suff->flags & SUFF_LIBRARY) {	gn->type |= OP_LIB;    }    /*     * Check for overriding transformation rule implied by sources     */    if (!Lst_IsEmpty(gn->children)) {	src = SuffFindCmds(targ, slst);	if (src != (Src *)NULL) {	    /*	     * Free up all the Src structures in the transformation path	     * up to, but not including, the parent node.	     */	    while (bottom && bottom->parent != NULL) {		if (Lst_Member(slst, (ClientData) bottom) == NULL) {		    Lst_AtEnd(slst, (ClientData) bottom);		}		bottom = bottom->parent;	    }	    bottom = src;	}    }    if (bottom == NULL) {	/*	 * No idea from where it can come -- return now.	 */	goto sfnd_abort;    }    /*     * We now have a list of Src structures headed by 'bottom' and linked via     * their 'parent' pointers. What we do next is create links between     * source and target nodes (which may or may not have been created)     * and set the necessary local variables in each target. The     * commands for each target are set from the commands of the     * transformation rule used to get from the src suffix to the targ     * suffix. Note that this causes the commands list of the original     * node, gn, to be replaced by the commands of the final     * transformation rule. Also, the unmade field of gn is incremented.     * Etc.     */    if (bottom->node == NULL) {	bottom->node = Targ_FindNode(bottom->file, TARG_CREATE);    }    for (src = bottom; src->parent != (Src *)NULL; src = src->parent) {	targ = src->parent;	src->node->suffix = src->suff;	if (targ->node == NULL) {	    targ->node = Targ_FindNode(targ->file, TARG_CREATE);	}	SuffApplyTransform(targ->node, src->node,			   targ->suff, src->suff);	if (targ->node != gn) {	    /*	     * Finish off the dependency-search process for any nodes	     * between bottom and gn (no point in questing around the	     * filesystem for their implicit source when it's already	     * known). Note that the node can't have any sources that	     * need expanding, since SuffFindThem will stop on an existing	     * node, so all we need to do is set the standard and System V	     * variables.	     */	    targ->node->type |= OP_DEPS_FOUND;	    Var_Set(PREFIX, targ->pref, targ->node);	    Var_Set(TARGET, targ->node->name, targ->node);	}    }    gn->suffix = src->suff;    /*     * So Dir_MTime doesn't go questing for it...     */    efree(gn->path);    gn->path = estrdup(gn->name);    /*     * Nuke the transformation path and the Src structures left over in the     * two lists.     */sfnd_return:    if (bottom)	if (Lst_Member(slst, (ClientData) bottom) == NULL)	    Lst_AtEnd(slst, (ClientData) bottom);    while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))	continue;    Lst_Concat(slst, srcs, LST_CONCLINK);    Lst_Concat(slst, targs, LST_CONCLINK);}