| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "parse.h" | ||
| 2 | #include "rxvt.h" | ||
| 3 | |||
| 4 | /* | ||
| 5 | rxvt uses some key codes that differ from the ones used by xterm. | ||
| 6 | They don't conflict or overlap with the xterm codes, but specifically | ||
| 7 | aren't handled by term_parse_sequence() because some of them violate | ||
| 8 | the ECMA-48 spec (notably, the ones ending with '$', which isn't a | ||
| 9 | valid final byte). | ||
| 10 | */ | ||
| 11 | 232 | ssize_t rxvt_parse_key(const char *buf, size_t length, KeyCode *k) | |
| 12 | { | ||
| 13 | 232 | KeyCode extra_mods = 0; | |
| 14 | 232 | size_t extra_bytes = 0; | |
| 15 |
3/4✓ Branch 0 (2→3) taken 183 times.
✓ Branch 1 (2→4) taken 49 times.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 183 times.
|
232 | if (length < 2 || buf[0] != '\033') { |
| 16 | 49 | goto generic; | |
| 17 | } | ||
| 18 | |||
| 19 | 183 | KeyCode mods; | |
| 20 |
3/4✓ Branch 0 (5→6) taken 5 times.
✓ Branch 1 (5→7) taken 79 times.
✓ Branch 2 (5→10) taken 99 times.
✗ Branch 3 (5→11) not taken.
|
183 | switch (buf[1]) { |
| 21 | 5 | case 'O': | |
| 22 | 5 | mods = MOD_CTRL; | |
| 23 | 5 | goto final; | |
| 24 | case '[': | ||
| 25 | mods = MOD_SHIFT; | ||
| 26 | 84 | final: | |
| 27 |
2/2✓ Branch 0 (7→8) taken 58 times.
✓ Branch 1 (7→35) taken 26 times.
|
84 | if (length < 3) { |
| 28 | return TPARSE_PARTIAL_MATCH; | ||
| 29 | } | ||
| 30 |
2/2✓ Branch 0 (8→9) taken 8 times.
✓ Branch 1 (8→11) taken 50 times.
|
58 | switch (buf[2]) { |
| 31 | 8 | case 'a': // Up | |
| 32 | case 'b': // Down | ||
| 33 | case 'c': // Right | ||
| 34 | case 'd': // Left | ||
| 35 | 8 | *k = mods | (KEY_UP + (buf[2] - 'a')); | |
| 36 | 8 | return 3; | |
| 37 | } | ||
| 38 | break; | ||
| 39 | 99 | case '\033': | |
| 40 | 99 | extra_mods = MOD_META; | |
| 41 | 99 | extra_bytes = 1; | |
| 42 | 99 | buf++; | |
| 43 | 99 | length--; | |
| 44 | 99 | break; | |
| 45 | } | ||
| 46 | |||
| 47 |
3/4✓ Branch 0 (11→12) taken 50 times.
✓ Branch 1 (11→13) taken 99 times.
✗ Branch 2 (12→13) not taken.
✓ Branch 3 (12→14) taken 50 times.
|
149 | if (length < 4 || buf[1] != '[') { |
| 48 | 99 | goto generic; | |
| 49 | } | ||
| 50 | |||
| 51 | 50 | KeyCode key; | |
| 52 | 50 | ssize_t n; | |
| 53 |
5/5✓ Branch 0 (14→15) taken 12 times.
✓ Branch 1 (14→16) taken 12 times.
✓ Branch 2 (14→17) taken 12 times.
✓ Branch 3 (14→18) taken 12 times.
✓ Branch 4 (14→19) taken 2 times.
|
50 | switch (buf[3]) { |
| 54 | 12 | case '~': key = 0; break; | |
| 55 | 12 | case '^': key = MOD_CTRL; break; | |
| 56 | 12 | case '$': key = MOD_SHIFT; break; | |
| 57 | 12 | case '@': key = MOD_SHIFT | MOD_CTRL; break; | |
| 58 | 2 | default: goto generic; | |
| 59 | } | ||
| 60 | |||
| 61 |
6/7✓ Branch 0 (20→21) taken 8 times.
✓ Branch 1 (20→22) taken 8 times.
✓ Branch 2 (20→23) taken 8 times.
✓ Branch 3 (20→24) taken 8 times.
✓ Branch 4 (20→25) taken 8 times.
✓ Branch 5 (20→26) taken 8 times.
✗ Branch 6 (20→27) not taken.
|
48 | switch (buf[2]) { |
| 62 | 8 | case '2': key |= KEY_INSERT; break; | |
| 63 | 8 | case '3': key |= KEY_DELETE; break; | |
| 64 | 8 | case '5': key |= KEY_PAGE_UP; break; | |
| 65 | 8 | case '6': key |= KEY_PAGE_DOWN; break; | |
| 66 | 8 | case '7': key |= KEY_HOME; break; | |
| 67 | 8 | case '8': key |= KEY_END; break; | |
| 68 | ✗ | default: goto generic; | |
| 69 | } | ||
| 70 | |||
| 71 | 48 | *k = key | extra_mods; | |
| 72 | 48 | return 4 + extra_bytes; | |
| 73 | |||
| 74 | 150 | generic: | |
| 75 | 150 | n = term_parse_sequence(buf, length, &key); | |
| 76 |
2/2✓ Branch 0 (30→31) taken 2 times.
✓ Branch 1 (30→35) taken 148 times.
|
150 | if (n <= 0) { |
| 77 | return n; | ||
| 78 | } | ||
| 79 |
3/4✓ Branch 0 (31→32) taken 1 times.
✓ Branch 1 (31→34) taken 1 times.
✓ Branch 2 (32→33) taken 1 times.
✗ Branch 3 (32→34) not taken.
|
2 | if (unlikely(key == KEY_IGNORE && extra_mods)) { |
| 80 | 1 | extra_mods = 0; | |
| 81 | } | ||
| 82 | 2 | *k = key | extra_mods; | |
| 83 | 2 | return n + extra_bytes; | |
| 84 | } | ||
| 85 |