1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 19:23:12 +02:00

Move StripControlCodes() from message.c to misc.c.

Because I need in the core (again) due to early calls / calls during
rehashes / etc...
This commit is contained in:
Bram Matthys
2022-05-23 10:10:47 +02:00
parent 8c1a858d2e
commit 3fbdb7fd4b
5 changed files with 101 additions and 104 deletions
+3 -100
View File
@@ -22,7 +22,6 @@
/* Forward declarations */
const char *_StripColors(const char *text);
const char *_StripControlCodes(const char *text);
int ban_version(Client *client, const char *text);
CMD_FUNC(cmd_private);
CMD_FUNC(cmd_notice);
@@ -47,7 +46,6 @@ MOD_TEST()
{
MARK_AS_OFFICIAL_MODULE(modinfo);
EfunctionAddConstString(modinfo->handle, EFUNC_STRIPCOLORS, _StripColors);
EfunctionAddConstString(modinfo->handle, EFUNC_STRIPCONTROLCODES, _StripControlCodes);
EfunctionAdd(modinfo->handle, EFUNC_CAN_SEND_TO_CHANNEL, _can_send_to_channel);
return MOD_SUCCESS;
}
@@ -526,8 +524,10 @@ CMD_FUNC(cmd_tagmsg)
/* Taken from xchat by Peter Zelezny
* changed very slightly by codemastr
* RGB color stripping support added -- codemastr
*
* NOTE: if you change/update/enhance StripColors() then consider changing
* the StripControlCodes() function as well (in misc.c) !!
*/
const char *_StripColors(const char *text)
{
int i = 0, len = strlen(text), save_len=0;
@@ -595,103 +595,6 @@ const char *_StripColors(const char *text)
return new_str;
}
/* strip color, bold, underline, and reverse codes from a string */
const char *_StripControlCodes(const char *text)
{
int i = 0, len = strlen(text), save_len=0;
char nc = 0, col = 0, rgb = 0;
const char *save_text=NULL;
static unsigned char new_str[4096];
while (len > 0)
{
if ( col && ((isdigit(*text) && nc < 2) || (*text == ',' && nc < 3)))
{
nc++;
if (*text == ',')
nc = 0;
}
/* Syntax for RGB is ^DHHHHHH where H is a hex digit.
* If < 6 hex digits are specified, the code is displayed
* as text
*/
else if ((rgb && isxdigit(*text) && nc < 6) || (rgb && *text == ',' && nc < 7))
{
nc++;
if (*text == ',')
nc = 0;
}
else
{
if (col)
col = 0;
if (rgb)
{
if (nc != 6)
{
text = save_text+1;
len = save_len-1;
rgb = 0;
continue;
}
rgb = 0;
}
switch (*text)
{
case 3:
/* color */
col = 1;
nc = 0;
break;
case 4:
/* RGB */
save_text = text;
save_len = len;
rgb = 1;
nc = 0;
break;
case 2:
/* bold */
break;
case 31:
/* underline */
break;
case 22:
/* reverse */
break;
case 15:
/* plain */
break;
case 29:
/* italic */
break;
case 30:
/* strikethrough */
break;
case 17:
/* monospace */
break;
case 0xe2:
if (!strncmp(text+1, "\x80\x8b", 2))
{
/* +2 means we skip 3 */
text += 2;
len -= 2;
break;
}
/*fallthrough*/
default:
new_str[i] = *text;
i++;
break;
}
}
text++;
len--;
}
new_str[i] = 0;
return new_str;
}
/** Check ban version { } blocks, returns 1 if banned and 0 if not. */
int ban_version(Client *client, const char *text)
{