home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_10 / 9n10037a < prev    next >
Text File  |  1991-08-15  |  1KB  |  57 lines

  1.  
  2. #include <stdio.h>
  3. #include "c_calls.h"
  4.  
  5. void print_calls(LIST list, const char *name, int depth, LIST *fcns)
  6.  
  7. /*
  8. Print out the name of the current fcn, and recursively print the names
  9. of all fcns called by the current fcn (i.e. "expand" the current fcn).
  10. */
  11.  
  12. {
  13. LIST tmp;
  14. int  i;
  15.  
  16. for (i = 1; i <= depth; i++)
  17.      printf("%1d   ", (i - 1) % 10);  /* Print name of current fcn. */
  18.  
  19. if (find_cell(*fcns, name) != NULL)  /* Don't continue recursive call. */
  20.      printf("%s...\n", name);
  21. else
  22.      {
  23.      printf("%s\n", name);
  24.  
  25.      /* Save the name of the current fcn to avoid infinite expansion. */
  26.      insert_cell(fcns, name);
  27.  
  28.      /* Print out names of all fcns called by the current fcn. */
  29.      tmp = find_cell(list, name);
  30.  
  31.      for (tmp = tmp->calls; tmp != NULL; tmp = tmp->next)
  32.           print_calls(list, tmp->name, depth + 1, fcns);
  33.  
  34.      /* Delete name of current fcn after completely expanding it. */
  35.      delete_cell(fcns, name);
  36.      }
  37. }
  38.  
  39.  
  40. void print_all_calls(LIST list)
  41.  
  42. /* Print the fcn call tree. */
  43.  
  44. {
  45. LIST tmp1, tmp2, fcns = NULL;
  46.  
  47. for (tmp1 = list; tmp1 != NULL; tmp1 = tmp1->next)
  48.      {
  49.      print_calls(list, tmp1->name, 0, &fcns);
  50.      printf("\n%s is called by:\n", tmp1->name);
  51.  
  52.      for (tmp2 = tmp1->called_from; tmp2 != NULL; tmp2 = tmp2->next)
  53.           printf("  %s\n", tmp2->name);
  54.      printf("\n\n");
  55.      }
  56. }
  57.