As lreeder, I would recommend code refactoring so that open and private files are in different files / libraries.
However, if this does not work for you, I think you should not resort to a complete analysis of the C code. Instead, you can do something simple, for example, put the personal parts of the file between comments like //PRIVATE and //END-PRIVATE . Then you can use ruby script to delete private sections:
#!/usr/bin/ruby # remove_private.rb: Removes all lines between "PRIVATE" and "END-PRIVATE" # # Usage 1, output to STDIO: cat filename.c | ruby remove_private.rb # Usage 2, output to STDIO: ruby remove_private.rb filename.c # Usage 3, in-place editing of file (and creating a backup): ruby -i.bak remove_private.rb filename.c while line = ARGF.gets unless (line =~ /PRIVATE/)..(line =~ /END-PRIVATE/) puts line end end
This uses some magic and convenient ruby functions to make the code short, but I think it will be much easier to debug and maintain than the full C parser. In addition, developers can easily see which functions are private while they work on the code. I did something very similar to this for the project I was working on, where we wanted to release part of the Makefile, but not all. Perhaps you can rewrite it in your favorite scripting language.
source share