mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Added function expand_escapes() which handles now escaping /EVAL and input
line if /SET expand_escapes is set. Supported escapes are \t, \r, \n, \e (ESC), \x (HEX, \x1b), \c (CTRL char, \cA), \000 (octal, \033) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1727 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
b667af72aa
commit
98b82723a1
@ -725,3 +725,47 @@ GSList *columns_sort_list(GSList *list, int rows)
|
|||||||
g_slist_length(list), sorted);
|
g_slist_length(list), sorted);
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Expand escape string, the first character in data should be the
|
||||||
|
one after '\'. Returns the expanded character or -1 if error. */
|
||||||
|
int expand_escape(const char **data)
|
||||||
|
{
|
||||||
|
char digit[4];
|
||||||
|
|
||||||
|
switch (**data) {
|
||||||
|
case 't':
|
||||||
|
return '\t';
|
||||||
|
case 'r':
|
||||||
|
return '\r';
|
||||||
|
case 'n':
|
||||||
|
return '\n';
|
||||||
|
case 'e':
|
||||||
|
return 27; /* ESC */
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
/* hex digit */
|
||||||
|
if (!isxdigit((*data)[1]) || !isxdigit((*data)[2]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
digit[0] = (*data)[1];
|
||||||
|
digit[1] = (*data)[2];
|
||||||
|
digit[2] = '\0';
|
||||||
|
*data += 2;
|
||||||
|
return strtol(digit, NULL, 16);
|
||||||
|
case 'c':
|
||||||
|
/* control character (\cA = ^A) */
|
||||||
|
(*data)++;
|
||||||
|
return toupper(**data) - 64;
|
||||||
|
default:
|
||||||
|
if (!isdigit(**data))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* octal */
|
||||||
|
digit[0] = (*data)[0];
|
||||||
|
digit[1] = (*data)[1];
|
||||||
|
digit[2] = (*data)[2];
|
||||||
|
digit[3] = '\0';
|
||||||
|
*data += 2;
|
||||||
|
return strtol(digit, NULL, 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -101,4 +101,8 @@ int get_max_column_count(GSList *items, COLUMN_LEN_FUNC len_func,
|
|||||||
/* Return a column sorted copy of a list. */
|
/* Return a column sorted copy of a list. */
|
||||||
GSList *columns_sort_list(GSList *list, int rows);
|
GSList *columns_sort_list(GSList *list, int rows);
|
||||||
|
|
||||||
|
/* Expand escape string, the first character in data should be the
|
||||||
|
one after '\'. Returns the expanded character or -1 if error. */
|
||||||
|
int expand_escape(const char **data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -471,7 +471,7 @@ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item,
|
|||||||
{
|
{
|
||||||
char code, **arglist, *ret;
|
char code, **arglist, *ret;
|
||||||
GString *str;
|
GString *str;
|
||||||
int need_free;
|
int need_free, chr;
|
||||||
|
|
||||||
g_return_val_if_fail(cmd != NULL, NULL);
|
g_return_val_if_fail(cmd != NULL, NULL);
|
||||||
g_return_val_if_fail(data != NULL, NULL);
|
g_return_val_if_fail(data != NULL, NULL);
|
||||||
@ -483,16 +483,17 @@ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item,
|
|||||||
code = 0;
|
code = 0;
|
||||||
str = g_string_new(NULL);
|
str = g_string_new(NULL);
|
||||||
while (*cmd != '\0') {
|
while (*cmd != '\0') {
|
||||||
if (code == '\\'){
|
if (code == '\\') {
|
||||||
switch (*cmd) {
|
if (*cmd == ';')
|
||||||
case 't':
|
g_string_append_c(str, ';');
|
||||||
g_string_append_c(str, '\t');
|
else {
|
||||||
break;
|
chr = expand_escape(&cmd);
|
||||||
case 'n':
|
if (chr != -1)
|
||||||
g_string_append_c(str, '\n');
|
g_string_append_c(str, chr);
|
||||||
break;
|
else {
|
||||||
default:
|
g_string_append_c(str, '\\');
|
||||||
g_string_append_c(str, *cmd);
|
g_string_append_c(str, *cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
code = 0;
|
code = 0;
|
||||||
} else if (code == '$') {
|
} else if (code == '$') {
|
||||||
|
@ -703,6 +703,7 @@ static char *expand_escapes(const char *line, SERVER_REC *server,
|
|||||||
WI_ITEM_REC *item)
|
WI_ITEM_REC *item)
|
||||||
{
|
{
|
||||||
char *ptr, *ret;
|
char *ptr, *ret;
|
||||||
|
int chr;
|
||||||
|
|
||||||
ret = ptr = g_malloc(strlen(line)+1);
|
ret = ptr = g_malloc(strlen(line)+1);
|
||||||
for (; *line != '\0'; line++) {
|
for (; *line != '\0'; line++) {
|
||||||
@ -726,16 +727,14 @@ static char *expand_escapes(const char *line, SERVER_REC *server,
|
|||||||
signal_emit("send text", 3, ret, server, item);
|
signal_emit("send text", 3, ret, server, item);
|
||||||
ptr = ret;
|
ptr = ret;
|
||||||
break;
|
break;
|
||||||
case 't':
|
|
||||||
*ptr++ = '\t';
|
|
||||||
break;
|
|
||||||
case '\\':
|
|
||||||
*ptr++ = '\\';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
*ptr++ = '\\';
|
chr = expand_escape(&line);
|
||||||
*ptr++ = *line;
|
if (chr != -1)
|
||||||
break;
|
*ptr++ = chr;
|
||||||
|
else {
|
||||||
|
*ptr++ = '\\';
|
||||||
|
*ptr++ = *line;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user