fn main() {
let a: Vec<String> = std::env::args().collect();
if a.len() < 2 {
eprintln!("usage: audit SCORE.pdf [OUT.json [OUT.musicxml [OUT.fmn]]]");
std::process::exit(2);
}
let bytes = std::fs::read(&a[1]).expect("reading the PDF");
let audit = match fm_vector::audit_pdf(&bytes) {
Ok(x) => x,
Err(e) => {
println!("refused: {}", e.why.replace('\n', " "));
std::process::exit(1);
}
};
if let Some(out) = a.get(2) {
std::fs::write(out, audit.to_json()).expect("writing the JSON");
}
if let Some(out) = a.get(3) {
std::fs::write(out, &audit.reading.musicxml).expect("writing the MusicXML");
}
if let Some(out) = a.get(4) {
std::fs::write(out, &audit.reading.fmn).expect("writing the .fmn");
}
let bars: usize = audit.systems.iter().map(|s| s.bars.len()).sum();
let findings: Vec<String> = (audit.findings.iter())
.map(|(k, n)| format!("{k}={n}"))
.collect();
println!(
"audited\t{:.1}\t{} systems\t{bars} bars\t{} unread\t{}",
audit.score,
audit.systems.len(),
audit.reading.unread.len(),
findings.join("; ")
);
let mut worst: Vec<&fm_vector::SystemAudit> = audit.systems.iter().collect();
worst.sort_by(|x, y| y.score.total_cmp(&x.score));
for s in worst.iter().take(10).filter(|s| s.score > 0.0) {
let mut why = s.reasons.clone();
for b in &s.bars {
why.extend(b.reasons.iter().map(|r| format!("bar {}: {r}", b.bar)));
}
println!(
"system\t{}\tpage {}\t{:.1}\t{}",
s.system + 1,
s.page + 1,
s.score,
why.join("; ")
);
}
}