if(s.buf[s.bufptr] == ISO_cr || s.buf[s.bufptr] == ISO_nl) { s.buf[s.bufptr] = 0; petsciiconv_topetscii(s.buf, LINELEN); shell_output(s.buf, ""); shell_input(s.buf); s.bufptr = 0; } else { ++s.bufptr; } }
switch(s.state) { case STATE_IAC: if(c == TELNET_IAC) { getchar(c); s.state = STATE_NORMAL; } else { switch(c) { case TELNET_WILL: s.state = STATE_WILL; break; case TELNET_WONT: s.state = STATE_WONT; break; case TELNET_DO: s.state = STATE_DO; break; case TELNET_DONT: s.state = STATE_DONT; break; default: s.state = STATE_NORMAL; break; } } break; case STATE_WILL:  sendopt(TELNET_DONT, c); s.state = STATE_NORMAL; break;  case STATE_WONT:  sendopt(TELNET_DONT, c); s.state = STATE_NORMAL; break; case STATE_DO:  sendopt(TELNET_WONT, c); s.state = STATE_NORMAL; break; case STATE_DONT:  sendopt(TELNET_WONT, c); s.state = STATE_NORMAL; break; case STATE_NORMAL: if(c == TELNET_IAC) { s.state = STATE_IAC; } else { getchar(c); } break; }   }
newdata(void){  u16_t len;  len = uip_datalen();    while(len > 0 && s.bufptr < sizeof(s.buf)) {    s.buf[s.bufptr] = *uip_appdata;    ++uip_appdata;    --len;    if(s.buf[s.bufptr] == ISO_cr ||       s.buf[s.bufptr] == ISO_nl) {      s.buf[s.bufptr] = 0;      petsciiconv_topetscii(s.buf, LINELEN);      shell_output(s.buf, "");      shell_input(s.buf);      s.bufptr = 0;    } else {      ++s.bufptr;    }  }  }