Skip to content

Commit 821a962

Browse files
emberianlilyball
authored andcommitted
Various terminfo parameterization changes
1 parent eadd83d commit 821a962

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/libextra/terminfo/parm.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ 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);
7172
let mut old_state = state;
7273
match state {
7374
Nothing => {
@@ -132,9 +133,36 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
132133
(Number(x), Number(y)) => stack.push(Number(x | y)),
133134
(_, _) => return Err(~"non-numbers on stack with |")
134135
},
135-
'A' => return Err(~"logical operations unimplemented"),
136-
'O' => return Err(~"logical operations unimplemented"),
137-
'!' => return Err(~"logical operations unimplemented"),
136+
'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")
145+
},
146+
'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")
155+
},
156+
'!' => match stack.pop() {
157+
Number(x) => {
158+
if x == 1 {
159+
stack.push(Number(0))
160+
} else {
161+
stack.push(Number(1))
162+
}
163+
},
164+
_ => return Err(~"non-number on stack with logical not")
165+
},
138166
'~' => match stack.pop() {
139167
Number(x) => stack.push(Number(!x)),
140168
_ => return Err(~"non-number on stack with %~")
@@ -181,7 +209,9 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
181209
state = CharClose;
182210
},
183211
CharClose => {
184-
assert!(cur == '\'', "malformed character constant");
212+
if cur != '\'' {
213+
return Err(~"malformed character constant");
214+
}
185215
},
186216
IntConstant => {
187217
if cur == '}' {

0 commit comments

Comments
 (0)