I have several C files. and I created a function which is named
X_STRING(arg1,arg2,arg3,arg4);
I called this function too many times from different C files. I want to replace the calling of all these functions to X_STRING(arg1, arg2, (arg1) * 2, (arg2) * 3);
awk seems to be the solution but I don’t know how to treat all the cases because I should consider the case where :
- I call the function with new lines inserted in the code between differnet arguments
e.g.
X_STRING(
arg1, arg2,
arg3,
arg4);
- an argument contains a parenthesis :
e.g.
X_STRING(arg1, arg2, (arg3 - 4)*3, arg4);
Someone can point me to good tools to resolve my problem ?
If you don’t mind changing the format in the output, you might be happy with an m4 solution. Put the following in a file:
And then run:
where file.c is your code and def_file is the name of the file with the above content. (The name is irrelevant.)
This should work if your code is well-formatted. (If you have unmatched parentheses, it will fail.)
This will change the whitespace, but otherwise should do what you want.