Skip to main content

survey/
survey.rs

1//! `cargo run -p fm-vector --release --example survey -- LIST.txt`: read every PDF named in the
2//! list (one path a line) and print one tab-separated line each: path, outcome, why.
3fn main() {
4    let list = std::fs::read_to_string(std::env::args().nth(1).expect("a list of PDFs")).unwrap();
5    for path in list.lines().filter(|l| !l.trim().is_empty()) {
6        let Ok(bytes) = std::fs::read(path) else {
7            println!("{path}\tunreadable\t");
8            continue;
9        };
10        let t = std::time::Instant::now();
11        let out = std::panic::catch_unwind(|| fm_vector::read_pdf(&bytes));
12        let ms = t.elapsed().as_millis();
13        match out {
14            Ok(Ok(r)) => println!(
15                "{path}\tread\t{} systems, {} notes, {} syllables, {ms} ms",
16                r.systems, r.notes, r.syllables
17            ),
18            Ok(Err(e)) => println!("{path}\trefused\t{}", e.to_string().replace('\n', " ")),
19            Err(_) => println!("{path}\tpanic\t"),
20        }
21    }
22}