home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 364_01 / linkl_ca.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  6KB  |  244 lines

  1. /*
  2. HEADER:         ;
  3. TITLE:          C-ACROSS;
  4. VERSION         1.02
  5.  
  6. DESCRIPTION:   "Utility for multiple module programs. Produces
  7.       Six indexes of functions, prototypes, and globals that
  8.       enable user to 'see across' modules for use in checking
  9.       and comparison.  One of these is type of hierarchical
  10.       functions list, a listing by module of functions
  11.       and calls made FROM them; another is alphabetical list
  12.       of functions and calls made TO them. Globals listed
  13.       in schematic descriptors which record all modifiers
  14.       and qualifiers and enable checking of declarators
  15.       across modules. Creates, on request, header file
  16.       consisting of prototypes constructed from function
  17.       definitions. Can list user types #defined and some
  18.       preprocessor #defines. Full documentation in README.CA";
  19.  
  20. KEYWORDS:       Utility, Cross Reference, Deubgging;
  21. SYSTEM:         MS-DOS;
  22. FILENAME:       LINKL_CA.C;
  23.  
  24. WARNINGS:      "1. Assumes function definitions conform with
  25.         ANSI standards and have prototype form. See
  26.         also "Caveats and Restrictions" in README.CA.
  27.         2. Assumes syntactically correct source files.
  28.         3. Written and tested using Microsoft QuickC.
  29.         4. Copyright retained.  See Copyright
  30.         information in README.CA.";
  31.  
  32. SEE-ALSO:      EXIT_CA.C, FUNC_CA.C, GLOB_CA.C, IFDEF_CA.C, INTF_CA.C,
  33.            PARSE_CA.C, TDEF_CA.C, TYPES_CA, UTIL_CA.C,
  34.            UTLG_CA.C, XRF_CA.C, README.CA,
  35.            CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
  36. AUTHORS:       Myron Turner;
  37. COMPILERS:     Microsoft C;
  38.  
  39. */
  40.  
  41.  
  42. /***************************  C-ACROSS  ***************************
  43.                    V. 1.02
  44.                Copyright (C) Myron Turner
  45.  
  46.               333 Bartlet Ave.
  47.               Winnipeg, Manitoba
  48.               Canada R3L 0Z9
  49.               (204) 284-8387
  50.  
  51. *********************************************************************/
  52.  
  53.  
  54. #include <stdio.h>
  55. #include <string.h>
  56. #include "ca.h"
  57. #include "ca_decl.h"
  58.  
  59. struct GLoc_fnptr_stack
  60. {
  61.    char fnptr[32];
  62.    char fn_name[32];
  63.    char *caller;
  64. };
  65.  
  66. extern struct GLoc_fnptr_stack *GLfptrstack;
  67.  
  68.  
  69. void print_ll (struct func *top, FILE *rpt)
  70. {
  71.    char dots[] = ". . . . . . . . . . . . . . . . . .";
  72.    int dot_len = 0, count = 0;
  73.  
  74.    print_headings(1, rpt );
  75.  
  76.    while (top){
  77.     if (!top->fnptr) {
  78.      dot_len = ( 36 - ((int) strlen(top->name) + (int) strlen(top->module)) );
  79.      fprintf (rpt,"%.27s%.*s%s",top->name, dot_len, dots, top->module);
  80.      if ( ++count % 2 == 0 ) {
  81.          fprintf (rpt,"\n");
  82.          paginate(rpt);
  83.          }
  84.          else fprintf (rpt,"    ");
  85.      }
  86.      top = top->next;
  87.    }
  88. }
  89.  
  90.  
  91. struct func *store_linked_list( struct func *i, struct func *top)
  92. {
  93.  static struct func *last = 0;
  94.  struct func *old, *start;
  95.  
  96.  start = top;
  97.  
  98.  if (!last) {
  99.    i->next = NULL;
  100.    last = i;
  101.    return i;
  102.         }
  103.  
  104.  old = NULL;
  105.  while (top) {
  106.    if (strcmp(top->name, i->name) < 0) {
  107.       old = top;
  108.       top = top->next;
  109.       }
  110.       else {
  111.      if (old) {
  112.         old->next = i;
  113.         i->next = top;
  114.         return (start);
  115.           }
  116.     i->next = top;
  117.     return (i);
  118.       }
  119.    }
  120.    last->next = i;
  121.    i->next = NULL;
  122.    last = i;
  123.    return (start);
  124. }
  125.  
  126. #if !defined(_GLOBALS_LIST)
  127. #define _MAX_MODS 6
  128. struct globals_list
  129.  {
  130.   char *variable;
  131.   char *module;
  132.   int type;
  133.   char *type_ident;    /* ptr to name of typedef type if type == TYPEDEF */
  134.   char *struct_ident; /* point to name of structure or union */
  135.   char *complex_decl;
  136.   char storage;       /* type of storage */
  137.   int modifiers[_MAX_MODS];     /* list of modifiers & qualfiers */
  138.   struct globals_list *next;
  139.  };
  140. #endif
  141. struct globals_list *store_ll_globals( struct globals_list *i,
  142.                         struct globals_list *top)
  143. {
  144.  static struct globals_list *last = 0;
  145.  struct globals_list *old, *start;
  146.  char *i_var, *top_var;
  147.  
  148.  start = top;
  149.  
  150.  if (!last) {
  151.    i->next = NULL;
  152.    last = i;
  153.    return i;
  154.         }
  155.  
  156.  old = NULL;
  157.  while (top) {
  158.    top_var = top->variable;
  159.    i_var = i->variable;
  160.    while ( is_in(*top_var, "*") ) top_var++;
  161.    while( is_in(*i_var, "*") ) i_var++;
  162.  
  163.    if (stricmp(top_var, i_var) < 0) {
  164.       old = top;
  165.       top = top->next;
  166.       }
  167.       else {
  168.      if (old) {
  169.         old->next = i;
  170.         i->next = top;
  171.         return (start);
  172.           }
  173.     i->next = top;
  174.     return (i);
  175.       }
  176.    }
  177.    last->next = i;
  178.    i->next = NULL;
  179.    last = i;
  180.    return (start);
  181. }
  182. FILE *open_reportfile(int rpt_number);
  183. static void prn_calls__fnptrs(struct func *func_start,
  184.                     int which, FILE *rptfp);
  185. void print_calls_from(struct func *func_start, FILE *rptfp)
  186. {
  187.  
  188.     print_headings(3, rptfp );
  189.     fprintf(rptfp, "\n<Function>\n       <Calling Functions>\n"
  190.            "        . . . .\n"  );
  191.     paginate(rptfp); paginate(rptfp);
  192.     paginate(rptfp); paginate(rptfp);
  193.  
  194.     prn_calls__fnptrs(func_start, 0, rptfp);
  195. }
  196.  
  197. void prn_all__fnptrs(FILE *rptfp);
  198. void print_fnptrs(struct func *func_start, FILE *rptfp)
  199. {
  200.  
  201.     print_headings(4, rptfp );
  202.     fprintf(rptfp, "\n<Global Pointers>\n       <Functions Called From>\n"
  203.            "        . . . .\n"  );
  204.     paginate(rptfp); paginate(rptfp);
  205.     paginate(rptfp); paginate(rptfp);
  206.  
  207.     prn_calls__fnptrs(func_start, 1, rptfp);
  208.     prn_all__fnptrs(rptfp);
  209. }
  210.  
  211. static void prn_calls__fnptrs(struct func *func_start, int which, FILE *rptfp)
  212.  {
  213.   struct func *top;
  214.   struct calls_from *ptr;
  215.   static char *msg[2] = { "UNUSED FUNCTION", "UNUSED PTR TO FUNCTION" };
  216.  
  217.     top = func_start;
  218.     while(top)
  219.     {
  220.      if(top->fnptr != which) goto getnext;
  221.      fprintf(rptfp, "\n\n%-33s [%s]\n", top->name, top->module);
  222.      paginate(rptfp); paginate(rptfp); paginate(rptfp);
  223.  
  224.      if (top->first_call) {
  225.     ptr = top->first_call;
  226.       do {
  227.          fprintf(rptfp,"      %-35s (%s)\n",
  228.                   ptr->caller->name, ptr->caller->module);
  229.          paginate(rptfp);
  230.          ptr = ptr->next;
  231.          }
  232.          while( ptr);
  233.     }
  234.     else if ( strcmp("main", top->name) ) {
  235.  
  236.            fprintf(rptfp,"      %s\n", msg[which] );
  237.            paginate(rptfp);
  238.            }
  239. getnext:
  240.      top = top->next;
  241.     }
  242. }
  243.  
  244.