need to remove a function from c source code

W

webwesen

hello gurus,
sorry for a newb question:

i have some c code with
------------------------
some c code
....
unsigned remove_me (blah blah)
{
blah blah;
if blah ()
{
blah;
}
blah
}
....
some more c code
------------------------

is there a way to safely remove function 'remove_me' without writing a
C parser? I was thinking about converting all tabs to spaces with
'expand', then removing duplicate spaces with 'tr', then I would scan
my file for the line 'unsigned remove_me' then count the number of
curly brackets until their number isn't even (each left bracket
corresponds to the right one), then recall the line numbers and remove
anything in between.

this solution seems kinda awkward to me. what do you think?
thanks a lot in advance
 
M

Martien Verbruggen

On 9 Feb 2005 19:32:43 -0800,

[snip]
is there a way to safely remove function 'remove_me' without writing a
C parser? I was thinking about converting all tabs to spaces with

Using an editor would be my preferred option.
'expand', then removing duplicate spaces with 'tr', then I would scan
my file for the line 'unsigned remove_me' then count the number of
curly brackets until their number isn't even (each left bracket
corresponds to the right one), then recall the line numbers and remove
anything in between.

What if you have unbalanced curlies in a string? or in a comment? You
can't parse C without writing (at least a partial) C parser.

There is no need to squash spaces and that stuff.


How is this related to Perl?


Martien
 
M

Martien Verbruggen

On 10 Feb 2005 07:56:46 -0800,

[In response to the question what this had to do with Perl]
Please next time quote some context.
well, i would have written scan + brackets search in Perl...
thanks

Your question was not about how to write it in Perl, but how to do it
at all.

I would probably not write something like this in Perl, but more
likely in C, with a state machine or something like that.

Martien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,913
Members
47,455
Latest member
Delilah Code

Latest Threads

Top