]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/file/magic/Magdir/c-lang
MFV r357712: file 5.38.
[FreeBSD/FreeBSD.git] / contrib / file / magic / Magdir / c-lang
1 #------------------------------------------------------------------------------
2 # $File: c-lang,v 1.28 2019/11/15 21:03:14 christos Exp $
3 # c-lang:  file(1) magic for C and related languages programs
4 #
5 # The strength is to beat standard HTML
6
7 # BCPL
8 0       search/8192     "libhdr"        BCPL source text
9 !:mime  text/x-bcpl
10 0       search/8192     "LIBHDR"        BCPL source text
11 !:mime  text/x-bcpl
12
13 # C
14 # Check for class if include is found, otherwise class is beaten by include because of lowered strength
15 0       search/8192     #include
16 >0      regex   \^#include                      C
17 >>0     regex   \^class[[:space:]]+
18 >>>&0   regex   \\{[\.\*]\\}(;)?$                       \b++
19 >>&0    clear   x                               source text
20 !:strength + 13
21 !:mime  text/x-c
22 0       search/8192     pragma
23 >0      regex   \^#[[:space:]]*pragma   C source text
24 !:mime  text/x-c
25 0       search/8192     endif
26 >0      regex   \^#[[:space:]]*(if\|ifn)def
27 >>&0    regex   \^#[[:space:]]*endif$   C source text
28 !:mime  text/x-c
29 0       search/8192     define
30 >0      regex   \^#[[:space:]]*(if\|ifn)def
31 >>&0    regex   \^#[[:space:]]*define   C source text
32 !:mime  text/x-c
33 0       search/8192     char
34 >0      regex   \^[[:space:]]*char(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$                   C source text
35 !:mime  text/x-c
36 0       search/8192     double
37 >0      regex   \^[[:space:]]*double(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$                 C source text
38 !:mime  text/x-c
39 0       search/8192     extern
40 >0      regex   \^[[:space:]]*extern[[:space:]]+                C source text
41 !:mime  text/x-c
42 0       search/8192     float
43 >0      regex   \^[[:space:]]*float(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$                  C source text
44 !:mime  text/x-c
45 0       search/8192     struct
46 >0      regex   \^struct[[:space:]]+            C source text
47 !:mime  text/x-c
48 0       search/8192     union
49 >0      regex   \^union[[:space:]]+             C source text
50 !:mime  text/x-c
51 0       search/8192     main(
52 >&0 regex       \\)[[:space:]]*\\{              C source text
53 !:mime  text/x-c
54
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
92 # Objective-C
93 0       search/8192     #import
94 >0      regex   \^#import                       Objective-C source text
95 !:strength + 25
96 !:mime  text/x-objective-c
97
98 # From: Mikhail Teterin <mi@aldan.algebra.com>
99 0       string          cscope          cscope reference data
100 >7      string          x               version %.2s
101 # We skip the path here, because it is often long (so file will
102 # truncate it) and mostly redundant.
103 # The inverted index functionality was added some time between
104 # versions 11 and 15, so look for -q if version is above 14:
105 >7      string          >14
106 >>10    search/100      \ -q\           with inverted index
107 >10     search/100      \ -c\           text (non-compressed)