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

  1. /* TLCSTAT.C - "The Last Cross-referencer" - Print Stats 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.             Print Stats routines";
  27.  
  28. KEYWORDS:    Utility, Cross-reference, C, Pascal, Apple, Macintosh, APW, Aztec;
  29. SYSTEM:        Macintosh MPW, v3.0;
  30. FILENAME:    TLCSTAT.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.  
  47. /*------------------------- definitions -------------------------*/
  48.  
  49. #define     PAGE_TITLE        "Stats"
  50. #define        stat_reswords    1
  51. #define        stat_fnames        2
  52.  
  53.  
  54. /*--------------------- external declarations --------------------*/
  55.  
  56. #include    "tlc.ext"
  57.  
  58. extern VOID     do_form_feed(),
  59.                 indent(),
  60.                 new_page();
  61. extern long     get_freemem();
  62.  
  63.  
  64. /*------------------------ static variables -----------------------*/
  65.  
  66. static    pos_int            out_line_number;
  67. static    pos_int            which_stat;
  68.  
  69.  
  70. /*===============[ setup_stat_stuff ]================*/
  71.  
  72. static VOID setup_stat_stuff()
  73.  
  74.     { /* setup_stat_stuff() */
  75.     } /* setup_stat_stuff() */
  76.  
  77.  
  78.  
  79. /*===============[ print_stat_line ]================*/
  80.  
  81. static VOID print_stat_line(line_to_print)
  82. char *    line_to_print;
  83.  
  84.     { /* print_stat_line() */
  85.     
  86. debug(printf("prntStatLn():outLn#=%d botLn=%d pg#=%d\n",\
  87. out_line_number,parm_rec.bot_line, out_page_number);)
  88.  
  89.     if (out_line_number >= parm_rec.bot_line || out_line_number == 0)
  90.         {
  91.         new_page(parm_rec.do_stats, PAGE_TITLE,
  92.                 &out_page_number, &out_line_number, NULL);
  93.         if (ok_to_print()
  94.             && parm_rec.do_stats
  95.             && (which_stat == stat_fnames))
  96.             {
  97.             indent();
  98.             fprintf(out_file, "-- List of Files --\n\n");
  99.             indent();
  100.             fprintf(out_file, "File# #Lines  FileName\n");
  101.             indent();
  102.             fprintf(out_file, "----- ------- --------\n");
  103.             out_line_number += 4;
  104.             }
  105.         }
  106.     if (ok_to_print() && parm_rec.do_stats)
  107.         {
  108.         indent();
  109.         fprintf(out_file, line_to_print);
  110.         fputc('\n', out_file);
  111.         }
  112.     out_line_number++;
  113.     } /* print_stat_line() */
  114.  
  115.  
  116.  
  117. /*===============[ finish_stat_stuff ]================*/
  118.  
  119. static VOID finish_stat_stuff()
  120.  
  121.     { /* finish_stat_stuff() */
  122.     if (ok_to_print())
  123.         {
  124.         do_form_feed(out_file, out_line_number);
  125.         }
  126.     } /* finish_stat_stuff() */
  127.  
  128.  
  129.  
  130. /*=================[ print_resword_tree ]=================*/
  131.  
  132. static VOID print_resword_tree(resw_node)
  133. resw_list_type *    resw_node;
  134.  
  135.     { /* print_resword_tree() */
  136.     static char    temp_line[30]; /* dont' need this allocated recursively! */
  137.     
  138.     if (resw_node != NULL)
  139.         {
  140.         /* print the lower words */
  141.         print_resword_tree(resw_node->left);
  142.         
  143.         /* print the current node's word */
  144.         sprintf(temp_line, "%8lu:%-16s",
  145.                 resw_node->occurrances, resw_node->resword);
  146.         if (strlen(curr_line)+strlen(temp_line) >
  147.             parm_rec.right_column - parm_rec.left_column)
  148.             { /* won't fit, dump full line first */
  149.             print_stat_line(curr_line);
  150.             curr_line[0] = '\0';
  151.             }
  152.         strcat(curr_line, temp_line);
  153.         
  154.         /* print the higher words */
  155.         print_resword_tree(resw_node->right);
  156.         }
  157.     } /* print_resword_tree() */
  158.  
  159.  
  160.  
  161. /*================[ print_reswords ]=================*/
  162.  
  163. static VOID print_reswords()
  164.  
  165.     { /* print_reswords() */
  166.  
  167.     if (verbose > 1)
  168.         {
  169.         putc('\n', stderr);
  170.         fprintf(stderr, memdispFmt, get_freemem());
  171.         fputs("-Reserved Word List..", stderr);
  172.         fflush(stderr);
  173.         }
  174.  
  175.     which_stat = stat_reswords;
  176.     out_line_number = 0;
  177.     print_stat_line("-- Reserved Word Occurrances --");
  178.     print_stat_line("");
  179.     curr_line[0] = '\0';
  180.     print_resword_tree(resw_rec.resw_list);
  181.     /* print any remaining non-full line */
  182.     if (strlen(curr_line) > 0)
  183.         print_stat_line(curr_line);
  184.     } /* print_reswords() */
  185.  
  186.  
  187. /*=================[ print_fname_list ]=================*/
  188.  
  189. static VOID print_fname_list(flist_node, num_fnames)
  190. file_list_type*    flist_node;
  191. pos_int            num_fnames; /* NOTE: so far, only needed for debug */
  192.  
  193.     { /* print_fname_list() */
  194.  
  195.     while (flist_node != NULL)
  196.         {        
  197. debug(printf("prntFnameLst():node=$%lx file#=%d fname='%s'\n",\
  198. flist_node,flist_node->file_num,flist_node->file_name);)
  199.         /* print the current node's info */
  200.         sprintf(curr_line, "%4d  %6u  %s",
  201.                 flist_node->file_num,
  202.                 flist_node->num_lines,
  203.                 flist_node->file_name);
  204.         print_stat_line(curr_line);
  205.     
  206.         /* go to next file name node */
  207.         flist_node = flist_node->next;
  208.         }
  209.     } /* print_fname_list() */
  210.  
  211.  
  212.  
  213. /*================[ print_filenames ]=================*/
  214.  
  215. static VOID print_filenames()
  216.  
  217.     { /* print_filenames() */
  218.  
  219.     if (verbose > 1)
  220.         {
  221.         putc('\n', stderr);
  222.         fprintf(stderr, memdispFmt, get_freemem());
  223.         fputs("-FileName List..", stderr);
  224.         fflush(stderr);
  225.         }
  226.  
  227.     which_stat = stat_fnames;
  228.     out_line_number = 0;
  229.     curr_line[0] = '\0';
  230.     print_fname_list(file_rec.file_list, file_rec.num_in_fnames);
  231.  
  232.     } /* print_filenames() */
  233.  
  234.  
  235. /*=================[ print_stats ]===================*/
  236.  
  237. VOID print_stats()
  238.  
  239.     { /* print_stats() */
  240.     
  241. debug(printf("print_stat:\n");)
  242.  
  243.     if (verbose)
  244.         {
  245.         fprintf(stderr, "\n[%8ld] Doing Statistics..\n", get_freemem());
  246.         fflush(stderr);
  247.         }
  248.  
  249.     setup_stat_stuff();
  250.     
  251.     print_reswords();
  252.     
  253.     print_filenames();
  254.  
  255.     finish_stat_stuff();
  256.  
  257.     } /* print_stats() */
  258.