Replaced custom arg1/arg2 CSI parser with generic arg[16] one

This commit is contained in:
Paul LeoNerd Evans 2008-02-07 02:47:15 +00:00
parent 63ed80a897
commit 1f6ae5e40d
1 changed files with 34 additions and 22 deletions

View File

@ -130,41 +130,53 @@ static termkey_result getkey_csi(termkey_t *tk, size_t introlen, termkey_key *ke
return TERMKEY_RES_NONE; return TERMKEY_RES_NONE;
unsigned char cmd = tk->buffer[csi_end]; unsigned char cmd = tk->buffer[csi_end];
int arg1 = -1; int arg[16];
int arg2 = -1; char present = 0;
int args = 0;
size_t p = introlen; size_t p = introlen;
// Now attempt to parse out up to the first two 1;2; separated arguments // Now attempt to parse out up number;number;... separated values
if(tk->buffer[p] >= '0' && tk->buffer[p] <= '9') { while(p < csi_end) {
arg1 = 0; unsigned char c = tk->buffer[p];
while(p < csi_end && tk->buffer[p] != ';') {
arg1 = (arg1 * 10) + tk->buffer[p] - '0';
p++;
}
if(tk->buffer[p] == ';') if(c >= '0' && c <= '9') {
p++; if(!present) {
arg[args] = c - '0';
if(tk->buffer[p] >= '0' && tk->buffer[p] <= '9') { present = 1;
arg2 = 0; }
while(p < csi_end && tk->buffer[p] != ';') { else {
arg2 = (arg2 * 10) + tk->buffer[p] - '0'; arg[args] = (arg[args] * 10) + c - '0';
p++;
} }
} }
else if(c == ';') {
if(!present)
arg[args] = -1;
present = 0;
args++;
if(args > 16)
break;
}
p++;
} }
if(!present)
arg[args] = -1;
args++;
eatbytes(tk, csi_end + 1); eatbytes(tk, csi_end + 1);
if(cmd == '~') { if(cmd == '~') {
if(arg1 >= 0 && arg1 < tk->ncsifuncs) if(arg[0] >= 0 && arg[0] < tk->ncsifuncs)
key->code = tk->csifuncs[arg1]; key->code = tk->csifuncs[arg[0]];
else else
key->code = TERMKEY_SYM_UNKNOWN; key->code = TERMKEY_SYM_UNKNOWN;
if(key->code == TERMKEY_SYM_UNKNOWN) if(key->code == TERMKEY_SYM_UNKNOWN)
fprintf(stderr, "CSI function key %d\n", arg1); fprintf(stderr, "CSI function key %d\n", arg[0]);
} }
else { else {
if(cmd < tk->ncsi_ss3s) if(cmd < tk->ncsi_ss3s)
@ -173,10 +185,10 @@ static termkey_result getkey_csi(termkey_t *tk, size_t introlen, termkey_key *ke
key->code = TERMKEY_SYM_UNKNOWN; key->code = TERMKEY_SYM_UNKNOWN;
if(key->code == TERMKEY_SYM_UNKNOWN) if(key->code == TERMKEY_SYM_UNKNOWN)
fprintf(stderr, "CSI arg1=%d arg2=%d cmd=%c\n", arg1, arg2, cmd); fprintf(stderr, "CSI arg1=%d arg2=%d cmd=%c\n", arg[0], arg[1], cmd);
} }
key->modifiers = arg2 == -1 ? 0 : arg2 - 1; key->modifiers = (args > 1 && arg[1] != -1) ? arg[1] - 1 : 0;
key->flags = TERMKEY_KEYFLAG_SPECIAL; key->flags = TERMKEY_KEYFLAG_SPECIAL;
return TERMKEY_RES_KEY; return TERMKEY_RES_KEY;