xref: /dragonfly/contrib/file/magic/Magdir/c-lang (revision 8f2ce533)
1#------------------------------------------------------------------------------
2# $File: c-lang,v 1.30 2021/08/16 10:17:05 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 because of lowered strength
150	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
220	search/8192	pragma
23>0	regex	\^#[[:space:]]*pragma	C source text
24!:mime	text/x-c
250	search/8192	endif
26>0	regex	\^#[[:space:]]*(if\|ifn)def
27>>&0	regex	\^#[[:space:]]*endif$	C source text
28!:mime	text/x-c
290	search/8192	define
30>0	regex	\^#[[:space:]]*(if\|ifn)def
31>>&0	regex	\^#[[:space:]]*define	C source text
32!:mime	text/x-c
330	search/8192	char
34>0	regex	\^[[:space:]]*char(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$			C source text
35!:mime	text/x-c
360	search/8192	double
37>0	regex	\^[[:space:]]*double(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$			C source text
38!:mime	text/x-c
390	search/8192	extern
40>0	regex	\^[[:space:]]*extern[[:space:]]+		C source text
41!:mime	text/x-c
420	search/8192	float
43>0	regex	\^[[:space:]]*float(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$			C source text
44!:mime	text/x-c
450	search/8192	struct
46>0	regex	\^struct[[:space:]]+		C source text
47!:mime	text/x-c
480	search/8192	union
49>0	regex	\^union[[:space:]]+		C source text
50!:mime	text/x-c
510	search/8192	main(
52>&0	search/64	String			Java source text
53!:mime	text/x-java
54>&0	default		x
55>>&0 regex	\\)[[:space:]]*\\{		C source text
56!:mime	text/x-c
57
58# C++
59# The strength of these rules is increased so they beat the C rules above
600	search/8192	namespace
61>0	regex	\^namespace[[:space:]]+[_[:alpha:]]{1,30}[[:space:]]*\\{	C++ source text
62!:strength + 30
63!:mime	text/x-c++
64# using namespace [namespace] or using std::[lib]
650	search/8192	using
66>0	regex	\^using[[:space:]]+(namespace\ )?std(::)?[[:alpha:]]*[[:space:]]*;		C++ source text
67!:strength + 30
68!:mime	text/x-c++
690	search/8192	template
70>0	regex	\^[[:space:]]*template[[:space:]]*<.*>[[:space:]]*$	C++ source text
71!:strength + 30
72!:mime	text/x-c++
730	search/8192	virtual
74>0	regex	\^[[:space:]]*virtual[[:space:]]+.*[};][[:space:]]*$		C++ source text
75!:strength + 30
76!:mime	text/x-c++
77# But class alone is reduced to avoid beating php (Jens Schleusener)
780	search/8192	class
79>0	regex	\^[[:space:]]*class[[:space:]]+[[:digit:][:alpha:]:_]+[[:space:]]*\\{(.*[\n]*)*\\}(;)?$		C++ source text
80!:strength + 13
81!:mime	text/x-c++
820	search/8192	public
83>0	regex	\^[[:space:]]*public:		C++ source text
84!:strength + 30
85!:mime	text/x-c++
860	search/8192	private
87>0	regex	\^[[:space:]]*private:		C++ source text
88!:strength + 30
89!:mime	text/x-c++
900	search/8192	protected
91>0	regex	\^[[:space:]]*protected:		C++ source text
92!:strength + 30
93!:mime	text/x-c++
94
95# Objective-C
960	search/8192	#import
97>0	regex	\^#import			Objective-C source text
98!:strength + 25
99!:mime	text/x-objective-c
100
101# From: Mikhail Teterin <mi@aldan.algebra.com>
1020	string		cscope		cscope reference data
103>7	string		x		version %.2s
104# We skip the path here, because it is often long (so file will
105# truncate it) and mostly redundant.
106# The inverted index functionality was added some time between
107# versions 11 and 15, so look for -q if version is above 14:
108>7	string		>14
109>>10	search/100	\ -q\ 		with inverted index
110>10	search/100	\ -c\ 		text (non-compressed)
111