add Minf checking and better error handling
parent
7e88ab62c8
commit
8ecca54b13
53
src/main.rs
53
src/main.rs
|
@ -14,6 +14,43 @@ use marathon::{wad, term};
|
|||
|
||||
use memmap::Mmap;
|
||||
|
||||
use durandal::bin::ResultS;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Minf
|
||||
{
|
||||
env: u16,
|
||||
phy: u16,
|
||||
mus: u16,
|
||||
mfl: u16,
|
||||
efl: u16,
|
||||
epf: u32,
|
||||
bip: bool,
|
||||
nam: String,
|
||||
}
|
||||
|
||||
impl Minf
|
||||
{
|
||||
fn chunk(b: &[u8]) -> ResultS<Minf>
|
||||
{
|
||||
use durandal::text::mac_roman_conv;
|
||||
use durandal::bin::*;
|
||||
|
||||
if b.len() < 88 {return Err("not enough data for Minf")}
|
||||
|
||||
let env = b.c_u16b( 0)?;
|
||||
let phy = b.c_u16b( 2)?;
|
||||
let mus = b.c_u16b( 4)?;
|
||||
let mfl = b.c_u16b( 6)?;
|
||||
let efl = b.c_u16b( 8)?;
|
||||
let bip = b[10] != 0;
|
||||
let nam = mac_roman_conv(&b[18..84]);
|
||||
let epf = b.c_u32b(84)?;
|
||||
|
||||
Ok(Minf{env, phy, mus, mfl, efl, epf, bip, nam})
|
||||
}
|
||||
}
|
||||
|
||||
fn write_ppm(fname: &str, im: &Image) -> io::Result<()>
|
||||
{
|
||||
let out = fs::File::create(fname)?;
|
||||
|
@ -53,9 +90,21 @@ fn main() -> io::Result<()>
|
|||
Err(e) => println!("entry {} has PICT (invalid: {:?})", id, e),
|
||||
}
|
||||
}
|
||||
else if let Some(b) = ent.map.get(b"term")
|
||||
|
||||
if let Some(b) = ent.map.get(b"term")
|
||||
{
|
||||
println!("entry {} has term {:#?}", id, term::Terminal::chunk(b));
|
||||
match term::Terminal::chunk(b) {
|
||||
Ok(c) => println!("entry {} has term {:#?}", id, c),
|
||||
Err(e) => println!("entry {} has term (invalid: {:?})", id, e),
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(b) = ent.map.get(b"Minf")
|
||||
{
|
||||
match Minf::chunk(b) {
|
||||
Ok(c) => println!("entry {} has Minf {:#?}", id, c),
|
||||
Err(e) => println!("entry {} has Minf (invalid: {:?})", id, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ impl Terminal
|
|||
let sta = end + beg;
|
||||
|
||||
let txt = &b[sta..sta+len];
|
||||
let txt = if enc {fuck_string(txt)} else {txt.to_vec()};
|
||||
let txt = mac_roman_conv(&txt);
|
||||
let txt = if enc {mac_roman_conv(&fuck_string(txt))}
|
||||
else {mac_roman_conv(&txt)};
|
||||
|
||||
grp.push(Group{typ, per, lns, txt});
|
||||
|
||||
|
@ -54,7 +54,7 @@ impl Terminal
|
|||
p += SIZE_FACE;
|
||||
}
|
||||
|
||||
Ok((len, Terminal{lns, grp, fcs}))
|
||||
Ok((len, Terminal{enc, lns, grp, fcs}))
|
||||
}
|
||||
|
||||
pub fn chunk(b: &[u8]) -> ResultS<Vec<Terminal>>
|
||||
|
@ -80,6 +80,7 @@ impl Terminal
|
|||
#[derive(Debug)]
|
||||
pub struct Terminal
|
||||
{
|
||||
enc: bool,
|
||||
lns: u16,
|
||||
grp: Vec<Group>,
|
||||
fcs: Vec<Face>,
|
||||
|
|
Loading…
Reference in New Issue