Tweak new terminfo logical operator support

This commit is contained in:
Kevin Ballard 2013-06-13 19:36:45 -07:00
parent 821a962feb
commit 9f9e505405

View File

@ -68,7 +68,6 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
while i < cap.len() {
cur = cap[i] as char;
debug!("current char: %c", cur);
let mut old_state = state;
match state {
Nothing => {
@ -134,33 +133,19 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
(_, _) => return Err(~"non-numbers on stack with |")
},
'A' => match (stack.pop(), stack.pop()) {
(Number(x), Number(y)) => {
if x == 1 && y == 1 {
stack.push(Number(1));
} else {
stack.push(Number(0));
}
},
(_, _) => return Err(~"non-numbers on stack with logical and")
(Number(0), Number(_)) => stack.push(Number(0)),
(Number(_), Number(0)) => stack.push(Number(0)),
(Number(_), Number(_)) => stack.push(Number(1)),
_ => return Err(~"non-numbers on stack with logical and")
},
'O' => match (stack.pop(), stack.pop()) {
(Number(x), Number(y)) => {
if x == 1 && y == 1 {
stack.push(Number(1));
} else {
stack.push(Number(0));
}
},
(_, _) => return Err(~"non-numbers on stack with logical or")
(Number(0), Number(0)) => stack.push(Number(0)),
(Number(_), Number(_)) => stack.push(Number(1)),
_ => return Err(~"non-numbers on stack with logical or")
},
'!' => match stack.pop() {
Number(x) => {
if x == 1 {
stack.push(Number(0))
} else {
stack.push(Number(1))
}
},
Number(0) => stack.push(Number(1)),
Number(_) => stack.push(Number(0)),
_ => return Err(~"non-number on stack with logical not")
},
'~' => match stack.pop() {
@ -168,9 +153,9 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
_ => return Err(~"non-number on stack with %~")
},
'i' => match (copy params[0], copy params[1]) {
(Number(x), Number(y)) => {
params[0] = Number(x + 1);
params[1] = Number(y + 1);
(Number(ref mut x), Number(ref mut y)) => {
*x += 1;
*y += 1;
},
(_, _) => return Err(~"first two params not numbers with %i")
},