> @@
> @@
>
> +#include <foo.h>
> #include <...>
That would add it before every include.

That is what I thought and did not try to do it this way.
But when I checked now, this rule works. It inserts foo.h
only before the 1st header include.

But there was another reason why I did not use this.
The includes may be

#include <...>

or

#include "..."  --> I am not sure how to match this.

which I do not know. I am trying to develop these rules for source code
I have not seen yet.

Thanks
Ajay

On Fri, Jul 1, 2011 at 3:46 PM, Julia Lawall <[email protected]> wrote:

> On Fri, 1 Jul 2011, Nicolas Palix wrote:
>
> > Hi,
> >
> > The following should work.
> >
> > @@
> > @@
> >
> > +#include <foo.h>
> > #include <...>
>
> That would add it before every include.  Perhaps it is possible to put a
> position variable somewhere on an include.  I will check.
>
> julia
>
> > On Fri, Jul 1, 2011 at 9:08 PM, Ajay Panyala <[email protected]> wrote:
> > > Hello,
> > >
> > > The example from demos/first.cocci which inserts a header file include
> > > right before the first function that appears in the code.
> > > @initialize:python@
> > >
> > > first = 0
> > >
> > > @first_fct@
> > > type T;
> > > identifier f;
> > > position p;
> > > @@
> > >
> > > T f@p (...) {...}
> > >
> > > @script:python@
> > > p << first_fct.p;
> > > @@
> > >
> > > if p[0].line > first and first == 0:
> > > first = p[0].line
> > > else:
> > > cocci.include_match(False)
> > >
> > > @@
> > > type T;
> > > identifier f;
> > > position first_fct.p;
> > > @@
> > >
> > > +#include <foo.h>
> > >
> > > T f@p (...) {...}
> > >
> > > How can this be modified to insert the header foo.h
> > > right before the 1st header include (instead of right
> > > before the 1st function) that appears in the
> > > program i.e
> > > before
> > > ----------
> > > #include <something.h>
> > > ..
> > > ..
> > > #include<somethingN.h>
> > >
> > >
> > > after
> > > ------
> > > #include <foo.h>
> > > #include <something.h>
> > > ..
> > > ..
> > > #include<somethingN.h>
> > >
> > > Thanks
> > > Ajay
> > >
> > > _______________________________________________
> > > Cocci mailing list
> > > [email protected]
> > > http://lists.diku.dk/mailman/listinfo/cocci
> > > (Web access from inside DIKUs LAN only)
> > >
> > >
> >
> >
> >
> > --
> > Nicolas Palix
> > http://sardes.inrialpes.fr/~npalix/
> > _______________________________________________
> > Cocci mailing list
> > [email protected]
> > http://lists.diku.dk/mailman/listinfo/cocci
> > (Web access from inside DIKUs LAN only)
> >
>



-- 
Ajay Panyala                              | Email: [email protected]
Department of Computer Science | Phone: +1 (225) 907 9501
Louisiana State University           |  www.csc.lsu.edu/~ajay
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to