Hi Tim, Charles,
I am rather looking at a generic substitution where the number of open
quotes are matched, and then add an argument to log(). IN a generic
aproach we may have a variable number of arguments, just like thwe way
printf() supports.
The strings like "module name", LOG_LEVEL_DEBUG, and "The Value of
status=" can be anything.
All these needs to be substituted in the .c files.
regards,
Srini...
On Tue, 2006-09-05 at 12:54 -0400, Charles E Campbell Jr wrote:
> Srinivas Rao. M wrote:
>
> >Hi Vimmers,
> >
> >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);
> >
> >
> >This pattern is appearing in hundreds of source files. Does anybody have
> >a quicker way/script to do this task ?.
> >I know it is possible through macro substitution by writing another
> >macro on top of this, But again it is not a cleaner way..
> >
> >
>
> Are those linebreaks really in there? I doubt it as one of them is in
> the middle of a string.
> OK, assuming they're not there, that its just a mailer thinking its
> smarter than you...
>
> :%g/log("module_name",/s/"The Value of status=%d
> message",status/LOG_LEVEL_DEBUG, "%s:The Value of status=%d
> message",__FUNCTION__,status);
>
> That'll do the trick for one file; then, of course, you'll want to save it:
> :w
>
> OK, now let's see how to automate this:
> qa
> :%g/log("module_name",/s/"The Value of status=%d
> message",status/LOG_LEVEL_DEBUG, "%s:The Value of status=%d
> message",__FUNCTION__,status);
> :w
> :n
> q
>
> That will store the command sequence into a register (I picked register
> a). To use it:
>
> vim PatternForHundredsOfSourceFiles
> qa
> :%g/log("module_name",/s/"The Value of status=%d
> message",status/LOG_LEVEL_DEBUG, "%s:The Value of status=%d
> message",__FUNCTION__,status);
> :w
> :n
> [EMAIL PROTECTED]
>
> Assuming you don't have 10,000 of these, eventually vim will report an
> error. A "PatternForHundredsOfSourceFiles"
> might be *.c */*.c */*/*.c (etc.)
>
> Regards,
> Chip Campbell
>
>