add --out-debug option for debug output rather than serde

png-branch
an 2019-02-16 13:08:12 -05:00
parent 2fd48d53a2
commit c258ee2558
1 changed files with 22 additions and 13 deletions

View File

@ -19,10 +19,15 @@ fn make_chunk(opt: &Options, cid: Ident, cnk: &[u8], eid: u16) -> ResultS<()>
Ok(())
}
fn make_yaml(data: &impl serde::Serialize) -> ResultS<()>
fn make_yaml<T>(opt: &Options, data: &T) -> ResultS<()>
where T: serde::Serialize + std::fmt::Debug
{
serde_yaml::to_writer(io::stdout(), &data)?;
println!();
if opt.out_debug {
println!("{:#?}", data);
} else {
serde_yaml::to_writer(io::stdout(), &data)?;
println!();
}
Ok(())
}
@ -39,12 +44,12 @@ fn dump_chunk(opt: &Options, cid: Ident, cnk: &[u8], eid: u16) -> ResultS<()>
let im = pict::load_pict(cnk)?;
make_tga(&format!("{}/pict_{}.tga", opt.out_dir, eid), &im)?;
}
b"Minf" => make_yaml(&map::Minf::chunk(cnk)?)?,
b"EPNT" => make_yaml(&map::Endpoint::chunk(cnk)?)?,
b"PNTS" => make_yaml(&map::Point::chunk(cnk)?)?,
b"LINS" => make_yaml(&map::Line::chunk(cnk)?)?,
b"SIDS" => make_yaml(&map::Side::chunk(cnk)?)?,
b"term" => make_yaml(&term::Terminal::chunk(cnk)?)?,
b"Minf" => make_yaml(opt, &map::Minf::chunk(cnk)?)?,
b"EPNT" => make_yaml(opt, &map::Endpoint::chunk(cnk)?)?,
b"PNTS" => make_yaml(opt, &map::Point::chunk(cnk)?)?,
b"LINS" => make_yaml(opt, &map::Line::chunk(cnk)?)?,
b"SIDS" => make_yaml(opt, &map::Side::chunk(cnk)?)?,
b"term" => make_yaml(opt, &term::Terminal::chunk(cnk)?)?,
_ => (),
}
}
@ -61,7 +66,7 @@ fn process_wad(opt: &Options, b: &[u8]) -> ResultS<()>
let wad = wad::Wad::new(b)?;
if opt.wad_header {
make_yaml(&wad.head)?;
make_yaml(opt, &wad.head)?;
}
for (eid, ent) in wad.entries {
@ -97,13 +102,13 @@ fn dump_bitmaps(opt: &Options, c: &shp::Collection, i: usize) -> ResultS<()>
fn write_shp_objs(opt: &Options, cl: &shp::Collection) -> ResultS<()>
{
if opt.shp_tab {
make_yaml(&cl.tabs)?;
make_yaml(opt, &cl.tabs)?;
}
if opt.shp_frm {
make_yaml(&cl.frms)?;
make_yaml(opt, &cl.frms)?;
}
if opt.shp_seq {
make_yaml(&cl.seqs)?;
make_yaml(opt, &cl.seqs)?;
}
Ok(())
}
@ -168,6 +173,9 @@ fn main() -> ResultS<()>
ap.refer(&mut opt.out_dir)
.add_option(&["--out-dir"], Store,
"Sets output directory for dump options");
ap.refer(&mut opt.out_debug)
.add_option(&["--out-debug"], StoreTrue,
"Writes debugging output rather than YAML");
ap.refer(&mut opt.inputs)
.add_argument("inputs", Collect, "Input files");
ap.parse_args_or_exit();
@ -215,6 +223,7 @@ struct Options
{
inputs: Vec<String>,
out_dir: String,
out_debug: bool,
shp_tab: bool,
shp_bmp: bool,
shp_bmp_all: bool,