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:
Timo Sirainen 2001-08-08 20:00:25 +00:00 committed by cras
commit 98b82723a1
4 changed files with 68 additions and 20 deletions

View file

@ -725,3 +725,47 @@ GSList *columns_sort_list(GSList *list, int rows)
g_slist_length(list), 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);
}
}