Line | Branch | Exec | Source |
---|---|---|---|
1 | static const struct FileExtensionMap { | ||
2 | const char ext[11]; | ||
3 | const uint8_t filetype; // FileTypeEnum | ||
4 | } extensions[] = { | ||
5 | {"ada", ADA}, | ||
6 | {"adb", ADA}, | ||
7 | {"adoc", ASCIIDOC}, | ||
8 | {"ads", ADA}, | ||
9 | {"asciidoc", ASCIIDOC}, | ||
10 | {"asd", LISP}, | ||
11 | {"asm", ASM}, | ||
12 | {"auk", AWK}, | ||
13 | {"automount", INI}, | ||
14 | {"avsc", JSON}, | ||
15 | {"awk", AWK}, | ||
16 | {"bash", SH}, | ||
17 | {"bat", BATCH}, | ||
18 | {"bats", SH}, // https://github.com/bats-core/bats-core | ||
19 | {"bbl", TEX}, | ||
20 | {"bib", BIBTEX}, | ||
21 | {"btm", BATCH}, | ||
22 | {"bzl", PYTHON}, // https://bazel.build/rules/language | ||
23 | {"c++", CPLUSPLUS}, | ||
24 | {"cbl", COBOL}, | ||
25 | {"cc", CPLUSPLUS}, | ||
26 | {"cjs", JAVASCRIPT}, | ||
27 | {"cl", LISP}, | ||
28 | {"clj", CLOJURE}, | ||
29 | {"cls", TEX}, | ||
30 | {"cmake", CMAKE}, | ||
31 | {"cmd", BATCH}, | ||
32 | {"cnc", GCODE}, | ||
33 | {"cob", COBOL}, | ||
34 | {"cobol", COBOL}, | ||
35 | {"cocci", COCCINELLE}, | ||
36 | {"coffee", COFFEESCRIPT}, | ||
37 | {"cpp", CPLUSPLUS}, | ||
38 | {"cr", RUBY}, | ||
39 | {"cs", CSHARP}, | ||
40 | {"csh", CSH}, | ||
41 | {"cshrc", CSH}, | ||
42 | {"cson", COFFEESCRIPT}, | ||
43 | {"css", CSS}, | ||
44 | {"csv", CSV}, | ||
45 | {"cxx", CPLUSPLUS}, | ||
46 | {"d2", D2}, | ||
47 | {"dart", DART}, | ||
48 | {"desktop", INI}, | ||
49 | {"di", D}, | ||
50 | {"diff", DIFF}, | ||
51 | {"dircolors", CONFIG}, | ||
52 | {"doap", XML}, | ||
53 | {"docbook", XML}, | ||
54 | {"docker", DOCKER}, | ||
55 | {"dot", DOT}, | ||
56 | {"doxy", CONFIG}, | ||
57 | {"dterc", DTE}, | ||
58 | {"dts", DEVICETREE}, | ||
59 | {"dtsi", DEVICETREE}, | ||
60 | {"dtx", TEX}, | ||
61 | {"ebuild", SH}, | ||
62 | {"el", LISP}, | ||
63 | {"emacs", LISP}, | ||
64 | {"eml", MAIL}, | ||
65 | {"eps", POSTSCRIPT}, | ||
66 | {"erl", ERLANG}, | ||
67 | {"ex", ELIXIR}, | ||
68 | {"exs", ELIXIR}, | ||
69 | {"fish", FISH}, | ||
70 | {"flatpakref", INI}, | ||
71 | {"frag", GLSL}, | ||
72 | {"gawk", AWK}, | ||
73 | {"gco", GCODE}, | ||
74 | {"gcode", GCODE}, | ||
75 | {"gd", GDSCRIPT}, | ||
76 | {"gemspec", RUBY}, | ||
77 | {"geojson", JSON}, | ||
78 | {"gitignore", GITIGNORE}, | ||
79 | {"glsl", GLSL}, | ||
80 | {"glslf", GLSL}, | ||
81 | {"glslv", GLSL}, | ||
82 | {"gltf", JSON}, | ||
83 | {"gml", XML}, | ||
84 | {"gnuplot", GNUPLOT}, | ||
85 | {"go", GO}, | ||
86 | {"god", RUBY}, | ||
87 | {"gp", GNUPLOT}, | ||
88 | {"gperf", GPERF}, | ||
89 | {"gpi", GNUPLOT}, | ||
90 | {"gql", GRAPHQL}, | ||
91 | {"graphql", GRAPHQL}, | ||
92 | {"graphqls", GRAPHQL}, | ||
93 | {"groovy", GROOVY}, | ||
94 | {"grxml", XML}, | ||
95 | {"gsed", SED}, | ||
96 | {"gv", DOT}, | ||
97 | {"har", JSON}, | ||
98 | {"hcl", HCL}, | ||
99 | {"hh", CPLUSPLUS}, | ||
100 | {"hpp", CPLUSPLUS}, | ||
101 | {"hrl", ERLANG}, | ||
102 | {"hs", HASKELL}, | ||
103 | {"htm", HTML}, | ||
104 | {"html", HTML}, | ||
105 | {"hxx", CPLUSPLUS}, | ||
106 | {"ini", INI}, | ||
107 | {"ino", CPLUSPLUS}, // https://arduino.github.io/arduino-cli/1.0/sketch-build-process/#pre-processing | ||
108 | {"ins", TEX}, | ||
109 | {"java", JAVA}, | ||
110 | {"jl", JULIA}, | ||
111 | {"jq", JQ}, | ||
112 | {"js", JAVASCRIPT}, | ||
113 | {"jslib", JAVASCRIPT}, | ||
114 | {"json", JSON}, | ||
115 | {"jsonl", JSON}, | ||
116 | {"jspre", JAVASCRIPT}, | ||
117 | {"kdl", KDL}, | ||
118 | {"kml", XML}, | ||
119 | {"ksh", SH}, | ||
120 | {"kt", KOTLIN}, | ||
121 | {"kts", KOTLIN}, | ||
122 | {"latex", TEX}, | ||
123 | {"lsp", LISP}, | ||
124 | {"ltx", TEX}, | ||
125 | {"lua", LUA}, | ||
126 | {"m3u", CONFIG}, | ||
127 | {"m3u8", CONFIG}, | ||
128 | {"m4", M4}, | ||
129 | {"mak", MAKE}, | ||
130 | {"make", MAKE}, | ||
131 | {"markdown", MARKDOWN}, | ||
132 | {"mawk", AWK}, | ||
133 | {"mcmeta", JSON}, | ||
134 | {"md", MARKDOWN}, | ||
135 | {"mdown", MARKDOWN}, | ||
136 | {"mk", MAKE}, | ||
137 | {"mkd", MARKDOWN}, | ||
138 | {"mkdn", MARKDOWN}, | ||
139 | {"ml", OCAML}, | ||
140 | {"mli", OCAML}, | ||
141 | {"moon", MOONSCRIPT}, | ||
142 | {"mount", INI}, | ||
143 | {"nawk", AWK}, | ||
144 | {"nft", NFTABLES}, | ||
145 | {"nginx", NGINX}, | ||
146 | {"nginxconf", NGINX}, | ||
147 | {"nim", NIM}, | ||
148 | {"ninja", NINJA}, | ||
149 | {"nix", NIX}, | ||
150 | {"nomad", HCL}, | ||
151 | {"odin", ODIN}, | ||
152 | {"opml", XML}, | ||
153 | {"page", XML}, | ||
154 | {"pas", PASCAL}, | ||
155 | {"patch", DIFF}, | ||
156 | {"path", INI}, | ||
157 | {"pc", PKGCONFIG}, | ||
158 | {"perl", PERL}, | ||
159 | {"php", PHP}, | ||
160 | {"pl", PERL}, | ||
161 | {"plist", XML}, | ||
162 | {"pls", INI}, | ||
163 | {"plt", GNUPLOT}, | ||
164 | {"pm", PERL}, | ||
165 | {"po", GETTEXT}, | ||
166 | {"podspec", RUBY}, | ||
167 | {"pot", GETTEXT}, | ||
168 | {"pp", RUBY}, | ||
169 | {"proto", PROTOBUF}, | ||
170 | {"ps", POSTSCRIPT}, | ||
171 | {"ps1", POWERSHELL}, | ||
172 | {"psd1", POWERSHELL}, | ||
173 | {"psm1", POWERSHELL}, | ||
174 | {"py", PYTHON}, | ||
175 | {"py3", PYTHON}, | ||
176 | {"qrc", XML}, | ||
177 | {"rake", RUBY}, | ||
178 | {"rb", RUBY}, | ||
179 | {"rbi", RUBY}, | ||
180 | {"rbx", RUBY}, | ||
181 | {"rdf", XML}, | ||
182 | {"re", C}, // re2c | ||
183 | {"rkt", RACKET}, | ||
184 | {"rktd", RACKET}, | ||
185 | {"rktl", RACKET}, | ||
186 | {"rockspec", LUA}, | ||
187 | {"roff", ROFF}, | ||
188 | {"rs", RUST}, | ||
189 | {"rss", XML}, | ||
190 | {"rst", RST}, | ||
191 | {"ru", RUBY}, | ||
192 | {"sarif", JSON}, | ||
193 | {"scala", SCALA}, | ||
194 | {"scm", SCHEME}, | ||
195 | {"scss", SCSS}, | ||
196 | {"scxml", XML}, | ||
197 | {"sed", SED}, | ||
198 | {"service", INI}, | ||
199 | {"sh", SH}, | ||
200 | {"sld", SCHEME}, | ||
201 | {"slice", INI}, | ||
202 | {"sls", SCHEME}, | ||
203 | {"socket", INI}, | ||
204 | {"spec", RPMSPEC}, | ||
205 | {"sql", SQL}, | ||
206 | {"ss", SCHEME}, | ||
207 | {"sty", TEX}, | ||
208 | {"supp", CONFIG}, | ||
209 | {"svg", XML}, | ||
210 | {"swift", SWIFT}, | ||
211 | {"target", INI}, | ||
212 | {"tcl", TCL}, | ||
213 | {"tcsh", CSH}, | ||
214 | {"tcshrc", CSH}, | ||
215 | {"terminfo", TERMINFO}, | ||
216 | {"tex", TEX}, | ||
217 | {"texi", TEXINFO}, | ||
218 | {"texinfo", TEXINFO}, | ||
219 | {"tf", HCL}, | ||
220 | {"tfvars", HCL}, | ||
221 | {"thor", RUBY}, | ||
222 | {"timer", INI}, | ||
223 | {"tlv", TLVERILOG}, | ||
224 | {"toml", TOML}, | ||
225 | {"topojson", JSON}, | ||
226 | {"tr", ROFF}, | ||
227 | {"ts", TYPESCRIPT}, | ||
228 | {"tsv", TSV}, | ||
229 | {"tsx", TYPESCRIPT}, | ||
230 | {"typ", TYPST}, | ||
231 | {"ui", XML}, | ||
232 | {"vala", VALA}, | ||
233 | {"vapi", VALA}, | ||
234 | {"vcard", VCARD}, | ||
235 | {"vcf", VCARD}, | ||
236 | {"ver", VERILOG}, | ||
237 | {"vert", GLSL}, | ||
238 | {"vh", VHDL}, | ||
239 | {"vhd", VHDL}, | ||
240 | {"vhdl", VHDL}, | ||
241 | {"vim", VIML}, | ||
242 | {"weechatlog", WEECHATLOG}, | ||
243 | {"wsgi", PYTHON}, | ||
244 | {"xbel", XML}, | ||
245 | {"xhtml", HTML}, | ||
246 | {"xml", XML}, | ||
247 | {"xsd", XML}, | ||
248 | {"xsl", XML}, | ||
249 | {"xslt", XML}, | ||
250 | {"xspf", XML}, | ||
251 | {"yaml", YAML}, | ||
252 | {"yml", YAML}, | ||
253 | {"zig", ZIG}, | ||
254 | {"zsh", SH}, | ||
255 | }; | ||
256 | |||
257 | 145 | static FileTypeEnum filetype_from_extension(const StringView ext) | |
258 | { | ||
259 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 65 times.
|
145 | if (ext.length == 0 || ext.length >= sizeof(extensions[0].ext)) { |
260 | return NONE; | ||
261 | } | ||
262 | |||
263 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 53 times.
|
80 | if (ext.length == 1) { |
264 |
10/10✓ Branch 0 taken 15 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 2 times.
|
27 | switch (ext.data[0]) { |
265 | case '1': case '2': case '3': | ||
266 | case '4': case '5': case '6': | ||
267 | case '7': case '8': case '9': | ||
268 | return ROFF; | ||
269 | 15 | case 'c': case 'h': | |
270 | 15 | return C; | |
271 | 2 | case 'C': case 'H': | |
272 | 2 | return CPLUSPLUS; | |
273 | 2 | case 'S': case 's': | |
274 | 2 | return ASM; | |
275 | 1 | case 'd': return D; | |
276 | 1 | case 'l': return LEX; | |
277 | 1 | case 'm': return OBJC; | |
278 | 1 | case 'v': return VERILOG; | |
279 | 1 | case 'y': return YACC; | |
280 | } | ||
281 | 1 | return NONE; | |
282 | } | ||
283 | |||
284 | 53 | const struct FileExtensionMap *e = BSEARCH(&ext, extensions, ft_compare); | |
285 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 23 times.
|
53 | return e ? e->filetype : NONE; |
286 | } | ||
287 |