I have a bunch of C code whose function names are in CamelCase and I have to convert them all to snake_case.
I found that there is a tool call clang-tidy
that seems to be able to do this but I can't make sense of the documentation, there are a lot of options and I am afraid to shoot myself in the foot.
Would you be kind enough to provide me with a one liner ?
Here is the one liner just to rename functions :
clang-tidy \
--fix \
--checks='-*,readability-identifier-naming' \
--config="{
CheckOptions: [
{key: readability-identifier-naming.FunctionCase, value: lower_case},
],
}" \
yourfile.c -- -std=c17
The purpose of --fix
is to apply changes in place, else you will just have a bunch of warnings on stdout.
Config is YAML. You can dump the config into a .clang-tidy
file and clang tidy will use that.
There are other options for renaming variables, structs... You name it : https://sarcasm.github.io/notes/dev/clang-tidy.html#identifier-naming