1b6cee71dSXin LI#------------------------------------------------------------------------------ 2*898496eeSXin LI# $File: c-lang,v 1.32 2023/06/16 19:57:19 christos Exp $ 3b6cee71dSXin LI# c-lang: file(1) magic for C and related languages programs 4b6cee71dSXin LI# 53e41d09dSXin LI# The strength is to beat standard HTML 6b6cee71dSXin LI 7b6cee71dSXin LI# BCPL 8b6cee71dSXin LI0 search/8192 "libhdr" BCPL source text 9b6cee71dSXin LI!:mime text/x-bcpl 10b6cee71dSXin LI0 search/8192 "LIBHDR" BCPL source text 11b6cee71dSXin LI!:mime text/x-bcpl 12b6cee71dSXin LI 13b6cee71dSXin LI# C 14d38c30c0SXin LI# Check for class if include is found, otherwise class is beaten by include because of lowered strength 1548c779cdSXin LI0 search/8192 #include 1648c779cdSXin LI>0 regex \^#include C 1748c779cdSXin LI>>0 regex \^class[[:space:]]+ 1848c779cdSXin LI>>>&0 regex \\{[\.\*]\\}(;)?$ \b++ 1948c779cdSXin LI>>&0 clear x source text 20*898496eeSXin LI!:strength + 15 21b6cee71dSXin LI!:mime text/x-c 2248c779cdSXin LI0 search/8192 pragma 2348c779cdSXin LI>0 regex \^#[[:space:]]*pragma C source text 24b6cee71dSXin LI!:mime text/x-c 2548c779cdSXin LI0 search/8192 endif 2648c779cdSXin LI>0 regex \^#[[:space:]]*(if\|ifn)def 2748c779cdSXin LI>>&0 regex \^#[[:space:]]*endif$ C source text 28b6cee71dSXin LI!:mime text/x-c 2948c779cdSXin LI0 search/8192 define 3048c779cdSXin LI>0 regex \^#[[:space:]]*(if\|ifn)def 3148c779cdSXin LI>>&0 regex \^#[[:space:]]*define C source text 32b6cee71dSXin LI!:mime text/x-c 3348c779cdSXin LI0 search/8192 char 3448c779cdSXin LI>0 regex \^[[:space:]]*char(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text 35b6cee71dSXin LI!:mime text/x-c 3648c779cdSXin LI0 search/8192 double 3748c779cdSXin LI>0 regex \^[[:space:]]*double(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text 38b6cee71dSXin LI!:mime text/x-c 3948c779cdSXin LI0 search/8192 extern 4048c779cdSXin LI>0 regex \^[[:space:]]*extern[[:space:]]+ C source text 41b6cee71dSXin LI!:mime text/x-c 4248c779cdSXin LI0 search/8192 float 4348c779cdSXin LI>0 regex \^[[:space:]]*float(\ \\*|\\*)(.+)(=.*)?;[[:space:]]*$ C source text 4440427ccaSGordon Tetlow!:mime text/x-c 4548c779cdSXin LI0 search/8192 struct 4648c779cdSXin LI>0 regex \^struct[[:space:]]+ C source text 4740427ccaSGordon Tetlow!:mime text/x-c 4848c779cdSXin LI0 search/8192 union 4948c779cdSXin LI>0 regex \^union[[:space:]]+ C source text 5040427ccaSGordon Tetlow!:mime text/x-c 5140427ccaSGordon Tetlow0 search/8192 main( 5243a5ec4eSXin LI>&0 search/64 String Java source text 5343a5ec4eSXin LI!:mime text/x-java 5443a5ec4eSXin LI>&0 default x 5543a5ec4eSXin LI>>&0 regex \\)[[:space:]]*\\{ C source text 56b6cee71dSXin LI!:mime text/x-c 57b6cee71dSXin LI 58b6cee71dSXin LI# C++ 59b6cee71dSXin LI# The strength of these rules is increased so they beat the C rules above 6048c779cdSXin LI0 search/8192 namespace 6148c779cdSXin LI>0 regex \^namespace[[:space:]]+[_[:alpha:]]{1,30}[[:space:]]*\\{ C++ source text 623e41d09dSXin LI!:strength + 30 63b6cee71dSXin LI!:mime text/x-c++ 6440427ccaSGordon Tetlow# using namespace [namespace] or using std::[lib] 6548c779cdSXin LI0 search/8192 using 6648c779cdSXin LI>0 regex \^using[[:space:]]+(namespace\ )?std(::)?[[:alpha:]]*[[:space:]]*; C++ source text 673e41d09dSXin LI!:strength + 30 68b6cee71dSXin LI!:mime text/x-c++ 6948c779cdSXin LI0 search/8192 template 7048c779cdSXin LI>0 regex \^[[:space:]]*template[[:space:]]*<.*>[[:space:]]*$ C++ source text 7140427ccaSGordon Tetlow!:strength + 30 7240427ccaSGordon Tetlow!:mime text/x-c++ 7348c779cdSXin LI0 search/8192 virtual 7448c779cdSXin LI>0 regex \^[[:space:]]*virtual[[:space:]]+.*[};][[:space:]]*$ C++ source text 7540427ccaSGordon Tetlow!:strength + 30 7640427ccaSGordon Tetlow!:mime text/x-c++ 7740427ccaSGordon Tetlow# But class alone is reduced to avoid beating php (Jens Schleusener) 7848c779cdSXin LI0 search/8192 class 7948c779cdSXin LI>0 regex \^[[:space:]]*class[[:space:]]+[[:digit:][:alpha:]:_]+[[:space:]]*\\{(.*[\n]*)*\\}(;)?$ C++ source text 80282e23f0SXin LI!:strength + 13 81b6cee71dSXin LI!:mime text/x-c++ 8248c779cdSXin LI0 search/8192 public 8348c779cdSXin LI>0 regex \^[[:space:]]*public: C++ source text 843e41d09dSXin LI!:strength + 30 85b6cee71dSXin LI!:mime text/x-c++ 8648c779cdSXin LI0 search/8192 private 8748c779cdSXin LI>0 regex \^[[:space:]]*private: C++ source text 8840427ccaSGordon Tetlow!:strength + 30 8940427ccaSGordon Tetlow!:mime text/x-c++ 9048c779cdSXin LI0 search/8192 protected 9148c779cdSXin LI>0 regex \^[[:space:]]*protected: C++ source text 923e41d09dSXin LI!:strength + 30 93b6cee71dSXin LI!:mime text/x-c++ 94b6cee71dSXin LI 95a5d223e6SXin LI# Objective-C 9648c779cdSXin LI0 search/8192 #import 97*898496eeSXin LI>0 regex \^#import[[:space:]]+["<] Objective-C source text 98a5d223e6SXin LI!:strength + 25 99a5d223e6SXin LI!:mime text/x-objective-c 100a5d223e6SXin LI 101b6cee71dSXin LI# From: Mikhail Teterin <mi@aldan.algebra.com> 102b6cee71dSXin LI0 string cscope cscope reference data 103b6cee71dSXin LI>7 string x version %.2s 104b6cee71dSXin LI# We skip the path here, because it is often long (so file will 105b6cee71dSXin LI# truncate it) and mostly redundant. 106b6cee71dSXin LI# The inverted index functionality was added some time between 107b6cee71dSXin LI# versions 11 and 15, so look for -q if version is above 14: 108b6cee71dSXin LI>7 string >14 109b6cee71dSXin LI>>10 search/100 \ -q\ with inverted index 110b6cee71dSXin LI>10 search/100 \ -c\ text (non-compressed) 111