Files
Sylpheed/crates/sylpheed-formats/examples/kind3002_names.rs
MechaCat02 62376dd4a1 style: rustfmt sweep — 107 files the lint gate never saw
This branch predates CI on `main`. `cargo fmt --all` only; no behaviour.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 16:34:40 +02:00

62 lines
2.2 KiB
Rust

//! What do 0x3002/0x3003 elements actually look like disc-wide?
//! The port's menu-item rule keys on this class; this asks whether the class is
//! uniformly menu-row-shaped or whether it contains other things too.
use std::collections::BTreeMap;
use std::path::PathBuf;
use sylpheed_formats::{pak::PakArchive, ui_layout};
fn main() {
let root = PathBuf::from(std::env::var("SYLPHEED_DISC").expect("SYLPHEED_DISC"));
let mut names: BTreeMap<String, usize> = BTreeMap::new();
let mut paks: Vec<_> = std::fs::read_dir(root.join("dat"))
.expect("dat")
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|p| p.extension().map(|x| x == "pak").unwrap_or(false))
.collect();
paks.sort();
for p in &paks {
let Ok(ar) = PakArchive::open(p) else {
continue;
};
for ent in ar.entries() {
let Ok(by) = ar.read(ent) else { continue };
let Some(b) = ui_layout::parse_build(&by) else {
continue;
};
for el in &b.elements {
if el.kind == 0x3002 || el.kind == 0x3003 {
let stem = el.name.split('.').next().unwrap_or("");
let cls: String = stem
.trim_end_matches(|c: char| c.is_ascii_digit())
.to_string();
*names.entry(cls).or_default() += 1;
}
}
}
}
let total: usize = names.values().sum();
println!(
"0x3002/0x3003 elements disc-wide: {total}, {} name-stems",
names.len()
);
let mut v: Vec<_> = names.into_iter().collect();
v.sort_by_key(|(_, n)| std::cmp::Reverse(*n));
let btn: usize = v
.iter()
.filter(|(k, _)| k.contains("btn"))
.map(|(_, n)| n)
.sum();
println!(
"stems containing \"btn\": {btn} of {total} ({:.1}%)",
100.0 * btn as f64 / total as f64
);
println!("\ntop stems:");
for (k, n) in v.iter().take(14) {
println!(" {n:5} {k}");
}
println!("\nNON-btn stems (the ones a menu-item rule would also claim):");
for (k, n) in v.iter().filter(|(k, _)| !k.contains("btn")).take(12) {
println!(" {n:5} {k}");
}
}