1fn main() {
8 let a: Vec<String> = std::env::args().collect();
9 if a.len() < 2 {
10 eprintln!("usage: audit SCORE.pdf [OUT.json [OUT.musicxml [OUT.fmn]]]");
11 std::process::exit(2);
12 }
13 let bytes = std::fs::read(&a[1]).expect("reading the PDF");
14 let audit = match fm_vector::audit_pdf(&bytes) {
15 Ok(x) => x,
16 Err(e) => {
17 println!("refused: {}", e.why.replace('\n', " "));
18 std::process::exit(1);
19 }
20 };
21 if let Some(out) = a.get(2) {
22 std::fs::write(out, audit.to_json()).expect("writing the JSON");
23 }
24 if let Some(out) = a.get(3) {
25 std::fs::write(out, &audit.reading.musicxml).expect("writing the MusicXML");
26 }
27 if let Some(out) = a.get(4) {
28 std::fs::write(out, &audit.reading.fmn).expect("writing the .fmn");
29 }
30 let bars: usize = audit.systems.iter().map(|s| s.bars.len()).sum();
31 let findings: Vec<String> = (audit.findings.iter())
32 .map(|(k, n)| format!("{k}={n}"))
33 .collect();
34 println!(
35 "audited\t{:.1}\t{} systems\t{bars} bars\t{} unread\t{}",
36 audit.score,
37 audit.systems.len(),
38 audit.reading.unread.len(),
39 findings.join("; ")
40 );
41 let mut worst: Vec<&fm_vector::SystemAudit> = audit.systems.iter().collect();
42 worst.sort_by(|x, y| y.score.total_cmp(&x.score));
43 for s in worst.iter().take(10).filter(|s| s.score > 0.0) {
44 let mut why = s.reasons.clone();
45 for b in &s.bars {
46 why.extend(b.reasons.iter().map(|r| format!("bar {}: {r}", b.bar)));
47 }
48 println!(
49 "system\t{}\tpage {}\t{:.1}\t{}",
50 s.system + 1,
51 s.page + 1,
52 s.score,
53 why.join("; ")
54 );
55 }
56}