xref: /dragonfly/contrib/file/magic/Magdir/c-lang (revision 9d626b29)
1#------------------------------------------------------------------------------
2# $File: c-lang,v 1.26 2017/08/14 07:40:38 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
80	search/8192	"libhdr"	BCPL source text
9!:mime	text/x-bcpl
100	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 becouse of lowered strength
150	regex	\^#include			C
16>0	regex	\^class[[:space:]]+
17>>&0	regex 	\\{[\.\*]\\}(;)?$			\b++
18>&0	clear	x				source text
19!:strength + 13
20!:mime	text/x-c
210	regex	\^#[[:space:]]*pragma	C source text
22!:mime	text/x-c
230	regex	\^#[[:space:]]*(if\|ifn)def
24>&0	regex	\^#[[:space:]]*endif$	C source text
25!:mime	text/x-c
260	regex	\^#[[:space:]]*(if\|ifn)def
27>&0	regex	\^#[[:space:]]*define	C source text
28!:mime	text/x-c
290	regex	\^[[:space:]]*char(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$			C source text
30!:mime	text/x-c
310	regex	\^[[:space:]]*double(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$			C source text
32!:mime	text/x-c
330	regex	\^[[:space:]]*extern[[:space:]]+		C source text
34!:mime	text/x-c
350	regex	\^[[:space:]]*float(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$			C source text
36!:mime	text/x-c
370	regex	\^struct[[:space:]]+		C source text
38!:mime	text/x-c
390	regex	\^union[[:space:]]+		C source text
40!:mime	text/x-c
410	search/8192	main(
42>&0 regex	\\)[[:space:]]*\\{		C source text
43!:mime	text/x-c
44
45# C++
46# The strength of these rules is increased so they beat the C rules above
470	regex	\^namespace[[:space:]]+[_[:alpha:]]{1,30}[[:space:]]*\\{	C++ source text
48!:strength + 30
49!:mime	text/x-c++
50# using namespace [namespace] or using std::[lib]
510	regex	\^using[[:space:]]+(namespace\ )?std(::)?[[:alpha:]]*[[:space:]]*;		C++ source text
52!:strength + 30
53!:mime	text/x-c++
540	regex	\^[[:space:]]*template[[:space:]]*<.*>[[:space:]]*$	C++ source text
55!:strength + 30
56!:mime	text/x-c++
570	regex	\^[[:space:]]*virtual[[:space:]]+.*[};][[:space:]]*$		C++ source text
58!:strength + 30
59!:mime	text/x-c++
60# But class alone is reduced to avoid beating php (Jens Schleusener)
610	regex	\^[[:space:]]*class[[:space:]]+[[:digit:][:alpha:]:_]+[[:space:]]*\\{(.*[\n]*)*\\}(;)?$		C++ source text
62!:strength + 13
63!:mime	text/x-c++
640	regex	\^[[:space:]]*public:		C++ source text
65!:strength + 30
66!:mime	text/x-c++
670	regex	\^[[:space:]]*private:		C++ source text
68!:strength + 30
69!:mime	text/x-c++
700	regex	\^[[:space:]]*protected:		C++ source text
71!:strength + 30
72!:mime	text/x-c++
73
74# Objective-C
750	regex	\^#import			Objective-C source text
76!:strength + 25
77!:mime	text/x-objective-c
78
79# From: Mikhail Teterin <mi@aldan.algebra.com>
800	string		cscope		cscope reference data
81>7	string		x		version %.2s
82# We skip the path here, because it is often long (so file will
83# truncate it) and mostly redundant.
84# The inverted index functionality was added some time between
85# versions 11 and 15, so look for -q if version is above 14:
86>7	string		>14
87>>10	search/100	\ -q\ 		with inverted index
88>10	search/100	\ -c\ 		text (non-compressed)
89