2019-04-01 02:09:01 -07:00
|
|
|
//! `Terminal` type.
|
|
|
|
|
|
|
|
use super::{trmf, trmg};
|
2019-06-13 18:09:07 -07:00
|
|
|
use crate::{bin, err::*, text};
|
2019-04-01 02:09:01 -07:00
|
|
|
|
|
|
|
/// Reads a `term` chunk.
|
|
|
|
pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)>
|
|
|
|
{
|
2019-07-05 20:21:11 -07:00
|
|
|
read_data! {
|
|
|
|
endian: BIG, buf: b, size: 10, start: 0, data {
|
|
|
|
let end = u16[0] usize;
|
|
|
|
let encoded = u16[2];
|
|
|
|
let lines = u16[4];
|
|
|
|
let group_n = u16[6] usize;
|
|
|
|
let face_n = u16[8] usize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let (i_grp, x) = bin::rd_array_num(&b[10..], group_n, trmg::read)?;
|
|
|
|
let (faces, y) = bin::rd_array_num(&b[10 + x..], face_n, trmf::read)?;
|
|
|
|
|
|
|
|
let text = ok!(b.get(10 + x + y..end), "not enough data")?;
|
|
|
|
let text = if encoded != 0 {
|
|
|
|
text::fuck_string(text)
|
|
|
|
} else {
|
|
|
|
text.to_vec()
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut groups = Vec::with_capacity(group_n);
|
|
|
|
|
|
|
|
for grp in &i_grp {
|
|
|
|
let flags = grp.flags;
|
|
|
|
let ttype = grp.ttype;
|
|
|
|
let lines = grp.lines;
|
|
|
|
let beg = grp.beg;
|
|
|
|
let len = grp.len;
|
|
|
|
let text = ok!(text.get(beg..beg + len), "bad offset")?;
|
|
|
|
let text = text::mac_roman_cstr(text);
|
|
|
|
|
|
|
|
groups.push(trmg::Group{flags, ttype, lines, text});
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok((Terminal{lines, groups, faces}, end))
|
2019-04-01 02:09:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A terminal definition, with collections of groups and faces.
|
|
|
|
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
2019-06-25 03:52:21 -07:00
|
|
|
pub struct Terminal {
|
2019-07-05 20:21:11 -07:00
|
|
|
pub lines: u16,
|
|
|
|
pub groups: Vec<trmg::Group>,
|
|
|
|
pub faces: Vec<trmf::Face>,
|
2019-04-01 02:09:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|