Skip to content

Commit

Permalink
hack allow macros with invalid params
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed Dec 13, 2024
1 parent 18b7b34 commit a482dff
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/til.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,34 +566,46 @@ impl TILMacro {
ensure!(flag & 0xFE00 == 0, "Unknown Macro flag value {flag}");
let have_param = flag & 0x100 != 0;
let param_num = have_param.then_some((flag & 0xFF) as u8);
if !have_param {
ensure!(flag & 0xFF == 0, "Unknown/Invalid value for TILMacro flag");
}
// TODO find the InnerRef for this
let value = input.read_c_string_raw()?;
let mut max_param = None;
// TODO check the implementation using the InnerRef
let value = value
let value: Vec<TILMacroValue> = value
.into_iter()
.map(|c| match c {
.filter_map(|c| match c {
0x00 => unreachable!(),
0x01..=0x7F => TILMacroValue::Char(c),
0x01..=0x7F => Some(TILMacroValue::Char(c)),
0x80..=0xFF => {
let param_idx = c & 0x7F;
if !have_param && matches!(param_idx, 0x20 | 0x25 | 0x29) {
// HACK: it's known that some macros, although having no params
// include some params in the value, It's unknown the menaing of those,
// maybe they are just bugs.
return None;
}
match (max_param, param_idx) {
(None, _) => max_param = Some(param_idx),
(Some(max), param_idx) if param_idx > max => max_param = Some(param_idx),
(Some(_), _) => {}
}
TILMacroValue::Param(param_idx)
Some(TILMacroValue::Param(param_idx))
}
})
.collect();
match (param_num, max_param) {
// the macro not using the defined params is allowed in all situations
(_, None) => {}
// having params, where should not
(None, Some(_)) => {
return Err(anyhow!(
"Macro value have param but it is not declared in the flag"
))
(None, Some(_max)) => {
println!(
"Macro value have params but it is not declared in the flag: {_max}",
)
//return Err(anyhow!(
// "Macro value have params but it is not declared in the flag",
//))
}
// only using params that exist
(Some(params), Some(max)) if max <= params => {
Expand Down

0 comments on commit a482dff

Please sign in to comment.