c-lang 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #------------------------------------------------------------------------------
  2. # $File: c-lang,v 1.31 2022/12/01 22:04:33 christos Exp $
  3. # c-lang: file(1) magic for C and related languages programs
  4. #
  5. # The strength is to beat standard HTML
  6. # BCPL
  7. 0 search/8192 "libhdr" BCPL source text
  8. !:mime text/x-bcpl
  9. 0 search/8192 "LIBHDR" BCPL source text
  10. !:mime text/x-bcpl
  11. # C
  12. # Check for class if include is found, otherwise class is beaten by include because of lowered strength
  13. 0 search/8192 #include
  14. >0 regex \^#include C
  15. >>0 regex \^class[[:space:]]+
  16. >>>&0 regex \\{[\.\*]\\}(;)?$ \b++
  17. >>&0 clear x source text
  18. !:strength + 13
  19. !:mime text/x-c
  20. 0 search/8192 pragma
  21. >0 regex \^#[[:space:]]*pragma C source text
  22. !:mime text/x-c
  23. 0 search/8192 endif
  24. >0 regex \^#[[:space:]]*(if\|ifn)def
  25. >>&0 regex \^#[[:space:]]*endif$ C source text
  26. !:mime text/x-c
  27. 0 search/8192 define
  28. >0 regex \^#[[:space:]]*(if\|ifn)def
  29. >>&0 regex \^#[[:space:]]*define C source text
  30. !:mime text/x-c
  31. 0 search/8192 char
  32. >0 regex \^[[:space:]]*char(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text
  33. !:mime text/x-c
  34. 0 search/8192 double
  35. >0 regex \^[[:space:]]*double(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text
  36. !:mime text/x-c
  37. 0 search/8192 extern
  38. >0 regex \^[[:space:]]*extern[[:space:]]+ C source text
  39. !:mime text/x-c
  40. 0 search/8192 float
  41. >0 regex \^[[:space:]]*float(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text
  42. !:mime text/x-c
  43. 0 search/8192 struct
  44. >0 regex \^struct[[:space:]]+ C source text
  45. !:mime text/x-c
  46. 0 search/8192 union
  47. >0 regex \^union[[:space:]]+ C source text
  48. !:mime text/x-c
  49. 0 search/8192 main(
  50. >&0 search/64 String Java source text
  51. !:mime text/x-java
  52. >&0 default x
  53. >>&0 regex \\)[[:space:]]*\\{ C source text
  54. !:mime text/x-c
  55. # C++
  56. # The strength of these rules is increased so they beat the C rules above
  57. 0 search/8192 namespace
  58. >0 regex \^namespace[[:space:]]+[_[:alpha:]]{1,30}[[:space:]]*\\{ C++ source text
  59. !:strength + 30
  60. !:mime text/x-c++
  61. # using namespace [namespace] or using std::[lib]
  62. 0 search/8192 using
  63. >0 regex \^using[[:space:]]+(namespace\ )?std(::)?[[:alpha:]]*[[:space:]]*; C++ source text
  64. !:strength + 30
  65. !:mime text/x-c++
  66. 0 search/8192 template
  67. >0 regex \^[[:space:]]*template[[:space:]]*<.*>[[:space:]]*$ C++ source text
  68. !:strength + 30
  69. !:mime text/x-c++
  70. 0 search/8192 virtual
  71. >0 regex \^[[:space:]]*virtual[[:space:]]+.*[};][[:space:]]*$ C++ source text
  72. !:strength + 30
  73. !:mime text/x-c++
  74. # But class alone is reduced to avoid beating php (Jens Schleusener)
  75. 0 search/8192 class
  76. >0 regex \^[[:space:]]*class[[:space:]]+[[:digit:][:alpha:]:_]+[[:space:]]*\\{(.*[\n]*)*\\}(;)?$ C++ source text
  77. !:strength + 13
  78. !:mime text/x-c++
  79. 0 search/8192 public
  80. >0 regex \^[[:space:]]*public: C++ source text
  81. !:strength + 30
  82. !:mime text/x-c++
  83. 0 search/8192 private
  84. >0 regex \^[[:space:]]*private: C++ source text
  85. !:strength + 30
  86. !:mime text/x-c++
  87. 0 search/8192 protected
  88. >0 regex \^[[:space:]]*protected: C++ source text
  89. !:strength + 30
  90. !:mime text/x-c++
  91. # Objective-C
  92. 0 search/8192 #import
  93. >0 regex \^#import[[:space:]]+["<] Objective-C source text
  94. !:strength + 25
  95. !:mime text/x-objective-c
  96. # From: Mikhail Teterin <mi@aldan.algebra.com>
  97. 0 string cscope cscope reference data
  98. >7 string x version %.2s
  99. # We skip the path here, because it is often long (so file will
  100. # truncate it) and mostly redundant.
  101. # The inverted index functionality was added some time between
  102. # versions 11 and 15, so look for -q if version is above 14:
  103. >7 string >14
  104. >>10 search/100 \ -q\ with inverted index
  105. >10 search/100 \ -c\ text (non-compressed)