Listing 3: Test harness for the Keyboard FSM
1: int main() {
2: Keyboard k;
3: KeyboardCtor(&k);
4: FsmInit((Fsm *)&k, 0);
5: for (;;) {
6: KeyboardEvt ke;
7: printf("\nSignal<-");
8: ke.code = getc(stdin);
9: getc(stdin); /* discard '\n' */
10: switch (ke.code) {
11: case '^': ke.super_.sig = SHIFT_DEPRESSED_SIG; break;
12: case '6': ke.super_.sig = SHIFT_RELEASED_SIG; break;
13: case '.': return 0; /* terminate the test */
14: default: ke.super_.sig = ANY_KEY_SIG; break;
15: }
16: FsmDispatch((Fsm *)&k, (Event *)&ke); /* dispatch */
17: }
18: return 0;
19: }