I am tasked to replace the pattern
log("module_name", LOG_LEVEL_DEBUG, "The Value of status=%d message",
status);
to
log("module_name", LOG_LEVEL_DEBUG, "%s:The Value of status=%d
message",__FUNCTION__, status);
Well, with unknown line-breaks, and not knowing which pieces are
subject to change, I'll take a stab at it. The biggest offender
would be if any of the contents of the statement has parens in
it, such as
log("module_name", LOG_LEVEL_DEBUG, "The value...%d", (4 + vbl))
which would cause problems. Also, if an escaped doublequote is
in your string, it would also cause it to choke, e.g.
"The Value of \"status\"=%d message"
The basic statement would be something like
:%s/log("\([^"]*\)"\_s*,\_s*\(LOG_LEVEL\w*\)\_s*,\_s*"\([^"]*\)"\_s*,\_s*\([^)]\+\))/log("\1",
\2, "%s:\3",__FUNCTION__, \4)/g
It pulls out each piece so you can manipulate further if needed.
This pattern is appearing in hundreds of source files. Does anybody have
a quicker way/script to do this task ?.
Once you've got the above working on one file, you can use vim's
argdo/bufdo functionality to do something like
vim *.c *.h
:set hidden
:argdo %s/..../..../g
after which you can check over them, before (if all's good) issuing
:wall
You can learn more about some of the nuances of this at
:help argdo
:help bufdo
:help 'hidden'
:help :wall
and the rest is just a big ugly regexp to match what I understand
you're hunting. :)
-tim