switch (state) {
case NORMAL:
if (*buf == IAC) { // handles IAC
state = COMMAND;
break;
}
… other stuff
break;
case COMMAND:
if (*buf == IAC) { // handles IAC IAC
.. copy single IAC to input
state = NORMAL;
…
}
if (*buf == AYT) { // IAC
…
}
… other commands
… other states
}
}
ostr filter_out(istr) { // Cplus-ish psuedo-code
loop through istr {
switch (outstate) {
case NORMAL:
if (*istr == IAC) { // handles IAC
ostr << *istr++;
state = COMMAND;
break;
} else {
ostr << *istr++;
}
break;
case COMMAND:
if (*istr == GA )||
(*isrt == AYT)||
…. more commands
ostr << *istr++;
state = NORMAL;
} else {
ostr << IAC
state = NORMAL;
}
break;
}
}