home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource5 / 345_01 / tlpprocf.c < prev    next >
C/C++ Source or Header  |  1989-07-11  |  17KB  |  656 lines

  1. /* TLPPROCF.C - "The Last Cross-referencer" - TLP Process Files routines*/
  2. /*    Last Modified:    07/02/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.             TLP Process Files routines";
  27.  
  28. KEYWORDS:    Utility, Cross-reference, C, Pascal, Apple, Macintosh, APW, Aztec;
  29. SYSTEM:        Macintosh MPW, v3.0;
  30. FILENAME:    TLPPROCF.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. /*------------------------ include files -------------------------*/
  40.  
  41. #include    <stdio.h>
  42. #include    <errno.h>
  43. #include    "tlc.h"
  44.  
  45.  
  46. /*------------------------- definitions -------------------------*/
  47.  
  48. #define     PAGE_TITLE        "List"
  49.  
  50.  
  51. /*--------------------- external declarations --------------------*/
  52.  
  53. #include    "tlc.ext"
  54.  
  55. extern FILE *    open_text_file();
  56. extern VOID     close_text_file(),
  57.                 do_emphasis(),
  58.                 undo_emphasis(),
  59.                 do_form_feed(),
  60.                 indent(),
  61.                 check_user_abort(),
  62.                 new_page();
  63. extern boolean    is_resword();
  64. extern long        get_freemem();
  65.  
  66.  
  67. /*------------------------ static variables -----------------------*/
  68.  
  69. static    pos_int            out_line_number;
  70. static    pos_int            block_level;
  71. static    boolean         saw_id;
  72. static    pos_int            prev_ref_kind;/* messy way to do it..*/
  73.  
  74.  
  75. /*===============[ setup_listing_stuff ]================*/
  76.  
  77. static VOID setup_listing_stuff()
  78.  
  79.     { /* setup_listing_stuff() */
  80. debug(puts("setup_listing_stuff:");)
  81.     } /* setup_listing_stuff() */
  82.  
  83.  
  84.  
  85. /*===============[ print_listing_line ]================*/
  86.  
  87. static VOID print_listing_line()
  88.  
  89.     { /* print_listing_line() */
  90.  
  91.     if (out_line_number >= parm_rec.bot_line || out_line_number == 0)
  92.         new_page(parm_rec.do_listing, PAGE_TITLE, &out_page_number,
  93.                 &out_line_number, file_rec.curr_file->file_name);
  94.     if (ok_to_print())
  95.         {
  96. debug(printf("prntLstLn():outLn#=%d botLn=%d pg#=%d\n",\
  97. out_line_number,parm_rec.bot_line, out_page_number);)
  98.         indent();
  99.         fprintf(out_file,"%4d | %s", file_rec.curr_file->num_lines, curr_line);
  100.         fputc('\n', out_file);
  101.         }
  102.     out_line_number++;
  103.     } /* print_listing_line() */
  104.  
  105.  
  106.  
  107. /*===============[ finish_listing_stuff ]================*/
  108.  
  109. static VOID finish_listing_stuff()
  110.  
  111.     { /* finish_listing_stuff() */
  112.     if (ok_to_print() && !parm_rec.do_xref)
  113.         {
  114.         do_form_feed(out_file, out_line_number);
  115.         }
  116.     } /* finish_listing_stuff() */
  117.  
  118.  
  119.  
  120. /*==================[ expand_tabs ]=====================*/
  121.  
  122. static VOID expand_tabs()
  123.  
  124.     { /* expand_tabs() */
  125.     short         count;
  126.     short         index,
  127.                 tab_fill;
  128.     char *        line_ptr;
  129. /*
  130. debug(puts("expand_tabs:");)
  131. */
  132.     index = 0;
  133.     line_ptr = curr_line;
  134.     while (*line_ptr)
  135.         {
  136.         if (*line_ptr == '\t')    /* horizontal tab (HT)? */
  137.             {
  138.             /* calc. # of spaces to replace tab with */
  139.             tab_fill = parm_rec.tab_width - (index % parm_rec.tab_width);
  140.  
  141.             /* if more than 1 space needed for tab, move the string */
  142.             /* and trailing null (\0) over                            */
  143.             if (tab_fill > 1)
  144.                 {
  145. /****************MOVE(line_ptr+tab_fill-1, line, strlen(line_ptr)+1); -- below is less risky */
  146.                 for (count=strlen(line_ptr); count>=0; count--)
  147.                     line_ptr[count-1+tab_fill] = line_ptr[count];
  148.                 }
  149.  
  150.             /* pad with spaces (& cover up tab as last char) */
  151. /***********FILL(line_ptr, tab_fill, ' '); -- below is less risky */
  152.             for (count=0; count<tab_fill; count++)
  153.                 line_ptr[count] = ' ';
  154.  
  155.             /* point to next char. after tab expansion */
  156.             line_ptr    += tab_fill;
  157.             index        += tab_fill;
  158.             }
  159.         else
  160.             {
  161.             /* no conversion, skip this character */
  162.             line_ptr++;
  163.             index++;
  164.             }
  165.         } /* while */
  166.     } /* expand_tabs() */
  167.  
  168.  
  169.  
  170. /*=================[ do_directives ]====================*/
  171.  
  172. static boolean do_directives()
  173.  
  174.     { /* do_directives() */
  175.  
  176. debug(puts("do_directives:");)
  177.  
  178. return(FALSE); /* DEBUG..*/
  179.     } /* do_directives() */
  180.  
  181.  
  182.  
  183. /*==================[ fill_ref_recs ]===================*/
  184.  
  185. static VOID fill_ref_recs(sym_ptr, line_ptr, ref_kind)
  186. sym_list_type*    sym_ptr;
  187. line_list_type* line_ptr;
  188. pos_int         ref_kind;
  189.  
  190.     { /* fill_ref_recs() */
  191.  
  192.     /* fill symbol record */
  193.  
  194.     /* NOTE: the symbol's name is VERY temporarily stored in token.tok_string*/
  195.     /* and is "malloc'ed" & copied into heap later by add_sym_rec() if needed*/
  196.     sym_ptr->sym_name        = token.tok_string;
  197.     sym_ptr->sym_type        = token.tok_type;
  198.  
  199.     /* fill line record */
  200.  
  201.     line_ptr->line_number    = file_rec.curr_file->num_lines;
  202.     line_ptr->file_ptr        = file_rec.curr_file;
  203.     line_ptr->reference_type= ref_kind;
  204.     } /* fill_ref_recs() */
  205.  
  206.  
  207.  
  208. /*===================[ add_sym_rec ]====================*/
  209.  
  210. static sym_list_type* add_sym_rec(sym_ptr)
  211. sym_list_type*    sym_ptr;
  212.  
  213.     { /* add_sym_rec() */
  214.     sym_list_type*    new_sym_ptr;
  215.     char*            new_sym_name;
  216. /*
  217. debug(puts("add_sym_rec:");)
  218. */
  219.     /* create a new symbol record & move info into it */
  220.     new_sym_ptr = (sym_list_type*)malloc(sizeof(sym_list_type));
  221.  
  222. debug(printf("add_sym_rec:malloc(new_sym_ptr)-$%06lx[$%x]\n",\
  223. (long)new_sym_ptr,sizeof(sym_list_type));)
  224.  
  225.     if (new_sym_ptr==NULL)
  226.         {
  227.         fprintf(stderr,"Error! out of memory on line #%u in file '%s'\n",
  228.                 file_rec.curr_file->num_lines+1, file_rec.curr_file->file_name);
  229.         }
  230.     else
  231.         {
  232. #ifdef STRUCT_ASSIGN
  233.         *new_sym_ptr = *sym_ptr;
  234. #else
  235.         MOVEBYTE(sym_ptr, new_sym_ptr, sizeof(sym_list_type));
  236. #endif
  237.         new_sym_ptr->line_list    = NULL;
  238.         new_sym_ptr->line_tail    = NULL;
  239.         new_sym_ptr->left        = NULL;
  240.         new_sym_ptr->right        = NULL;
  241.         }
  242.  
  243.     /* create a place for the symbol name & move from temp area */
  244.  
  245.     if (new_sym_ptr!=NULL)
  246.         {
  247.         new_sym_name = malloc(strlen(new_sym_ptr->sym_name)+1);
  248.  
  249. debug(printf("add_line_rec:malloc(new_sym_name)-$%06lx[$%x]\n",\
  250. (long)new_sym_name,strlen(new_sym_ptr->sym_name)+1);)
  251.  
  252.         if (new_sym_name==NULL)
  253.             {
  254.             fprintf(stderr,"Error! out of memory on line #%u in file '%s'\n",
  255.                     file_rec.curr_file->num_lines+1, file_rec.curr_file->file_name);
  256.             }
  257.         else
  258.             {
  259.             strcpy(new_sym_name, sym_ptr->sym_name);
  260.             new_sym_ptr->sym_name = new_sym_name;
  261.             }
  262.         }
  263.  
  264.     /* return the pointer to the new record, or NULL if out of mem */
  265.  
  266.     return(new_sym_ptr);
  267.  
  268.     } /* add_sym_rec() */
  269.  
  270.  
  271. /*==================[ add_line_rec ]====================*/
  272.  
  273. static int add_line_rec(sym_ptr, line_ptr)
  274. sym_list_type*    sym_ptr;
  275. line_list_type* line_ptr;
  276.  
  277.     { /* add_line_rec() */
  278.     line_list_type* new_line_ptr;
  279.  
  280. debug(puts("add_line_rec:");)
  281.  
  282.     /* create new line ref. record on heap */
  283.     new_line_ptr = (line_list_type*)malloc(sizeof(line_list_type));
  284.  
  285. debug(printf("add_line_rec:malloc(new_line_ptr)-$%06lx[$%x]\n",\
  286. (long)new_line_ptr,sizeof(line_list_type));)
  287.  
  288.     if (new_line_ptr==NULL)
  289.         {
  290.         fprintf(stderr,"Error! out of memory on line #%u in file '%s'\n",
  291.                 file_rec.curr_file->num_lines+1, file_rec.curr_file->file_name);
  292.         return(BAD_EXIT);
  293.         }
  294. #ifdef STRUCT_ASSIGN
  295.     *new_line_ptr = *line_ptr;
  296. #else
  297.     MOVEBYTE(line_ptr, new_line_ptr, sizeof(line_list_type));
  298. #endif
  299.  
  300.     /* add line ref. record to symbol's list */
  301.     new_line_ptr->next = NULL;
  302.     if (sym_ptr->line_list == NULL)
  303.         { /* first on list */
  304. debug(puts("  1st liner