parse key:command[,key2:command2,...] after BINDINGS= prefix has been stripped; returns False if any problem seen, True if every binding in the comma-separated list is successful */
| 7593 | stripped; returns False if any problem seen, True if every binding in |
| 7594 | the comma-separated list is successful */ |
| 7595 | boolean |
| 7596 | parsebindings(char *bindings) |
| 7597 | { |
| 7598 | char *bind; |
| 7599 | uchar key; |
| 7600 | int i; |
| 7601 | boolean ret = TRUE; /* assume success */ |
| 7602 | static const char *const mousebtn_names[NUM_MOUSE_BUTTONS] = { |
| 7603 | "mouse1", "mouse2" |
| 7604 | }; |
| 7605 | |
| 7606 | /* look for first comma, then decide whether it is the key being bound |
| 7607 | or a list element separator; if it's a key, find separator beyond it */ |
| 7608 | if ((bind = strchr(bindings, ',')) != 0) { |
| 7609 | /* at start so it represents a key */ |
| 7610 | if (bind == bindings) |
| 7611 | bind = strchr(bind + 1, ','); |
| 7612 | |
| 7613 | /* to get here, bind is non-Null and not equal to bindings, |
| 7614 | so it is greater than bindings and bind[-1] is valid; check |
| 7615 | whether current comma happens to be for "\,:cmd" or "',':cmd" |
| 7616 | (":cmd" part is assumed if the comma has expected quoting) */ |
| 7617 | else if (bind[-1] == '\\' || (bind[-1] == '\'' && bind[1] == '\'')) |
| 7618 | bind = strchr(bind + 2, ','); |
| 7619 | } |
| 7620 | /* if a comma separator has been found, break off first binding from rest; |
| 7621 | parse the rest and then handle this first one when recursion returns */ |
| 7622 | if (bind) { |
| 7623 | *bind++ = '\0'; |
| 7624 | if (!parsebindings(bind)) |
| 7625 | ret = FALSE; |
| 7626 | } |
| 7627 | |
| 7628 | /* parse a single binding: first split around : */ |
| 7629 | if (! (bind = strchr(bindings, ':'))) |
| 7630 | return FALSE; /* it's not a binding */ |
| 7631 | *bind++ = 0; |
| 7632 | |
| 7633 | bind = trimspaces(bind); |
| 7634 | |
| 7635 | for (i = 0; i < SIZE(mousebtn_names); i++) |
| 7636 | if (!strcmp(bindings, mousebtn_names[i])) { |
| 7637 | if (!bind_mousebtn(i + 1, bind)) { |
| 7638 | config_error_add("Error binding mouse button %i", i + 1); |
| 7639 | } else { |
| 7640 | return ret; |
| 7641 | } |
| 7642 | } |
| 7643 | |
| 7644 | /* read the key to be bound */ |
| 7645 | key = txt2key(bindings); |
| 7646 | if (!key) { |
| 7647 | config_error_add("Unknown key binding key '%s'", bindings); |
| 7648 | return FALSE; |
| 7649 | } |
| 7650 | |
| 7651 | /* is it a special key? */ |
| 7652 | if (bind_specialkey(key, bind)) |
no test coverage detected