I have a lot of c code in which I would like to replace old syntax style with a new style. E.g. the following prefixes "si":
int siName;
should become "i":
int iName;
But the reg-expression or other find/replace tool, should not touch any source code comments. Any solution?
You can try out coccinelle. It has a bit of a learning curve, but it parses the C code and executes the transformations given to it in a script. For example, for renaming a function from foo to bar, the script would look like this (from here):
@@
@@
-foo()
+bar()
It can probably rename variables based on regular expressions as well, I haven't yet found out a way though.
In vi use
:%s/\<Oldword\>/Newword/gc
This asks you whether or not to replace a particular occurrence of the whole word which you may happily neglect if it is a part of the comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With