home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 345_01 / tlcxref.c < prev    next >
C/C++ Source or Header  |  1989-07-10  |  7KB  |  274 lines

  1. /* TLCXREF.C - "The Last Cross-referencer" - Print Xref routines        */
  2. /*    Last Modified:    02/10/89                                            */
  3.  
  4. /*
  5. ---------------------------------------------------------------------
  6. Copyright (c) 1987-1989, Eduard Schwan Programs [esp] - All rights reserved
  7. TLC (The Last C-Cross-Referencer) and TLP (same, but for Pascal) are
  8. Cross-Reference Generators crafted and shot into the Public Domain by
  9. Eduard Schwan.  The source code and executable program may be freely
  10. distributed as long as the copyright/author notices remain intact, and
  11. it is not used in part or whole as the basis of a commercial product.
  12. Any comments, bug-fixes, or enhancements are welcome.
  13. Also, if you find TLC and it's source code useful, a contribution of
  14. $20 (check/money order) is encouraged!  Hopefully we will all see more
  15. source code distributed!
  16.     Eduard Schwan, 1112 Oceanic Drive, Encinitas, Calif. 92024
  17. ---------------------------------------------------------------------
  18. */
  19.  
  20. /*
  21. HEADER:        The Last Cross-Referencer;
  22. TITLE:        TLC/TLP - The Last Cross-Referencer;
  23. VERSION:    1.01;
  24.  
  25. DESCRIPTION: "TLC/TLP.
  26.             C Print Xref routines";
  27.  
  28. KEYWORDS:    Utility, Cross-reference, C, Pascal, Apple, Macintosh, APW, Aztec;
  29. SYSTEM:        Macintosh MPW, v3.0;
  30. FILENAME:    TLCXREF.C;
  31. WARNINGS:    "Has not yet been ported to MS-DOS.
  32.             Shareware, $20 Check/Money Order suggested.";
  33.  
  34. SEE-ALSO:    README.TLC,TLCHELP.DOC,TLPHELP.DOC;
  35. AUTHORS:    Eduard Schwan;
  36. COMPILERS:    AZTEC C65 v3.2b, APPLEIIGS APW C v1.0, APPLE MACINTOSH MPW C v3.0;
  37. */
  38.  
  39.  
  40. /*------------------------ include files -------------------------*/
  41.  
  42. #include    <stdio.h>
  43. #include    "tlc.h"
  44.  
  45.  
  46. /*------------------------- definitions -------------------------*/
  47.  
  48. #define     REF_NUM_SIZE        6    /* width of line# field */
  49. #define        VSYM_PER_LINE        50    /* # of sym chrs dsplyd in -v mode */
  50. #define     PAGE_TITLE            "Xref"
  51.  
  52.  
  53.  
  54. /*--------------------- external declarations --------------------*/
  55.  
  56. #include    "tlc.ext"
  57.  
  58. extern VOID     do_form_feed(),
  59.                 indent(),
  60.                 do_emphasis(),
  61.                 undo_emphasis(),
  62.                 check_user_abort(),
  63.                 new_page();
  64. extern long        get_freemem();
  65.  
  66.  
  67. /*------------------------ static variables -----------------------*/
  68.  
  69. static pos_int        out_line_number;
  70. static pos_int        out_column;
  71. static pos_int        out_vsym_count;        /* verbose ABC.. display counter */
  72.  
  73.  
  74.  
  75. /*===============[ setup_xref_stuff ]================*/
  76.  
  77. static VOID setup_xref_stuff()
  78.  
  79.     { /* setup_xref_stuff() */
  80.     new_page(parm_rec.do_xref, PAGE_TITLE, &out_page_number,
  81.             &out_line_number, NULL);
  82.     } /* setup_xref_stuff() */
  83.  
  84.  
  85.  
  86. /*===============[ add_ref_to_line ]=================*/
  87.  
  88. static VOID add_ref_to_line(new_sym, new_file, sym_ptr, line_ptr)
  89. boolean         new_sym;
  90. boolean         new_file;
  91. sym_list_type*    sym_ptr;
  92. line_list_type* line_ptr;
  93.  
  94.     { /* add_ref_to_line() */
  95.     pos_int     local_indent;
  96.  
  97. /*
  98. debug(printf("addRefToLine:NewSym=%d NewFile=%d\n",new_sym,new_file);)
  99. */
  100.     /* time for a new line? */
  101.     if (new_sym || new_file ||
  102.         out_column+REF_NUM_SIZE>=parm_rec.right_column)
  103.         {
  104.         /* terminate previous line */
  105.         putc('\n', out_file);
  106.         out_line_number++;
  107.  
  108.         /* time for a new page heading? */
  109.         if (out_line_number>parm_rec.bot_line ||
  110.             out_line_number>parm_rec.bot_line-4 && new_file) /*will do 4 lines*/
  111.             {                                    
  112.             new_page(parm_rec.do_xref, PAGE_TITLE, &out_page_number,
  113.                     &out_line_number, NULL);
  114.             new_sym = TRUE;
  115.             new_file = TRUE;
  116.             }
  117.  
  118.         /* time for a new symbol heading? */
  119.         if (new_sym)
  120.             {
  121.             /* skip a line */
  122.             putc('\n', out_file);
  123.             indent();
  124.             out_column = parm_rec.left_column;
  125.  
  126.             /* write the symbol */
  127.             do_emphasis(parm_rec.emph_symbols);
  128.             fprintf(out_file,"%s",sym_ptr->sym_name);
  129.             undo_emphasis(parm_rec.emph_symbols);
  130.             fputc('\n', out_file);
  131.             out_line_number += 2;
  132.             }
  133.  
  134.         indent();
  135.         out_column = parm_rec.left_column;
  136.  
  137.         /* time for new file heading? */
  138.         if (new_file)
  139.             {
  140.             /* filename indent spacing */
  141.             for (local_indent = 0; local_indent < 6; local_indent++)
  142.                 {
  143.                 putc(' ', out_file);
  144.                 out_column++;
  145.                 }
  146.             fprintf(out_file,"%s:\n",line_ptr->file_ptr->file_name);
  147.             indent();
  148.             out_column = parm_rec.left_column;
  149.             out_line_number++;
  150.             }
  151.  
  152.         /* first line # on line indent spacing */
  153.         for (local_indent = 0; local_indent < 6; local_indent++)
  154.             {
  155.             putc(' ', out_file);
  156.             out_column++;
  157.             }
  158.         } /* time for new line */
  159.  
  160. /*debug(fprintf(out_file, "Dx%d: line#%5d%c\n", \
  161. ok_to_print(), line_ptr->line_number, ref_chars[line_ptr->reference_type]);)*/
  162.  
  163.         fprintf(out_file, "%5d%c",     /*note:REF_NUM_SIZE*/
  164.             line_ptr->line_number, ref_chars[line_ptr->reference_type]);
  165.     out_column += REF_NUM_SIZE;
  166.  
  167.     } /* add_ref_to_line() */
  168.  
  169.  
  170. /*===============[ finish_xref_stuff ]================*/
  171.  
  172. static VOID finish_xref_stuff()
  173.  
  174.     { /* finish_xref_stuff() */
  175.     putc('\n', out_file);    /* finish previous line */
  176.     out_line_number++;        /* finish previous line */
  177.     do_form_feed(out_file, out_line_number);
  178.     } /* finish_xref_stuff() */
  179.  
  180.  
  181.  
  182. /*===============[ print_sym_tree ]=================*/
  183.  
  184. static VOID print_sym_tree(sym_node)
  185. sym_list_type*    sym_node;
  186.  
  187.     { /* print_sym_tree() */
  188.     static boolean            new_symbol;
  189.     static boolean            new_file;
  190.     static file_list_type*    prev_file_ptr;
  191.     static line_list_type*    line_ptr;
  192.  
  193.     /* print next non-null node */
  194.     if (sym_node!=NULL)
  195.         {
  196.         /*
  197.         print left subtree first (NOTE: recursion)
  198.         */
  199.         print_sym_tree(sym_node->left);
  200.  
  201.         /* see if user wants to abort.. */
  202.         check_user_abort();
  203.  
  204.         /*
  205.         traverse the reference line # list for this symbol
  206.         */
  207. debug(printf("print_sym(%s):\n",sym_node->sym_name);)
  208.         if (verbose > 1)
  209.             {
  210.             if (out_vsym_count % VSYM_PER_LINE == 0)
  211.                 {
  212.                 putc('\n', stderr);
  213.                 fprintf(stderr, memdispFmt, get_freemem());
  214.                 }
  215.             fprintf(stderr,"%c",sym_node->sym_name[0]);
  216.             fflush(stderr);
  217.             out_vsym_count++;
  218.             }
  219.         prev_file_ptr = NULL;
  220.         new_symbol = TRUE;
  221.         line_ptr   = sym_node->line_list;
  222.         while (line_ptr != NULL)
  223.             {
  224. debug(printf("print_sym:line#%d in file '%s'\n",\
  225. line_ptr->line_number,line_ptr->file_ptr->file_name);)
  226.             new_file = (line_ptr->file_ptr != prev_file_ptr);
  227.             add_ref_to_line(new_symbol, new_file, sym_node, line_ptr);
  228.             prev_file_ptr = line_ptr->file_ptr;
  229.             line_ptr = line_ptr->next;
  230.             new_symbol = FALSE;
  231.             } /*while2*/
  232.  
  233.         /*
  234.         now print right subtree (NOTE: recursion)
  235.         */
  236.         print_sym_tree(sym_node->right);
  237.         } /*if*/
  238.     } /* print_sym_tree() */
  239.  
  240.  
  241.  
  242. /*=================[ print_xref ]===================*/
  243.  
  244. VOID print_xref()
  245.  
  246.     { /* print_xref() */
  247.     
  248. debug(puts("print_xref:");)
  249.  
  250.     if (verbose)
  251.         {
  252.         putc('\n', stderr);
  253.         fprintf(stderr, memdispFmt, get_freemem());
  254.         fputs("Doing Cross-Reference..", stderr);
  255.         fflush(stderr);
  256.         }
  257.  
  258.     setup_xref_stuff();
  259.  
  260.     /*
  261.     traverse the symbol list, printing each symbol & its
  262.     associated list of line references.
  263.     */
  264.  
  265.     out_vsym_count = 0;
  266.     print_sym_tree(symbol_table.symbol_list);
  267.     
  268.     if (verbose)
  269.         putc('\n', stderr);
  270.  
  271.     finish_xref_stuff();
  272.  
  273.     } /* print_xref() */
  274.