0

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 ?

cassepipe
  • 371
  • 6
  • 16
  • 1
    Are you using version control? If not, you should be. Then there is no risk of shooting yourself in the foot - worst case scenario you just revert your changes. – 0x5453 Apr 20 '21 at 19:11

1 Answers1

3

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} ]}" \
    mycode.c -- -std=c17

The purpose of --fix is to apply changes, else you will just have a bunch of warnings.

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

cassepipe
  • 371
  • 6
  • 16