[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Include Collector (may be OT)



Chris Lawrence wrote:
> 
> On Jul 26, Bolan Meek wrote:
> > In beginning maintenance & improvement (a.k.a adoption)
> > of the xmailtool source, I've wanted to collect all the
> > '#include <whatever.h>' statements that are common to
> > several of the source files with a Perl script, as opposed
> > to a error-vulnerable method of doing it by hand.
> 
> This should work (untested):
> 
> cat `find . -name '*.[ch]'` | egrep '^\s+#include <' | sort | uniq -d

Thanks.  But I also want to remove the #include statements from
the source files, and have one instance of #include for the header
file into which the #includes are collected.  Sorry for being so
picky.

I've never used uniq, though I've seen it in the man page listing...
Anyway, the command pipe above isn't working...
`grep include *.c` shows all my includes.  `grep include *.c | uniq -d`
isn't showing any.
Here are the contents (in my test, all I have are #include statements):

ex1.c:#include <1a.h>
ex1.c:#include <2.h>
ex1.c:#include <3.h>
ex1.c:#include <4.h>
ex1.c:#include "5.h"
ex1.c:#include <1b.h>

ex2.c:#include <1c.h>
ex2.c:#include <2.h>
ex2.c:#include <3.h>
ex2.c:#include <4.h>
ex2.c:#include "5.h"
ex2.c:#include <1d.h>

ex3.c:#include <1e.h>
ex3.c:#include <3.h>
ex3.c:#include <4.h>
ex3.c:#include "5.h"
ex3.c:#include <1f.h>

ex4.c:#include <1g.h>
ex4.c:#include <4.h>
ex4.c:#include "5.h"
ex4.c:#include <1h.h>

ex5.c:#include <1i.h>
ex5.c:#include "5.h"
ex5.c:#include <1j.h>

The "ex?.c" at the beginning of each makes each line unique, so uniq -d
can't
process.  Also the \s+ in your egrep command can't match ^#include ...
Thanks anyway:  I know I could strip out the ex?.c, but this still
doesn't
get me what I want...
> 
> Chris
> 
> --
> To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

-- 
Bolan.Meek@wcom.com 972-729-5387
bolan@koyote.com (home ph. on Q) http://www.koyote.com/users/bolan
RE: xmailtool http://www.koyote.com/users/bolan/xmailtool/index.html
RMS of Borg: "Resistance is futile; you shall be freed."



Reply to: