home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3881 < prev    next >
Encoding:
Text File  |  1992-07-23  |  2.9 KB  |  78 lines

  1. Xref: sparky comp.unix.programmer:3881 comp.unix.questions:9371 comp.lang.c:11550
  2. Path: sparky!uunet!infoserv!rick
  3. From: rick@rick.infoserv.com (Rick Klement)
  4. Newsgroups: comp.unix.programmer,comp.unix.questions,comp.lang.c
  5. Subject: Re: #include file dependancies
  6. Summary: how I did it...
  7. Message-ID: <45.26075@rick.infoserv.com>
  8. Date: 24 Jul 92 04:39:20 GMT
  9. References: <AJG.92Jul22114544@sp1.ccd.harris.com>
  10. Followup-To: comp.lang.c
  11. Distribution: comp
  12. Organization: Rick's Place, San Jose, CA, USA
  13. Lines: 63
  14.  
  15. In article <AJG.92Jul22114544@sp1.ccd.harris.com>, ajg@controls.ccd.harris.com (Arnold Goldberg) writes:
  16. > We here have a very large source tree.
  17. > What I'm looking for is a script or utility that will somehow tell
  18. > me which #include files are not actually needed for a source file.
  19. > any takers???
  20.  
  21. I did this specifically for BCC++ on (ugh!) MSDOS written in C, so no
  22. code included here. (Would rather have done it in perl :-)
  23.  
  24. Here's how:
  25.  
  26. 1) for each argument to program (assumed to be name of C file)
  27. 2) spawn (?) compile for this program, verifying good compile
  28.     (or go to next file)
  29. 3) read and store line numbers of all #include statements.
  30. 4) store original copy somewhere
  31. 5) make new file by same name with one #include left out (line missing)
  32.     (I started from highest line number to lowest, meant I
  33.     didn't have to adjust line numbers)
  34. 6) recompile, checking for compile error
  35. 7) if compile error, re-insert #include line, if no error, leave out
  36. 8) repeat from 5) for each include...
  37. 9) if last compile fails, do one more compile
  38.  
  39. Assumptions...
  40.  
  41. a) I have a very consistent organization for all my compiles, they are
  42. all the same, so it's no trouble to figure out how a file is compiled.
  43. This knowledge is built into the include remover. (I don't believe in
  44. custom make files.)
  45.  
  46. b) I have plenty of time. For 'n' #includes, I actually compile the
  47. file 'n+2' times (I want to leave a good object when I am done).
  48. However, this process doesn't destroy anything, so it could be run
  49. overnight.
  50.  
  51. c) This still doesn't work all the time. There are cases where an include
  52. file is required for what it defines at link time (compile still works,
  53. link fails), but I think this is bad design and am trying to get the
  54. person responsible to change this design...
  55.  
  56.  
  57. This was written to go along with an environment for compiling that
  58. recognized Borland error messages like 'prototype missing for printf'
  59. and automatically inserted #includes (from a preprocessed list), but
  60. because some functions are in more than one include file, generally too
  61. many includes were inserted.  Also, some of us like to write programs
  62. by copying an existing file and changing things (like removing
  63. graphics), so we generally have too many #includes.
  64.  
  65. Conclusions:
  66.  
  67. It (mostly) works.
  68. It seems ugly.
  69. -- 
  70. Rick Klement - email:   rick@infoserv.com
  71.  
  72. #include <standard.disclaimer>
  73. RULE #7: When you can say something in a positive way or a negative way,
  74.          don't say it in the negative way.
  75.