comparison mcabber/mcabber/screen.c @ 2101:f56c214a19dc

Add a guard for 'attention_char'
author Mikael Berthe <mikael@lilotux.net>
date Sun, 11 May 2014 15:07:07 +0200
parents 113d3b96ae3e
children 54548cf8f646
comparison
equal deleted inserted replaced
2100:113d3b96ae3e 2101:f56c214a19dc
1531 roster_msg_setflag(winId, special, TRUE); 1531 roster_msg_setflag(winId, special, TRUE);
1532 update_roster = TRUE; 1532 update_roster = TRUE;
1533 } 1533 }
1534 } 1534 }
1535 1535
1536 static char *attention_sign_guard(const gchar *key, const gchar *new_value)
1537 {
1538 update_roster = TRUE;
1539 if (g_strcmp0(settings_opt_get(key), new_value)) {
1540 guint sign;
1541 char *c;
1542 if (!new_value || !*new_value)
1543 return NULL;
1544 sign = get_char(new_value);
1545 c = next_char((char*)new_value);
1546 if (get_char_width(new_value) != 1 || !iswprint(sign) || *c) {
1547 scr_log_print(LPRINT_NORMAL, "attention_char value is invalid.");
1548 return NULL;
1549 }
1550 // The new value looks good (1-char wide and printable)
1551 return g_strdup(new_value);
1552 }
1553 return g_strdup(new_value);
1554 }
1555
1556 // scr_init_settings()
1557 // Create guards for UI settings
1558 void scr_init_settings(void)
1559 {
1560 settings_set_guard("attention_char", attention_sign_guard);
1561 }
1562
1536 static unsigned int attention_sign(void) 1563 static unsigned int attention_sign(void)
1537 { 1564 {
1538 guint sign;
1539 const char *as = settings_opt_get("attention_char"); 1565 const char *as = settings_opt_get("attention_char");
1540 if (!as) 1566 if (!as)
1541 return DEFAULT_ATTENTION_CHAR; 1567 return DEFAULT_ATTENTION_CHAR;
1542 sign = get_char(as); 1568 return get_char(as);
1543 if (get_char_width(as) != 1 || !iswprint(sign)) // XXX Better use a guard
1544 return DEFAULT_ATTENTION_CHAR;
1545 return sign;
1546 } 1569 }
1547 1570
1548 // scr_update_main_status(forceupdate) 1571 // scr_update_main_status(forceupdate)
1549 // Redraw the main (bottom) status line. 1572 // Redraw the main (bottom) status line.
1550 // You can set forceupdate to FALSE in order to optimize screen refresh 1573 // You can set forceupdate to FALSE in order to optimize screen refresh