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