1

I have a macro in C, say LOG(), which prints given string. The macro adds "\n" at the end. Because of this, if we have LOG("hello\n"), the new line is redundant.

How can I find such macro with newline at the end with coccinelle and remove it?

BTW, LOG() takes format and args just like printf().

Yasushi Shoji
  • 4,028
  • 1
  • 26
  • 47

1 Answers1

0

I've successfully found strings ending with \n with the following coccinelle script.

@r@
expression E =~ ".*\\n";
@@
LOG(E, ...);

@script:python@
re << r.E;
@@
print(f"{re}")
Yasushi Shoji
  • 4,028
  • 1
  • 26
  • 47