getch2: Reimplement getch2 as a state machine

Almost non-backtracking: we have to backtrack in case we find no match in
the part of the termcap db that gets loaded. The getch2_pos-- in some of
the switch cases is to make the next state see the same character this
state did.

WORKSFORME, tried all PC105 keyboard keys.