ctb_formats_detection/text.rs
1/*
2$File: COPYING,v 1.2 2018/09/09 20:33:28 christos Exp $
3Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
4Software written by Ian F. Darwin and others;
5maintained 1994- Christos Zoulas.
6
7This software is not subject to any export provision of the United States
8Department of Commerce, and may be exported to any country or planet.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions
12are met:
131. Redistributions of source code must retain the above copyright
14 notice immediately at the beginning of the file, without modification,
15 this list of conditions, and the following disclaimer.
162. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution.
19
20THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30SUCH DAMAGE.
31
32The preceding notice is from COPYING in `file`.
33
34
35
36/*
37 * Copyright (c) Ian F. Darwin 1986-1995.
38 * Software written by Ian F. Darwin and others;
39 * maintained 1995-present by Christos Zoulas and others.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice immediately at the beginning of the file, without modification,
46 * this list of conditions, and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
55 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 */
63
64The preceding notice is from src/apprentice.c, src/ascmagic.c, src/compress.c, src/encoding.c, src/file.c, src/file.h, src/fsmagic.c, src/missing/asprintf.c, src/missing/dprintf.c, src/print.c, src/softmagic.c, src/swap.c, and src/swap.h in `file`.
65
66
67
68/*
69 * Copyright (c) Christos Zoulas 2017.
70 * All Rights Reserved.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the above copyright
76 * notice immediately at the beginning of the file, without modification,
77 * this list of conditions, and the following disclaimer.
78 * 2. Redistributions in binary form must reproduce the above copyright
79 * notice, this list of conditions and the following disclaimer in the
80 * documentation and/or other materials provided with the distribution.
81 *
82 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
86 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * SUCH DAMAGE.
93 */
94
95The preceding notice is from src/buffer.c in `file`.
96
97
98
99/*
100 * Copyright (c) Christos Zoulas 2008.
101 * All Rights Reserved.
102 *
103 * Redistribution and use in source and binary forms, with or without
104 * modification, are permitted provided that the following conditions
105 * are met:
106 * 1. Redistributions of source code must retain the above copyright
107 * notice immediately at the beginning of the file, without modification,
108 * this list of conditions, and the following disclaimer.
109 * 2. Redistributions in binary form must reproduce the above copyright
110 * notice, this list of conditions and the following disclaimer in the
111 * documentation and/or other materials provided with the distribution.
112 *
113 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
114 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
115 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
116 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
117 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
119 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
120 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
121 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
122 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
123 * SUCH DAMAGE.
124 */
125
126The preceding notice is from src/elfclass.h in `file`.
127
128
129
130/*
131 * Copyright (c) Christos Zoulas 2003.
132 * All Rights Reserved.
133 *
134 * Redistribution and use in source and binary forms, with or without
135 * modification, are permitted provided that the following conditions
136 * are met:
137 * 1. Redistributions of source code must retain the above copyright
138 * notice immediately at the beginning of the file, without modification,
139 * this list of conditions, and the following disclaimer.
140 * 2. Redistributions in binary form must reproduce the above copyright
141 * notice, this list of conditions and the following disclaimer in the
142 * documentation and/or other materials provided with the distribution.
143 *
144 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
145 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
146 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
147 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
148 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
149 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
150 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
151 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
152 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
153 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
154 * SUCH DAMAGE.
155 */
156
157The preceding notice is from src/funcs.c, src/magic.c, src/magic.h.in, src/readelf.c, and src/readelf.h in `file`.
158
159
160
161/*
162 * Copyright (c) Ian F. Darwin 1986-1995.
163 * Software written by Ian F. Darwin and others;
164 * maintained 1995-present by Christos Zoulas and others.
165 *
166 * Redistribution and use in source and binary forms, with or without
167 * modification, are permitted provided that the following conditions
168 * are met:
169 * 1. Redistributions of source code must retain the above copyright
170 * notice immediately at the beginning of the file, without modification,
171 * this list of conditions, and the following disclaimer.
172 * 2. Redistributions in binary form must reproduce the above copyright
173 * notice, this list of conditions and the following disclaimer in the
174 * documentation and/or other materials provided with the distribution.
175 *
176 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
178 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
180 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
182 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
183 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
184 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
185 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
186 * SUCH DAMAGE.
187 */
188
189/*
190 * is_tar() -- figure out whether file is a tar archive.
191 *
192 * Stolen (by the author!) from the file_public domain tar program:
193 * Public Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
194 *
195 * @(#)list.c 1.18 9/23/86 Public Domain - gnu
196 *
197 * Comments changed and some code/comments reformatted
198 * for file command by Ian Darwin.
199 */
200
201The preceding notice is from src/is_tar.c in `file`.
202
203
204
205/*
206 * Redistribution and use in source and binary forms, with or without
207 * modification, are permitted provided that the following conditions
208 * are met:
209 * 1. Redistributions of source code must retain the above copyright
210 * notice immediately at the beginning of the file, without modification,
211 * this list of conditions, and the following disclaimer.
212 * 2. Redistributions in binary form must reproduce the above copyright
213 * notice, this list of conditions and the following disclaimer in the
214 * documentation and/or other materials provided with the distribution.
215 *
216 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
217 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
220 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
223 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
225 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
226 * SUCH DAMAGE.
227 */
228
229The preceding notice is from src/landlock.c and src/seccomp.c in `file`.
230
231
232
233/*
234 * Copyright (c) Christos Zoulas 2021.
235 * All Rights Reserved.
236 *
237 * Redistribution and use in source and binary forms, with or without
238 * modification, are permitted provided that the following conditions
239 * are met:
240 * 1. Redistributions of source code must retain the above copyright
241 * notice immediately at the beginning of the file, without modification,
242 * this list of conditions, and the following disclaimer.
243 * 2. Redistributions in binary form must reproduce the above copyright
244 * notice, this list of conditions and the following disclaimer in the
245 * documentation and/or other materials provided with the distribution.
246 *
247 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
248 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
249 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
250 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
251 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
255 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257 * SUCH DAMAGE.
258 */
259
260The preceding notice is from src/memtest.c in `file`.
261
262
263
264/*
265 * Copyright (c) Ian F. Darwin 1986-1995.
266 * Software written by Ian F. Darwin and others;
267 * maintained 1995-present by Christos Zoulas and others.
268 *
269 * Redistribution and use in source and binary forms, with or without
270 * modification, are permitted provided that the following conditions
271 * are met:
272 * 1. Redistributions of source code must retain the above copyright
273 * notice immediately at the beginning of the file, without modification,
274 * this list of conditions, and the following disclaimer.
275 * 2. Redistributions in binary form must reproduce the above copyright
276 * notice, this list of conditions and the following disclaimer in the
277 * documentation and/or other materials provided with the distribution.
278 *
279 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
280 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
282 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
283 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
284 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
285 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
287 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289 * SUCH DAMAGE.
290 */
291
292/*###########################################################################
293 # #
294 # vasprintf #
295 # #
296 # Copyright (c) 2002-2005 David TAILLANDIER #
297 # #
298 ###########################################################################*/
299
300/*
301
302This software is distributed under the "modified BSD licence".
303
304This software is also released with GNU license (GPL) in another file (same
305source-code, only license differ).
306
307
308
309Redistribution and use in source and binary forms, with or without
310modification, are permitted provided that the following conditions are met:
311
312Redistributions of source code must retain the above copyright notice, this
313list of conditions and the following disclaimer. Redistributions in binary
314form must reproduce the above copyright notice, this list of conditions and
315the following disclaimer in the documentation and/or other materials
316provided with the distribution. The name of the author may not be used to
317endorse or promote products derived from this software without specific
318prior written permission.
319
320THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
321WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
322MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
323EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
324SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
325PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
326OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
327WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
328OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
329ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330
331====================
332
333Hacked from xnprintf version of 26th February 2005 to provide only
334vasprintf by Reuben Thomas <rrt@sc3d.org>.
335
336====================
337
338
339'printf' function family use the following format string:
340
341%[flag][width][.prec][modifier]type
342
343%% is the escape sequence to print a '%'
344% followed by an unknown format will print the characters without
345trying to do any interpretation
346
347flag: none + - # (blank)
348width: n 0n *
349prec: none .0 .n .*
350modifier: F N L h l ll z t ('F' and 'N' are ms-dos/16-bit specific)
351type: d i o u x X f e g E G c s p n
352
353
354The function needs to allocate memory to store the full text before to
355actually writing it. i.e if you want to fnprintf() 1000 characters, the
356functions will allocate 1000 bytes.
357This behaviour can be modified: you have to customise the code to flush the
358internal buffer (writing to screen or file) when it reach a given size. Then
359the buffer can have a shorter length. But what? If you really need to write
360HUGE string, don't use printf!
361During the process, some other memory is allocated (1024 bytes minimum)
362to handle the output of partial sprintf() calls. If you have only 10000 bytes
363free in memory, you *may* not be able to nprintf() an 8000 bytes-long text.
364
365note: if a buffer overflow occurs, exit() is called. This situation should
366never appear ... but if you want to be *really* sure, you have to modify the
367code to handle those situations (only one place to modify).
368A buffer overflow can only occur if your sprintf() do strange things or when
369you use strange formats.
370
371*/
372
373The preceding notice is from src/missing/vasprintf.c in `file`.
374
375
376
377/*
378 * Copyright (c) Ian F. Darwin 1986-1995.
379 * Software written by Ian F. Darwin and others;
380 * maintained 1995-present by Christos Zoulas and others.
381 *
382 * Redistribution and use in source and binary forms, with or without
383 * modification, are permitted provided that the following conditions
384 * are met:
385 * 1. Redistributions of source code must retain the above copyright
386 * notice immediately at the beginning of the file, without modification,
387 * this list of conditions, and the following disclaimer.
388 * 2. Redistributions in binary form must reproduce the above copyright
389 * notice, this list of conditions and the following disclaimer in the
390 * documentation and/or other materials provided with the distribution.
391 *
392 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
393 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
394 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
395 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
396 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
397 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
398 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
399 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
400 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
401 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
402 * SUCH DAMAGE.
403 */
404
405/*
406 * Header file for file_public domain tar (tape archive) program.
407 *
408 * @(#)tar.h 1.20 86/10/29 Public Domain.
409 *
410 * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
411 *
412 * $File: tar.h,v 1.16 2022/12/26 17:31:14 christos Exp $ # checkin only
413 */
414
415The preceding notice is from src/tar.h in `file`.
416*/
417
418// SPDX-License-Identifier: AGPL-3.0-or-later AND BSD-2-Clause-Darwin AND Apache-2.0 AND MIT AND BSD-3-Clause
419// SPDX-License-Identifier for parts derived from `file` (libmagic): BSD-2-Clause-Darwin AND BSD-3-Clause
420// SPDX-License-Identifier for parts derived from polyfile: Apache-2.0
421// SPDX-License-Identifier for parts derived from fileid and binwalk: MIT
422// SPDX-License-Identifier for parts derived from DROID: BSD-3-Clause
423/*
424This file is part of Collective Toolbox, a database and document workspace and utilities.
425Copyright (C) 2026 Collective Toolbox Developers
426Contact: info@collectivetoolbox.com
427
428This program is free software: you can redistribute it and/or modify it under
429the terms of the GNU Affero General Public License as published by the Free
430Software Foundation, either version 3 of the License, or (at your option) any
431later version.
432
433This program is distributed in the hope that it will be useful, but WITHOUT ANY
434WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
435A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
436
437You should have received a copy of the GNU Affero General Public License along
438with this program. If not, see <https://www.gnu.org/licenses/>.
439*/
440
441// The Collective Toolbox file detection tools, of which this file is a part, combine elements from several other similar tools: `file`, polyfile, binwalk, fileid, and DROID.
442// See license texts at the beginning and end of this file for full license details for parts derived from `file` <https://www.darwinsys.com/file/>.
443// See the full license details for parts derived from polyfile <https://github.com/trailofbits/polyfile>, binwalk <https://github.com/ReFirmLabs/binwalk>, fileid <https://github.com/DBHeise/fileid>, and DROID <https://github.com/digital-preservation/droid> at the end of this file.
444
445//! Text and character encoding detection subsystem ported from `file`
446//! (`ascmagic.c`, `encoding.c`) and `PolyFile`.
447//!
448//! Provides comprehensive character set identification (UTF-8, UTF-16, UTF-32,
449//! ASCII, ISO-8859, non-ISO extended ASCII, EBCDIC), line ending and layout
450//! profiling, and text language and syntax heuristics (shebang, programming
451//! languages, markup, mail headers).
452
453#[allow(
454 unused_imports,
455 clippy::wildcard_imports,
456 reason = "Standard workspace module prelude"
457)]
458use crate::utilities::*;
459
460use crate::detection::source::DetectionSource;
461use crate::detection::types::{
462 ConfidenceTier, DetectionCandidate, DetectionEvidence, DetectionHint,
463};
464use crate::encoding::{CharEncoding, LineEndingKind};
465use crate::format_id::{FormatCategory, FormatId};
466
467/// Longest line length considered sane before flagging long lines.
468/// Ported from `MAXLINELEN` in `ascmagic.c`.
469pub const MAX_LINE_LENGTH: usize = 300;
470
471/// Maximum number of bytes inspected for text encoding detection.
472/// Ported from `FILE_ENCODING_MAX` in `file.h`.
473pub const TEXT_ENCODING_MAX_BYTES: usize = 64 * 1024;
474
475// Character class codes ported from `encoding.c`.
476// F: Character never appears in text.
477const CHAR_F: u8 = 0;
478// T: Character appears in plain 7-bit ASCII text.
479const CHAR_T: u8 = 1;
480// I: Character appears in ISO-8859 text (0xA0..=0xFF).
481const CHAR_I: u8 = 2;
482// X: Character appears in non-ISO extended ASCII (CP437, MacRoman, Win-1252).
483const CHAR_X: u8 = 3;
484
485/// Character class table ported from `text_chars` in `encoding.c`.
486/// Maps each 8-bit byte value to its text membership class.
487pub static TEXT_CHARS: [u8; 256] = [
488 // 0x00-0x0F: BEL(7), BS(8), HT(9), LF(10), VT(11), FF(12), CR(13)
489 CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_T, CHAR_T,
490 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_F, CHAR_F,
491 // 0x10-0x1F: SUB(26), ESC(27)
492 CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F, CHAR_F,
493 CHAR_F, CHAR_T, CHAR_T, CHAR_F, CHAR_F, CHAR_F, CHAR_F,
494 // 0x20-0x2F: Printable ASCII
495 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
496 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
497 // 0x30-0x3F: Printable ASCII
498 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
499 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
500 // 0x40-0x4F: Printable ASCII
501 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
502 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
503 // 0x50-0x5F: Printable ASCII
504 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
505 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
506 // 0x60-0x6F: Printable ASCII
507 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
508 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
509 // 0x70-0x7F: Printable ASCII, DEL(0x7F) is CHAR_F
510 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T,
511 CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_T, CHAR_F,
512 // 0x80-0x8F: NEL(0x85) is CHAR_T
513 CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_T, CHAR_X, CHAR_X, CHAR_X,
514 CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X,
515 // 0x90-0x9F
516 CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X,
517 CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X, CHAR_X,
518 // 0xA0-0xAF: ISO-8859 printable characters
519 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
520 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
521 // 0xB0-0xBF
522 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
523 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
524 // 0xC0-0xCF
525 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
526 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
527 // 0xD0-0xDF
528 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
529 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
530 // 0xE0-0xEF
531 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
532 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
533 // 0xF0-0xFF
534 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
535 CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I, CHAR_I,
536];
537
538/// EBCDIC-to-ASCII mapping table ported from `ebcdic_to_ascii` in `encoding.c`.
539/// Based on POSIX P1003.2 draft 11.2 `dd(1)` rationale.
540pub static EBCDIC_TO_ASCII: [u8; 256] = [
541 0, 1, 2, 3, 156, 9, 134, 127, 151, 141, 142, 11, 12, 13, 14, 15, 16, 17,
542 18, 19, 157, 133, 8, 135, 24, 25, 146, 143, 28, 29, 30, 31, 128, 129, 130,
543 131, 132, 10, 23, 27, 136, 137, 138, 139, 140, 5, 6, 7, 144, 145, 22, 147,
544 148, 149, 150, 4, 152, 153, 154, 155, 20, 21, 158, 26, b' ', 160, 161, 162,
545 163, 164, 165, 166, 167, 168, 213, b'.', b'<', b'(', b'+', b'|', b'&', 169,
546 170, 171, 172, 173, 174, 175, 176, 177, b'!', b'$', b'*', b')', b';', b'~',
547 b'-', b'/', 178, 179, 180, 181, 182, 183, 184, 185, 203, b',', b'%', b'_',
548 b'>', b'?', 186, 187, 188, 189, 190, 191, 192, 193, 194, b'`', b':', b'#',
549 b'@', b'\'', b'=', b'"', 195, b'a', b'b', b'c', b'd', b'e', b'f', b'g',
550 b'h', b'i', 196, 197, 198, 199, 200, 201, 202, b'j', b'k', b'l', b'm',
551 b'n', b'o', b'p', b'q', b'r', b'^', 204, 205, 206, 207, 208, 209, 229,
552 b's', b't', b'u', b'v', b'w', b'x', b'y', b'z', 210, 211, 212, b'[', 214,
553 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, b']',
554 230, 231, b'{', b'A', b'B', b'C', b'D', b'E', b'F', b'G', b'H', b'I', 232,
555 233, 234, 235, 236, 237, b'}', b'J', b'K', b'L', b'M', b'N', b'O', b'P',
556 b'Q', b'R', 238, 239, 240, 241, 242, 243, b'\\', 159, b'S', b'T', b'U',
557 b'V', b'W', b'X', b'Y', b'Z', 244, 245, 246, 247, 248, 249, b'0', b'1',
558 b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', 250, 251, 252, 253, 254,
559 255,
560];
561
562/// Identified character set encoding family.
563#[derive(Debug, Clone, Copy, PartialEq, Eq)]
564pub enum IdentifiedEncoding {
565 Ascii,
566 Utf8 { with_bom: bool },
567 Utf16Le { with_bom: bool },
568 Utf16Be { with_bom: bool },
569 Utf32Le { with_bom: bool },
570 Utf32Be { with_bom: bool },
571 Iso8859_1,
572 ExtendedAscii(CharEncoding),
573 Ebcdic,
574 InternationalEbcdic,
575}
576
577impl IdentifiedEncoding {
578 /// Human-readable label matching libmagic's conventions.
579 #[must_use]
580 pub fn description_label(&self) -> &'static str {
581 match self {
582 Self::Ascii => "ASCII",
583 Self::Utf8 { with_bom: false } => "Unicode text, UTF-8",
584 Self::Utf8 { with_bom: true } => "Unicode text, UTF-8 (with BOM)",
585 Self::Utf16Le { .. } => "Unicode text, UTF-16, little-endian",
586 Self::Utf16Be { .. } => "Unicode text, UTF-16, big-endian",
587 Self::Utf32Le { .. } => "Unicode text, UTF-32, little-endian",
588 Self::Utf32Be { .. } => "Unicode text, UTF-32, big-endian",
589 Self::Iso8859_1 => "ISO-8859",
590 Self::ExtendedAscii(enc) => match enc {
591 CharEncoding::MacRoman => "Macintosh",
592 CharEncoding::Windows1252 => "Non-ISO extended-ASCII",
593 CharEncoding::Cp437 { .. } => "IBM PC",
594 _ => "Non-ISO extended-ASCII",
595 },
596 Self::Ebcdic => "EBCDIC",
597 Self::InternationalEbcdic => "International EBCDIC",
598 }
599 }
600
601 /// Corresponding MIME charset attribute string.
602 #[must_use]
603 pub fn mime_charset(&self) -> &'static str {
604 match self {
605 Self::Ascii => "us-ascii",
606 Self::Utf8 { .. } => "utf-8",
607 Self::Utf16Le { .. } => "utf-16le",
608 Self::Utf16Be { .. } => "utf-16be",
609 Self::Utf32Le { .. } => "utf-32le",
610 Self::Utf32Be { .. } => "utf-32be",
611 Self::Iso8859_1 => "iso-8859-1",
612 Self::ExtendedAscii(enc) => match enc {
613 CharEncoding::Windows1252 => "windows-1252",
614 CharEncoding::MacRoman => "macintosh",
615 CharEncoding::Cp437 { .. } => "cp437",
616 _ => "unknown-8bit",
617 },
618 Self::Ebcdic | Self::InternationalEbcdic => "ebcdic",
619 }
620 }
621
622 /// Corresponding `FormatId` if an exact mapping exists in the format catalog.
623 #[must_use]
624 pub fn format_id(&self) -> Option<FormatId> {
625 match self {
626 Self::Ascii => Some(FormatId::Ascii),
627 Self::Utf8 { .. } => Some(FormatId::Utf8),
628 Self::Iso8859_1 => Some(FormatId::Iso88591),
629 Self::ExtendedAscii(enc) => Some(enc.to_format_id()),
630 _ => Some(FormatId::Text),
631 }
632 }
633}
634
635/// Syntax or programming language classification deduced from text content.
636#[derive(Debug, Clone, PartialEq, Eq)]
637pub enum TextSyntaxKind {
638 ShebangScript {
639 interpreter: String,
640 format_id: Option<FormatId>,
641 mime: String,
642 label: String,
643 },
644 CSource,
645 CppSource,
646 PythonScript,
647 ShellScript,
648 PerlScript,
649 RubySource,
650 LispSource,
651 AssemblerSource,
652 HtmlDocument,
653 XmlDocument,
654 SgmlDocument,
655 RoffDocument,
656 TeXDocument,
657 MailOrNewsHeader,
658}
659
660impl TextSyntaxKind {
661 /// Suggested `FormatId` for this text syntax kind.
662 #[must_use]
663 pub fn format_id(&self) -> Option<FormatId> {
664 match self {
665 Self::ShebangScript { format_id, .. } => *format_id,
666 Self::CSource => Some(FormatId::C),
667 Self::CppSource => Some(FormatId::Cpp),
668 Self::PythonScript => None,
669 Self::ShellScript => Some(FormatId::Sh),
670 Self::PerlScript => Some(FormatId::Perl),
671 Self::RubySource => None,
672 Self::LispSource => None,
673 Self::AssemblerSource => None,
674 Self::HtmlDocument => Some(FormatId::Html),
675 Self::XmlDocument => Some(FormatId::Xml),
676 Self::SgmlDocument => None,
677 Self::RoffDocument => None,
678 Self::TeXDocument => None,
679 Self::MailOrNewsHeader => None,
680 }
681 }
682
683 /// Primary MIME type for this syntax kind.
684 #[must_use]
685 pub fn mime_type(&self) -> &str {
686 match self {
687 Self::ShebangScript { mime, .. } => mime.as_str(),
688 Self::CSource => "text/x-c",
689 Self::CppSource => "text/x-c++",
690 Self::PythonScript => "text/x-python",
691 Self::ShellScript => "text/x-shellscript",
692 Self::PerlScript => "text/x-perl",
693 Self::RubySource => "text/x-ruby",
694 Self::LispSource => "text/x-lisp",
695 Self::AssemblerSource => "text/x-asm",
696 Self::HtmlDocument => "text/html",
697 Self::XmlDocument => "application/xml",
698 Self::SgmlDocument => "text/sgml",
699 Self::RoffDocument => "text/troff",
700 Self::TeXDocument => "text/x-tex",
701 Self::MailOrNewsHeader => "message/rfc822",
702 }
703 }
704
705 /// Descriptive prefix for `file` parity description generation.
706 #[must_use]
707 pub fn description_prefix(&self) -> &str {
708 match self {
709 Self::ShebangScript { label, .. } => label.as_str(),
710 Self::CSource => "C source",
711 Self::CppSource => "C++ source",
712 Self::PythonScript => "Python script",
713 Self::ShellScript => "POSIX shell script",
714 Self::PerlScript => "Perl script",
715 Self::RubySource => "Ruby source",
716 Self::LispSource => "Lisp source",
717 Self::AssemblerSource => "Assembler source",
718 Self::HtmlDocument => "HTML document",
719 Self::XmlDocument => "XML 1.0 document",
720 Self::SgmlDocument => "SGML document",
721 Self::RoffDocument => "troff or preprocessor input text",
722 Self::TeXDocument => "LaTeX 2e document",
723 Self::MailOrNewsHeader => "mail or news text",
724 }
725 }
726
727 /// Returns true if this syntax represents an executable script.
728 #[must_use]
729 pub fn is_executable(&self) -> bool {
730 matches!(
731 self,
732 Self::ShebangScript { .. }
733 | Self::PythonScript
734 | Self::ShellScript
735 | Self::PerlScript
736 )
737 }
738}
739
740/// Comprehensive profile of detected text properties and layout conventions.
741#[derive(Debug, Clone, PartialEq, Eq)]
742pub struct TextProfile {
743 pub encoding: IdentifiedEncoding,
744 pub primary_line_ending: Option<LineEndingKind>,
745 pub n_lf: usize,
746 pub n_crlf: usize,
747 pub n_cr: usize,
748 pub n_nel: usize,
749 pub has_long_lines: bool,
750 pub max_line_length: usize,
751 pub has_escapes: bool,
752 pub has_backspace: bool,
753 pub syntax: Option<TextSyntaxKind>,
754}
755
756/// Trims trailing NUL bytes while preserving parity for UTF-16 character boundaries.
757/// Ported from `trim_nuls` in `ascmagic.c`.
758#[must_use]
759pub fn trim_nuls(buf: &[u8]) -> &[u8] {
760 let mut len = buf.len();
761 while len > 1 && buf.get(len.saturating_sub(1)) == Some(&0) {
762 len = len.saturating_sub(1);
763 }
764 // Avoid trimming at an odd byte if original buffer was evenly sized;
765 // this avoids losing the last character on UTF-16 LE text.
766 let rem = len.checked_rem(2);
767 let buf_rem = buf.len().checked_rem(2);
768 if rem == Some(1) && buf_rem == Some(0) && len < buf.len() {
769 len = len.saturating_add(1);
770 }
771 // Reason for fallback: slice indexing within validated bounds never fails
772 buf.get(..len).unwrap_or(buf)
773}
774
775/// Checks whether `buf` consists solely of valid 7-bit ASCII text characters.
776#[must_use]
777pub fn looks_ascii(buf: &[u8]) -> bool {
778 if buf.is_empty() {
779 return false;
780 }
781 buf.iter().all(|&b| {
782 // Reason for fallback: index within 0..=255 bounds is always valid
783 let cls = TEXT_CHARS.get(usize::from(b)).copied().unwrap_or(CHAR_F);
784 cls == CHAR_T
785 })
786}
787
788/// Evaluates whether `buf` is valid UTF-8 text.
789#[must_use]
790pub fn looks_utf8(buf: &[u8]) -> Option<(IdentifiedEncoding, bool)> {
791 if buf.len() < 2 {
792 return None;
793 }
794 let (with_bom, content) =
795 if let Some(rest) = buf.strip_prefix(b"\xEF\xBB\xBF") {
796 (true, rest)
797 } else {
798 (false, buf)
799 };
800
801 if content.is_empty() {
802 if with_bom {
803 return Some((IdentifiedEncoding::Utf8 { with_bom: true }, true));
804 }
805 return None;
806 }
807
808 // Try decoding up to the largest valid UTF-8 prefix in case of cut-off
809 let mut valid_end = content.len();
810 let mut s_res = std::str::from_utf8(content);
811 if let Err(err) = s_res {
812 let valid_up_to = err.valid_up_to();
813 if valid_up_to > 0 && err.error_len().is_none() {
814 // Cut-off at end of buffer
815 valid_end = valid_up_to;
816 if let Some(prefix) = content.get(..valid_end) {
817 s_res = std::str::from_utf8(prefix);
818 } else {
819 return None;
820 }
821 } else {
822 return None;
823 }
824 }
825
826 let Ok(s) = s_res else {
827 return None;
828 };
829
830 let mut has_multibyte = false;
831 for ch in s.chars() {
832 let codepoint = u32::from(ch);
833 if codepoint < 128 {
834 let Ok(b) = u8::try_from(codepoint) else {
835 return None;
836 };
837 // Reason for fallback: index within 0..=255 bounds is always valid
838 let cls = TEXT_CHARS.get(usize::from(b)).copied().unwrap_or(CHAR_F);
839 if cls != CHAR_T {
840 return None;
841 }
842 } else {
843 has_multibyte = true;
844 }
845 }
846
847 if with_bom {
848 Some((IdentifiedEncoding::Utf8 { with_bom: true }, has_multibyte))
849 } else if has_multibyte {
850 Some((IdentifiedEncoding::Utf8 { with_bom: false }, true))
851 } else {
852 Some((IdentifiedEncoding::Ascii, false))
853 }
854}
855
856/// Evaluates whether `buf` is UTF-16 text (with or without BOM, LE or BE).
857#[must_use]
858pub fn looks_utf16(buf: &[u8]) -> Option<IdentifiedEncoding> {
859 if buf.len() < 2 {
860 return None;
861 }
862
863 // Check BOM
864 if buf.len() >= 2 {
865 let first = buf.first().copied();
866 let second = buf.get(1).copied();
867 if first == Some(0xFF) && second == Some(0xFE) {
868 // Ensure not UTF-32LE BOM (FF FE 00 00)
869 let third = buf.get(2).copied();
870 let fourth = buf.get(3).copied();
871 if third != Some(0x00) || fourth != Some(0x00) {
872 // Reason for fallback: slice beyond 2-byte BOM defaults to empty slice if buffer is truncated
873 let payload = buf.get(2..).unwrap_or(&[]);
874 if validate_utf16_content(payload, false) {
875 return Some(IdentifiedEncoding::Utf16Le {
876 with_bom: true,
877 });
878 }
879 }
880 } else if first == Some(0xFE) && second == Some(0xFF) {
881 // Reason for fallback: slice beyond 2-byte BOM defaults to empty slice if buffer is truncated
882 let payload = buf.get(2..).unwrap_or(&[]);
883 if validate_utf16_content(payload, true) {
884 return Some(IdentifiedEncoding::Utf16Be { with_bom: true });
885 }
886 }
887 }
888
889 // Without BOM: check whether it looks like UTF-16
890 if buf.len() >= 4 {
891 let inspect_len = buf.len().saturating_sub(buf.len() & 1);
892 // Reason for fallback: slice calculation beyond buffer bounds falls back to full buffer
893 let slice = buf.get(..inspect_len).unwrap_or(buf);
894
895 // Check if even or odd bytes are predominantly 0x00 for ASCII ranges
896 let mut even_zeros = 0usize;
897 let mut odd_zeros = 0usize;
898 let chunks = slice.chunks_exact(2);
899 let pairs = chunks.len();
900 if pairs >= 2 {
901 for chunk in chunks {
902 if let &[b0, b1] = chunk {
903 if b0 == 0 {
904 even_zeros = even_zeros.saturating_add(1);
905 }
906 if b1 == 0 {
907 odd_zeros = odd_zeros.saturating_add(1);
908 }
909 }
910 }
911
912 // UTF-16 LE: odd bytes are mostly 0 for ASCII text
913 // Reason for fallback: division by non-zero pairs cannot fail on unsigned integers
914 let odd_ratio = odd_zeros
915 .saturating_mul(100)
916 .checked_div(pairs)
917 .unwrap_or(0);
918 if odd_ratio >= 40 && validate_utf16_content(slice, false) {
919 return Some(IdentifiedEncoding::Utf16Le { with_bom: false });
920 }
921
922 // UTF-16 BE: even bytes are mostly 0 for ASCII text
923 // Reason for fallback: division by non-zero pairs cannot fail on unsigned integers
924 let even_ratio = even_zeros
925 .saturating_mul(100)
926 .checked_div(pairs)
927 .unwrap_or(0);
928 if even_ratio >= 40 && validate_utf16_content(slice, true) {
929 return Some(IdentifiedEncoding::Utf16Be { with_bom: false });
930 }
931 }
932 }
933
934 None
935}
936
937/// Helper validating UTF-16 code units, surrogates, and text characters.
938fn validate_utf16_content(buf: &[u8], big_endian: bool) -> bool {
939 let chunks = buf.chunks_exact(2);
940 if chunks.len() == 0 {
941 return true;
942 }
943
944 let mut hi_surrogate: Option<u32> = None;
945 let mut valid_chars = 0usize;
946
947 for chunk in chunks {
948 let &[b0, b1] = chunk else { continue };
949
950 let uc = if big_endian {
951 u32::from(b1) | (u32::from(b0) << 8)
952 } else {
953 u32::from(b0) | (u32::from(b1) << 8)
954 };
955
956 // Reject non-characters
957 if uc == 0xFFFE || uc == 0xFFFF || (0xFDD0..=0xFDEF).contains(&uc) {
958 return false;
959 }
960
961 if let Some(_hi) = hi_surrogate {
962 // Must be low surrogate
963 if !(0xDC00..=0xDFFF).contains(&uc) {
964 return false;
965 }
966 hi_surrogate = None;
967 valid_chars = valid_chars.saturating_add(1);
968 continue;
969 }
970
971 if (0xD800..=0xDBFF).contains(&uc) {
972 hi_surrogate = Some(uc);
973 continue;
974 } else if (0xDC00..=0xDFFF).contains(&uc) {
975 // Low surrogate without high surrogate
976 return false;
977 }
978
979 if uc < 128 {
980 let Ok(byte_val) = u8::try_from(uc) else {
981 return false;
982 };
983 // Reason for fallback: index within 0..=255 bounds is always valid
984 let cls = TEXT_CHARS
985 .get(usize::from(byte_val))
986 .copied()
987 .unwrap_or(CHAR_F);
988 if cls != CHAR_T && byte_val != 0 {
989 return false;
990 }
991 }
992
993 valid_chars = valid_chars.saturating_add(1);
994 }
995
996 hi_surrogate.is_none() && valid_chars > 0
997}
998
999/// Evaluates whether `buf` is UTF-32 text (with or without BOM, LE or BE).
1000#[must_use]
1001pub fn looks_utf32(buf: &[u8]) -> Option<IdentifiedEncoding> {
1002 if buf.len() < 4 {
1003 return None;
1004 }
1005
1006 // Check BOM
1007 if buf.len() >= 4 {
1008 let b0 = buf.first().copied();
1009 let b1 = buf.get(1).copied();
1010 let b2 = buf.get(2).copied();
1011 let b3 = buf.get(3).copied();
1012
1013 if b0 == Some(0xFF)
1014 && b1 == Some(0xFE)
1015 && b2 == Some(0x00)
1016 && b3 == Some(0x00)
1017 {
1018 // Reason for fallback: slice beyond 4-byte BOM defaults to empty slice if buffer is truncated
1019 let payload = buf.get(4..).unwrap_or(&[]);
1020 if validate_utf32_content(payload, false) {
1021 return Some(IdentifiedEncoding::Utf32Le { with_bom: true });
1022 }
1023 } else if b0 == Some(0x00)
1024 && b1 == Some(0x00)
1025 && b2 == Some(0xFE)
1026 && b3 == Some(0xFF)
1027 {
1028 // Reason for fallback: slice beyond 4-byte BOM defaults to empty slice if buffer is truncated
1029 let payload = buf.get(4..).unwrap_or(&[]);
1030 if validate_utf32_content(payload, true) {
1031 return Some(IdentifiedEncoding::Utf32Be { with_bom: true });
1032 }
1033 }
1034 }
1035
1036 // Without BOM
1037 if buf.len() >= 8 {
1038 let inspect_len = buf.len().saturating_sub(buf.len() & 3);
1039 // Reason for fallback: slice calculation beyond buffer bounds falls back to full buffer
1040 let slice = buf.get(..inspect_len).unwrap_or(buf);
1041 let chunks = slice.chunks_exact(4);
1042 let quads = chunks.len();
1043
1044 if quads >= 2 {
1045 let mut le_matches = 0usize;
1046 let mut be_matches = 0usize;
1047
1048 for chunk in chunks {
1049 if let &[b0, b1, b2, b3] = chunk {
1050 if b1 == 0 && b2 == 0 && b3 == 0 && b0 > 0 && b0 < 128 {
1051 le_matches = le_matches.saturating_add(1);
1052 }
1053 if b0 == 0 && b1 == 0 && b2 == 0 && b3 > 0 && b3 < 128 {
1054 be_matches = be_matches.saturating_add(1);
1055 }
1056 }
1057 }
1058
1059 // Reason for fallback: division by non-zero quads cannot fail on unsigned integers
1060 let le_ratio = le_matches
1061 .saturating_mul(100)
1062 .checked_div(quads)
1063 .unwrap_or(0);
1064 if le_ratio >= 40 && validate_utf32_content(slice, false) {
1065 return Some(IdentifiedEncoding::Utf32Le { with_bom: false });
1066 }
1067
1068 // Reason for fallback: division by non-zero quads cannot fail on unsigned integers
1069 let be_ratio = be_matches
1070 .saturating_mul(100)
1071 .checked_div(quads)
1072 .unwrap_or(0);
1073 if be_ratio >= 40 && validate_utf32_content(slice, true) {
1074 return Some(IdentifiedEncoding::Utf32Be { with_bom: false });
1075 }
1076 }
1077 }
1078
1079 None
1080}
1081
1082/// Helper validating UTF-32 code units.
1083fn validate_utf32_content(buf: &[u8], big_endian: bool) -> bool {
1084 let chunks = buf.chunks_exact(4);
1085 if chunks.len() == 0 {
1086 return true;
1087 }
1088
1089 for chunk in chunks {
1090 let &[b0, b1, b2, b3] = chunk else { continue };
1091
1092 let uc = if big_endian {
1093 u32::from(b3)
1094 | (u32::from(b2) << 8)
1095 | (u32::from(b1) << 16)
1096 | (u32::from(b0) << 24)
1097 } else {
1098 u32::from(b0)
1099 | (u32::from(b1) << 8)
1100 | (u32::from(b2) << 16)
1101 | (u32::from(b3) << 24)
1102 };
1103
1104 if uc > 0x0010_FFFF
1105 || (0xD800..=0xDFFF).contains(&uc)
1106 || uc == 0xFFFE
1107 || uc == 0xFFFF
1108 {
1109 return false;
1110 }
1111
1112 if uc < 128 {
1113 let Ok(byte_val) = u8::try_from(uc) else {
1114 return false;
1115 };
1116 // Reason for fallback: index within 0..=255 bounds is always valid
1117 let cls = TEXT_CHARS
1118 .get(usize::from(byte_val))
1119 .copied()
1120 .unwrap_or(CHAR_F);
1121 if cls != CHAR_T && byte_val != 0 {
1122 return false;
1123 }
1124 }
1125 }
1126
1127 true
1128}
1129
1130/// Evaluates whether `buf` is ISO-8859 text (characters in ASCII text or 0xA0..=0xFF).
1131#[must_use]
1132pub fn looks_iso8859(buf: &[u8]) -> Option<IdentifiedEncoding> {
1133 if buf.is_empty() {
1134 return None;
1135 }
1136 let mut has_high = false;
1137 for &b in buf {
1138 // Reason for fallback: index within 0..=255 bounds is always valid
1139 let cls = TEXT_CHARS.get(usize::from(b)).copied().unwrap_or(CHAR_F);
1140 if cls == CHAR_I {
1141 has_high = true;
1142 } else if cls != CHAR_T {
1143 return None;
1144 }
1145 }
1146 if has_high {
1147 Some(IdentifiedEncoding::Iso8859_1)
1148 } else {
1149 Some(IdentifiedEncoding::Ascii)
1150 }
1151}
1152
1153/// Evaluates whether `buf` is non-ISO 8-bit extended ASCII (CP437, `MacRoman`, Windows-1252).
1154#[must_use]
1155pub fn looks_extended_ascii(buf: &[u8]) -> Option<IdentifiedEncoding> {
1156 if buf.is_empty() {
1157 return None;
1158 }
1159 let mut has_extended = false;
1160 for &b in buf {
1161 // Reason for fallback: index within 0..=255 bounds is always valid
1162 let cls = TEXT_CHARS.get(usize::from(b)).copied().unwrap_or(CHAR_F);
1163 if cls == CHAR_X {
1164 has_extended = true;
1165 } else if cls != CHAR_T && cls != CHAR_I {
1166 return None;
1167 }
1168 }
1169
1170 if has_extended {
1171 // Evaluate likelihood of Windows-1252 vs MacRoman vs CP437
1172 // Windows-1252 has unused bytes at 0x81, 0x8D, 0x8F, 0x90, 0x9D
1173 let has_win_unused = buf
1174 .iter()
1175 .any(|&b| matches!(b, 0x81 | 0x8D | 0x8F | 0x90 | 0x9D));
1176 if has_win_unused {
1177 Some(IdentifiedEncoding::ExtendedAscii(CharEncoding::cp437()))
1178 } else {
1179 Some(IdentifiedEncoding::ExtendedAscii(
1180 CharEncoding::windows_1252(),
1181 ))
1182 }
1183 } else {
1184 None
1185 }
1186}
1187
1188/// Evaluates whether `buf` is EBCDIC text using the POSIX dd translation table.
1189#[must_use]
1190pub fn looks_ebcdic(buf: &[u8]) -> Option<IdentifiedEncoding> {
1191 if buf.len() < 2 {
1192 return None;
1193 }
1194
1195 let mut is_ascii = true;
1196 let mut is_international = true;
1197
1198 for &b in buf {
1199 // Reason for fallback: index within 0..=255 bounds is always valid
1200 let translated =
1201 EBCDIC_TO_ASCII.get(usize::from(b)).copied().unwrap_or(0);
1202 // Reason for fallback: out-of-bounds byte class defaults to non-text CHAR_F
1203 let cls = TEXT_CHARS
1204 .get(usize::from(translated))
1205 .copied()
1206 .unwrap_or(CHAR_F);
1207 if cls != CHAR_T {
1208 is_ascii = false;
1209 if cls != CHAR_I {
1210 is_international = false;
1211 break;
1212 }
1213 }
1214 }
1215
1216 if is_ascii {
1217 Some(IdentifiedEncoding::Ebcdic)
1218 } else if is_international {
1219 Some(IdentifiedEncoding::InternationalEbcdic)
1220 } else {
1221 None
1222 }
1223}
1224
1225/// Identifies the character set encoding family of `data`.
1226/// Ported from `file_encoding` in `encoding.c`.
1227#[must_use]
1228pub fn detect_text_encoding(data: &[u8]) -> Option<IdentifiedEncoding> {
1229 let trimmed = trim_nuls(data);
1230 if trimmed.is_empty() {
1231 return None;
1232 }
1233
1234 // 1. 7-bit ASCII
1235 if looks_ascii(trimmed) {
1236 return Some(IdentifiedEncoding::Ascii);
1237 }
1238
1239 // 2. UTF-8 (with BOM or valid multibyte sequences)
1240 if let Some((enc, _)) = looks_utf8(trimmed) {
1241 return Some(enc);
1242 }
1243
1244 // 3. UTF-32 (UCS-4)
1245 if let Some(enc) = looks_utf32(trimmed) {
1246 return Some(enc);
1247 }
1248
1249 // 4. UTF-16 (UCS-2)
1250 if let Some(enc) = looks_utf16(trimmed) {
1251 return Some(enc);
1252 }
1253
1254 // 5. ISO-8859 (Latin-1)
1255 if let Some(enc) = looks_iso8859(trimmed) {
1256 return Some(enc);
1257 }
1258
1259 // 6. Non-ISO 8-bit extended ASCII
1260 if let Some(enc) = looks_extended_ascii(trimmed) {
1261 return Some(enc);
1262 }
1263
1264 // 7. EBCDIC
1265 if let Some(enc) = looks_ebcdic(trimmed) {
1266 return Some(enc);
1267 }
1268
1269 None
1270}
1271
1272/// Profiles text layout conventions, line endings, long lines, and escape sequences.
1273/// Ported from `file_ascmagic_with_encoding` in `ascmagic.c`.
1274#[must_use]
1275pub fn profile_text_layout(
1276 data: &[u8],
1277 encoding: IdentifiedEncoding,
1278) -> TextProfile {
1279 let trimmed = trim_nuls(data);
1280
1281 let mut n_lf = 0usize;
1282 let mut n_cr = 0usize;
1283 let mut n_crlf = 0usize;
1284 let mut n_nel = 0usize;
1285
1286 let mut seen_cr = false;
1287 let mut has_escapes = false;
1288 let mut has_backspace = false;
1289
1290 let mut max_line_length = 0usize;
1291 let mut current_line_len = 0usize;
1292
1293 // Decode or scan characters based on encoding
1294 match encoding {
1295 IdentifiedEncoding::Utf16Le { .. }
1296 | IdentifiedEncoding::Utf16Be { .. } => {
1297 let big_end =
1298 matches!(encoding, IdentifiedEncoding::Utf16Be { .. });
1299 let offset = if data.starts_with(b"\xFF\xFE")
1300 || data.starts_with(b"\xFE\xFF")
1301 {
1302 2usize
1303 } else {
1304 0usize
1305 };
1306 let payload = if offset > 0 {
1307 // Reason for fallback: slice offset exceeding buffer length defaults to empty slice
1308 trimmed.get(offset..).unwrap_or(&[])
1309 } else {
1310 trimmed
1311 };
1312 for chunk in payload.chunks_exact(2) {
1313 let &[b0, b1] = chunk else { continue };
1314 let uc = if big_end {
1315 u32::from(b1) | (u32::from(b0) << 8)
1316 } else {
1317 u32::from(b0) | (u32::from(b1) << 8)
1318 };
1319 process_char_for_layout(
1320 uc,
1321 &mut seen_cr,
1322 &mut n_lf,
1323 &mut n_cr,
1324 &mut n_crlf,
1325 &mut n_nel,
1326 &mut has_escapes,
1327 &mut has_backspace,
1328 &mut current_line_len,
1329 &mut max_line_length,
1330 );
1331 }
1332 }
1333 IdentifiedEncoding::Ebcdic
1334 | IdentifiedEncoding::InternationalEbcdic => {
1335 for &b in trimmed {
1336 // Reason for fallback: index within 0..=255 bounds is always valid
1337 let translated =
1338 EBCDIC_TO_ASCII.get(usize::from(b)).copied().unwrap_or(0);
1339 process_char_for_layout(
1340 u32::from(translated),
1341 &mut seen_cr,
1342 &mut n_lf,
1343 &mut n_cr,
1344 &mut n_crlf,
1345 &mut n_nel,
1346 &mut has_escapes,
1347 &mut has_backspace,
1348 &mut current_line_len,
1349 &mut max_line_length,
1350 );
1351 }
1352 }
1353 _ => {
1354 // ASCII, UTF-8, ISO-8859, Extended ASCII
1355 let content =
1356 if let Some(stripped) = trimmed.strip_prefix(b"\xEF\xBB\xBF") {
1357 stripped
1358 } else {
1359 trimmed
1360 };
1361 for &b in content {
1362 process_char_for_layout(
1363 u32::from(b),
1364 &mut seen_cr,
1365 &mut n_lf,
1366 &mut n_cr,
1367 &mut n_crlf,
1368 &mut n_nel,
1369 &mut has_escapes,
1370 &mut has_backspace,
1371 &mut current_line_len,
1372 &mut max_line_length,
1373 );
1374 }
1375 }
1376 }
1377
1378 if seen_cr && n_cr == 0 && n_crlf == 0 {
1379 n_cr = n_cr.saturating_add(1);
1380 }
1381 max_line_length = max_line_length.max(current_line_len);
1382
1383 let has_long_lines = max_line_length > MAX_LINE_LENGTH;
1384
1385 // Determine primary line ending convention
1386 let primary_line_ending = if n_crlf >= n_lf && n_crlf >= n_cr && n_crlf > 0
1387 {
1388 Some(LineEndingKind::CrLf)
1389 } else if n_lf >= n_cr && n_lf > 0 {
1390 Some(LineEndingKind::Lf)
1391 } else if n_cr > 0 {
1392 Some(LineEndingKind::Cr)
1393 } else if n_nel > 0 {
1394 Some(LineEndingKind::Nl)
1395 } else {
1396 None
1397 };
1398
1399 let syntax = detect_text_syntax(trimmed);
1400
1401 TextProfile {
1402 encoding,
1403 primary_line_ending,
1404 n_lf,
1405 n_crlf,
1406 n_cr,
1407 n_nel,
1408 has_long_lines,
1409 max_line_length,
1410 has_escapes,
1411 has_backspace,
1412 syntax,
1413 }
1414}
1415
1416/// Helper updating layout counters for a single decoded character code.
1417#[expect(
1418 clippy::too_many_arguments,
1419 reason = "Layout counters are tracked individually for accurate newline profiling"
1420)]
1421fn process_char_for_layout(
1422 uc: u32,
1423 seen_cr: &mut bool,
1424 n_lf: &mut usize,
1425 n_cr: &mut usize,
1426 n_crlf: &mut usize,
1427 n_nel: &mut usize,
1428 has_escapes: &mut bool,
1429 has_backspace: &mut bool,
1430 current_line_len: &mut usize,
1431 max_line_length: &mut usize,
1432) {
1433 if uc == 0x0A {
1434 // '\n'
1435 if *seen_cr {
1436 *n_crlf = n_crlf.saturating_add(1);
1437 } else {
1438 *n_lf = n_lf.saturating_add(1);
1439 }
1440 *seen_cr = false;
1441 *max_line_length = (*max_line_length).max(*current_line_len);
1442 *current_line_len = 0;
1443 } else {
1444 if *seen_cr {
1445 *n_cr = n_cr.saturating_add(1);
1446 *max_line_length = (*max_line_length).max(*current_line_len);
1447 *current_line_len = 0;
1448 }
1449 *seen_cr = uc == 0x0D; // '\r'
1450
1451 if uc == 0x85 {
1452 // NEL
1453 *n_nel = n_nel.saturating_add(1);
1454 *max_line_length = (*max_line_length).max(*current_line_len);
1455 *current_line_len = 0;
1456 } else if uc != 0x0D {
1457 *current_line_len = current_line_len.saturating_add(1);
1458 }
1459
1460 if uc == 0x1B {
1461 *has_escapes = true;
1462 }
1463 if uc == 0x08 {
1464 *has_backspace = true;
1465 }
1466 }
1467}
1468
1469/// Detects programming languages, markup formats, and syntax patterns.
1470#[must_use]
1471pub fn detect_text_syntax(data: &[u8]) -> Option<TextSyntaxKind> {
1472 // 1. Shebang (`#!`) interpreter extraction
1473 if data.starts_with(b"#!") {
1474 if let Some(shebang) = extract_shebang(data) {
1475 return Some(shebang);
1476 }
1477 }
1478
1479 // Convert sample prefix to string for text searches
1480 let sample_len = data.len().min(8192);
1481 // Reason for fallback: slice indexing within validated min bound is always valid
1482 let sample_bytes = data.get(..sample_len).unwrap_or(data);
1483 let sample = String::from_utf8_lossy(sample_bytes);
1484
1485 // 2. XML declaration: <?xml
1486 let trimmed_sample = sample.trim_start();
1487 if trimmed_sample.starts_with("<?xml") {
1488 return Some(TextSyntaxKind::XmlDocument);
1489 }
1490
1491 // 3. HTML heuristics
1492 let sample_lower = sample.to_ascii_lowercase();
1493 if sample_lower.contains("<!doctype html")
1494 || sample_lower.contains("<html")
1495 || (sample_lower.contains("<head") && sample_lower.contains("<body"))
1496 {
1497 return Some(TextSyntaxKind::HtmlDocument);
1498 }
1499
1500 // 4. SGML declaration
1501 if trimmed_sample.starts_with("<!doctype ")
1502 || trimmed_sample.starts_with("<!sgml")
1503 {
1504 return Some(TextSyntaxKind::SgmlDocument);
1505 }
1506
1507 // 5. roff/troff commands (.TH, .SH, .PP at start of line)
1508 for line in sample.lines().take(10) {
1509 let t = line.trim_start();
1510 if t.starts_with(".TH ")
1511 || t.starts_with(".so ")
1512 || t.starts_with(".SH ")
1513 || t.starts_with(".PP")
1514 {
1515 return Some(TextSyntaxKind::RoffDocument);
1516 }
1517 }
1518
1519 // 6. TeX / LaTeX heuristics
1520 if sample.contains("\\documentclass")
1521 || sample.contains("\\begin{document}")
1522 || sample.contains("\\usepackage{")
1523 {
1524 return Some(TextSyntaxKind::TeXDocument);
1525 }
1526
1527 // 7. RFC 822 / Mail / News header heuristics
1528 if sample.starts_with("From: ")
1529 || sample.starts_with("Received: ")
1530 || (sample.contains("\nFrom: ") && sample.contains("\nSubject: "))
1531 || (sample.contains("\nFrom: ") && sample.contains("\nDate: "))
1532 {
1533 return Some(TextSyntaxKind::MailOrNewsHeader);
1534 }
1535
1536 // 8. C / C++ heuristics
1537 let has_c_include =
1538 sample.contains("#include <") || sample.contains("#include \"");
1539 let has_c_main =
1540 sample.contains("int main(") || sample.contains("void main(");
1541 let has_c_define = sample.contains("#define ")
1542 || sample.contains("#ifdef ")
1543 || sample.contains("#ifndef ");
1544 let has_cpp_features = sample.contains("namespace ")
1545 || sample.contains("std::")
1546 || sample.contains("class ")
1547 || sample.contains("template<")
1548 || sample.contains("cout <<")
1549 || sample.contains("#include <iostream>")
1550 || sample.contains("#include <vector>");
1551
1552 if (has_c_include && (has_c_main || has_c_define))
1553 || (has_c_main && has_c_define)
1554 {
1555 if has_cpp_features {
1556 return Some(TextSyntaxKind::CppSource);
1557 }
1558 return Some(TextSyntaxKind::CSource);
1559 }
1560
1561 // 9. Python heuristics
1562 let has_py_def = sample.contains("def ") && sample.contains(":\n");
1563 let has_py_import = sample.contains("import ") || sample.contains("from ");
1564 let has_py_dunder = sample.contains("__name__ == '__main__'")
1565 || sample.contains("__name__ == \"__main__\"");
1566 let has_py_triple = sample.contains("\"\"\"") || sample.contains("'''");
1567 if (has_py_def && has_py_import)
1568 || (has_py_dunder && has_py_import)
1569 || (has_py_def && has_py_triple)
1570 {
1571 return Some(TextSyntaxKind::PythonScript);
1572 }
1573
1574 // 10. Shell script heuristics
1575 let has_sh_fi = sample.contains("if [ ")
1576 && sample.contains("then")
1577 && sample.contains("fi");
1578 let has_sh_case = sample.contains("case ")
1579 && sample.contains(" in\n")
1580 && sample.contains("esac");
1581 let has_sh_export = sample.contains("export ")
1582 && (sample.contains("echo ") || sample.contains("exit "));
1583 if has_sh_fi || has_sh_case || has_sh_export {
1584 return Some(TextSyntaxKind::ShellScript);
1585 }
1586
1587 // 11. Perl heuristics
1588 let has_perl_strict =
1589 sample.contains("use strict;") || sample.contains("use warnings;");
1590 let has_perl_my = sample.contains("my $") && sample.contains("sub ");
1591 if has_perl_strict || has_perl_my {
1592 return Some(TextSyntaxKind::PerlScript);
1593 }
1594
1595 // 12. Ruby heuristics
1596 let has_ruby_def = sample.contains("def ") && sample.contains("\nend");
1597 let has_ruby_require =
1598 sample.contains("require '") || sample.contains("require \"");
1599 let has_ruby_attr =
1600 sample.contains("attr_accessor") || sample.contains("attr_reader");
1601 if (has_ruby_def && has_ruby_require) || has_ruby_attr {
1602 return Some(TextSyntaxKind::RubySource);
1603 }
1604
1605 // 13. Lisp heuristics
1606 if sample.contains("(defun ")
1607 || sample.contains("(defmacro ")
1608 || (sample.contains("(let ") && sample.contains(";;;"))
1609 {
1610 return Some(TextSyntaxKind::LispSource);
1611 }
1612
1613 // 14. Assembler heuristics
1614 let has_asm_section = sample.contains(".global ")
1615 || sample.contains(".globl ")
1616 || sample.contains(".section ");
1617 let has_asm_inst = sample.contains("mov ")
1618 || sample.contains("jmp ")
1619 || sample.contains("push ")
1620 || sample.contains("pop ");
1621 if has_asm_section && has_asm_inst {
1622 return Some(TextSyntaxKind::AssemblerSource);
1623 }
1624
1625 None
1626}
1627
1628/// Extracts interpreter details from a shebang line.
1629fn extract_shebang(data: &[u8]) -> Option<TextSyntaxKind> {
1630 // Reason for fallback: if no newline delimiter is found, shebang line spans to the end of data
1631 let line_end = data
1632 .iter()
1633 .position(|&b| b == b'\n' || b == b'\r')
1634 .unwrap_or(data.len());
1635 let line_bytes = data.get(..line_end)?;
1636 let line_str = std::str::from_utf8(line_bytes)
1637 .ok()?
1638 .trim_start_matches("#!")
1639 .trim();
1640 if line_str.is_empty() {
1641 return None;
1642 }
1643
1644 let mut parts = line_str.split_whitespace();
1645 let prog_path = parts.next()?;
1646 // Reason for fallback: path without directory separators uses entire string as program name
1647 let prog_name = prog_path.rsplit(['/', '\\']).next().unwrap_or(prog_path);
1648
1649 let (interp, _args) = if prog_name == "env" {
1650 // Handled format: #!/usr/bin/env <cmd> [args...]
1651 // Reason for fallback: #!/usr/bin/env without following arguments defaults to env interpreter
1652 let cmd = parts.next().unwrap_or("env");
1653 (cmd, parts.collect::<Vec<_>>())
1654 } else {
1655 (prog_name, parts.collect::<Vec<_>>())
1656 };
1657
1658 let interp_clean = interp.trim_start_matches(['-', '/']);
1659 let (fmt, mime, label) = match interp_clean {
1660 "sh" => (
1661 Some(FormatId::Sh),
1662 "text/x-shellscript".to_string(),
1663 "POSIX shell script".to_string(),
1664 ),
1665 "bash" => (
1666 Some(FormatId::Bash),
1667 "text/x-shellscript".to_string(),
1668 "Bourne-Again shell script".to_string(),
1669 ),
1670 "zsh" => (
1671 Some(FormatId::Sh),
1672 "text/x-shellscript".to_string(),
1673 "Zsh shell script".to_string(),
1674 ),
1675 "ksh" => (
1676 Some(FormatId::Sh),
1677 "text/x-shellscript".to_string(),
1678 "Korn shell script".to_string(),
1679 ),
1680 "csh" | "tcsh" => (
1681 Some(FormatId::Sh),
1682 "text/x-shellscript".to_string(),
1683 "C shell script".to_string(),
1684 ),
1685 "python" | "python3" | "python2" => (
1686 None,
1687 "text/x-python".to_string(),
1688 "Python script".to_string(),
1689 ),
1690 "perl" | "perl5" => (
1691 Some(FormatId::Perl),
1692 "text/x-perl".to_string(),
1693 "Perl script".to_string(),
1694 ),
1695 "ruby" => (None, "text/x-ruby".to_string(), "Ruby script".to_string()),
1696 "node" | "nodejs" => (
1697 Some(FormatId::JavaScript),
1698 "application/javascript".to_string(),
1699 "Node.js script".to_string(),
1700 ),
1701 "php" => (
1702 Some(FormatId::Php),
1703 "text/x-php".to_string(),
1704 "PHP script".to_string(),
1705 ),
1706 "awk" | "gawk" | "nawk" | "mawk" => {
1707 (None, "text/x-awk".to_string(), "AWK script".to_string())
1708 }
1709 "sed" => (None, "text/x-sed".to_string(), "Sed script".to_string()),
1710 "lua" => (None, "text/x-lua".to_string(), "Lua script".to_string()),
1711 other => (None, "text/plain".to_string(), format!("{other} script")),
1712 };
1713
1714 Some(TextSyntaxKind::ShebangScript {
1715 interpreter: interp.to_string(),
1716 format_id: fmt,
1717 mime,
1718 label,
1719 })
1720}
1721
1722/// Formats the final description string with `file` parity.
1723#[must_use]
1724pub fn format_text_description(profile: &TextProfile) -> String {
1725 let mut desc = String::new();
1726
1727 // 1. Syntax prefix or encoding name
1728 if let Some(syntax) = &profile.syntax {
1729 desc.push_str(syntax.description_prefix());
1730 desc.push_str(", ");
1731 desc.push_str(profile.encoding.description_label());
1732 desc.push_str(" text");
1733 if syntax.is_executable() {
1734 desc.push_str(" executable");
1735 }
1736 } else {
1737 desc.push_str(profile.encoding.description_label());
1738 desc.push_str(" text");
1739 }
1740
1741 // 2. Very long lines clause
1742 if profile.has_long_lines {
1743 desc.push_str(&format!(
1744 ", with very long lines ({})",
1745 profile.max_line_length
1746 ));
1747 }
1748
1749 // 3. Line terminators clause (only reported if not standard single LF, or if none)
1750 let n_total_lines = profile
1751 .n_crlf
1752 .saturating_add(profile.n_lf)
1753 .saturating_add(profile.n_cr)
1754 .saturating_add(profile.n_nel);
1755 if n_total_lines == 0 {
1756 desc.push_str(", with no line terminators");
1757 } else if profile.n_crlf > 0 || profile.n_cr > 0 || profile.n_nel > 0 {
1758 desc.push_str(", with ");
1759 let mut terms = Vec::new();
1760 if profile.n_crlf > 0 {
1761 terms.push("CRLF");
1762 }
1763 if profile.n_cr > 0 {
1764 terms.push("CR");
1765 }
1766 if profile.n_lf > 0 {
1767 terms.push("LF");
1768 }
1769 if profile.n_nel > 0 {
1770 terms.push("NEL");
1771 }
1772 desc.push_str(&terms.join(", "));
1773 desc.push_str(" line terminators");
1774 }
1775
1776 // 4. Escapes and overstriking
1777 if profile.has_escapes {
1778 desc.push_str(", with escape sequences");
1779 }
1780 if profile.has_backspace {
1781 desc.push_str(", with overstriking");
1782 }
1783
1784 desc
1785}
1786
1787/// Performs complete text detection on a data source, returning a candidate if text is confirmed.
1788pub fn detect_text_candidate(
1789 source: &mut dyn DetectionSource,
1790 hint: Option<&DetectionHint>,
1791) -> Result<Option<DetectionCandidate>> {
1792 Ok(detect_text_candidate_and_encoding(source, hint)?.map(|(cand, _)| cand))
1793}
1794
1795/// Performs complete text detection on a data source, returning a candidate if
1796/// text is confirmed, together with the `FormatId` of the detected character
1797/// encoding itself (without syntax-format overrides). The encoding format ID
1798/// lets callers reason about encoding entailment (e.g. corroborating an
1799/// extension candidate whose format implies a specific encoding); it is `None`
1800/// when the detected encoding has no exact format catalog mapping.
1801pub fn detect_text_candidate_and_encoding(
1802 source: &mut dyn DetectionSource,
1803 hint: Option<&DetectionHint>,
1804) -> Result<Option<(DetectionCandidate, Option<FormatId>)>> {
1805 let mut sample_buf = vec![0u8; TEXT_ENCODING_MAX_BYTES.min(4096)];
1806 let n = source.read_at(0, &mut sample_buf)?;
1807 if n == 0 {
1808 return Ok(None);
1809 }
1810 // Reason for fallback: slice indexing within read count `n` is always valid
1811 let sample = sample_buf.get(..n).unwrap_or(&sample_buf);
1812
1813 let Some(encoding) = detect_text_encoding(sample) else {
1814 return Ok(None);
1815 };
1816
1817 let profile = profile_text_layout(sample, encoding);
1818 let description = format_text_description(&profile);
1819
1820 // Determine candidate FormatId and MIME type
1821 let (format_id, mime) = if let Some(syntax) = &profile.syntax {
1822 (
1823 syntax.format_id().or_else(|| encoding.format_id()),
1824 Some(syntax.mime_type().to_string()),
1825 )
1826 } else {
1827 (
1828 encoding.format_id(),
1829 Some(format!("text/plain; charset={}", encoding.mime_charset())),
1830 )
1831 };
1832
1833 // Calculate score
1834 let mut score = if profile.syntax.is_some() {
1835 80u32
1836 } else {
1837 65u32
1838 };
1839 let mut evidence = Vec::new();
1840
1841 evidence.push(DetectionEvidence::Encoding {
1842 encoding: encoding.description_label().to_string(),
1843 score: 35,
1844 });
1845
1846 evidence.push(DetectionEvidence::TextProperties {
1847 line_ending: profile.primary_line_ending,
1848 has_long_lines: profile.has_long_lines,
1849 has_escapes: profile.has_escapes,
1850 score: 30,
1851 });
1852
1853 if let Some(syntax) = &profile.syntax {
1854 score = score.saturating_add(10);
1855 evidence.push(DetectionEvidence::CtbRule {
1856 description: syntax.description_prefix().to_string(),
1857 score: 10,
1858 });
1859 }
1860
1861 // Concordance with hint extension
1862 if let Some(h) = hint {
1863 if let Some(ext) = h.extension.as_deref().or(h.filename.as_deref()) {
1864 let ext_lower = ext.to_ascii_lowercase();
1865 let is_match = match profile.syntax {
1866 Some(TextSyntaxKind::HtmlDocument) => {
1867 ext_lower.ends_with(".html") || ext_lower.ends_with(".htm")
1868 }
1869 Some(TextSyntaxKind::XmlDocument) => {
1870 ext_lower.ends_with(".xml")
1871 }
1872 Some(TextSyntaxKind::CSource) => {
1873 ext_lower.ends_with(".c") || ext_lower.ends_with(".h")
1874 }
1875 Some(TextSyntaxKind::CppSource) => {
1876 ext_lower.ends_with(".cpp")
1877 || ext_lower.ends_with(".cc")
1878 || ext_lower.ends_with(".cxx")
1879 || ext_lower.ends_with(".hpp")
1880 }
1881 Some(TextSyntaxKind::PythonScript) => {
1882 ext_lower.ends_with(".py")
1883 }
1884 Some(TextSyntaxKind::ShellScript) => {
1885 ext_lower.ends_with(".sh") || ext_lower.ends_with(".bash")
1886 }
1887 Some(TextSyntaxKind::PerlScript) => {
1888 ext_lower.ends_with(".pl") || ext_lower.ends_with(".pm")
1889 }
1890 Some(TextSyntaxKind::RubySource) => ext_lower.ends_with(".rb"),
1891 _ => ext_lower.ends_with(".txt"),
1892 };
1893 if is_match {
1894 score = score.saturating_add(15);
1895 evidence.push(DetectionEvidence::Extension {
1896 ext: ext.to_string(),
1897 is_primary: true,
1898 score: 15,
1899 });
1900 }
1901 }
1902
1903 if let (Some(exp_cat), Some(fid)) = (h.expected_category, format_id) {
1904 if fid.category() == exp_cat {
1905 score = score.saturating_add(10);
1906 evidence.push(DetectionEvidence::CategoryMatch {
1907 category: exp_cat,
1908 score: 10,
1909 });
1910 }
1911 }
1912 }
1913
1914 let confidence = if score >= 85 {
1915 ConfidenceTier::HighestConfidence
1916 } else if score >= 65 {
1917 ConfidenceTier::Strong
1918 } else {
1919 ConfidenceTier::Moderate
1920 };
1921
1922 Ok(Some((
1923 DetectionCandidate {
1924 format_id,
1925 dc_id: None,
1926 mime,
1927 description,
1928 confidence,
1929 score,
1930 evidence,
1931 chain_layers: None,
1932 },
1933 encoding.format_id(),
1934 )))
1935}
1936
1937#[cfg(test)]
1938#[allow(
1939 clippy::panic,
1940 clippy::expect_used,
1941 clippy::unwrap_used,
1942 clippy::unwrap_in_result,
1943 clippy::panic_in_result_fn,
1944 clippy::indexing_slicing,
1945 clippy::arithmetic_side_effects,
1946 reason = "Standard repository test boilerplate"
1947)]
1948mod tests {
1949 use super::*;
1950
1951 #[crate::ctb_test]
1952 fn test_looks_ascii_valid() {
1953 let ascii_data = b"Hello, world! 123 \t\r\n";
1954 assert!(looks_ascii(ascii_data));
1955 assert_eq!(
1956 detect_text_encoding(ascii_data),
1957 Some(IdentifiedEncoding::Ascii)
1958 );
1959 }
1960
1961 #[crate::ctb_test]
1962 fn test_looks_ascii_invalid_controls() {
1963 let binary_data = b"Hello\x00World";
1964 assert!(!looks_ascii(binary_data));
1965 assert_eq!(detect_text_encoding(binary_data), None);
1966 }
1967
1968 #[crate::ctb_test]
1969 fn test_single_byte_ascii_detection() {
1970 assert!(looks_ascii(b"A"));
1971 assert_eq!(detect_text_encoding(b"A"), Some(IdentifiedEncoding::Ascii));
1972 let mut slice: &[u8] = b"A";
1973 let cand = detect_text_candidate(&mut slice, None).unwrap();
1974 assert!(cand.is_some());
1975 assert_eq!(cand.unwrap().format_id, Some(FormatId::Ascii));
1976 }
1977
1978 #[crate::ctb_test]
1979 fn test_utf8_with_bom() {
1980 let data = b"\xEF\xBB\xBFHello, UTF-8 \xC3\xA9!";
1981 let res = detect_text_encoding(data);
1982 assert_eq!(res, Some(IdentifiedEncoding::Utf8 { with_bom: true }));
1983 }
1984
1985 #[crate::ctb_test]
1986 fn test_utf8_without_bom() {
1987 let data = "Hello, UTF-8 café and naïve \u{1F600}!".as_bytes();
1988 let res = detect_text_encoding(data);
1989 assert_eq!(res, Some(IdentifiedEncoding::Utf8 { with_bom: false }));
1990 }
1991
1992 #[crate::ctb_test]
1993 fn test_utf16_le_with_bom() {
1994 let mut data = vec![0xFF, 0xFE];
1995 for b in b"Hello, UTF-16LE!" {
1996 data.push(*b);
1997 data.push(0x00);
1998 }
1999 let res = detect_text_encoding(&data);
2000 assert_eq!(res, Some(IdentifiedEncoding::Utf16Le { with_bom: true }));
2001 }
2002
2003 #[crate::ctb_test]
2004 fn test_utf16_be_with_bom() {
2005 let mut data = vec![0xFE, 0xFF];
2006 for b in b"Hello, UTF-16BE!" {
2007 data.push(0x00);
2008 data.push(*b);
2009 }
2010 let res = detect_text_encoding(&data);
2011 assert_eq!(res, Some(IdentifiedEncoding::Utf16Be { with_bom: true }));
2012 }
2013
2014 #[crate::ctb_test]
2015 fn test_utf16_without_bom() {
2016 let mut data_le = Vec::new();
2017 for b in b"Hello without BOM in LE!" {
2018 data_le.push(*b);
2019 data_le.push(0x00);
2020 }
2021 assert_eq!(
2022 detect_text_encoding(&data_le),
2023 Some(IdentifiedEncoding::Utf16Le { with_bom: false })
2024 );
2025
2026 let mut data_be = Vec::new();
2027 for b in b"Hello without BOM in BE!" {
2028 data_be.push(0x00);
2029 data_be.push(*b);
2030 }
2031 assert_eq!(
2032 detect_text_encoding(&data_be),
2033 Some(IdentifiedEncoding::Utf16Be { with_bom: false })
2034 );
2035 }
2036
2037 #[crate::ctb_test]
2038 fn test_utf32_with_bom() {
2039 let mut data_le = vec![0xFF, 0xFE, 0x00, 0x00];
2040 for b in b"Hello UTF-32 LE!" {
2041 data_le.push(*b);
2042 data_le.push(0x00);
2043 data_le.push(0x00);
2044 data_le.push(0x00);
2045 }
2046 assert_eq!(
2047 detect_text_encoding(&data_le),
2048 Some(IdentifiedEncoding::Utf32Le { with_bom: true })
2049 );
2050 }
2051
2052 #[crate::ctb_test]
2053 fn test_iso8859_latin1() {
2054 // 'café' in ISO-8859-1: 'é' is 0xE9 (in CHAR_I range 0xA0..=0xFF)
2055 let data = b"caf\xE9 au lait\n";
2056 assert_eq!(
2057 detect_text_encoding(data),
2058 Some(IdentifiedEncoding::Iso8859_1)
2059 );
2060 }
2061
2062 #[crate::ctb_test]
2063 fn test_ebcdic() {
2064 // Translate "HELLO" to EBCDIC
2065 // EBCDIC values: 'H'=0xC8, 'E'=0xC5, 'L'=0xD3, 'O'=0xD6
2066 let ebcdic_data = [0xC8, 0xC5, 0xD3, 0xD3, 0xD6, 0x15]; // 0x15 translates to newline (10)
2067 let res = detect_text_encoding(&ebcdic_data);
2068 assert_eq!(res, Some(IdentifiedEncoding::Ebcdic));
2069 }
2070
2071 #[crate::ctb_test]
2072 fn test_line_ending_and_layout_profiling() {
2073 let crlf_data = b"Line 1\r\nLine 2\r\nLine 3\r\n";
2074 let prof = profile_text_layout(crlf_data, IdentifiedEncoding::Ascii);
2075 assert_eq!(prof.primary_line_ending, Some(LineEndingKind::CrLf));
2076 assert_eq!(prof.n_crlf, 3);
2077 assert_eq!(prof.n_lf, 0);
2078 assert!(!prof.has_long_lines);
2079
2080 let desc = format_text_description(&prof);
2081 assert_eq!(desc, "ASCII text, with CRLF line terminators");
2082 }
2083
2084 #[crate::ctb_test]
2085 fn test_long_line_reporting() {
2086 let mut long_data = vec![b'A'; 350];
2087 long_data.push(b'\n');
2088 let prof = profile_text_layout(&long_data, IdentifiedEncoding::Ascii);
2089 assert!(prof.has_long_lines);
2090 assert_eq!(prof.max_line_length, 350);
2091
2092 let desc = format_text_description(&prof);
2093 assert_eq!(desc, "ASCII text, with very long lines (350)");
2094 }
2095
2096 #[crate::ctb_test]
2097 fn test_shebang_detection() {
2098 let py_script = b"#!/usr/bin/env python3\nprint('hello')\n";
2099 let prof = profile_text_layout(py_script, IdentifiedEncoding::Ascii);
2100 assert!(
2101 matches!(prof.syntax, Some(TextSyntaxKind::ShebangScript { ref interpreter, .. }) if interpreter == "python3")
2102 );
2103
2104 let desc = format_text_description(&prof);
2105 assert_eq!(desc, "Python script, ASCII text executable");
2106
2107 let sh_script = b"#!/bin/sh\necho \"running\"\n";
2108 let prof_sh = profile_text_layout(sh_script, IdentifiedEncoding::Ascii);
2109 let desc_sh = format_text_description(&prof_sh);
2110 assert_eq!(desc_sh, "POSIX shell script, ASCII text executable");
2111 }
2112
2113 #[crate::ctb_test]
2114 fn test_c_source_heuristic() {
2115 let c_code = b"#include <stdio.h>\n\nint main(void) {\n printf(\"Hello\\n\");\n return 0;\n}\n";
2116 let prof = profile_text_layout(c_code, IdentifiedEncoding::Ascii);
2117 assert_eq!(prof.syntax, Some(TextSyntaxKind::CSource));
2118
2119 let desc = format_text_description(&prof);
2120 assert_eq!(desc, "C source, ASCII text");
2121 }
2122
2123 #[crate::ctb_test]
2124 fn test_html_heuristic() {
2125 let html_data = b"<!DOCTYPE html>\n<html><head><title>Test</title></head><body><p>Hello</p></body></html>\n";
2126 let prof = profile_text_layout(html_data, IdentifiedEncoding::Ascii);
2127 assert_eq!(prof.syntax, Some(TextSyntaxKind::HtmlDocument));
2128
2129 let desc = format_text_description(&prof);
2130 assert_eq!(desc, "HTML document, ASCII text");
2131 }
2132
2133 #[crate::ctb_test]
2134 fn test_xml_heuristic() {
2135 let xml_data = b"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root><item id=\"1\"/></root>\n";
2136 let prof = profile_text_layout(xml_data, IdentifiedEncoding::Ascii);
2137 assert_eq!(prof.syntax, Some(TextSyntaxKind::XmlDocument));
2138
2139 let desc = format_text_description(&prof);
2140 assert_eq!(desc, "XML 1.0 document, ASCII text");
2141 }
2142}
2143/*
2144/*
2145 * Adapted from: apptype.c, Written by Eberhard Mattes and put into the
2146 * file_public domain
2147 *
2148 * Notes: 1. Qualify the filename so that DosQueryAppType does not do extraneous
2149 * searches.
2150 *
2151 * 2. DosQueryAppType will return FAPPTYP_DOS on a file ending with ".com"
2152 * (other than an OS/2 exe or Win exe with this name). Eberhard Mattes
2153 * remarks Tue, 6 Apr 93: Moreover, it reports the type of the (new and very
2154 * bug ridden) Win Emacs as "OS/2 executable".
2155 *
2156 * 3. apptype() uses the filename if given, otherwise a tmp file is created with
2157 * the contents of buf. If buf is not the complete file, apptype can
2158 * incorrectly identify the exe type. The "-z" option of "file" is the reason
2159 * for this ugly code.
2160 */
2161
2162The preceding notice is from src/apptype.c in `file`.
2163
2164
2165
2166/*-
2167 * Copyright (c) 2008 Christos Zoulas
2168 * All rights reserved.
2169 *
2170 * Redistribution and use in source and binary forms, with or without
2171 * modification, are permitted provided that the following conditions
2172 * are met:
2173 * 1. Redistributions of source code must retain the above copyright
2174 * notice, this list of conditions and the following disclaimer.
2175 * 2. Redistributions in binary form must reproduce the above copyright
2176 * notice, this list of conditions and the following disclaimer in the
2177 * documentation and/or other materials provided with the distribution.
2178 *
2179 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2180 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2181 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2182 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2183 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2184 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2185 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2186 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2187 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2188 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2189 * POSSIBILITY OF SUCH DAMAGE.
2190 */
2191
2192The preceding notice is from src/cdf.c, src/cdf.h, and src/cdf_time.c in `file`.
2193
2194
2195
2196/*-
2197 * Copyright (c) 2016 Christos Zoulas
2198 * All rights reserved.
2199 *
2200 * Redistribution and use in source and binary forms, with or without
2201 * modification, are permitted provided that the following conditions
2202 * are met:
2203 * 1. Redistributions of source code must retain the above copyright
2204 * notice, this list of conditions and the following disclaimer.
2205 * 2. Redistributions in binary form must reproduce the above copyright
2206 * notice, this list of conditions and the following disclaimer in the
2207 * documentation and/or other materials provided with the distribution.
2208 *
2209 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2210 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2211 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2212 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2213 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2214 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2215 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2216 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2217 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2218 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2219 * POSSIBILITY OF SUCH DAMAGE.
2220 */
2221
2222The preceding notice is from src/der.c and src/der.h in `file`.
2223
2224
2225
2226/*-
2227 * Copyright (c) 2019 Christos Zoulas
2228 * All rights reserved.
2229 *
2230 * Redistribution and use in source and binary forms, with or without
2231 * modification, are permitted provided that the following conditions
2232 * are met:
2233 * 1. Redistributions of source code must retain the above copyright
2234 * notice, this list of conditions and the following disclaimer.
2235 * 2. Redistributions in binary form must reproduce the above copyright
2236 * notice, this list of conditions and the following disclaimer in the
2237 * documentation and/or other materials provided with the distribution.
2238 *
2239 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2240 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2241 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2242 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2243 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2244 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2245 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2246 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2247 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2248 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2249 * POSSIBILITY OF SUCH DAMAGE.
2250 */
2251
2252The preceding notice is from src/is_csv.c in `file`.
2253
2254
2255
2256/*-
2257 * Copyright (c) 2018 Christos Zoulas
2258 * All rights reserved.
2259 *
2260 * Redistribution and use in source and binary forms, with or without
2261 * modification, are permitted provided that the following conditions
2262 * are met:
2263 * 1. Redistributions of source code must retain the above copyright
2264 * notice, this list of conditions and the following disclaimer.
2265 * 2. Redistributions in binary form must reproduce the above copyright
2266 * notice, this list of conditions and the following disclaimer in the
2267 * documentation and/or other materials provided with the distribution.
2268 *
2269 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2270 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2271 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2272 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2273 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2274 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2275 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2276 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2277 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2278 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2279 * POSSIBILITY OF SUCH DAMAGE.
2280 */
2281
2282The preceding notice is from src/is_json.c in `file`.
2283
2284
2285
2286/*-
2287 * Copyright (c) 2023 Christos Zoulas
2288 * All rights reserved.
2289 *
2290 * Redistribution and use in source and binary forms, with or without
2291 * modification, are permitted provided that the following conditions
2292 * are met:
2293 * 1. Redistributions of source code must retain the above copyright
2294 * notice, this list of conditions and the following disclaimer.
2295 * 2. Redistributions in binary form must reproduce the above copyright
2296 * notice, this list of conditions and the following disclaimer in the
2297 * documentation and/or other materials provided with the distribution.
2298 *
2299 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2300 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2301 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2302 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2303 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2304 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2305 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2306 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2307 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2308 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2309 * POSSIBILITY OF SUCH DAMAGE.
2310 */
2311
2312The preceding notice is from src/is_simh.c in `file`.
2313
2314
2315
2316/*-
2317 * SPDX-License-Identifier: BSD-3-Clause
2318 *
2319 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2320 * Copyright (c) 1992, 1993, 1994
2321 * The Regents of the University of California. All rights reserved.
2322 *
2323 * This code is derived from software contributed to Berkeley by
2324 * Henry Spencer.
2325 *
2326 * Redistribution and use in source and binary forms, with or without
2327 * modification, are permitted provided that the following conditions
2328 * are met:
2329 * 1. Redistributions of source code must retain the above copyright
2330 * notice, this list of conditions and the following disclaimer.
2331 * 2. Redistributions in binary form must reproduce the above copyright
2332 * notice, this list of conditions and the following disclaimer in the
2333 * documentation and/or other materials provided with the distribution.
2334 * 3. Neither the name of the University nor the names of its contributors
2335 * may be used to endorse or promote products derived from this software
2336 * without specific prior written permission.
2337 *
2338 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2339 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2340 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2341 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2342 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2343 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2344 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2345 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2346 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2347 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2348 * SUCH DAMAGE.
2349 *
2350 * @(#)cname.h 8.3 (Berkeley) 3/20/94
2351 * $FreeBSD: head/lib/libc/regex/cname.h 326025 2017-11-20 19:49:47Z pfg $
2352 */
2353
2354The preceding notice is from src/missing/cname.h in `file`.
2355
2356
2357
2358/*-
2359 * SPDX-License-Identifier: BSD-3-Clause
2360 *
2361 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2362 * Copyright (c) 1992, 1993, 1994
2363 * The Regents of the University of California. All rights reserved.
2364 *
2365 * This code is derived from software contributed to Berkeley by
2366 * Henry Spencer.
2367 *
2368 * Redistribution and use in source and binary forms, with or without
2369 * modification, are permitted provided that the following conditions
2370 * are met:
2371 * 1. Redistributions of source code must retain the above copyright
2372 * notice, this list of conditions and the following disclaimer.
2373 * 2. Redistributions in binary form must reproduce the above copyright
2374 * notice, this list of conditions and the following disclaimer in the
2375 * documentation and/or other materials provided with the distribution.
2376 * 3. Neither the name of the University nor the names of its contributors
2377 * may be used to endorse or promote products derived from this software
2378 * without specific prior written permission.
2379 *
2380 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2381 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2382 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2383 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2384 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2385 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2386 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2387 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2388 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2389 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2390 * SUCH DAMAGE.
2391 *
2392 * @(#)engine.c 8.5 (Berkeley) 3/20/94
2393 */
2394
2395The preceding notice is from src/missing/engine.c in `file`.
2396
2397
2398
2399/*-
2400 * Copyright (c) 2000 The NetBSD Foundation, Inc.
2401 * All rights reserved.
2402 *
2403 * This code was contributed to The NetBSD Foundation by Allen Briggs.
2404 *
2405 * Redistribution and use in source and binary forms, with or without
2406 * modification, are permitted provided that the following conditions
2407 * are met:
2408 * 1. Redistributions of source code must retain the above copyright
2409 * notice, this list of conditions and the following disclaimer.
2410 * 2. Redistributions in binary form must reproduce the above copyright
2411 * notice, this list of conditions and the following disclaimer in the
2412 * documentation and/or other materials provided with the distribution.
2413 *
2414 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2415 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2416 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2417 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2418 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2419 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2420 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2421 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2422 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2423 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
2425 */
2426
2427The preceding notice is from src/missing/fmtcheck.c in `file`.
2428
2429
2430
2431/*-
2432 * Copyright (c) 2011 The NetBSD Foundation, Inc.
2433 * All rights reserved.
2434 *
2435 * This code is derived from software contributed to The NetBSD Foundation
2436 * by Christos Zoulas.
2437 *
2438 * Redistribution and use in source and binary forms, with or without
2439 * modification, are permitted provided that the following conditions
2440 * are met:
2441 * 1. Redistributions of source code must retain the above copyright
2442 * notice, this list of conditions and the following disclaimer.
2443 * 2. Redistributions in binary form must reproduce the above copyright
2444 * notice, this list of conditions and the following disclaimer in the
2445 * documentation and/or other materials provided with the distribution.
2446 *
2447 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2448 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2449 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2450 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2451 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2452 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2453 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2454 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2455 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2456 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2457 * POSSIBILITY OF SUCH DAMAGE.
2458 */
2459
2460The preceding notice is from src/missing/getline.c in `file`.
2461
2462
2463
2464/*-
2465 * Copyright (c) 2000 The NetBSD Foundation, Inc.
2466 * All rights reserved.
2467 *
2468 * This code is derived from software contributed to The NetBSD Foundation
2469 * by Dieter Baron and Thomas Klausner.
2470 *
2471 * Redistribution and use in source and binary forms, with or without
2472 * modification, are permitted provided that the following conditions
2473 * are met:
2474 * 1. Redistributions of source code must retain the above copyright
2475 * notice, this list of conditions and the following disclaimer.
2476 * 2. Redistributions in binary form must reproduce the above copyright
2477 * notice, this list of conditions and the following disclaimer in the
2478 * documentation and/or other materials provided with the distribution.
2479 *
2480 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2481 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2482 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2483 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2484 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2485 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2486 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2487 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2488 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2489 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2490 * POSSIBILITY OF SUCH DAMAGE.
2491 */
2492
2493The preceding notice is from src/missing/getopt_long.c and src/mygetopt.h in `file`.
2494
2495
2496
2497/*
2498 * Public domain fallback for reallocarray(3), for platforms (e.g.
2499 * AmigaOS/libnix) whose C library declares it but does not implement it.
2500 */
2501
2502The preceding notice is from src/missing/reallocarray.c in `file`.
2503
2504
2505
2506/*-
2507 * SPDX-License-Identifier: BSD-3-Clause
2508 *
2509 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2510 * Copyright (c) 1992, 1993, 1994
2511 * The Regents of the University of California. All rights reserved.
2512 *
2513 * Copyright (c) 2011 The FreeBSD Foundation
2514 * All rights reserved.
2515 * Portions of this software were developed by David Chisnall
2516 * under sponsorship from the FreeBSD Foundation.
2517 *
2518 * This code is derived from software contributed to Berkeley by
2519 * Henry Spencer.
2520 *
2521 * Redistribution and use in source and binary forms, with or without
2522 * modification, are permitted provided that the following conditions
2523 * are met:
2524 * 1. Redistributions of source code must retain the above copyright
2525 * notice, this list of conditions and the following disclaimer.
2526 * 2. Redistributions in binary form must reproduce the above copyright
2527 * notice, this list of conditions and the following disclaimer in the
2528 * documentation and/or other materials provided with the distribution.
2529 * 3. Neither the name of the University nor the names of its contributors
2530 * may be used to endorse or promote products derived from this software
2531 * without specific prior written permission.
2532 *
2533 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2534 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2535 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2536 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2537 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2538 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2539 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2540 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2541 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2542 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2543 * SUCH DAMAGE.
2544 *
2545 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
2546 */
2547
2548The preceding notice is from src/missing/regcomp.c in `file`.
2549
2550
2551
2552/*-
2553 * SPDX-License-Identifier: BSD-3-Clause
2554 *
2555 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2556 * Copyright (c) 1992, 1993, 1994
2557 * The Regents of the University of California. All rights reserved.
2558 *
2559 * This code is derived from software contributed to Berkeley by
2560 * Henry Spencer.
2561 *
2562 * Redistribution and use in source and binary forms, with or without
2563 * modification, are permitted provided that the following conditions
2564 * are met:
2565 * 1. Redistributions of source code must retain the above copyright
2566 * notice, this list of conditions and the following disclaimer.
2567 * 2. Redistributions in binary form must reproduce the above copyright
2568 * notice, this list of conditions and the following disclaimer in the
2569 * documentation and/or other materials provided with the distribution.
2570 * 3. Neither the name of the University nor the names of its contributors
2571 * may be used to endorse or promote products derived from this software
2572 * without specific prior written permission.
2573 *
2574 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2575 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2576 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2577 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2578 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2579 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2580 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2581 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2582 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2583 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2584 * SUCH DAMAGE.
2585 *
2586 * @(#)regerror.c 8.4 (Berkeley) 3/20/94
2587 */
2588
2589The preceding notice is from src/missing/regerror.c in `file`.
2590
2591
2592
2593$NetBSD: COPYRIGHT,v 1.5 2003/08/07 16:43:19 agc Exp $
2594
2595Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
2596This software is not subject to any license of the American Telephone
2597and Telegraph Company or of the Regents of the University of California.
2598
2599Permission is granted to anyone to use this software for any purpose on
2600any computer system, and to alter it and redistribute it, subject
2601to the following restrictions:
2602
26031. The author is not responsible for the consequences of use of this
2604 software, no matter how awful, even if they arise from flaws in it.
2605
26062. The origin of this software must not be misrepresented, either by
2607 explicit claim or by omission. Since few users ever read sources,
2608 credits must appear in the documentation.
2609
26103. Altered versions must be plainly marked as such, and must not be
2611 misrepresented as being the original software. Since few users
2612 ever read sources, credits must appear in the documentation.
2613
26144. This notice may not be removed or altered.
2615
2616=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2617/*-
2618 * Copyright (c) 1994
2619 * The Regents of the University of California. All rights reserved.
2620 *
2621 * Redistribution and use in source and binary forms, with or without
2622 * modification, are permitted provided that the following conditions
2623 * are met:
2624 * 1. Redistributions of source code must retain the above copyright
2625 * notice, this list of conditions and the following disclaimer.
2626 * 2. Redistributions in binary form must reproduce the above copyright
2627 * notice, this list of conditions and the following disclaimer in the
2628 * documentation and/or other materials provided with the distribution.
2629 * 3. Neither the name of the University nor the names of its contributors
2630 * may be used to endorse or promote products derived from this software
2631 * without specific prior written permission.
2632 *
2633 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2634 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2635 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2636 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2637 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2638 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2639 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2640 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2641 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2642 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2643 * SUCH DAMAGE.
2644 *
2645 * @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
2646 */
2647
2648The preceding notice is from src/missing/REGEX-COPYRIGHT in `file`.
2649
2650
2651
2652/*-
2653 * SPDX-License-Identifier: BSD-3-Clause
2654 *
2655 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2656 * Copyright (c) 1992, 1993, 1994
2657 * The Regents of the University of California. All rights reserved.
2658 *
2659 * This code is derived from software contributed to Berkeley by
2660 * Henry Spencer.
2661 *
2662 * Redistribution and use in source and binary forms, with or without
2663 * modification, are permitted provided that the following conditions
2664 * are met:
2665 * 1. Redistributions of source code must retain the above copyright
2666 * notice, this list of conditions and the following disclaimer.
2667 * 2. Redistributions in binary form must reproduce the above copyright
2668 * notice, this list of conditions and the following disclaimer in the
2669 * documentation and/or other materials provided with the distribution.
2670 * 3. Neither the name of the University nor the names of its contributors
2671 * may be used to endorse or promote products derived from this software
2672 * without specific prior written permission.
2673 *
2674 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2675 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2676 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2677 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2678 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2679 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2680 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2681 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2682 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2683 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2684 * SUCH DAMAGE.
2685 *
2686 * @(#)regex2.h 8.4 (Berkeley) 3/20/94
2687 * $FreeBSD: head/lib/libc/regex/regex2.h 368359 2020-12-05 03:18:48Z kevans $
2688 */
2689
2690The preceding notice is from src/missing/regex2.h in `file`.
2691
2692
2693
2694/*-
2695 * SPDX-License-Identifier: BSD-3-Clause
2696 *
2697 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2698 * Copyright (c) 1992, 1993, 1994
2699 * The Regents of the University of California. All rights reserved.
2700 *
2701 * This code is derived from software contributed to Berkeley by
2702 * Henry Spencer.
2703 *
2704 * Redistribution and use in source and binary forms, with or without
2705 * modification, are permitted provided that the following conditions
2706 * are met:
2707 * 1. Redistributions of source code must retain the above copyright
2708 * notice, this list of conditions and the following disclaimer.
2709 * 2. Redistributions in binary form must reproduce the above copyright
2710 * notice, this list of conditions and the following disclaimer in the
2711 * documentation and/or other materials provided with the distribution.
2712 * 3. Neither the name of the University nor the names of its contributors
2713 * may be used to endorse or promote products derived from this software
2714 * without specific prior written permission.
2715 *
2716 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2717 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2718 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2719 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2720 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2721 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2722 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2723 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2724 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2725 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2726 * SUCH DAMAGE.
2727 *
2728 * @(#)regexec.c 8.3 (Berkeley) 3/20/94
2729 */
2730
2731The preceding notice is from src/missing/regexec.c in `file`.
2732
2733
2734
2735/*-
2736 * SPDX-License-Identifier: BSD-3-Clause
2737 *
2738 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2739 * Copyright (c) 1992, 1993, 1994
2740 * The Regents of the University of California. All rights reserved.
2741 *
2742 * This code is derived from software contributed to Berkeley by
2743 * Henry Spencer.
2744 *
2745 * Redistribution and use in source and binary forms, with or without
2746 * modification, are permitted provided that the following conditions
2747 * are met:
2748 * 1. Redistributions of source code must retain the above copyright
2749 * notice, this list of conditions and the following disclaimer.
2750 * 2. Redistributions in binary form must reproduce the above copyright
2751 * notice, this list of conditions and the following disclaimer in the
2752 * documentation and/or other materials provided with the distribution.
2753 * 3. Neither the name of the University nor the names of its contributors
2754 * may be used to endorse or promote products derived from this software
2755 * without specific prior written permission.
2756 *
2757 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2758 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2759 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2760 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2761 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2762 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2763 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2764 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2765 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2766 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2767 * SUCH DAMAGE.
2768 *
2769 * @(#)regfree.c 8.3 (Berkeley) 3/20/94
2770 */
2771
2772The preceding notice is from src/missing/regfree.c in `file`.
2773
2774
2775
2776/*-
2777 * Copyright (c) 1990, 1993
2778 * The Regents of the University of California. All rights reserved.
2779 *
2780 * This code is derived from software contributed to Berkeley by
2781 * Chris Torek.
2782 *
2783 * Redistribution and use in source and binary forms, with or without
2784 * modification, are permitted provided that the following conditions
2785 * are met:
2786 * 1. Redistributions of source code must retain the above copyright
2787 * notice, this list of conditions and the following disclaimer.
2788 * 2. Redistributions in binary form must reproduce the above copyright
2789 * notice, this list of conditions and the following disclaimer in the
2790 * documentation and/or other materials provided with the distribution.
2791 * 3. Neither the name of the University nor the names of its contributors
2792 * may be used to endorse or promote products derived from this software
2793 * without specific prior written permission.
2794 *
2795 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2796 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2797 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2798 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2799 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2800 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2801 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2802 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2803 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2804 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2805 * SUCH DAMAGE.
2806 */
2807
2808The preceding notice is from src/missing/strcasestr.c in `file`.
2809
2810
2811
2812/*
2813 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
2814 *
2815 * Permission to use, copy, modify, and distribute this software for any
2816 * purpose with or without fee is hereby granted, provided that the above
2817 * copyright notice and this permission notice appear in all copies.
2818 *
2819 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2820 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2821 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2822 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2823 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2824 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2825 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2826 */
2827
2828The preceding notice is from src/missing/strlcat.c and src/missing/strlcpy.c in `file`.
2829
2830
2831
2832/*-
2833 * SPDX-License-Identifier: BSD-3-Clause
2834 *
2835 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
2836 * Copyright (c) 1992, 1993, 1994
2837 * The Regents of the University of California. All rights reserved.
2838 *
2839 * This code is derived from software contributed to Berkeley by
2840 * Henry Spencer.
2841 *
2842 * Redistribution and use in source and binary forms, with or without
2843 * modification, are permitted provided that the following conditions
2844 * are met:
2845 * 1. Redistributions of source code must retain the above copyright
2846 * notice, this list of conditions and the following disclaimer.
2847 * 2. Redistributions in binary form must reproduce the above copyright
2848 * notice, this list of conditions and the following disclaimer in the
2849 * documentation and/or other materials provided with the distribution.
2850 * 3. Neither the name of the University nor the names of its contributors
2851 * may be used to endorse or promote products derived from this software
2852 * without specific prior written permission.
2853 *
2854 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2855 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2856 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2857 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2858 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2859 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2860 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2861 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2862 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2863 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2864 * SUCH DAMAGE.
2865 *
2866 * @(#)utils.h 8.3 (Berkeley) 3/20/94
2867 * $FreeBSD: head/lib/libc/regex/utils.h 341838 2018-12-12 04:23:00Z yuripv $
2868 */
2869
2870The preceding notice is from src/missing/utils.h in `file`.
2871
2872
2873
2874/*-
2875 * Copyright (c) 2008, 2016 Christos Zoulas
2876 * All rights reserved.
2877 *
2878 * Redistribution and use in source and binary forms, with or without
2879 * modification, are permitted provided that the following conditions
2880 * are met:
2881 * 1. Redistributions of source code must retain the above copyright
2882 * notice, this list of conditions and the following disclaimer.
2883 * 2. Redistributions in binary form must reproduce the above copyright
2884 * notice, this list of conditions and the following disclaimer in the
2885 * documentation and/or other materials provided with the distribution.
2886 *
2887 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2888 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2889 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2890 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2891 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2892 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2893 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2894 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2895 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2896 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2897 * POSSIBILITY OF SUCH DAMAGE.
2898 */
2899
2900The preceding notice is from src/readcdf.c in `file`.
2901
2902
2903
2904/*-
2905 * Copyright (c) 1992 Henry Spencer.
2906 * Copyright (c) 1992, 1993
2907 * The Regents of the University of California. All rights reserved.
2908 *
2909 * This code is derived from software contributed to Berkeley by
2910 * Henry Spencer of the University of Toronto.
2911 *
2912 * Redistribution and use in source and binary forms, with or without
2913 * modification, are permitted provided that the following conditions
2914 * are met:
2915 * 1. Redistributions of source code must retain the above copyright
2916 * notice, this list of conditions and the following disclaimer.
2917 * 2. Redistributions in binary form must reproduce the above copyright
2918 * notice, this list of conditions and the following disclaimer in the
2919 * documentation and/or other materials provided with the distribution.
2920 * 3. Neither the name of the University nor the names of its contributors
2921 * may be used to endorse or promote products derived from this software
2922 * without specific prior written permission.
2923 *
2924 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2925 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2926 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2927 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2928 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2929 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2930 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2931 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2932 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2933 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2934 * SUCH DAMAGE.
2935 *
2936 * @(#)regex.h 8.2 (Berkeley) 1/3/94
2937 * $FreeBSD: src/include/regex.h,v 1.12 2010/02/16 19:39:50 imp Exp $
2938 */
2939
2940The preceding notice is from src/regex-bsd.h in `file`.
2941*/
2942/*
2943
2944Text of LICENSE from DROID:
2945
2946Copyright (c) 2016, The National Archives <pronom@nationalarchives.gov.uk>
2947All rights reserved.
2948
2949Redistribution and use in source and binary forms, with or without
2950modification, are permitted provided that the following
2951conditions are met:
2952
2953 * Redistributions of source code must retain the above copyright
2954 notice, this list of conditions and the following disclaimer.
2955
2956 * Redistributions in binary form must reproduce the above copyright
2957 notice, this list of conditions and the following disclaimer in the
2958 documentation and/or other materials provided with the distribution.
2959
2960 * Neither the name of the The National Archives nor the
2961 names of its contributors may be used to endorse or promote products
2962 derived from this software without specific prior written permission.
2963
2964THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2965AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2966IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2967PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
2968CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2969EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2970PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2971PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2972LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2973NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2974SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2975*/
2976
2977/*
2978
2979Text of LICENSE from fileid:
2980
2981The MIT License (MIT)
2982
2983Copyright (c) 2015 David B Heise
2984
2985Permission is hereby granted, free of charge, to any person obtaining a copy of
2986this software and associated documentation files (the "Software"), to deal in
2987the Software without restriction, including without limitation the rights to
2988use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
2989the Software, and to permit persons to whom the Software is furnished to do so,
2990subject to the following conditions:
2991
2992The above copyright notice and this permission notice shall be included in all
2993copies or substantial portions of the Software.
2994
2995THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2996IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
2997FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
2998COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
2999IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3000CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3001
3002
3003*/
3004
3005/*
3006Text of LICENSE from binwalk:
3007
3008
3009MIT License
3010
3011Copyright (c) 2024 devttys0
3012
3013Permission is hereby granted, free of charge, to any person obtaining a copy
3014of this software and associated documentation files (the "Software"), to deal
3015in the Software without restriction, including without limitation the rights
3016to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3017copies of the Software, and to permit persons to whom the Software is
3018furnished to do so, subject to the following conditions:
3019
3020The above copyright notice and this permission notice shall be included in all
3021copies or substantial portions of the Software.
3022
3023THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3024IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3025FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3026AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3027LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3028OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3029SOFTWARE.
3030
3031*/
3032
3033/*
3034Text of LICENSE from polyfile:
3035
3036
3037 Apache License
3038 Version 2.0, January 2004
3039 http://www.apache.org/licenses/
3040
3041 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
3042
3043 1. Definitions.
3044
3045 "License" shall mean the terms and conditions for use, reproduction,
3046 and distribution as defined by Sections 1 through 9 of this document.
3047
3048 "Licensor" shall mean the copyright owner or entity authorized by
3049 the copyright owner that is granting the License.
3050
3051 "Legal Entity" shall mean the union of the acting entity and all
3052 other entities that control, are controlled by, or are under common
3053 control with that entity. For the purposes of this definition,
3054 "control" means (i) the power, direct or indirect, to cause the
3055 direction or management of such entity, whether by contract or
3056 otherwise, or (ii) ownership of fifty percent (50%) or more of the
3057 outstanding shares, or (iii) beneficial ownership of such entity.
3058
3059 "You" (or "Your") shall mean an individual or Legal Entity
3060 exercising permissions granted by this License.
3061
3062 "Source" form shall mean the preferred form for making modifications,
3063 including but not limited to software source code, documentation
3064 source, and configuration files.
3065
3066 "Object" form shall mean any form resulting from mechanical
3067 transformation or translation of a Source form, including but
3068 not limited to compiled object code, generated documentation,
3069 and conversions to other media types.
3070
3071 "Work" shall mean the work of authorship, whether in Source or
3072 Object form, made available under the License, as indicated by a
3073 copyright notice that is included in or attached to the work
3074 (an example is provided in the Appendix below).
3075
3076 "Derivative Works" shall mean any work, whether in Source or Object
3077 form, that is based on (or derived from) the Work and for which the
3078 editorial revisions, annotations, elaborations, or other modifications
3079 represent, as a whole, an original work of authorship. For the purposes
3080 of this License, Derivative Works shall not include works that remain
3081 separable from, or merely link (or bind by name) to the interfaces of,
3082 the Work and Derivative Works thereof.
3083
3084 "Contribution" shall mean any work of authorship, including
3085 the original version of the Work and any modifications or additions
3086 to that Work or Derivative Works thereof, that is intentionally
3087 submitted to Licensor for inclusion in the Work by the copyright owner
3088 or by an individual or Legal Entity authorized to submit on behalf of
3089 the copyright owner. For the purposes of this definition, "submitted"
3090 means any form of electronic, verbal, or written communication sent
3091 to the Licensor or its representatives, including but not limited to
3092 communication on electronic mailing lists, source code control systems,
3093 and issue tracking systems that are managed by, or on behalf of, the
3094 Licensor for the purpose of discussing and improving the Work, but
3095 excluding communication that is conspicuously marked or otherwise
3096 designated in writing by the copyright owner as "Not a Contribution."
3097
3098 "Contributor" shall mean Licensor and any individual or Legal Entity
3099 on behalf of whom a Contribution has been received by Licensor and
3100 subsequently incorporated within the Work.
3101
3102 2. Grant of Copyright License. Subject to the terms and conditions of
3103 this License, each Contributor hereby grants to You a perpetual,
3104 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
3105 copyright license to reproduce, prepare Derivative Works of,
3106 publicly display, publicly perform, sublicense, and distribute the
3107 Work and such Derivative Works in Source or Object form.
3108
3109 3. Grant of Patent License. Subject to the terms and conditions of
3110 this License, each Contributor hereby grants to You a perpetual,
3111 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
3112 (except as stated in this section) patent license to make, have made,
3113 use, offer to sell, sell, import, and otherwise transfer the Work,
3114 where such license applies only to those patent claims licensable
3115 by such Contributor that are necessarily infringed by their
3116 Contribution(s) alone or by combination of their Contribution(s)
3117 with the Work to which such Contribution(s) was submitted. If You
3118 institute patent litigation against any entity (including a
3119 cross-claim or counterclaim in a lawsuit) alleging that the Work
3120 or a Contribution incorporated within the Work constitutes direct
3121 or contributory patent infringement, then any patent licenses
3122 granted to You under this License for that Work shall terminate
3123 as of the date such litigation is filed.
3124
3125 4. Redistribution. You may reproduce and distribute copies of the
3126 Work or Derivative Works thereof in any medium, with or without
3127 modifications, and in Source or Object form, provided that You
3128 meet the following conditions:
3129
3130 (a) You must give any other recipients of the Work or
3131 Derivative Works a copy of this License; and
3132
3133 (b) You must cause any modified files to carry prominent notices
3134 stating that You changed the files; and
3135
3136 (c) You must retain, in the Source form of any Derivative Works
3137 that You distribute, all copyright, patent, trademark, and
3138 attribution notices from the Source form of the Work,
3139 excluding those notices that do not pertain to any part of
3140 the Derivative Works; and
3141
3142 (d) If the Work includes a "NOTICE" text file as part of its
3143 distribution, then any Derivative Works that You distribute must
3144 include a readable copy of the attribution notices contained
3145 within such NOTICE file, excluding those notices that do not
3146 pertain to any part of the Derivative Works, in at least one
3147 of the following places: within a NOTICE text file distributed
3148 as part of the Derivative Works; within the Source form or
3149 documentation, if provided along with the Derivative Works; or,
3150 within a display generated by the Derivative Works, if and
3151 wherever such third-party notices normally appear. The contents
3152 of the NOTICE file are for informational purposes only and
3153 do not modify the License. You may add Your own attribution
3154 notices within Derivative Works that You distribute, alongside
3155 or as an addendum to the NOTICE text from the Work, provided
3156 that such additional attribution notices cannot be construed
3157 as modifying the License.
3158
3159 You may add Your own copyright statement to Your modifications and
3160 may provide additional or different license terms and conditions
3161 for use, reproduction, or distribution of Your modifications, or
3162 for any such Derivative Works as a whole, provided Your use,
3163 reproduction, and distribution of the Work otherwise complies with
3164 the conditions stated in this License.
3165
3166 5. Submission of Contributions. Unless You explicitly state otherwise,
3167 any Contribution intentionally submitted for inclusion in the Work
3168 by You to the Licensor shall be under the terms and conditions of
3169 this License, without any additional terms or conditions.
3170 Notwithstanding the above, nothing herein shall supersede or modify
3171 the terms of any separate license agreement you may have executed
3172 with Licensor regarding such Contributions.
3173
3174 6. Trademarks. This License does not grant permission to use the trade
3175 names, trademarks, service marks, or product names of the Licensor,
3176 except as required for reasonable and customary use in describing the
3177 origin of the Work and reproducing the content of the NOTICE file.
3178
3179 7. Disclaimer of Warranty. Unless required by applicable law or
3180 agreed to in writing, Licensor provides the Work (and each
3181 Contributor provides its Contributions) on an "AS IS" BASIS,
3182 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
3183 implied, including, without limitation, any warranties or conditions
3184 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
3185 PARTICULAR PURPOSE. You are solely responsible for determining the
3186 appropriateness of using or redistributing the Work and assume any
3187 risks associated with Your exercise of permissions under this License.
3188
3189 8. Limitation of Liability. In no event and under no legal theory,
3190 whether in tort (including negligence), contract, or otherwise,
3191 unless required by applicable law (such as deliberate and grossly
3192 negligent acts) or agreed to in writing, shall any Contributor be
3193 liable to You for damages, including any direct, indirect, special,
3194 incidental, or consequential damages of any character arising as a
3195 result of this License or out of the use or inability to use the
3196 Work (including but not limited to damages for loss of goodwill,
3197 work stoppage, computer failure or malfunction, or any and all
3198 other commercial damages or losses), even if such Contributor
3199 has been advised of the possibility of such damages.
3200
3201 9. Accepting Warranty or Additional Liability. While redistributing
3202 the Work or Derivative Works thereof, You may choose to offer,
3203 and charge a fee for, acceptance of support, warranty, indemnity,
3204 or other liability obligations and/or rights consistent with this
3205 License. However, in accepting such obligations, You may act only
3206 on Your own behalf and on Your sole responsibility, not on behalf
3207 of any other Contributor, and only if You agree to indemnify,
3208 defend, and hold each Contributor harmless for any liability
3209 incurred by, or claims asserted against, such Contributor by reason
3210 of your accepting any such warranty or additional liability.
3211
3212 END OF TERMS AND CONDITIONS
3213
3214 APPENDIX: How to apply the Apache License to your work.
3215
3216 To apply the Apache License to your work, attach the following
3217 boilerplate notice, with the fields enclosed by brackets "[]"
3218 replaced with your own identifying information. (Don't include
3219 the brackets!) The text should be enclosed in the appropriate
3220 comment syntax for the file format. We also recommend that a
3221 file or class name and description of purpose be included on the
3222 same "printed page" as the copyright notice for easier
3223 identification within third-party archives.
3224
3225 Copyright [yyyy] [name of copyright owner]
3226
3227 Licensed under the Apache License, Version 2.0 (the "License");
3228 you may not use this file except in compliance with the License.
3229 You may obtain a copy of the License at
3230
3231 http://www.apache.org/licenses/LICENSE-2.0
3232
3233 Unless required by applicable law or agreed to in writing, software
3234 distributed under the License is distributed on an "AS IS" BASIS,
3235 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3236 See the License for the specific language governing permissions and
3237 limitations under the License.
3238
3239*/