+ /*
+ * This particularly hideous bit of code from RDB
+ * allows ordinary ^M^J to do the same thing as
+ * magic-^M when in Raw protocol. The line `case
+ * KCTRL('M'):' is _inside_ the if block. Thus:
+ *
+ * - receiving regular ^M goes straight to the
+ * default clause and inserts as a literal ^M.
+ * - receiving regular ^J _not_ directly after a
+ * literal ^M (or not in Raw protocol) fails the
+ * if condition, leaps to the bottom of the if,
+ * and falls through into the default clause
+ * again.
+ * - receiving regular ^J just after a literal ^M
+ * in Raw protocol passes the if condition,
+ * deletes the literal ^M, and falls through
+ * into the magic-^M code
+ * - receiving a magic-^M empties the line buffer,
+ * signals end-of-line in one of the various
+ * entertaining ways, and _doesn't_ fall out of
+ * the bottom of the if and through to the
+ * default clause because of the break.
+ */
+ case CTRL('J'):
+ if (cfg.protocol == PROT_RAW &&
+ term_buflen > 0 && term_buf[term_buflen - 1] == '\r') {
+ if (ECHOING)
+ bsb(plen(term_buf[term_buflen - 1]));
+ term_buflen--;
+ /* FALLTHROUGH */
+ case KCTRL('M'): /* send with newline */
+ if (term_buflen > 0)
+ back->send(term_buf, term_buflen);
+ if (cfg.protocol == PROT_RAW)
+ back->send("\r\n", 2);
+ else if (cfg.protocol == PROT_TELNET)
+ back->special(TS_EOL);
+ else
+ back->send("\r", 1);
+ if (ECHOING)
+ c_write("\r\n", 2);
+ term_buflen = 0;
+ break;
+ }
+ /* FALLTHROUGH */