scancode-toolkit icon indicating copy to clipboard operation
scancode-toolkit copied to clipboard

Incorrect programming language reported for a config.h.in file

Open pombredanne opened this issue 9 years ago • 7 comments

FileName: ./config.h.in
IsSource: True
IsScript: False
ProgLanguage: JavaScript+Lasso

From https://raw.githubusercontent.com/vysheng/tg/master/config.h.in if I upgrade pygments to 2.2.0 the programming language is "Rexx" We need to supplement this with a file name and extension registry: after all config.h.in is kinda well known autotools pattern

This is also closely related to #426

Reported by tglx

pombredanne avatar Apr 21 '17 14:04 pombredanne

This is now reported as "ASCII text" which is quite acceptable given that this is a generated file.

pombredanne avatar Nov 05 '18 22:11 pombredanne

Hey!! @pombredanne I want to help you with this issue. May I know what I should do about that? Give me a chance that I could understand the system and the issue.

D-lang14 avatar Dec 13 '20 09:12 D-lang14

@D-lang14 sorry for the late reply. The key issue is that we are putting too much emphasis on using Pygments and libmagic to detect programming langauges. A config.h should ALWAYS be reported as C/C++ So this would consists in:

  1. study the way we detect and report types in typecode
  2. in particular check out our we use a registry of extensions
  3. evolve the way we report programming languages to work first (and only?) from the registry for some cases

pombredanne avatar Feb 12 '21 09:02 pombredanne

Hello @pombredanne I have studied the typecode library thoroughly and made some changes in pygments_lexers_mapping.py in site-packages and I am getting the desired results but it seems Lib\site-packages are git ignored. So where would I make the changes such that after configuring, the package changes would be reflected? I aspire to join AboutCode in GSoC-21.

Mitrajit avatar Mar 23 '21 20:03 Mitrajit

@pombredanne A slight change in typecode can give the correct results by changing 'CLexer': ('typecode._vendor.pygments.lexers.c_cpp', 'C', ('c',), ('*.c', '*.h', '*.idc'), ('text/x-chdr', 'text/x-csrc')), to 'CLexer': ('typecode._vendor.pygments.lexers.c_cpp', 'C', ('c',), ('*.c', '*.h', '*.idc','config.h.in'), ('text/x-chdr', 'text/x-csrc')),

Mitrajit avatar Mar 24 '21 15:03 Mitrajit

Hi @pombredanne, I'd like to work on this.

I reproduced it on the current typecode main: for config.h.in, programming_language is ___, while config.h gives C.

From what I can see, get_pygments_lexer in contenttype.py only guesses from the file content when there is no extension. config.h.in has a .in extension and no lexer matches it, so nothing is detected.

Which fix would you prefer?

  1. Add *.h.in to the C lexer patterns (Rust already has *.rs.in in pygments_lexers_mapping.py), or
  2. The filename and extension lookup first approach you suggested in 2021?

I'd open the PR in typecode with a test in tests/data/filetest/code/c/. Does that work?

dipesh-svg avatar Nov 05 '26 09:11 dipesh-svg

Hi!

I have submitted a pull request addressing this issue in the TypeCode repository.

PR: https://github.com/aboutcode-org/typecode/pull/55

The implementation adds *.h.in to the CLexer filename patterns and includes a regression fixture with data-driven expectations.

I have verified the fix locally and tested the existing C/C++ test suite.

I would appreciate your feedback on whether this focused solution is preferred over the broader filename/extension registry approach discussed earlier.

Thank you!

nikhilanand0105 avatar Nov 05 '26 16:11 nikhilanand0105