1

Open Hub provides statistics on a number of open source projects. Some of this data is categorized by programming language. How do they identify the programming languages in the source code? Is is by examining the content of the files, by file type or by project tagging. For example, is a specific file Fortran or C? Open Hub Programming Languages

2 Answers 2

3

Examining the source for ohcount provided by 3D1T0R, there are various ways that are used. Specifically, for C and Fortran, extensions.gperf shows that for "LANG_C" the file extension "c" is sufficient to identity the programming language. Whereas for the file extensions for "fortran" the file extension can be ambiguous:

c, LANG_C
...
f, DISAMBIGUATE("fortran")
f03, DISAMBIGUATE("fortran")
f08, DISAMBIGUATE("fortran")
f77, DISAMBIGUATE("fortran")
f90, DISAMBIGUATE("fortran")
f95, DISAMBIGUATE("fortran")
for, DISAMBIGUATE("fortran")
fpp, DISAMBIGUATE("fortran")
ftn, DISAMBIGUATE("fortran")

Within detector.c the disambiguate_fortran() function returns either LANG_FORTRANFREE or LANG_FORTRANFIXED:

  // Try the assumption of a fixed formatted source code, and return free
  // format if anything opposes this assumption.

For other languages the above two links can be examined.

2

Ohloh (the predecessor of OpenHub) created an open source (GPLv2) "source code line counter" for gathering this information. It detects which "primary language family" is present in a source file and also parses the whole file to generate a "line-by-line breakdown" of what languages are in it.

It's called Ohcount, and it can be found at https://github.com/blackducksoftware/ohcount.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.