Skip to content

Commit 9f9e505

Browse files
committed
Tweak new terminfo logical operator support
1 parent 821a962 commit 9f9e505

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/libextra/terminfo/parm.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
6868

6969
while i < cap.len() {
7070
cur = cap[i] as char;
71-
debug!("current char: %c", cur);
7271
let mut old_state = state;
7372
match state {
7473
Nothing => {
@@ -134,43 +133,29 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
134133
(_, _) => return Err(~"non-numbers on stack with |")
135134
},
136135
'A' => match (stack.pop(), stack.pop()) {
137-
(Number(x), Number(y)) => {
138-
if x == 1 && y == 1 {
139-
stack.push(Number(1));
140-
} else {
141-
stack.push(Number(0));
142-
}
143-
},
144-
(_, _) => return Err(~"non-numbers on stack with logical and")
136+
(Number(0), Number(_)) => stack.push(Number(0)),
137+
(Number(_), Number(0)) => stack.push(Number(0)),
138+
(Number(_), Number(_)) => stack.push(Number(1)),
139+
_ => return Err(~"non-numbers on stack with logical and")
145140
},
146141
'O' => match (stack.pop(), stack.pop()) {
147-
(Number(x), Number(y)) => {
148-
if x == 1 && y == 1 {
149-
stack.push(Number(1));
150-
} else {
151-
stack.push(Number(0));
152-
}
153-
},
154-
(_, _) => return Err(~"non-numbers on stack with logical or")
142+
(Number(0), Number(0)) => stack.push(Number(0)),
143+
(Number(_), Number(_)) => stack.push(Number(1)),
144+
_ => return Err(~"non-numbers on stack with logical or")
155145
},
156146
'!' => match stack.pop() {
157-
Number(x) => {
158-
if x == 1 {
159-
stack.push(Number(0))
160-
} else {
161-
stack.push(Number(1))
162-
}
163-
},
147+
Number(0) => stack.push(Number(1)),
148+
Number(_) => stack.push(Number(0)),
164149
_ => return Err(~"non-number on stack with logical not")
165150
},
166151
'~' => match stack.pop() {
167152
Number(x) => stack.push(Number(!x)),
168153
_ => return Err(~"non-number on stack with %~")
169154
},
170155
'i' => match (copy params[0], copy params[1]) {
171-
(Number(x), Number(y)) => {
172-
params[0] = Number(x + 1);
173-
params[1] = Number(y + 1);
156+
(Number(ref mut x), Number(ref mut y)) => {
157+
*x += 1;
158+
*y += 1;
174159
},
175160
(_, _) => return Err(~"first two params not numbers with %i")
176161
},

0 commit comments

Comments
 (0)