c-lang 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #------------------------------------------------------------------------------
  2. # $File: c-lang,v 1.38 2025/05/30 13:36:08 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 + 30
  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:]]*define C source text
  29. !:mime text/x-c
  30. 0 search/8192 char
  31. >0 regex \^[[:space:]]*char(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text
  32. !:mime text/x-c
  33. 0 search/8192 double
  34. >0 regex \^[[:space:]]*double(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text
  35. !:mime text/x-c
  36. 0 search/8192 extern
  37. >0 regex \^[[:space:]]*extern[[:space:]]+ C source text
  38. !:mime text/x-c
  39. 0 search/8192 float
  40. >0 regex \^[[:space:]]*float(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text
  41. !:mime text/x-c
  42. 0 search/8192 struct
  43. >0 regex \^struct[[:space:]]+ C source text
  44. !:mime text/x-c
  45. 0 search/8192 union
  46. >0 regex \^union[[:space:]]+ C source text
  47. !:mime text/x-c
  48. 0 search/8192 main(
  49. >&0 search/64 String Java source text
  50. !:mime text/x-java
  51. >&0 default x
  52. >>&0 regex \\)[[:space:]]*\\{ C source text
  53. !:mime text/x-c
  54. # C++
  55. # The strength of these rules is increased so they beat the C rules above
  56. 0 search/8192 namespace
  57. >0 regex \^namespace[[:space:]]+[_[:alpha:]]{1,20}[[:space:]]*\\{ C++ source text
  58. !:strength + 45
  59. !:mime text/x-c++
  60. # using namespace [namespace] or using std::[lib]
  61. 0 search/8192 using
  62. >0 regex \^using[[:space:]]+(namespace\ )?std(::)?[[:alpha:]]*[[:space:]]*; C++ source text
  63. !:strength + 45
  64. !:mime text/x-c++
  65. 0 search/8192 template
  66. >0 regex \^[[:space:]]*template[[:space:]]*<.*>[[:space:]]*$ C++ source text
  67. !:strength + 45
  68. !:mime text/x-c++
  69. 0 search/8192 virtual
  70. >0 regex \^[[:space:]]*virtual[[:space:]]+.*[};][[:space:]]*$ C++ source text
  71. !:strength + 45
  72. !:mime text/x-c++
  73. # But class alone is reduced to avoid beating php (Jens Schleusener)
  74. 0 search/8192 class
  75. >0 regex \^[[:space:]]*class[[:space:]]+[[:digit:][:alpha:]:_]+[[:space:]]*\\{(.*[\n]*)*\\}(;)?$ C++ source text
  76. !:strength + 13
  77. !:mime text/x-c++
  78. 0 search/8192 public
  79. >0 regex \^[[:space:]]*public: C++ source text
  80. !:strength + 45
  81. !:mime text/x-c++
  82. 0 search/8192 private
  83. >0 regex \^[[:space:]]*private: C++ source text
  84. !:strength + 45
  85. !:mime text/x-c++
  86. 0 search/8192 protected
  87. >0 regex \^[[:space:]]*protected: C++ source text
  88. !:strength + 45
  89. !:mime text/x-c++
  90. # Objective-C
  91. 0 search/8192 #import
  92. >0 regex \^#import[[:space:]]+["<] Objective-C source text
  93. !:strength + 25
  94. !:mime text/x-objective-c
  95. # Typst
  96. # https://github.com/typst/typst
  97. 0 regex \^[[:space:]]*#(import|include)[[:space:]]+"@[[:alnum:]-]+ Typst source text
  98. !:strength + 45
  99. !:mime text/vnd.typst
  100. !:ext typ
  101. 0 regex \^[[:space:]]*#(import|include)[[:space:]]+"[[:alnum:]]+.typ" Typst source text
  102. !:strength + 45
  103. !:mime text/vnd.typst
  104. !:ext typ
  105. 0 regex \^[[:space:]]*#(set|show|let) Typst source text
  106. !:strength + 45
  107. !:mime text/vnd.typst
  108. !:ext typ
  109. # From: Mikhail Teterin <mi@aldan.algebra.com>
  110. 0 string cscope cscope reference data
  111. >7 string x version %.2s
  112. # We skip the path here, because it is often long (so file will
  113. # truncate it) and mostly redundant.
  114. # The inverted index functionality was added some time between
  115. # versions 11 and 30, so look for -q if version is above 14:
  116. >7 string >14
  117. >>10 search/100 \ -q\ with inverted index
  118. >10 search/100 \ -c\ text (non-compressed)