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 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 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 570 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] 620 search/8192 using 63>0 regex \^using[[:space:]]+(namespace\ )?std(::)?[[:alpha:]]*[[:space:]]*; C++ source text 64!:strength + 30 65!:mime text/x-c++ 660 search/8192 template 67>0 regex \^[[:space:]]*template[[:space:]]*<.*>[[:space:]]*$ C++ source text 68!:strength + 30 69!:mime text/x-c++ 700 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) 750 search/8192 class 76>0 regex \^[[:space:]]*class[[:space:]]+[[:digit:][:alpha:]:_]+[[:space:]]*\\{(.*[\n]*)*\\}(;)?$ C++ source text 77!:strength + 13 78!:mime text/x-c++ 790 search/8192 public 80>0 regex \^[[:space:]]*public: C++ source text 81!:strength + 30 82!:mime text/x-c++ 830 search/8192 private 84>0 regex \^[[:space:]]*private: C++ source text 85!:strength + 30 86!:mime text/x-c++ 870 search/8192 protected 88>0 regex \^[[:space:]]*protected: C++ source text 89!:strength + 30 90!:mime text/x-c++ 91 92# Objective-C 930 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> 990 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) 108