Convert function names to snake case with clang-tidy

4.1k views Asked by At

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 ?

1

There are 1 answers

0
cassepipe On BEST ANSWER

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, 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