ctb_formats_detection/mime_derivation.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//! Build-time and runtime derivation of MIME type and extension mappings to
446//! authoritative Document Characters (Dcs) and Format IDs.
447
448#[allow(
449 unused_imports,
450 clippy::wildcard_imports,
451 reason = "Standard workspace module prelude"
452)]
453use crate::utilities::*;
454
455use crate::format_id::FormatId;
456use std::collections::HashMap;
457use std::sync::LazyLock;
458
459/// Mapping record associating an external MIME type or extension with an
460/// authoritative Document Character format definition.
461#[derive(Debug, Clone, PartialEq, Eq)]
462pub struct FormatMapping {
463 /// Authoritative workspace `FormatId` if a matching variant exists.
464 pub format_id: Option<FormatId>,
465 /// Global graph Document Character ID (offset by 2,228,224 for format Dcs).
466 pub dc_id: u128,
467 /// Short format ID (column 2 in format CSVs).
468 pub short_id: usize,
469 /// Identifier string (Rust-friendly ident from column 3).
470 pub ident: String,
471 /// Human-readable label (column 4).
472 pub label: String,
473 /// Category string (column 5).
474 pub category: String,
475 /// Associated primary and alternative file extensions.
476 pub extensions: Vec<String>,
477 /// Primary and alternative MIME types.
478 pub mime_types: Vec<String>,
479 /// Associated operating systems extracted from `@os(...)` format shorthands.
480 pub os_associations: Vec<FormatId>,
481 /// Associated Apple Uniform Type Identifiers (UTIs) from column 8.
482 pub apple_utis: Vec<String>,
483 /// Associated 4-character Apple Type / `OSType` codes from column 9.
484 pub apple_type_codes: Vec<[u8; 4]>,
485 /// Parent formats inherited from `@based_on(...)` or `@implies(...)`.
486 pub parent_formats: Vec<FormatId>,
487 /// Parent format names or shorthands inherited from `@based_on(...)` or `@implies(...)`.
488 pub parent_idents: Vec<String>,
489 /// Magic description strings extracted from `@magic_name(...)`.
490 pub magic_names: Vec<String>,
491}
492
493impl FormatMapping {
494 /// Checks whether this format is associated with or compatible with a target OS.
495 #[must_use]
496 pub fn matches_os(&self, target_os: FormatId) -> bool {
497 self.os_associations
498 .iter()
499 .any(|&cand_os| crate::detection::is_os_match(cand_os, target_os))
500 }
501}
502
503/// Universal directed inheritance graph representing format specialization
504/// and MIME inheritance relationships (`sub-class-of`).
505///
506/// Models subtype hierarchies across all workspace formats (whether or not
507/// they have an associated MIME type) as well as MIME media type hierarchies.
508#[derive(Debug, Default, Clone)]
509pub struct FormatInheritanceGraph {
510 parents_by_format: HashMap<FormatId, Vec<FormatId>>,
511 parents_by_ident: HashMap<String, Vec<String>>,
512 parents_by_mime: HashMap<String, Vec<String>>,
513}
514
515impl FormatInheritanceGraph {
516 /// Registers a parent format for a child format.
517 pub fn add_format_parent(&mut self, child: FormatId, parent: FormatId) {
518 if child == parent {
519 return;
520 }
521 let entry = self.parents_by_format.entry(child).or_default();
522 if !entry.contains(&parent) {
523 entry.push(parent);
524 }
525 }
526
527 /// Registers a parent format identity for a child format identity.
528 /// This works with inheritance relationships between formats with no MIME type.
529 pub fn add_ident_parent(&mut self, child: &str, parent: &str) {
530 let child_norm = child.trim().to_ascii_lowercase();
531 let parent_norm = parent.trim().to_ascii_lowercase();
532 if child_norm.is_empty()
533 || parent_norm.is_empty()
534 || child_norm == parent_norm
535 {
536 return;
537 }
538 let entry = self.parents_by_ident.entry(child_norm).or_default();
539 if !entry.contains(&parent_norm) {
540 entry.push(parent_norm);
541 }
542 }
543
544 /// Registers a parent MIME type for a child MIME type.
545 pub fn add_mime_parent(&mut self, child_mime: String, parent_mime: String) {
546 let child_norm = child_mime.trim().to_ascii_lowercase();
547 let parent_norm = parent_mime.trim().to_ascii_lowercase();
548 if child_norm.is_empty()
549 || parent_norm.is_empty()
550 || child_norm == parent_norm
551 {
552 return;
553 }
554 let entry = self.parents_by_mime.entry(child_norm).or_default();
555 if !entry.contains(&parent_norm) {
556 entry.push(parent_norm);
557 }
558 }
559
560 /// Checks whether `child` is a subclass/specialization of `parent`
561 /// (either directly or transitively).
562 #[must_use]
563 pub fn is_subclass_of(&self, child: FormatId, parent: FormatId) -> bool {
564 if child == parent {
565 return true;
566 }
567 let mut visited = Vec::new();
568 let mut queue = vec![child];
569 while let Some(current) = queue.pop() {
570 if visited.contains(¤t) {
571 continue;
572 }
573 visited.push(current);
574 if let Some(parents) = self.parents_by_format.get(¤t) {
575 for &p in parents {
576 if p == parent {
577 return true;
578 }
579 if !visited.contains(&p) {
580 queue.push(p);
581 }
582 }
583 }
584 }
585 let child_ident = format!("{child:?}");
586 let parent_ident = format!("{parent:?}");
587 self.is_ident_subclass_of(&child_ident, &parent_ident)
588 }
589
590 /// Checks whether `child` format identity is a subclass/specialization of `parent` format identity
591 /// (either directly or transitively). Works for formats with or without MIME types.
592 #[must_use]
593 pub fn is_ident_subclass_of(&self, child: &str, parent: &str) -> bool {
594 let child_norm = child.trim().to_ascii_lowercase();
595 let parent_norm = parent.trim().to_ascii_lowercase();
596 if child_norm == parent_norm {
597 return true;
598 }
599 let mut visited = Vec::new();
600 let mut queue = vec![child_norm];
601 while let Some(current) = queue.pop() {
602 if visited.contains(¤t) {
603 continue;
604 }
605 visited.push(current.clone());
606 if let Some(parents) = self.parents_by_ident.get(¤t) {
607 for p in parents {
608 if p == &parent_norm {
609 return true;
610 }
611 if !visited.contains(p) {
612 queue.push(p.clone());
613 }
614 }
615 }
616 }
617 false
618 }
619
620 /// Checks whether `child_mime` is a subclass of `parent_mime`
621 /// (either directly or transitively).
622 #[must_use]
623 pub fn is_mime_subclass_of(
624 &self,
625 child_mime: &str,
626 parent_mime: &str,
627 ) -> bool {
628 let child_norm = child_mime.trim().to_ascii_lowercase();
629 let parent_norm = parent_mime.trim().to_ascii_lowercase();
630 if child_norm == parent_norm {
631 return true;
632 }
633 if ctb_formats_mime::is_mime_subclass_of(&child_norm, &parent_norm) {
634 return true;
635 }
636 let mut visited = Vec::new();
637 let mut queue = vec![child_norm];
638 while let Some(current) = queue.pop() {
639 if visited.contains(¤t) {
640 continue;
641 }
642 visited.push(current.clone());
643
644 let mut dynamic_parents = Vec::new();
645 if current.ends_with("+xml") && current != "application/xml" {
646 dynamic_parents.push("application/xml".to_string());
647 }
648 if current == "application/xml"
649 || current == "text/xml"
650 || (current.starts_with("text/") && current != "text/plain")
651 || current.ends_with("+json")
652 {
653 dynamic_parents.push("text/plain".to_string());
654 }
655 if (current.ends_with("+zip")
656 || current.starts_with(
657 "application/vnd.openxmlformats-officedocument.",
658 )
659 || current.starts_with("application/vnd.oasis.opendocument.")
660 || current == "application/java-archive"
661 || current == "application/vnd.android.package-archive")
662 && current != "application/zip"
663 {
664 dynamic_parents.push("application/zip".to_string());
665 }
666 if current.ends_with("+json") && current != "application/json" {
667 dynamic_parents.push("application/json".to_string());
668 }
669 if (current == "application/vnd.gentoo.gpkg"
670 || current.ends_with("+tar"))
671 && current != "application/x-tar"
672 {
673 dynamic_parents.push("application/x-tar".to_string());
674 }
675 if (current == "application/x-hwp"
676 || current == "application/msword"
677 || current == "application/vnd.ms-excel"
678 || current == "application/vnd.ms-powerpoint")
679 && current != "application/x-ole-storage"
680 {
681 dynamic_parents.push("application/x-ole-storage".to_string());
682 }
683 if current == "image/apng" {
684 dynamic_parents.push("image/png".to_string());
685 }
686
687 for dp in dynamic_parents {
688 if dp == parent_norm {
689 return true;
690 }
691 if !visited.contains(&dp) {
692 queue.push(dp);
693 }
694 }
695
696 if let Some(parents) = self.parents_by_mime.get(¤t) {
697 for p in parents {
698 if p == &parent_norm {
699 return true;
700 }
701 if !visited.contains(p) {
702 queue.push(p.clone());
703 }
704 }
705 }
706 }
707 false
708 }
709
710 /// Returns direct and indirect ancestors of a format.
711 #[must_use]
712 pub fn ancestors(&self, format: FormatId) -> Vec<FormatId> {
713 let mut ancestors = Vec::new();
714 let mut queue = vec![format];
715 while let Some(current) = queue.pop() {
716 if let Some(parents) = self.parents_by_format.get(¤t) {
717 for &p in parents {
718 if !ancestors.contains(&p) {
719 ancestors.push(p);
720 queue.push(p);
721 }
722 }
723 }
724 }
725 ancestors
726 }
727
728 /// Returns direct and indirect ancestors of a format by ident string.
729 #[must_use]
730 pub fn ident_ancestors(&self, ident: &str) -> Vec<String> {
731 let mut ancestors = Vec::new();
732 let mut queue = vec![ident.trim().to_ascii_lowercase()];
733 while let Some(current) = queue.pop() {
734 if let Some(parents) = self.parents_by_ident.get(¤t) {
735 for p in parents {
736 if !ancestors.contains(p) {
737 ancestors.push(p.clone());
738 queue.push(p.clone());
739 }
740 }
741 }
742 }
743 ancestors
744 }
745}
746
747/// Consolidated lookup table mapping MIME types, extensions, and idents to
748/// format mappings.
749#[derive(Debug, Default)]
750pub struct FormatCatalog {
751 by_mime: HashMap<String, FormatMapping>,
752 by_ident: HashMap<String, FormatMapping>,
753 by_extension: HashMap<String, Vec<FormatMapping>>,
754 by_apple_type: HashMap<[u8; 4], FormatMapping>,
755 by_apple_uti: HashMap<String, FormatMapping>,
756 by_format_id: HashMap<FormatId, FormatMapping>,
757 by_magic_name: HashMap<String, FormatMapping>,
758 sorted_magic_names: Vec<(String, FormatMapping)>,
759 inheritance: FormatInheritanceGraph,
760}
761
762impl FormatCatalog {
763 /// Creates a new catalog by parsing the formats dataset.
764 pub fn build() -> Self {
765 let mut catalog = Self::default();
766
767 // Populate from the canonical seed graph format definitions in ctb_formats_dcdata
768 for defn in ctb_formats_dcdata::get_all_format_defns() {
769 let dc_id = defn.dc_id;
770 let Some(short_id) = defn.short_id else {
771 continue;
772 };
773 let Some(fmt) = &defn.format else {
774 continue;
775 };
776
777 // Reason for fallback: formats without a Rust identifier have an empty ident string in FormatMapping.
778 let ident = defn.ident.clone().unwrap_or_default();
779 let label = defn.name.clone();
780 // Reason for fallback: script strings without the ".Formats:" prefix are already bare category names.
781 let category = defn
782 .script
783 .strip_prefix(".Formats:")
784 .unwrap_or(&defn.script)
785 .to_string();
786 // Reason for fallback: formats without extensions have an empty extension list.
787 let ext_field = fmt.extensions.as_deref().unwrap_or("");
788 // Reason for fallback: formats without MIME types have an empty MIME list.
789 let mime_field = fmt.mime.as_deref().unwrap_or("");
790
791 let extensions: Vec<String> = ext_field
792 .split(',')
793 .map(|s| {
794 let trimmed = s.trim().trim_matches('"');
795 // Reason for fallback: extensions without a leading dot are already bare extensions
796 trimmed.strip_prefix('.').unwrap_or(trimmed).to_string()
797 })
798 .filter(|s| !s.is_empty())
799 .collect();
800
801 let mime_types: Vec<String> = mime_field
802 .split(',')
803 .map(|s| s.trim().trim_matches('"').to_ascii_lowercase())
804 .filter(|s| !s.is_empty())
805 .collect();
806
807 let mut os_associations = Vec::new();
808 for os_shorthand in &defn.os_associations {
809 if let Some(fid) = FormatId::from_shorthand(os_shorthand) {
810 if !os_associations.contains(&fid) {
811 os_associations.push(fid);
812 }
813 }
814 }
815
816 let mut parent_formats = Vec::new();
817 let mut parent_idents = Vec::new();
818 for parent_expr in defn.implies.iter().chain(defn.based_on.iter()) {
819 for token in parent_expr.split(['&', '|', ',', ' ']) {
820 let trimmed = token.trim();
821 if trimmed.is_empty() {
822 continue;
823 }
824 if !parent_idents.contains(&trimmed.to_string()) {
825 parent_idents.push(trimmed.to_string());
826 }
827 if let Some(parent_fid) = FormatId::from_shorthand(trimmed)
828 {
829 if !parent_formats.contains(&parent_fid) {
830 parent_formats.push(parent_fid);
831 }
832 }
833 }
834 }
835 let magic_names = defn.magic_names.clone();
836
837 // Reason for fallback: formats without Apple UTIs have an empty UTI list.
838 let uti_field = fmt.uti.as_deref().unwrap_or("");
839 // Reason for fallback: formats without Apple OSType codes have an empty code list.
840 let apple_type_field = fmt.apple_type.as_deref().unwrap_or("");
841
842 let apple_utis: Vec<String> = uti_field
843 .split(',')
844 .map(|s| s.trim().trim_matches('"').to_string())
845 .filter(|s| !s.is_empty())
846 .collect();
847
848 let apple_type_codes: Vec<[u8; 4]> = apple_type_field
849 .split(',')
850 .filter_map(|s| {
851 let trimmed = s.trim().trim_matches('"').trim_matches('\'');
852 let bytes = trimmed.as_bytes();
853 if bytes.len() == 4 {
854 let mut arr = [0u8; 4];
855 arr.copy_from_slice(bytes);
856 Some(arr)
857 } else if !bytes.is_empty() && bytes.len() < 4 {
858 let mut arr = [b' '; 4];
859 if let Some(target) = arr.get_mut(..bytes.len()) {
860 target.copy_from_slice(bytes);
861 Some(arr)
862 } else {
863 None
864 }
865 } else {
866 None
867 }
868 })
869 .collect();
870
871 // Reason for fallback: formats without nicknames have an empty nickname list.
872 let nicknames_field = fmt.nicknames.as_deref().unwrap_or("");
873 let nicknames: Vec<String> = nicknames_field
874 .split(',')
875 .map(|s| s.trim().trim_matches('"').to_string())
876 .filter(|s| !s.is_empty())
877 .collect();
878
879 let format_id = FormatId::from_ident(&ident);
880
881 let mapping = FormatMapping {
882 format_id,
883 dc_id,
884 short_id,
885 ident: ident.clone(),
886 label,
887 category,
888 extensions: extensions.clone(),
889 mime_types: mime_types.clone(),
890 os_associations,
891 apple_utis: apple_utis.clone(),
892 apple_type_codes: apple_type_codes.clone(),
893 parent_formats,
894 parent_idents,
895 magic_names: magic_names.clone(),
896 };
897
898 if !ident.is_empty() {
899 catalog
900 .by_ident
901 .insert(ident.to_ascii_lowercase(), mapping.clone());
902 }
903
904 for nick in nicknames {
905 catalog
906 .by_ident
907 .entry(nick.to_ascii_lowercase())
908 .or_insert_with(|| mapping.clone());
909 }
910
911 for mn in magic_names {
912 catalog
913 .by_magic_name
914 .entry(mn.trim().to_ascii_lowercase())
915 .or_insert_with(|| mapping.clone());
916 }
917
918 for mime in mime_types {
919 catalog
920 .by_mime
921 .entry(mime)
922 .or_insert_with(|| mapping.clone());
923 }
924
925 for ext in extensions {
926 catalog
927 .by_extension
928 .entry(ext.to_ascii_lowercase())
929 .or_default()
930 .push(mapping.clone());
931 }
932
933 for &type_code in &apple_type_codes {
934 catalog
935 .by_apple_type
936 .entry(type_code)
937 .or_insert_with(|| mapping.clone());
938 }
939
940 for uti in &apple_utis {
941 catalog
942 .by_apple_uti
943 .entry(uti.to_ascii_lowercase())
944 .or_insert_with(|| mapping.clone());
945 }
946
947 if let Some(fid) = format_id {
948 catalog.by_format_id.insert(fid, mapping.clone());
949 }
950 }
951
952 // Ingest supplementary MIME-to-extension mappings from the embedded
953 // Apache HTTPD MIME database via ctb-formats-mime.
954 if let Some(httpd_bytes) = ctb_formats_mime::get_httpd_mime_types() {
955 if let Ok(content) = std::str::from_utf8(httpd_bytes) {
956 for (mime_lower, exts) in
957 ctb_formats_mime::parse_apache_mime_types(content)
958 {
959 if !catalog.by_mime.contains_key(&mime_lower) {
960 for ext in &exts {
961 if let Some(candidates) =
962 catalog.by_extension.get(ext)
963 {
964 if let Some(m) = candidates.first() {
965 catalog
966 .by_mime
967 .insert(mime_lower.clone(), m.clone());
968 break;
969 }
970 }
971 }
972 }
973 }
974 }
975 }
976
977 // Populate inheritance graph edges from format relationships and MIME subtypes
978 for mapping in catalog.by_ident.values() {
979 for parent_ident in &mapping.parent_idents {
980 catalog
981 .inheritance
982 .add_ident_parent(&mapping.ident, parent_ident);
983 }
984 if let Some(child_id) = mapping.format_id {
985 for &parent_id in &mapping.parent_formats {
986 catalog.inheritance.add_format_parent(child_id, parent_id);
987 }
988 }
989 if let Some(child_mime) = mapping.mime_types.first() {
990 for &parent_id in &mapping.parent_formats {
991 if let Some(parent_mapping) =
992 catalog.by_format_id.get(&parent_id)
993 {
994 if let Some(parent_mime) =
995 parent_mapping.mime_types.first()
996 {
997 catalog.inheritance.add_mime_parent(
998 child_mime.clone(),
999 parent_mime.clone(),
1000 );
1001 }
1002 }
1003 }
1004 if child_mime.ends_with("+xml")
1005 && child_mime != "application/xml"
1006 {
1007 catalog.inheritance.add_mime_parent(
1008 child_mime.clone(),
1009 "application/xml".to_string(),
1010 );
1011 }
1012 if child_mime == "application/xml"
1013 || child_mime == "text/xml"
1014 || (child_mime.starts_with("text/")
1015 && child_mime != "text/plain")
1016 || child_mime.ends_with("+json")
1017 {
1018 catalog.inheritance.add_mime_parent(
1019 child_mime.clone(),
1020 "text/plain".to_string(),
1021 );
1022 }
1023 if child_mime.ends_with("+zip")
1024 && child_mime != "application/zip"
1025 {
1026 catalog.inheritance.add_mime_parent(
1027 child_mime.clone(),
1028 "application/zip".to_string(),
1029 );
1030 }
1031 }
1032 }
1033
1034 let mut sorted: Vec<(String, FormatMapping)> = catalog
1035 .by_magic_name
1036 .iter()
1037 .map(|(k, v)| (k.clone(), v.clone()))
1038 .collect();
1039 sorted.sort_by(|a, b| b.0.len().cmp(&a.0.len()));
1040 catalog.sorted_magic_names = sorted;
1041
1042 catalog
1043 }
1044
1045 /// Looks up a format mapping by 4-byte Apple Type / `OSType` code.
1046 #[must_use]
1047 pub fn lookup_apple_type_code(
1048 &self,
1049 code: &[u8; 4],
1050 ) -> Option<&FormatMapping> {
1051 self.by_apple_type.get(code)
1052 }
1053
1054 /// Looks up a format mapping by Apple Uniform Type Identifier (UTI).
1055 #[must_use]
1056 pub fn lookup_apple_uti(&self, uti: &str) -> Option<&FormatMapping> {
1057 self.by_apple_uti.get(&uti.trim().to_ascii_lowercase())
1058 }
1059
1060 /// Looks up a format mapping by its authoritative `FormatId`.
1061 #[must_use]
1062 pub fn lookup_format_id(
1063 &self,
1064 format_id: FormatId,
1065 ) -> Option<&FormatMapping> {
1066 self.by_format_id.get(&format_id)
1067 }
1068
1069 /// Reference to the global format inheritance graph.
1070 #[must_use]
1071 pub const fn inheritance(&self) -> &FormatInheritanceGraph {
1072 &self.inheritance
1073 }
1074
1075 /// Checks whether `child` is a subclass of `parent` in the inheritance graph.
1076 #[must_use]
1077 pub fn is_subclass_of(&self, child: FormatId, parent: FormatId) -> bool {
1078 self.inheritance.is_subclass_of(child, parent)
1079 }
1080
1081 /// Checks whether `child` format identity is a subclass of `parent` format identity.
1082 /// Works for formats with or without MIME types.
1083 #[must_use]
1084 pub fn is_ident_subclass_of(&self, child: &str, parent: &str) -> bool {
1085 self.inheritance.is_ident_subclass_of(child, parent)
1086 }
1087
1088 /// Checks whether `child_mime` is a subclass of `parent_mime`.
1089 #[must_use]
1090 pub fn is_mime_subclass_of(
1091 &self,
1092 child_mime: &str,
1093 parent_mime: &str,
1094 ) -> bool {
1095 if self
1096 .inheritance
1097 .is_mime_subclass_of(child_mime, parent_mime)
1098 {
1099 return true;
1100 }
1101 if let (Some(c_fmt), Some(p_fmt)) = (
1102 self.lookup_mime(child_mime).and_then(|m| m.format_id),
1103 self.lookup_mime(parent_mime).and_then(|m| m.format_id),
1104 ) {
1105 return self.is_subclass_of(c_fmt, p_fmt);
1106 }
1107 false
1108 }
1109
1110 /// Looks up a format mapping by exact MIME type.
1111 pub fn lookup_mime(&self, mime: &str) -> Option<&FormatMapping> {
1112 let normalized = mime.trim().to_ascii_lowercase();
1113 self.by_mime.get(&normalized)
1114 }
1115
1116 /// Looks up a format mapping by format identifier name.
1117 pub fn lookup_ident(&self, ident: &str) -> Option<&FormatMapping> {
1118 let normalized = ident.trim().to_ascii_lowercase();
1119 self.by_ident.get(&normalized)
1120 }
1121
1122 /// Looks up a format mapping by libmagic description string (exact match or longest prefix match).
1123 #[must_use]
1124 pub fn lookup_magic_name(
1125 &self,
1126 description: &str,
1127 ) -> Option<&FormatMapping> {
1128 let trimmed = description.trim();
1129 if trimmed.is_empty() {
1130 return None;
1131 }
1132 let normalized = trimmed.to_ascii_lowercase();
1133 // 1. Exact match
1134 if let Some(m) = self.by_magic_name.get(&normalized) {
1135 return Some(m);
1136 }
1137 // 2. Longest prefix match
1138 for (prefix, mapping) in &self.sorted_magic_names {
1139 if normalized.starts_with(prefix) {
1140 if normalized.len() == prefix.len() {
1141 return Some(mapping);
1142 }
1143 if let Some(next_char) = normalized
1144 .get(prefix.len()..)
1145 .and_then(|s| s.chars().next())
1146 {
1147 if next_char.is_whitespace()
1148 || next_char == ','
1149 || next_char == ':'
1150 || next_char == ';'
1151 || next_char == '-'
1152 || next_char == '('
1153 {
1154 return Some(mapping);
1155 }
1156 }
1157 }
1158 }
1159 None
1160 }
1161
1162 /// Looks up a format mapping by format identifier name or exact nickname.
1163 pub fn lookup_description_or_ident(
1164 &self,
1165 text: &str,
1166 ) -> Option<&FormatMapping> {
1167 let trimmed = text.trim();
1168 if trimmed.is_empty() {
1169 return None;
1170 }
1171 self.lookup_ident(trimmed)
1172 }
1173
1174 /// Looks up candidate format mappings for an extension.
1175 pub fn lookup_extension(&self, ext: &str) -> &[FormatMapping] {
1176 let trimmed = ext.trim().trim_start_matches('.');
1177 let normalized = trimmed.to_ascii_lowercase();
1178 match self.by_extension.get(&normalized) {
1179 Some(list) => list.as_slice(),
1180 None => &[],
1181 }
1182 }
1183}
1184
1185/// Global shared format catalog instance.
1186pub static FORMAT_CATALOG: LazyLock<FormatCatalog> =
1187 LazyLock::new(FormatCatalog::build);
1188
1189#[cfg(test)]
1190#[allow(
1191 clippy::panic,
1192 clippy::expect_used,
1193 clippy::unwrap_used,
1194 clippy::unwrap_in_result,
1195 clippy::panic_in_result_fn,
1196 clippy::indexing_slicing,
1197 clippy::arithmetic_side_effects,
1198 reason = "Standard repository test boilerplate"
1199)]
1200mod tests {
1201 use super::*;
1202
1203 #[ctb_test]
1204 fn test_format_inheritance_graph_non_mime() {
1205 let mut graph = FormatInheritanceGraph::default();
1206 // Models relationships between formats that have NO MIME type
1207 graph.add_ident_parent("U32", "Integer");
1208 graph.add_ident_parent("Integer", "AbstractNumber");
1209
1210 assert!(graph.is_ident_subclass_of("U32", "Integer"));
1211 assert!(graph.is_ident_subclass_of("U32", "AbstractNumber"));
1212 assert!(graph.is_ident_subclass_of("Integer", "AbstractNumber"));
1213 assert!(!graph.is_ident_subclass_of("Integer", "U32"));
1214 assert!(!graph.is_ident_subclass_of("AbstractNumber", "U32"));
1215 assert_eq!(
1216 graph.ident_ancestors("U32"),
1217 vec!["integer".to_string(), "abstractnumber".to_string()]
1218 );
1219 }
1220
1221 #[ctb_test]
1222 fn test_format_inheritance_graph_mime_structural() {
1223 let graph = &FORMAT_CATALOG.inheritance;
1224 // SVG specializes XML
1225 assert!(graph.is_mime_subclass_of("image/svg+xml", "application/xml"));
1226 // XML specializes text/plain
1227 assert!(graph.is_mime_subclass_of("application/xml", "text/plain"));
1228 // Transitive: SVG specializes text/plain
1229 assert!(graph.is_mime_subclass_of("image/svg+xml", "text/plain"));
1230 }
1231
1232 #[ctb_test]
1233 fn test_format_catalog_apple_type_lookup() {
1234 // Confirm dynamic catalog lookups without hardcoded mappings in code
1235 let text_res = FORMAT_CATALOG.lookup_apple_type_code(b"TEXT");
1236 if let Some(m) = text_res {
1237 assert!(
1238 m.ident.contains("text")
1239 || m.category.contains("text")
1240 || m.mime_types.contains(&"text/plain".to_string())
1241 );
1242 }
1243 }
1244}
1245/*
1246/*
1247 * Adapted from: apptype.c, Written by Eberhard Mattes and put into the
1248 * file_public domain
1249 *
1250 * Notes: 1. Qualify the filename so that DosQueryAppType does not do extraneous
1251 * searches.
1252 *
1253 * 2. DosQueryAppType will return FAPPTYP_DOS on a file ending with ".com"
1254 * (other than an OS/2 exe or Win exe with this name). Eberhard Mattes
1255 * remarks Tue, 6 Apr 93: Moreover, it reports the type of the (new and very
1256 * bug ridden) Win Emacs as "OS/2 executable".
1257 *
1258 * 3. apptype() uses the filename if given, otherwise a tmp file is created with
1259 * the contents of buf. If buf is not the complete file, apptype can
1260 * incorrectly identify the exe type. The "-z" option of "file" is the reason
1261 * for this ugly code.
1262 */
1263
1264The preceding notice is from src/apptype.c in `file`.
1265
1266
1267
1268/*-
1269 * Copyright (c) 2008 Christos Zoulas
1270 * All rights reserved.
1271 *
1272 * Redistribution and use in source and binary forms, with or without
1273 * modification, are permitted provided that the following conditions
1274 * are met:
1275 * 1. Redistributions of source code must retain the above copyright
1276 * notice, this list of conditions and the following disclaimer.
1277 * 2. Redistributions in binary form must reproduce the above copyright
1278 * notice, this list of conditions and the following disclaimer in the
1279 * documentation and/or other materials provided with the distribution.
1280 *
1281 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1282 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1283 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1284 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1285 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1286 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1287 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1288 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1289 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1290 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1291 * POSSIBILITY OF SUCH DAMAGE.
1292 */
1293
1294The preceding notice is from src/cdf.c, src/cdf.h, and src/cdf_time.c in `file`.
1295
1296
1297
1298/*-
1299 * Copyright (c) 2016 Christos Zoulas
1300 * All rights reserved.
1301 *
1302 * Redistribution and use in source and binary forms, with or without
1303 * modification, are permitted provided that the following conditions
1304 * are met:
1305 * 1. Redistributions of source code must retain the above copyright
1306 * notice, this list of conditions and the following disclaimer.
1307 * 2. Redistributions in binary form must reproduce the above copyright
1308 * notice, this list of conditions and the following disclaimer in the
1309 * documentation and/or other materials provided with the distribution.
1310 *
1311 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1312 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1313 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1314 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1315 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1316 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1317 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1318 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1319 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1320 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1321 * POSSIBILITY OF SUCH DAMAGE.
1322 */
1323
1324The preceding notice is from src/der.c and src/der.h in `file`.
1325
1326
1327
1328/*-
1329 * Copyright (c) 2019 Christos Zoulas
1330 * All rights reserved.
1331 *
1332 * Redistribution and use in source and binary forms, with or without
1333 * modification, are permitted provided that the following conditions
1334 * are met:
1335 * 1. Redistributions of source code must retain the above copyright
1336 * notice, this list of conditions and the following disclaimer.
1337 * 2. Redistributions in binary form must reproduce the above copyright
1338 * notice, this list of conditions and the following disclaimer in the
1339 * documentation and/or other materials provided with the distribution.
1340 *
1341 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1342 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1343 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1344 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1345 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1346 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1347 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1348 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1349 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1350 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1351 * POSSIBILITY OF SUCH DAMAGE.
1352 */
1353
1354The preceding notice is from src/is_csv.c in `file`.
1355
1356
1357
1358/*-
1359 * Copyright (c) 2018 Christos Zoulas
1360 * All rights reserved.
1361 *
1362 * Redistribution and use in source and binary forms, with or without
1363 * modification, are permitted provided that the following conditions
1364 * are met:
1365 * 1. Redistributions of source code must retain the above copyright
1366 * notice, this list of conditions and the following disclaimer.
1367 * 2. Redistributions in binary form must reproduce the above copyright
1368 * notice, this list of conditions and the following disclaimer in the
1369 * documentation and/or other materials provided with the distribution.
1370 *
1371 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1372 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1373 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1374 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1375 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1376 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1377 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1378 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1379 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1380 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1381 * POSSIBILITY OF SUCH DAMAGE.
1382 */
1383
1384The preceding notice is from src/is_json.c in `file`.
1385
1386
1387
1388/*-
1389 * Copyright (c) 2023 Christos Zoulas
1390 * All rights reserved.
1391 *
1392 * Redistribution and use in source and binary forms, with or without
1393 * modification, are permitted provided that the following conditions
1394 * are met:
1395 * 1. Redistributions of source code must retain the above copyright
1396 * notice, this list of conditions and the following disclaimer.
1397 * 2. Redistributions in binary form must reproduce the above copyright
1398 * notice, this list of conditions and the following disclaimer in the
1399 * documentation and/or other materials provided with the distribution.
1400 *
1401 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1402 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1403 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1404 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1405 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1406 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1407 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1408 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1409 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1410 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1411 * POSSIBILITY OF SUCH DAMAGE.
1412 */
1413
1414The preceding notice is from src/is_simh.c in `file`.
1415
1416
1417
1418/*-
1419 * SPDX-License-Identifier: BSD-3-Clause
1420 *
1421 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1422 * Copyright (c) 1992, 1993, 1994
1423 * The Regents of the University of California. All rights reserved.
1424 *
1425 * This code is derived from software contributed to Berkeley by
1426 * Henry Spencer.
1427 *
1428 * Redistribution and use in source and binary forms, with or without
1429 * modification, are permitted provided that the following conditions
1430 * are met:
1431 * 1. Redistributions of source code must retain the above copyright
1432 * notice, this list of conditions and the following disclaimer.
1433 * 2. Redistributions in binary form must reproduce the above copyright
1434 * notice, this list of conditions and the following disclaimer in the
1435 * documentation and/or other materials provided with the distribution.
1436 * 3. Neither the name of the University nor the names of its contributors
1437 * may be used to endorse or promote products derived from this software
1438 * without specific prior written permission.
1439 *
1440 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1441 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1442 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1443 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1444 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1445 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1446 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1447 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1448 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1449 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1450 * SUCH DAMAGE.
1451 *
1452 * @(#)cname.h 8.3 (Berkeley) 3/20/94
1453 * $FreeBSD: head/lib/libc/regex/cname.h 326025 2017-11-20 19:49:47Z pfg $
1454 */
1455
1456The preceding notice is from src/missing/cname.h in `file`.
1457
1458
1459
1460/*-
1461 * SPDX-License-Identifier: BSD-3-Clause
1462 *
1463 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1464 * Copyright (c) 1992, 1993, 1994
1465 * The Regents of the University of California. All rights reserved.
1466 *
1467 * This code is derived from software contributed to Berkeley by
1468 * Henry Spencer.
1469 *
1470 * Redistribution and use in source and binary forms, with or without
1471 * modification, are permitted provided that the following conditions
1472 * are met:
1473 * 1. Redistributions of source code must retain the above copyright
1474 * notice, this list of conditions and the following disclaimer.
1475 * 2. Redistributions in binary form must reproduce the above copyright
1476 * notice, this list of conditions and the following disclaimer in the
1477 * documentation and/or other materials provided with the distribution.
1478 * 3. Neither the name of the University nor the names of its contributors
1479 * may be used to endorse or promote products derived from this software
1480 * without specific prior written permission.
1481 *
1482 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1483 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1484 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1485 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1486 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1487 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1488 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1489 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1490 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1491 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1492 * SUCH DAMAGE.
1493 *
1494 * @(#)engine.c 8.5 (Berkeley) 3/20/94
1495 */
1496
1497The preceding notice is from src/missing/engine.c in `file`.
1498
1499
1500
1501/*-
1502 * Copyright (c) 2000 The NetBSD Foundation, Inc.
1503 * All rights reserved.
1504 *
1505 * This code was contributed to The NetBSD Foundation by Allen Briggs.
1506 *
1507 * Redistribution and use in source and binary forms, with or without
1508 * modification, are permitted provided that the following conditions
1509 * are met:
1510 * 1. Redistributions of source code must retain the above copyright
1511 * notice, this list of conditions and the following disclaimer.
1512 * 2. Redistributions in binary form must reproduce the above copyright
1513 * notice, this list of conditions and the following disclaimer in the
1514 * documentation and/or other materials provided with the distribution.
1515 *
1516 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1517 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1518 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1519 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1520 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1521 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1522 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1523 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1524 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1525 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1526 * POSSIBILITY OF SUCH DAMAGE.
1527 */
1528
1529The preceding notice is from src/missing/fmtcheck.c in `file`.
1530
1531
1532
1533/*-
1534 * Copyright (c) 2011 The NetBSD Foundation, Inc.
1535 * All rights reserved.
1536 *
1537 * This code is derived from software contributed to The NetBSD Foundation
1538 * by Christos Zoulas.
1539 *
1540 * Redistribution and use in source and binary forms, with or without
1541 * modification, are permitted provided that the following conditions
1542 * are met:
1543 * 1. Redistributions of source code must retain the above copyright
1544 * notice, this list of conditions and the following disclaimer.
1545 * 2. Redistributions in binary form must reproduce the above copyright
1546 * notice, this list of conditions and the following disclaimer in the
1547 * documentation and/or other materials provided with the distribution.
1548 *
1549 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1550 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1551 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1552 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1553 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1554 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1555 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1556 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1557 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1558 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1559 * POSSIBILITY OF SUCH DAMAGE.
1560 */
1561
1562The preceding notice is from src/missing/getline.c in `file`.
1563
1564
1565
1566/*-
1567 * Copyright (c) 2000 The NetBSD Foundation, Inc.
1568 * All rights reserved.
1569 *
1570 * This code is derived from software contributed to The NetBSD Foundation
1571 * by Dieter Baron and Thomas Klausner.
1572 *
1573 * Redistribution and use in source and binary forms, with or without
1574 * modification, are permitted provided that the following conditions
1575 * are met:
1576 * 1. Redistributions of source code must retain the above copyright
1577 * notice, this list of conditions and the following disclaimer.
1578 * 2. Redistributions in binary form must reproduce the above copyright
1579 * notice, this list of conditions and the following disclaimer in the
1580 * documentation and/or other materials provided with the distribution.
1581 *
1582 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1583 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1584 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1585 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1586 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1587 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1588 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1589 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1590 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1591 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1592 * POSSIBILITY OF SUCH DAMAGE.
1593 */
1594
1595The preceding notice is from src/missing/getopt_long.c and src/mygetopt.h in `file`.
1596
1597
1598
1599/*
1600 * Public domain fallback for reallocarray(3), for platforms (e.g.
1601 * AmigaOS/libnix) whose C library declares it but does not implement it.
1602 */
1603
1604The preceding notice is from src/missing/reallocarray.c in `file`.
1605
1606
1607
1608/*-
1609 * SPDX-License-Identifier: BSD-3-Clause
1610 *
1611 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1612 * Copyright (c) 1992, 1993, 1994
1613 * The Regents of the University of California. All rights reserved.
1614 *
1615 * Copyright (c) 2011 The FreeBSD Foundation
1616 * All rights reserved.
1617 * Portions of this software were developed by David Chisnall
1618 * under sponsorship from the FreeBSD Foundation.
1619 *
1620 * This code is derived from software contributed to Berkeley by
1621 * Henry Spencer.
1622 *
1623 * Redistribution and use in source and binary forms, with or without
1624 * modification, are permitted provided that the following conditions
1625 * are met:
1626 * 1. Redistributions of source code must retain the above copyright
1627 * notice, this list of conditions and the following disclaimer.
1628 * 2. Redistributions in binary form must reproduce the above copyright
1629 * notice, this list of conditions and the following disclaimer in the
1630 * documentation and/or other materials provided with the distribution.
1631 * 3. Neither the name of the University nor the names of its contributors
1632 * may be used to endorse or promote products derived from this software
1633 * without specific prior written permission.
1634 *
1635 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1636 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1637 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1638 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1639 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1640 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1641 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1642 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1643 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1644 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1645 * SUCH DAMAGE.
1646 *
1647 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
1648 */
1649
1650The preceding notice is from src/missing/regcomp.c in `file`.
1651
1652
1653
1654/*-
1655 * SPDX-License-Identifier: BSD-3-Clause
1656 *
1657 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1658 * Copyright (c) 1992, 1993, 1994
1659 * The Regents of the University of California. All rights reserved.
1660 *
1661 * This code is derived from software contributed to Berkeley by
1662 * Henry Spencer.
1663 *
1664 * Redistribution and use in source and binary forms, with or without
1665 * modification, are permitted provided that the following conditions
1666 * are met:
1667 * 1. Redistributions of source code must retain the above copyright
1668 * notice, this list of conditions and the following disclaimer.
1669 * 2. Redistributions in binary form must reproduce the above copyright
1670 * notice, this list of conditions and the following disclaimer in the
1671 * documentation and/or other materials provided with the distribution.
1672 * 3. Neither the name of the University nor the names of its contributors
1673 * may be used to endorse or promote products derived from this software
1674 * without specific prior written permission.
1675 *
1676 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1677 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1678 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1679 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1680 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1681 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1682 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1683 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1684 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1685 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1686 * SUCH DAMAGE.
1687 *
1688 * @(#)regerror.c 8.4 (Berkeley) 3/20/94
1689 */
1690
1691The preceding notice is from src/missing/regerror.c in `file`.
1692
1693
1694
1695$NetBSD: COPYRIGHT,v 1.5 2003/08/07 16:43:19 agc Exp $
1696
1697Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
1698This software is not subject to any license of the American Telephone
1699and Telegraph Company or of the Regents of the University of California.
1700
1701Permission is granted to anyone to use this software for any purpose on
1702any computer system, and to alter it and redistribute it, subject
1703to the following restrictions:
1704
17051. The author is not responsible for the consequences of use of this
1706 software, no matter how awful, even if they arise from flaws in it.
1707
17082. The origin of this software must not be misrepresented, either by
1709 explicit claim or by omission. Since few users ever read sources,
1710 credits must appear in the documentation.
1711
17123. Altered versions must be plainly marked as such, and must not be
1713 misrepresented as being the original software. Since few users
1714 ever read sources, credits must appear in the documentation.
1715
17164. This notice may not be removed or altered.
1717
1718=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1719/*-
1720 * Copyright (c) 1994
1721 * The Regents of the University of California. All rights reserved.
1722 *
1723 * Redistribution and use in source and binary forms, with or without
1724 * modification, are permitted provided that the following conditions
1725 * are met:
1726 * 1. Redistributions of source code must retain the above copyright
1727 * notice, this list of conditions and the following disclaimer.
1728 * 2. Redistributions in binary form must reproduce the above copyright
1729 * notice, this list of conditions and the following disclaimer in the
1730 * documentation and/or other materials provided with the distribution.
1731 * 3. Neither the name of the University nor the names of its contributors
1732 * may be used to endorse or promote products derived from this software
1733 * without specific prior written permission.
1734 *
1735 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1736 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1737 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1738 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1739 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1740 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1741 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1742 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1743 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1744 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1745 * SUCH DAMAGE.
1746 *
1747 * @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
1748 */
1749
1750The preceding notice is from src/missing/REGEX-COPYRIGHT in `file`.
1751
1752
1753
1754/*-
1755 * SPDX-License-Identifier: BSD-3-Clause
1756 *
1757 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1758 * Copyright (c) 1992, 1993, 1994
1759 * The Regents of the University of California. All rights reserved.
1760 *
1761 * This code is derived from software contributed to Berkeley by
1762 * Henry Spencer.
1763 *
1764 * Redistribution and use in source and binary forms, with or without
1765 * modification, are permitted provided that the following conditions
1766 * are met:
1767 * 1. Redistributions of source code must retain the above copyright
1768 * notice, this list of conditions and the following disclaimer.
1769 * 2. Redistributions in binary form must reproduce the above copyright
1770 * notice, this list of conditions and the following disclaimer in the
1771 * documentation and/or other materials provided with the distribution.
1772 * 3. Neither the name of the University nor the names of its contributors
1773 * may be used to endorse or promote products derived from this software
1774 * without specific prior written permission.
1775 *
1776 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1777 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1778 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1779 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1780 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1781 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1782 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1783 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1784 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1785 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1786 * SUCH DAMAGE.
1787 *
1788 * @(#)regex2.h 8.4 (Berkeley) 3/20/94
1789 * $FreeBSD: head/lib/libc/regex/regex2.h 368359 2020-12-05 03:18:48Z kevans $
1790 */
1791
1792The preceding notice is from src/missing/regex2.h in `file`.
1793
1794
1795
1796/*-
1797 * SPDX-License-Identifier: BSD-3-Clause
1798 *
1799 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1800 * Copyright (c) 1992, 1993, 1994
1801 * The Regents of the University of California. All rights reserved.
1802 *
1803 * This code is derived from software contributed to Berkeley by
1804 * Henry Spencer.
1805 *
1806 * Redistribution and use in source and binary forms, with or without
1807 * modification, are permitted provided that the following conditions
1808 * are met:
1809 * 1. Redistributions of source code must retain the above copyright
1810 * notice, this list of conditions and the following disclaimer.
1811 * 2. Redistributions in binary form must reproduce the above copyright
1812 * notice, this list of conditions and the following disclaimer in the
1813 * documentation and/or other materials provided with the distribution.
1814 * 3. Neither the name of the University nor the names of its contributors
1815 * may be used to endorse or promote products derived from this software
1816 * without specific prior written permission.
1817 *
1818 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1819 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1820 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1821 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1822 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1823 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1824 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1825 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1826 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1827 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1828 * SUCH DAMAGE.
1829 *
1830 * @(#)regexec.c 8.3 (Berkeley) 3/20/94
1831 */
1832
1833The preceding notice is from src/missing/regexec.c in `file`.
1834
1835
1836
1837/*-
1838 * SPDX-License-Identifier: BSD-3-Clause
1839 *
1840 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1841 * Copyright (c) 1992, 1993, 1994
1842 * The Regents of the University of California. All rights reserved.
1843 *
1844 * This code is derived from software contributed to Berkeley by
1845 * Henry Spencer.
1846 *
1847 * Redistribution and use in source and binary forms, with or without
1848 * modification, are permitted provided that the following conditions
1849 * are met:
1850 * 1. Redistributions of source code must retain the above copyright
1851 * notice, this list of conditions and the following disclaimer.
1852 * 2. Redistributions in binary form must reproduce the above copyright
1853 * notice, this list of conditions and the following disclaimer in the
1854 * documentation and/or other materials provided with the distribution.
1855 * 3. Neither the name of the University nor the names of its contributors
1856 * may be used to endorse or promote products derived from this software
1857 * without specific prior written permission.
1858 *
1859 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1860 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1861 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1862 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1863 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1864 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1865 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1866 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1867 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1868 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1869 * SUCH DAMAGE.
1870 *
1871 * @(#)regfree.c 8.3 (Berkeley) 3/20/94
1872 */
1873
1874The preceding notice is from src/missing/regfree.c in `file`.
1875
1876
1877
1878/*-
1879 * Copyright (c) 1990, 1993
1880 * The Regents of the University of California. All rights reserved.
1881 *
1882 * This code is derived from software contributed to Berkeley by
1883 * Chris Torek.
1884 *
1885 * Redistribution and use in source and binary forms, with or without
1886 * modification, are permitted provided that the following conditions
1887 * are met:
1888 * 1. Redistributions of source code must retain the above copyright
1889 * notice, this list of conditions and the following disclaimer.
1890 * 2. Redistributions in binary form must reproduce the above copyright
1891 * notice, this list of conditions and the following disclaimer in the
1892 * documentation and/or other materials provided with the distribution.
1893 * 3. Neither the name of the University nor the names of its contributors
1894 * may be used to endorse or promote products derived from this software
1895 * without specific prior written permission.
1896 *
1897 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1898 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1899 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1900 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1901 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1902 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1903 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1904 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1905 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1906 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1907 * SUCH DAMAGE.
1908 */
1909
1910The preceding notice is from src/missing/strcasestr.c in `file`.
1911
1912
1913
1914/*
1915 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
1916 *
1917 * Permission to use, copy, modify, and distribute this software for any
1918 * purpose with or without fee is hereby granted, provided that the above
1919 * copyright notice and this permission notice appear in all copies.
1920 *
1921 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1922 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1923 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1924 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1925 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1926 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1927 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1928 */
1929
1930The preceding notice is from src/missing/strlcat.c and src/missing/strlcpy.c in `file`.
1931
1932
1933
1934/*-
1935 * SPDX-License-Identifier: BSD-3-Clause
1936 *
1937 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
1938 * Copyright (c) 1992, 1993, 1994
1939 * The Regents of the University of California. All rights reserved.
1940 *
1941 * This code is derived from software contributed to Berkeley by
1942 * Henry Spencer.
1943 *
1944 * Redistribution and use in source and binary forms, with or without
1945 * modification, are permitted provided that the following conditions
1946 * are met:
1947 * 1. Redistributions of source code must retain the above copyright
1948 * notice, this list of conditions and the following disclaimer.
1949 * 2. Redistributions in binary form must reproduce the above copyright
1950 * notice, this list of conditions and the following disclaimer in the
1951 * documentation and/or other materials provided with the distribution.
1952 * 3. Neither the name of the University nor the names of its contributors
1953 * may be used to endorse or promote products derived from this software
1954 * without specific prior written permission.
1955 *
1956 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1957 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1958 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1959 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1960 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1961 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1962 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1963 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1964 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1965 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1966 * SUCH DAMAGE.
1967 *
1968 * @(#)utils.h 8.3 (Berkeley) 3/20/94
1969 * $FreeBSD: head/lib/libc/regex/utils.h 341838 2018-12-12 04:23:00Z yuripv $
1970 */
1971
1972The preceding notice is from src/missing/utils.h in `file`.
1973
1974
1975
1976/*-
1977 * Copyright (c) 2008, 2016 Christos Zoulas
1978 * All rights reserved.
1979 *
1980 * Redistribution and use in source and binary forms, with or without
1981 * modification, are permitted provided that the following conditions
1982 * are met:
1983 * 1. Redistributions of source code must retain the above copyright
1984 * notice, this list of conditions and the following disclaimer.
1985 * 2. Redistributions in binary form must reproduce the above copyright
1986 * notice, this list of conditions and the following disclaimer in the
1987 * documentation and/or other materials provided with the distribution.
1988 *
1989 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1990 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1991 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1992 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1993 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1994 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1995 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1996 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1997 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1998 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1999 * POSSIBILITY OF SUCH DAMAGE.
2000 */
2001
2002The preceding notice is from src/readcdf.c in `file`.
2003
2004
2005
2006/*-
2007 * Copyright (c) 1992 Henry Spencer.
2008 * Copyright (c) 1992, 1993
2009 * The Regents of the University of California. All rights reserved.
2010 *
2011 * This code is derived from software contributed to Berkeley by
2012 * Henry Spencer of the University of Toronto.
2013 *
2014 * Redistribution and use in source and binary forms, with or without
2015 * modification, are permitted provided that the following conditions
2016 * are met:
2017 * 1. Redistributions of source code must retain the above copyright
2018 * notice, this list of conditions and the following disclaimer.
2019 * 2. Redistributions in binary form must reproduce the above copyright
2020 * notice, this list of conditions and the following disclaimer in the
2021 * documentation and/or other materials provided with the distribution.
2022 * 3. Neither the name of the University nor the names of its contributors
2023 * may be used to endorse or promote products derived from this software
2024 * without specific prior written permission.
2025 *
2026 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2027 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2029 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2030 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2031 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2032 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2033 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2034 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2035 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2036 * SUCH DAMAGE.
2037 *
2038 * @(#)regex.h 8.2 (Berkeley) 1/3/94
2039 * $FreeBSD: src/include/regex.h,v 1.12 2010/02/16 19:39:50 imp Exp $
2040 */
2041
2042The preceding notice is from src/regex-bsd.h in `file`.
2043*/
2044/*
2045
2046Text of LICENSE from DROID:
2047
2048Copyright (c) 2016, The National Archives <pronom@nationalarchives.gov.uk>
2049All rights reserved.
2050
2051Redistribution and use in source and binary forms, with or without
2052modification, are permitted provided that the following
2053conditions are met:
2054
2055 * Redistributions of source code must retain the above copyright
2056 notice, this list of conditions and the following disclaimer.
2057
2058 * Redistributions in binary form must reproduce the above copyright
2059 notice, this list of conditions and the following disclaimer in the
2060 documentation and/or other materials provided with the distribution.
2061
2062 * Neither the name of the The National Archives nor the
2063 names of its contributors may be used to endorse or promote products
2064 derived from this software without specific prior written permission.
2065
2066THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2067AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2068IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2069PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
2070CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2071EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2072PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2073PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2074LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2075NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2076SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2077*/
2078
2079/*
2080
2081Text of LICENSE from fileid:
2082
2083The MIT License (MIT)
2084
2085Copyright (c) 2015 David B Heise
2086
2087Permission is hereby granted, free of charge, to any person obtaining a copy of
2088this software and associated documentation files (the "Software"), to deal in
2089the Software without restriction, including without limitation the rights to
2090use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
2091the Software, and to permit persons to whom the Software is furnished to do so,
2092subject to the following conditions:
2093
2094The above copyright notice and this permission notice shall be included in all
2095copies or substantial portions of the Software.
2096
2097THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2098IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
2099FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
2100COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
2101IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2102CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2103
2104
2105*/
2106
2107/*
2108Text of LICENSE from binwalk:
2109
2110
2111MIT License
2112
2113Copyright (c) 2024 devttys0
2114
2115Permission is hereby granted, free of charge, to any person obtaining a copy
2116of this software and associated documentation files (the "Software"), to deal
2117in the Software without restriction, including without limitation the rights
2118to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2119copies of the Software, and to permit persons to whom the Software is
2120furnished to do so, subject to the following conditions:
2121
2122The above copyright notice and this permission notice shall be included in all
2123copies or substantial portions of the Software.
2124
2125THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2126IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2127FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2128AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2129LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2130OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2131SOFTWARE.
2132
2133*/
2134
2135/*
2136Text of LICENSE from polyfile:
2137
2138
2139 Apache License
2140 Version 2.0, January 2004
2141 http://www.apache.org/licenses/
2142
2143 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
2144
2145 1. Definitions.
2146
2147 "License" shall mean the terms and conditions for use, reproduction,
2148 and distribution as defined by Sections 1 through 9 of this document.
2149
2150 "Licensor" shall mean the copyright owner or entity authorized by
2151 the copyright owner that is granting the License.
2152
2153 "Legal Entity" shall mean the union of the acting entity and all
2154 other entities that control, are controlled by, or are under common
2155 control with that entity. For the purposes of this definition,
2156 "control" means (i) the power, direct or indirect, to cause the
2157 direction or management of such entity, whether by contract or
2158 otherwise, or (ii) ownership of fifty percent (50%) or more of the
2159 outstanding shares, or (iii) beneficial ownership of such entity.
2160
2161 "You" (or "Your") shall mean an individual or Legal Entity
2162 exercising permissions granted by this License.
2163
2164 "Source" form shall mean the preferred form for making modifications,
2165 including but not limited to software source code, documentation
2166 source, and configuration files.
2167
2168 "Object" form shall mean any form resulting from mechanical
2169 transformation or translation of a Source form, including but
2170 not limited to compiled object code, generated documentation,
2171 and conversions to other media types.
2172
2173 "Work" shall mean the work of authorship, whether in Source or
2174 Object form, made available under the License, as indicated by a
2175 copyright notice that is included in or attached to the work
2176 (an example is provided in the Appendix below).
2177
2178 "Derivative Works" shall mean any work, whether in Source or Object
2179 form, that is based on (or derived from) the Work and for which the
2180 editorial revisions, annotations, elaborations, or other modifications
2181 represent, as a whole, an original work of authorship. For the purposes
2182 of this License, Derivative Works shall not include works that remain
2183 separable from, or merely link (or bind by name) to the interfaces of,
2184 the Work and Derivative Works thereof.
2185
2186 "Contribution" shall mean any work of authorship, including
2187 the original version of the Work and any modifications or additions
2188 to that Work or Derivative Works thereof, that is intentionally
2189 submitted to Licensor for inclusion in the Work by the copyright owner
2190 or by an individual or Legal Entity authorized to submit on behalf of
2191 the copyright owner. For the purposes of this definition, "submitted"
2192 means any form of electronic, verbal, or written communication sent
2193 to the Licensor or its representatives, including but not limited to
2194 communication on electronic mailing lists, source code control systems,
2195 and issue tracking systems that are managed by, or on behalf of, the
2196 Licensor for the purpose of discussing and improving the Work, but
2197 excluding communication that is conspicuously marked or otherwise
2198 designated in writing by the copyright owner as "Not a Contribution."
2199
2200 "Contributor" shall mean Licensor and any individual or Legal Entity
2201 on behalf of whom a Contribution has been received by Licensor and
2202 subsequently incorporated within the Work.
2203
2204 2. Grant of Copyright License. Subject to the terms and conditions of
2205 this License, each Contributor hereby grants to You a perpetual,
2206 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
2207 copyright license to reproduce, prepare Derivative Works of,
2208 publicly display, publicly perform, sublicense, and distribute the
2209 Work and such Derivative Works in Source or Object form.
2210
2211 3. Grant of Patent License. Subject to the terms and conditions of
2212 this License, each Contributor hereby grants to You a perpetual,
2213 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
2214 (except as stated in this section) patent license to make, have made,
2215 use, offer to sell, sell, import, and otherwise transfer the Work,
2216 where such license applies only to those patent claims licensable
2217 by such Contributor that are necessarily infringed by their
2218 Contribution(s) alone or by combination of their Contribution(s)
2219 with the Work to which such Contribution(s) was submitted. If You
2220 institute patent litigation against any entity (including a
2221 cross-claim or counterclaim in a lawsuit) alleging that the Work
2222 or a Contribution incorporated within the Work constitutes direct
2223 or contributory patent infringement, then any patent licenses
2224 granted to You under this License for that Work shall terminate
2225 as of the date such litigation is filed.
2226
2227 4. Redistribution. You may reproduce and distribute copies of the
2228 Work or Derivative Works thereof in any medium, with or without
2229 modifications, and in Source or Object form, provided that You
2230 meet the following conditions:
2231
2232 (a) You must give any other recipients of the Work or
2233 Derivative Works a copy of this License; and
2234
2235 (b) You must cause any modified files to carry prominent notices
2236 stating that You changed the files; and
2237
2238 (c) You must retain, in the Source form of any Derivative Works
2239 that You distribute, all copyright, patent, trademark, and
2240 attribution notices from the Source form of the Work,
2241 excluding those notices that do not pertain to any part of
2242 the Derivative Works; and
2243
2244 (d) If the Work includes a "NOTICE" text file as part of its
2245 distribution, then any Derivative Works that You distribute must
2246 include a readable copy of the attribution notices contained
2247 within such NOTICE file, excluding those notices that do not
2248 pertain to any part of the Derivative Works, in at least one
2249 of the following places: within a NOTICE text file distributed
2250 as part of the Derivative Works; within the Source form or
2251 documentation, if provided along with the Derivative Works; or,
2252 within a display generated by the Derivative Works, if and
2253 wherever such third-party notices normally appear. The contents
2254 of the NOTICE file are for informational purposes only and
2255 do not modify the License. You may add Your own attribution
2256 notices within Derivative Works that You distribute, alongside
2257 or as an addendum to the NOTICE text from the Work, provided
2258 that such additional attribution notices cannot be construed
2259 as modifying the License.
2260
2261 You may add Your own copyright statement to Your modifications and
2262 may provide additional or different license terms and conditions
2263 for use, reproduction, or distribution of Your modifications, or
2264 for any such Derivative Works as a whole, provided Your use,
2265 reproduction, and distribution of the Work otherwise complies with
2266 the conditions stated in this License.
2267
2268 5. Submission of Contributions. Unless You explicitly state otherwise,
2269 any Contribution intentionally submitted for inclusion in the Work
2270 by You to the Licensor shall be under the terms and conditions of
2271 this License, without any additional terms or conditions.
2272 Notwithstanding the above, nothing herein shall supersede or modify
2273 the terms of any separate license agreement you may have executed
2274 with Licensor regarding such Contributions.
2275
2276 6. Trademarks. This License does not grant permission to use the trade
2277 names, trademarks, service marks, or product names of the Licensor,
2278 except as required for reasonable and customary use in describing the
2279 origin of the Work and reproducing the content of the NOTICE file.
2280
2281 7. Disclaimer of Warranty. Unless required by applicable law or
2282 agreed to in writing, Licensor provides the Work (and each
2283 Contributor provides its Contributions) on an "AS IS" BASIS,
2284 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
2285 implied, including, without limitation, any warranties or conditions
2286 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
2287 PARTICULAR PURPOSE. You are solely responsible for determining the
2288 appropriateness of using or redistributing the Work and assume any
2289 risks associated with Your exercise of permissions under this License.
2290
2291 8. Limitation of Liability. In no event and under no legal theory,
2292 whether in tort (including negligence), contract, or otherwise,
2293 unless required by applicable law (such as deliberate and grossly
2294 negligent acts) or agreed to in writing, shall any Contributor be
2295 liable to You for damages, including any direct, indirect, special,
2296 incidental, or consequential damages of any character arising as a
2297 result of this License or out of the use or inability to use the
2298 Work (including but not limited to damages for loss of goodwill,
2299 work stoppage, computer failure or malfunction, or any and all
2300 other commercial damages or losses), even if such Contributor
2301 has been advised of the possibility of such damages.
2302
2303 9. Accepting Warranty or Additional Liability. While redistributing
2304 the Work or Derivative Works thereof, You may choose to offer,
2305 and charge a fee for, acceptance of support, warranty, indemnity,
2306 or other liability obligations and/or rights consistent with this
2307 License. However, in accepting such obligations, You may act only
2308 on Your own behalf and on Your sole responsibility, not on behalf
2309 of any other Contributor, and only if You agree to indemnify,
2310 defend, and hold each Contributor harmless for any liability
2311 incurred by, or claims asserted against, such Contributor by reason
2312 of your accepting any such warranty or additional liability.
2313
2314 END OF TERMS AND CONDITIONS
2315
2316 APPENDIX: How to apply the Apache License to your work.
2317
2318 To apply the Apache License to your work, attach the following
2319 boilerplate notice, with the fields enclosed by brackets "[]"
2320 replaced with your own identifying information. (Don't include
2321 the brackets!) The text should be enclosed in the appropriate
2322 comment syntax for the file format. We also recommend that a
2323 file or class name and description of purpose be included on the
2324 same "printed page" as the copyright notice for easier
2325 identification within third-party archives.
2326
2327 Copyright [yyyy] [name of copyright owner]
2328
2329 Licensed under the Apache License, Version 2.0 (the "License");
2330 you may not use this file except in compliance with the License.
2331 You may obtain a copy of the License at
2332
2333 http://www.apache.org/licenses/LICENSE-2.0
2334
2335 Unless required by applicable law or agreed to in writing, software
2336 distributed under the License is distributed on an "AS IS" BASIS,
2337 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2338 See the License for the specific language governing permissions and
2339 limitations under the License.
2340
2341*/