Beispiel #1
0
/*
 *	given this parent, depth first number its children.
 */
void
dfn(nltype *parentp)
{
	arctype	*arcp;

#ifdef DEBUG
	if (debug & DFNDEBUG) {
		(void) printf("[dfn] dfn(");
		printname(parentp);
		(void) printf(")\n");
	}
#endif /* DEBUG */

	if (!dfn_stack) {
		dfn_sz = DFN_DEPTH;
		dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype));
		if (!dfn_stack) {
			(void) fprintf(stderr,
			    "fatal: can't malloc %d objects\n", dfn_sz);
			exit(1);
		}
	}

	/*
	 *	if we're already numbered, no need to look any furthur.
	 */
	if (dfn_numbered(parentp))
		return;

	/*
	 *	if we're already busy, must be a cycle
	 */
	if (dfn_busy(parentp)) {
		dfn_findcycle(parentp);
		return;
	}

	/*
	 *	visit yourself before your children
	 */
	dfn_pre_visit(parentp);

	/*
	 *	visit children
	 */
	for (arcp = parentp->children; arcp; arcp = arcp->arc_childlist)
		dfn(arcp->arc_childp);

	/*
	 *	visit yourself after your children
	 */
	dfn_post_visit(parentp);
}
Beispiel #2
0
    /*
     *	given this parent, depth first number its children.
     */
void
dfn(nltype *parentp)
{
    arctype	*arcp;

#   ifdef DEBUG
	if ( debug & DFNDEBUG ) {
	    printf( "[dfn] dfn(" );
	    printname( parentp );
	    printf( ")\n" );
	}
#   endif /* DEBUG */
	/*
	 *	if we're already numbered, no need to look any further.
	 */
    if ( dfn_numbered( parentp ) ) {
	return;
    }
	/*
	 *	if we're already busy, must be a cycle
	 */
    if ( dfn_busy( parentp ) ) {
	dfn_findcycle( parentp );
	return;
    }
	/*
	 *	visit yourself before your children
	 */
    dfn_pre_visit( parentp );
	/*
	 *	visit children
	 */
    for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) {
	    if ( arcp -> arc_flags & DEADARC )
		continue;
	    dfn( arcp -> arc_childp );
    }
	/*
	 *	visit yourself after your children
	 */
    dfn_post_visit( parentp );
}