Listing 4
#include <stdio.h> #include "c_calls.h" void print_calls(LIST list, const char *name, int depth, LIST *fcns) /* Print out the name of the current fcn, and recursively print the names of all fcns called by the current fcn (i.e. "expand" the current fcn). */ { LIST tmp; int i; for (i = 1; i <= depth; i++) printf("%1d ", (i - 1) % 10); /* Print name of current fcn. */ if (find_cell{*fcns, name) != NULL) /* Don't continue recursive call. */ printf("%s...\n", name); else { printf("%s\n", name); /* Save the name of the current fcn to avoid infinite expansion. */ insert_cell(fcns, name); /* Print out names of all fcns called by the current fcn. */ tmp = find_cell(list, name); for (tmp = tmp->calls; tmp != NULL; tmp = tmp->next) print_calls(list, tmp->name, depth + 1, fcns); /* Delete name of current fcn after completely expanding it. */ delete_cell(fcns, name); } } void print_all_calls(LIST list) /* Print the fcn call tree. */ { LIST tmp1, tmp2, fcns = NULL; for (tmp1 = list; tmp1 != NULL; tmp1 = tmp1->next) { print_calls(list, tmp1->name, 0, &fcns); printf("\n%s is called by:\n", tmp1->name); for (tmp2 = tmp1->called_from; tmp2 != NULL; tmp2 = tmp2->next) printf(" %s\n", tmp2->name); printf("\n\n"); } } /* End of File */