Re: Search and replace as per format

2006-09-06 Thread A.J.Mechelynck

Srinivas Rao. M wrote:

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);

[...]

Well, please describe exactly what you want to do, and in particular, 
how to determine which string(s) to modify (like The Value of... and 
which not to (like module name).


I suspect the problem can be solved with an :args command (such as 
:args **/*.[ch]) followed by :argdo 
g/\log(/s/something/something/g. Possibly wrapping it in a function if 
things like __FUNCTION__ must be specified on each invocation.




Best regards,
Tony.


Search and replace as per format

2006-09-05 Thread Srinivas Rao. M

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..

Any help Most welcome.
regards,
srini...




Re: Search and replace as per format

2006-09-05 Thread Charles E Campbell Jr

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



Re: Search and replace as per format

2006-09-05 Thread Tim Chase

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