=== modified file 'driver-csi.c' --- driver-csi.c 2017-03-29 21:42:11 +0000 +++ driver-csi.c 2017-03-29 19:26:44 +0000 @@ -11,8 +11,6 @@ typedef struct { TermKey *tk; - int saved_string_id; - char *saved_string; } TermKeyCsi; typedef TermKeyResult CsiHandler(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args); @@ -510,8 +508,6 @@ return NULL; csi->tk = tk; - csi->saved_string_id = 0; - csi->saved_string = NULL; return csi; } @@ -520,9 +516,6 @@ { TermKeyCsi *csi = info; - if(csi->saved_string) - free(csi->saved_string); - free(csi); } @@ -644,52 +637,6 @@ return TERMKEY_RES_KEY; } -static TermKeyResult peekkey_ctrlstring(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep) -{ - size_t str_end = introlen; - - while(str_end < tk->buffcount) { - if(CHARAT(str_end) == 0x9c) // ST - break; - if(CHARAT(str_end) == 0x1b && - (str_end + 1) < tk->buffcount && - CHARAT(str_end+1) == 0x5c) // ESC-prefixed ST - break; - - str_end++; - } - - if(str_end >= tk->buffcount) - return TERMKEY_RES_AGAIN; - -#ifdef DEBUG - fprintf(stderr, "Found a control string: %*s", - str_end - introlen, tk->buffer + introlen); -#endif - - *nbytep = str_end + 1; - if(CHARAT(str_end) == 0x1b) - (*nbytep)++; - - if(csi->saved_string) - free(csi->saved_string); - - size_t len = str_end - introlen; - - csi->saved_string_id++; - csi->saved_string = malloc(len + 1); - - strncpy(csi->saved_string, (char *)tk->buffer + introlen, len); - csi->saved_string[len] = 0; - - key->type = (CHARAT(introlen-1) & 0x1f) == 0x10 ? - TERMKEY_TYPE_DCS : TERMKEY_TYPE_OSC; - key->code.number = csi->saved_string_id; - key->modifiers = 0; - - return TERMKEY_RES_KEY; -} - static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytep) { if(tk->buffcount == 0) @@ -706,10 +653,6 @@ case 0x4f: // ESC-prefixed SS3 return peekkey_ss3(tk, csi, 2, key, force, nbytep); - case 0x50: // ESC-prefixed DCS - case 0x5d: // ESC-prefixed OSC - return peekkey_ctrlstring(tk, csi, 2, key, force, nbytep); - case 0x5b: // ESC-prefixed CSI return peekkey_csi(tk, csi, 2, key, force, nbytep); } @@ -719,10 +662,6 @@ case 0x8f: // SS3 return peekkey_ss3(tk, csi, 1, key, force, nbytep); - case 0x90: // DCS - case 0x9d: // OSC - return peekkey_ctrlstring(tk, csi, 1, key, force, nbytep); - case 0x9b: // CSI return peekkey_csi(tk, csi, 1, key, force, nbytep); } @@ -738,27 +677,3 @@ .peekkey = peekkey, }; - -TermKeyResult termkey_interpret_string(TermKey *tk, const TermKeyKey *key, const char **strp) -{ - struct TermKeyDriverNode *p; - for(p = tk->drivers; p; p = p->next) - if(p->driver == &termkey_driver_csi) - break; - - if(!p) - return TERMKEY_RES_NONE; - - if(key->type != TERMKEY_TYPE_DCS && - key->type != TERMKEY_TYPE_OSC) - return TERMKEY_RES_NONE; - - TermKeyCsi *csi = p->info; - - if(csi->saved_string_id != key->code.number) - return TERMKEY_RES_NONE; - - *strp = csi->saved_string; - - return TERMKEY_RES_KEY; -} === modified file 'man/termkey.7' --- man/termkey.7 2017-03-29 21:42:11 +0000 +++ man/termkey.7 2016-11-30 17:51:58 +0000 @@ -55,12 +55,6 @@ .B TERMKEY_TYPE_MODEREPORT an ANSI or DEC mode value report. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_modereport\fP(3) may be used to interpret it. .TP -.B TERMKEY_TYPE_DCS -a DCS sequence including its terminator. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_string\fP(3) may be used to interpret it. -.TP -.B TERMKEY_TYPE_OSC -a OSC sequence including its terminator. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_string\fP(3) may be used to interpret it. -.TP .B TERMKEY_TYPE_UNKNOWN_CSI an unrecognised CSI sequence. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_csi\fP(3) may be used to interpret it. .PP @@ -146,8 +140,6 @@ The \fBTERMKEY_TYPE_POSITION\fP event type indicates a cursor position report. This is typically sent by a terminal in response to the Report Cursor Position command (\f(CWCSI ? 6 n\fP). The event bytes are opaque, but can be obtained by calling \fBtermkey_interpret_position\fP(3) passing the event structure and pointers to integers to store the result in. Note that only a DEC CPR sequence (\f(CWCSI ? R\fP) is recognised, and not the non-DEC prefixed \f(CWCSI R\fP because the latter could be interpreted as the \f(CWF3\fP function key instead. .SS Mode Reports The \fBTERMKEY_TYPE_MODEREPORT\fP event type indicates an ANSI or DEC mode report. This is typically sent by a terminal in response to the Request Mode command (\f(CWCSI $p\fP or \f(CWCSI ? $p\fP). The event bytes are opaque, but can be obtained by calling \fBtermkey_interpret_modereport\fP(3) passing the event structure and pointers to integers to store the result in. -.SS Control Strings -The \fBTERMKEY_TYPE_DCS\fP and \fBTERMKEY_TYPE_OSC\fP event types indicate a DCS or OSC control string. These are typically sent by the terminal in response of similar kinds of strings being sent as queries by the application. The event bytes are opaque, but the body of the string itself can be obtained by calling \fBtermkey_interpret_string\fP(3) immediately after this event is received. The underlying \fBtermkey\fP instance itself can only store one pending string, so the application should be sure to call this function in a timely manner soon after the event is received; at the very least, before calling any other functions that will insert bytes into or remove key events from the instance. .SS Unrecognised CSIs The \fBTERMKEY_TYPE_UNKNOWN_CSI\fP event type indicates a CSI sequence that the \fBtermkey\fP does not recognise. It will have been extracted from the stream, but is available to the application to inspect by calling \fBtermkey_interpret_csi\fP(3). It is important that if the application wishes to inspect this sequence it is done immediately, before any other IO operations on the \fBtermkey\fP instance (specifically, before calling \fBtermkey_waitkey\fP() or \fBtermkey_getkey\fP() again), otherwise the buffer space consumed by the sequence will be overwritten. Other types of key event do not suffer this limitation as the \fBTermKeyKey\fP structure is sufficient to contain all the information required. .SH "SEE ALSO" === removed file 'man/termkey_interpret_string.3' --- man/termkey_interpret_string.3 2017-03-29 21:42:11 +0000 +++ man/termkey_interpret_string.3 1970-01-01 00:00:00 +0000 @@ -1,24 +0,0 @@ -.TH TERMKEY_INTERPRET_STRING 3 -.SH NAME -termkey_interpret_string \- fetch stored control string -.SH SYNOPSIS -.nf -.B #include -.sp -.BI "TermKeyResult termkey_interpret_string(TermKey *" tk ", const TermKeyKey *" key ", " -.BI " const char **" strp ); -.fi -.sp -Link with \fI-ltermkey\fP. -.SH DESCRIPTION -\fBtermkey_interpret_string\fP() fetches the string stored in the \fBTermKey\fP instance from the most recently received \fBTERMKEY_TYPE_DCS\fP or \fBTERMKEY_TYPE_OSC\fP event. Note that it is important to call this function as soon as possible after obtaining a one of these string key event; specifically, before calling \fBtermkey_getkey\fP() or \fBtermkey_waitkey\fP() again, as a subsequent call will overwrite the buffer space currently containing this string. -.PP -The string pointer whose address is given by \fIstrp\fP will be set to point at the actual stored string in the instance. The caller is free to read this string (which will be correctly NUL-terminated), but should not modify it. It is not necessary to \fBfree\fP() the pointer; the containing \fBTermKey\fP instance will do that. -.SH "RETURN VALUE" -If passed the most recent \fIkey\fP event of the type \fBTERMKEY_TYPE_DCS\fP or \fBTERMKEY_TYPE_OSC\fP, this function will return \fBTERMKEY_RES_KEY\fP and will affect the variables whose pointers were passed in, as described above. -.PP -For other event types, or stale events, it will return \fBTERMKEY_RES_NONE\fP, and its effects on any variables whose pointers were passed in are undefined. -.SH "SEE ALSO" -.BR termkey_waitkey (3), -.BR termkey_getkey (3), -.BR termkey (7) === removed file 't/39dcs.c' --- t/39dcs.c 2017-03-29 21:42:11 +0000 +++ t/39dcs.c 1970-01-01 00:00:00 +0000 @@ -1,56 +0,0 @@ -#include "../termkey.h" -#include "taplib.h" - -int main(int argc, char *argv[]) -{ - TermKey *tk; - TermKeyKey key; - const char *str; - - plan_tests(18); - - tk = termkey_new_abstract("xterm", 0); - - // 7bit DCS - termkey_push_bytes(tk, "\eP1$r1 q\e\\", 10); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for DCS"); - - is_int(key.type, TERMKEY_TYPE_DCS, "key.type for DCS"); - is_int(key.modifiers, 0, "key.modifiers for DCS"); - - is_int(termkey_interpret_string(tk, &key, &str), TERMKEY_RES_KEY, "termkey_interpret_string() gives string"); - is_str(str, "1$r1 q", "termkey_interpret_string() yields correct string"); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey again yields RES_NONE"); - - // 8bit DCS - termkey_push_bytes(tk, "\x90""1$r2 q""\x9c", 8); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for DCS"); - - is_int(key.type, TERMKEY_TYPE_DCS, "key.type for DCS"); - is_int(key.modifiers, 0, "key.modifiers for DCS"); - - is_int(termkey_interpret_string(tk, &key, &str), TERMKEY_RES_KEY, "termkey_interpret_string() gives string"); - is_str(str, "1$r2 q", "termkey_interpret_string() yields correct string"); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey again yields RES_NONE"); - - // 7bit OSC - termkey_push_bytes(tk, "\e]15;abc\e\\", 10); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for OSC"); - - is_int(key.type, TERMKEY_TYPE_OSC, "key.type for OSC"); - is_int(key.modifiers, 0, "key.modifiers for OSC"); - - is_int(termkey_interpret_string(tk, &key, &str), TERMKEY_RES_KEY, "termkey_interpret_string() gives string"); - is_str(str, "15;abc", "termkey_interpret_string() yields correct string"); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey again yields RES_NONE"); - - termkey_destroy(tk); - - return exit_status(); -} === modified file 'termkey.c' --- termkey.c 2017-03-29 21:42:11 +0000 +++ termkey.c 2016-11-30 18:18:55 +0000 @@ -159,12 +159,6 @@ fprintf(stderr, "Mode report mode=%s %d val=%d\n", initial == '?' ? "DEC" : "ANSI", mode, value); } break; - case TERMKEY_TYPE_DCS: - fprintf(stderr, "Device Control String"); - break; - case TERMKEY_TYPE_OSC: - fprintf(stderr, "Operating System Control"); - break; case TERMKEY_TYPE_UNKNOWN_CSI: fprintf(stderr, "unknown CSI\n"); break; @@ -1398,12 +1392,6 @@ else l = snprintf(buffer + pos, len - pos, "Mode(%d=%d)", mode, value); } - case TERMKEY_TYPE_DCS: - l = snprintf(buffer + pos, len - pos, "DCS"); - break; - case TERMKEY_TYPE_OSC: - l = snprintf(buffer + pos, len - pos, "OSC"); - break; case TERMKEY_TYPE_UNKNOWN_CSI: l = snprintf(buffer + pos, len - pos, "CSI %c", key->code.number & 0xff); break; @@ -1532,9 +1520,6 @@ return col1 - col2; } break; - case TERMKEY_TYPE_DCS: - case TERMKEY_TYPE_OSC: - return key1p - key2p; case TERMKEY_TYPE_MODEREPORT: { int initial1, initial2, mode1, mode2, value1, value2; === modified file 'termkey.h.in' --- termkey.h.in 2017-03-29 21:42:11 +0000 +++ termkey.h.in 2016-11-30 18:18:55 +0000 @@ -98,8 +98,6 @@ TERMKEY_TYPE_MOUSE, TERMKEY_TYPE_POSITION, TERMKEY_TYPE_MODEREPORT, - TERMKEY_TYPE_DCS, - TERMKEY_TYPE_OSC, /* add other recognised types here */ TERMKEY_TYPE_UNKNOWN_CSI = -1 @@ -217,8 +215,6 @@ TermKeyResult termkey_interpret_csi(TermKey *tk, const TermKeyKey *key, long args[], size_t *nargs, unsigned long *cmd); -TermKeyResult termkey_interpret_string(TermKey *tk, const TermKeyKey *key, const char **strp); - typedef enum { TERMKEY_FORMAT_LONGMOD = 1 << 0, /* Shift-... instead of S-... */ TERMKEY_FORMAT_CARETCTRL = 1 << 1, /* ^X instead of C-X */