On 06/15/2012 12:10 PM, SF Markus Elfring wrote:
>>> Hi guys, I wanna covert linux's printk:
>>>     printk(KERN_DEBUG "MAC address is multicast\n");
>>> to freebsd's print:
>>>     printf("MAC address is multicast\n");
> 
> Would an approach like the following work with the semantic patch language?
> 
> @@
> declarer name xyz =~ "KERN_DEBUG";
> @@
> -printk(xyz "my message\n");
> +printf("%s", "my message\n");

That's ugly. A string is a constant so there is no need to have it in
literal.

Something as easy as
@@ @@
-KERN_DEBUG

might work.

Or maybe coccinelle detects
  KERN_DEBUG "MAC address is multicast\n"
as string concatenation and then it would capture it in:
@@
constant C;
@@
 printk(C, ...)

C can then be then passed through a python rule to remove KERN_DEBUG and
back to a SmPL rule to do the transformation.

But both approaches need testing. And I'm waaay too lazy^Wpragmatic to
do it right in coccinelle. A "%g/^+/ s/\s*KERN_DEBUG\s*//" is far faster
to type into vim while looking at the diff.

bye
        michael

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to