home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / flower.zip / printrpt.c < prev    next >
Text File  |  1997-06-23  |  9KB  |  272 lines

  1.  
  2. /* Copyright (c) 1996, 1997 Craig Schneiderwent */
  3. /*
  4. Program: flower
  5. File:    printrpt.c
  6. Author:  Craig Schneiderwent
  7.          74631.165@compuserve.com
  8. Date:    20-Apr-1996
  9.  
  10. Print cross-reference reports, which
  11. functions call which functions, which
  12. functions are called from which functions
  13. and a call tree.
  14.  
  15. */
  16.  
  17. #define INDENT_VALUE    "    \0"
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <time.h>
  22. #include "mydebug.h"
  23. #include "structs.h"
  24. #include "mniplist.h"
  25. #include "printrpt.h"
  26.  
  27. void printBanner( void );
  28. void printSubTree( struct fileInfo *
  29.                  , struct funcInfo *
  30.                  , short
  31.                  , short );
  32. void printFunction( struct funcInfo * );
  33. void printFunctionIndented( struct funcInfo *
  34.                           , short );
  35.  
  36. void printCalledFuncReport( struct fileInfo *psFileInfo )
  37. {
  38.     struct fileInfo *nextFile = NULL;
  39.     struct funcInfo *nextFunc = NULL;
  40.     struct funcInfo *nextCalledFunc = NULL;
  41.     short           isRecursive = 0;
  42.  
  43.     nextFile = psFileInfo;
  44.  
  45.     while ( nextFile != NULL ) {
  46.         printBanner();
  47.         printf( "\n\n---------- %s ----------\n", nextFile->fileNm );
  48.         nextFunc = nextFile->funcListStart;
  49.         while ( nextFunc != NULL ) {
  50.             printf( "\n%s - ", nextFunc->funcNm );
  51.             if ( nextFunc->callsFromMe > 1 || nextFunc->callsFromMe == 0 ) {
  52.                 printf( "%ld function calls\n"
  53.                       , nextFunc->callsFromMe );
  54.             } else {
  55.                 printf( "%ld function call\n"
  56.                       , nextFunc->callsFromMe );
  57.             } /* endif */
  58.             nextCalledFunc = nextFunc->calledFuncListStart;
  59.             while ( nextCalledFunc != NULL ) {
  60.                 printFunctionIndented( nextCalledFunc, 1 );
  61.                 isRecursive = !strcmp( nextCalledFunc->funcNm
  62.                                      , nextFunc->funcNm );
  63.                 if ( isRecursive ) {
  64.                     printf( " recursive" );
  65.                 } /* endif */
  66.                 printf( "\n" );
  67.                 nextCalledFunc = nextCalledFunc->next;
  68.             } /* endwhile */
  69.             nextFunc = nextFunc->next;
  70.         } /* endwhile */
  71.         nextFile = nextFile->next;
  72.     } /* endwhile */
  73.  
  74.     return;
  75. }
  76.  
  77. void printCallingFuncReport( struct isCalledByFuncInfo *psFuncInfo )
  78. {
  79.     struct isCalledByFuncInfo *nextCalledFunc = NULL;
  80.     struct isCalledByFuncInfo *nextCallingFunc = NULL;
  81.  
  82.     printBanner();
  83.  
  84.     nextCalledFunc = psFuncInfo;
  85.     if ( nextCalledFunc == NULL ) {
  86.         return;
  87.     } /* endif */
  88.     nextCallingFunc = psFuncInfo->callingFuncListStart;
  89.  
  90.     while ( nextCalledFunc != NULL ) {
  91.         printf( "\n%s", nextCalledFunc->funcNm );
  92.         if ( strlen( nextCalledFunc->fileNm ) > 0 ) {
  93.             printf( " [%s]", nextCalledFunc->fileNm );
  94.         } /* endif */
  95.         printf( " is called" );
  96.         if ( nextCalledFunc->count > 1 ) {
  97.             printf( " a total of %ld times", nextCalledFunc->count );
  98.         } /* endif */
  99.         printf( " from:\n" );
  100.         while ( nextCallingFunc != NULL ) {
  101.             printf( "%s%s"
  102.                   , INDENT_VALUE
  103.                   , nextCallingFunc->funcNm );
  104.             if ( strlen( nextCallingFunc->fileNm ) > 0 ) {
  105.                 printf( " [%s]", nextCallingFunc->fileNm );
  106.             } /* endif */
  107.             if ( nextCallingFunc->count > 1 ) {
  108.                 printf( " %ld times", nextCallingFunc->count );
  109.             } /* endif */
  110.             printf( "\n" );
  111.             nextCallingFunc = nextCallingFunc->next;
  112.         } /* endwhile */
  113.         nextCalledFunc = nextCalledFunc->next;
  114.         if ( nextCalledFunc != NULL ) {
  115.             nextCallingFunc = nextCalledFunc->callingFuncListStart;
  116.         } /* endif */
  117.     } /* endwhile */
  118.  
  119.     return;
  120. }
  121.  
  122. void printCallTreeReport( struct fileInfo *psFileInfo )
  123. {
  124.     struct fileInfo *nextFile = NULL;
  125.     struct funcInfo *nextFunc = NULL;
  126.     struct funcInfo *nextCalledFunc = NULL;
  127.     short           isRecursive = 0;
  128.  
  129.     printf( "\n\nCall Tree\n" );
  130.  
  131.     nextFile = psFileInfo;
  132.  
  133.     while ( nextFile != NULL ) {
  134.         nextFunc = nextNotCalledFunc( nextFile->funcListStart );
  135.         if ( nextFunc == NULL ) {
  136.             nextFile = nextFile->next;
  137.             continue;
  138.         } /* endif */
  139.         printBanner();
  140.         printf( "\n\n---------- %s ----------\n", nextFile->fileNm );
  141.         while ( nextFunc != NULL ) {
  142.             printf( "\n%s\n", nextFunc->funcNm );
  143.             nextCalledFunc = nextFunc->calledFuncListStart;
  144.             if ( nextCalledFunc != NULL ) {
  145.                 isRecursive = !strcmp( nextCalledFunc->funcNm
  146.                                      , nextFunc->funcNm );
  147.                 if ( isRecursive ) {
  148.                     printFunctionIndented( nextCalledFunc, 1 );
  149.                     printf( " recursive\n" );
  150.                 } else {
  151.                     printSubTree( psFileInfo, nextCalledFunc, 1, 0 );
  152.                 } /* endif */
  153.             } /* endif */
  154.             nextFunc = nextNotCalledFunc( nextFunc->next );
  155.         } /* endwhile */
  156.         nextFile = nextFile->next;
  157.     } /* endwhile */
  158.  
  159.     return;
  160. }
  161.  
  162. void printSubTree( struct fileInfo *pFileListStart
  163.                  , struct funcInfo *pFunc
  164.                  , short level
  165.                  , short endOfTreeLevel )
  166. {
  167.     struct funcInfo *pNextCalledFunc = NULL;
  168.     struct funcInfo *pNextLevelFuncBase = NULL;
  169.     struct funcInfo *pNextLevelCallListStart = NULL;
  170.     short           endOfTheBranchLevel = 0;
  171.  
  172.     if ( level < 0 || pFunc == NULL ) {
  173.         return;
  174.     } /* endif */
  175.  
  176.     pNextCalledFunc = pFunc;
  177.  
  178.     while ( pNextCalledFunc != NULL ) {
  179.         if ( pNextCalledFunc->next == NULL ) {
  180.             endOfTheBranchLevel = endOfTreeLevel + 1;
  181.         } else {
  182.             endOfTheBranchLevel = 0;
  183.         } /* endif */
  184.         printFunctionIndented( pNextCalledFunc, level );
  185.         pNextLevelFuncBase = pNextCalledFunc->calledFuncBase;
  186.         if ( pNextLevelFuncBase == NULL ) {
  187.             printf( "\n" );
  188.             pNextCalledFunc = pNextCalledFunc->next;
  189.             continue;
  190.         } else {
  191.             pNextLevelCallListStart = 
  192.                    pNextLevelFuncBase->calledFuncListStart;
  193.         } /* endif */
  194.         if ( pNextLevelCallListStart == NULL ) {
  195.             printf( "\n" );
  196.         } else {
  197.             if ( pNextCalledFunc->isCircularReference ) {
  198.                 printf( " <circular reference>\n" );
  199.             } else {
  200.                 printf( "\n" );
  201.                 printSubTree( pFileListStart
  202.                             , pNextLevelCallListStart
  203.                             , (level + 1 )
  204.                             , endOfTheBranchLevel );
  205.             } /* endif */
  206.         } /* endif */
  207.         pNextCalledFunc = pNextCalledFunc->next;
  208.     } /* endwhile */
  209.  
  210.     return;
  211. }
  212.  
  213. void printFunction( struct funcInfo *pFunc )
  214. {
  215.     printf( "%s", pFunc->funcNm );
  216.     if ( strlen( pFunc->fileNm ) > 0 ) {
  217.         printf( " [%s]", pFunc->fileNm );
  218.     } /* endif */
  219.     if ( pFunc->callsToMe > 1 ) {
  220.         printf( " %ld times", pFunc->callsToMe );
  221.     } /* endif */
  222.  
  223.     return;
  224. }
  225.  
  226. void printFunctionIndented( struct funcInfo *pFunc
  227.                           , short level )
  228. {
  229.     short indent = 0;
  230.  
  231.     for ( indent = 0; indent < level; indent++ ) {
  232.         printf( "%s", INDENT_VALUE );
  233.     } /* endfor */
  234.  
  235.     printFunction( pFunc );
  236.  
  237.     return;
  238. }
  239.  
  240. void printBanner( void )
  241. {
  242.     time_t aTime;
  243.  
  244.     time( &aTime );
  245.  
  246.     printf( "\n\n%s %s\t\t%s\n", MYNAME, MYVERSION, ctime( &aTime ) );
  247.  
  248.     return;
  249. }
  250.  
  251. void showSyntax( void )
  252. {
  253.     printf( "%s %s\n", MYNAME, MYVERSION );
  254.     printf( "Syntax:\n\n");
  255.     printf( "\t%s [-abct] file1.c [file2.c] [...] [-x exFunc1 [exFunc2] [...]]\n"
  256.           , MYNAME );
  257.     printf( "  or\n\t%s [-abct] @filelist.txt [-x exFunc1 [exFunc2] [...]]\n"
  258.           , MYNAME );
  259.     printf( "  or\n\t%s [-abct] @filelist.txt [-x @exFileNm]\n\n", MYNAME );
  260.     printf( "Writes a function cross reference to standard output\n" );
  261.     printf( "\nOptions:\n" );
  262.     printf( "\t-a all reports\n" );
  263.     printf( "\t-b functions and which functions call them\n" );
  264.     printf( "\t-c functions and which functions they call\n" );
  265.     printf( "\t-t call tree\n" );
  266.     printf( "\t-x exclude these functions\n\n" );
  267.     printf( "Default is all three reports\n" );
  268.  
  269.     return;
  270. }
  271.  
  272.