On Thu, 19 May 2011, Francis Galiegue wrote:
> Slowly delving into coccinelle, I now find I have to use python for this...
>
> I want to replace stralloc2() all along the code, but it depends on
> the arguments - here, e1 and e2 are classical expressions, c1 and c2
> are character constants:
>
> stralloc2(e1, e2) --> g_strjoin(NULL, e1, e2, NULL)
> stralloc("c1", e2) --> g_strdup_printf("c1%s", e2)
> stralloc(e1, "c2") --> g_strdup_printf("%sc2", e1)
>
>
> I already know that a char constant can be declared as:
>
> constant char[] c1;
>
> But in this particular case, I need to transform that constant... How
> is it done? I don't know python at all :(
Do you know ocaml? You can use that as well.
In any case, try the following:
@case2@
constant char [] c;
expression e;
position p;
@@
stralloc@p(c, e)
@script:python name@
c << case2.c;
newc;
@@
coccinelle.newc = "\"%s%%s\"" " c
@@
position case2.p;
identifier name.newc;
expression e1,e2;
@@
- stralloc@p(e1,e2)
+ g_strdup_printf(newc, e2)
Note that I am not very sure about the right hand side of the assignment
of newc in the python code. I don't know python either :)
You would have a set of rules like this for each of your cases. You
should put the more specific ones (case 2 and case 3) first. I'm not sure
what you want to do in the case where there are two explicit strings;
maybe that can't arise?
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)