This patch addresses two bugs with dtach related to its non-handling of terminal control sequences. It creates a minimal, flexible "parser" which uses a stateful KMP search to filter out answerback control sequences and keep track of the terminal's keypad mode (smkx/rmkx) state. The I/O buffer is moved into struct pty so that incomplete control sequences will persist between calls to pty_activity. (This could later be used to create a "history" or "replay" buffer to simplistically attempt to restore screen state when reattaching.)
https://sourceforge.net/tracker/?func=detail&aid=2707252&group_id=36489&atid=417357
To solve the keypad-mode bug, the parser loads the smkx and rmkx sequences from the current terminfo and watches for them, keeping track of the current state of the pty. When a new client attaches, the master replays the smkx sequence if keypad mode is currently set.
https://sourceforge.net/tracker/?func=detail&aid=1777929&group_id=36489&atid=417357
To solve the answerback-sequence bug, the parser filters out ^E, ^[Z, ^[[c, ^[[>c, and ^[[>0c sequences as known answerbacks. Unfortunately, these are not defined in terminfo, so we have to try to catch all of them. (This set appears to make vim and emacs work.) It would be possible to modify the code so that the dtach master replies to these answerbacks itself.
To enable the parser under this patch, dtach must be configured with the --enable-parser flag.
Creates parser.c and adds parser hooks