home *** CD-ROM | disk | FTP | other *** search
- Cross Reference Generator in C; A Program Conversion Aid.
- 25 November 88
- Ken Gant
- Albuquerque, NM
- (505) 299-9303
-
- CREDITS
- -------
- First off, credit where credit is due. About 90% of this is taken
- verbatim (with only stylistic editing) from the listing in Dr. Dobb's
- TOOLBOOK OF C, starting on page 479. According to the book, "This
- chapter originally appeared in DDJ #68 (June 1982)." So, if the code
- looks familiar, you know why. It was originally written by Jeff
- Taylor. My major effort was porting it to MS-DOS in MicroSoft C 5.1
- The details can be found in the title block in the code.
-
- USAGE
- -----
-
- cref [filename [filename ...]]
-
- If no files are listed on the command line, standard input is used as
- the source.
- The output is to standard output, so to get the results in a file,
- output redirection must be used.
-
- NEAT STUFF
- ----------
- The neat things about this cross-referencer are:
-
- 1. It takes multiple files as input. Not so extraordinary, but not
- all of them out there do.
-
- 2. It prints entries in the following format:
- node
- cref.c 51 55 57 62 63 74 75 96 100 102 111
- 123 175 419 459
-
- "node" is the symbol name. "cref.c" is the file for the following
- line numbers. As for the numbers, figure it out, Sherlock. If the
- symbol is defined in multiple files, all the file entries are listed
- alphabetically under the symbol entry. So, priority is given to the
- symbol, not the file.
-
- 3. It doesn't print the file. I view this as a big plus; I didn't
- want a pretty printer, or even program lister. I just wanted a
- reasonable cross-referencer.
-
- 4. With minor modifications (i.e. to the reserved words table and the
- preprocessor directive handling section of xref()), this program can
- be used for any other language. I suppose any x-reffer with source is
- like that, but I still think it's neat.
-
- 5. Code for both recursive and non-recursive operation is included
- here (it was in the original).
-
- The changes I've made are in the output formatting, and one bug that I
- fixed in the function xref(). It seems that if you put a comment
- starting on a line with a #define and ending on another line (see
- example), the contents of the second line were interpereted as valid
- identifiers, because after the program had parsed off the first token
- following the #define (i.e. MAGIC here), it went and got a new line
- from the input, without checking to see if a comment might just have
- started later on the line. I fixed that. See the code; lines 378-382.
-
- example:
- #define MAGIC 18 /* numbers are bad, but 18 = 4 + 14; 4 for left
- margin, 14 for max UNIX filename length. KRG */
-
-
- PUTTING IT TOGETHER
- -------------------
- 1. If you have MicroSoft C, use the makefile. Otherwise, go on
- to #2.
- 2. The files needed are:
- cref.c
- esccref.c
- strcref.c
- style.h
-
- Compile 'em and link 'em with whatever you have. If your
- compiler is ANSI-compatible, the only change you might have to
- make is in the call to the function itoa() from the function
- list_file() (line 443 of cref.c). According to the back of my
- manual, itoa() isn't ANSI. Mr. Taylor had written a version,
- but I commented it out and used the MS function instead. All
- the old code is still there, so mere shifting of comment
- delimiters is required to reactivate it. Everything else, I
- believe, is in the ANSI standard library, so should be no
- problema.
-
- File set:
- cref.c
- esccref.c
- strcref.c
- style.h
- cref.doc
- cref.mak
-
- NEXT
- ----
- What'll happen next is that I'll introduce classes of identifiers to
- the program, so that functions are listed as such, as opposed to other
- identifiers. However, I'm not in a terrible hurry. Maybe a couple of
- months down the road.
-
- KRG
-