Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Julia Lawall <julia <at> diku.dk>
Subject: Re: Calling spatch from python
Newsgroups: gmane.comp.version-control.coccinelle
Date: Friday 12th August 2011 13:41:32 UTC (over 6 years ago)
Programming beyond print in python is completely beyond me :)

It looks like maybe there is something unexpected in the .cocci file.

Perhaps you want what I call command line Coccinelle in the new 
(1.0.0-rc5) release?  Now you can say:

spatch -sp "E->Fld" file

to find all of the structure field dereferences in file, or more 
interestingly:

spatch -sp "e:struct foo *:->Fld" file

to find only those where the structure has type struct foo *.  By default, 
anything that begins with a capital letter is a metavariable.  You can 
also declare a metavariable by concatenating the variable name with ::, 
with the type of the metavariable between the colons.

You can also use ..., and when, but the argument to when has to be a 
single token (eg an identifier name or a metavariable).

julia


On Fri, 12 Aug 2011, Eric Leblond wrote:

> Hello,
> 
> I'm currently trying to code a semantic grep using coccinelle (By the
> way, if there is one tell me;). I did not find better than making a
> python script calling spatch...
> 
> If the grep code like is easy to build with coccinelle, I've got some
> difficulty to call coccinelle with python using for example "call"
> function of the subprocess module:
> 
> # launch spatch
> cmd = ["spatch", "-sp_file", tmp_cocci_file.name, file_name]
> print "running: %s." % " ".join(cmd)
> 
> output = call(cmd)
> 
> Running the script does:
> [email protected]:~/git/coccigrep (master) $ python ./coccigrep.py
> running: spatch -sp_file /tmp/tmpoiump0.cocci
/home/eric/git/oisf/src/detect-noalert.c.
> init_defs_builtins: /usr/share/coccinelle/standard.h
> Fatal error: exception Failure("unexpected code before the first rule
> ")
> 2
> 
> 
> Running the command is ok:
> 
> [email protected]:~/git/coccigrep (master) $ spatch
> -sp_file /tmp/tmpoiump0.cocci /home/eric/git/oisf/src/detect-noalert.c
> init_defs_builtins: /usr/share/coccinelle/standard.h
> HANDLING: /home/eric/git/oisf/src/detect-noalert.c
> /home/eric/git/oisf/src/detect-noalert.c:49:
>         SCLogError(SC_ERR_INVALID_VALUE, "nocase has no value");
>         return -1;
>     }
> 
>     s->flags |= SIG_FLAG_NOALERT;
>     return 0;
> }
> 
> If I use Popen without argument, everything is fine.
> 
> Any idea ?
> 
> BR,
> -- 
> Eric Leblond 
> Blog: http://home.regit.org/
>
 
CD: 4ms