-
-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ".C" as a C++ extension #1024
Comments
glazari
added a commit
to glazari/tokei
that referenced
this issue
Aug 14, 2023
/# Motivation It turns out that some projects use capital .C to refer to C++. This is true for the OpenFoam project which is a widely used open source software for physics simulations. Although I do not know of other projects that follow this convention it is worth noting that both github and `cloc` recognize the .C extension as a C++ file. This was showed in more detail in this Issue: XAMPPRocky#1024 /# Implementation The file `languages.json` contains a list of extensions for each supported language. So adding ".C" should have been enough for this feature. But the code was casting extensions to lowercase, which makes .c and .C indistinguishable. Because of this the `.to_lower` was also removed from the get_extension utility function. The "to_lower" was probably added for a purpouse. In order to not break functionality I added a second check. If the case sensitive test does not return any result, a second test is done with the to-lower. This will make the code a tiny bit slower, but only when the case-sensitive check fails and will only repeat a rather fast check. /# Testing Tests are created by the `build.rs` script according to the files present in `tests/data`. In order to test my solution I copied the `tests/data/cpp.cpp` into a file called `tests/data/cpp_C.C`. Adding this file without modifying the code will cause a failing test, which is what we want. This is mostly a coincidence I think, for some reason the C language summarize blank lines differently than the Cpp summarize. I think the more appropriate test would be that each of these files also contain the name of the language that they are meant to be as part of the top comment. This would require additional code changes which I think is a bit outside of the scope of this change. I do intend to create a different PR adding this to the tests, if that is ok. Observation: Since this new file is a copy of an existing one, it does not occupy extra space in the git file-store, since it stores files by content hash. /# Additional considerations In Windows the file-system is case-insensitive but case-preserving. I believe that this means that the current version of the code will work correctly on windows to identify .C as cpp. But I do not have a windows system to test this on.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The OpenFoam software uses the peculiar standard of marking its c++ files with capital C ".C" extension.
https://github.com/OpenFOAM/OpenFOAM-dev
Github recognizes the project as being primarily C++ based
Running tokei however shows it as primarily c code.
Running
cloc
it properly recognizes the project as primarily c++I am not aware of any other projects that use this ".C" extension for C++. But OpenFoam is a very popular open source Simulation software widely used in the industry. Also, given the fact that both github and
cloc
are able to properly identify the project as CPP I think it makes sense to include this as an extension.Am I missing some reason why this extension should not be added? does it conflict with the conventions of some other C project?
I can help with implementation if there is agreement in that this is a good addition.
my version of tokei is:
The text was updated successfully, but these errors were encountered: