fix(xtext): move hexcolor_parse to its own file for the standalone xtext tests

master's new xtext_tests target compiles xtext.c on its own with only
GTK linked, so hexcolor_parse cannot live in util.c. Keep it in a
dependency-free hexcolor.c that both test targets compile, and register
it in the Visual Studio project for the Windows build.

Claude-Session: https://claude.ai/code/session_01Jxd4AknGzdAENADWAGHCzx
This commit is contained in:
BareMetal
2026-10-11 23:58:09 -06:00
parent 39daca9d22
commit 0a4367b1da
10 changed files with 72 additions and 38 deletions
+1 -36
View File
@@ -47,6 +47,7 @@
#include "zoitechatc.h"
#include <ctype.h>
#include "util.h"
#include "hexcolor.h"
#if defined (__FreeBSD__) || defined (__APPLE__)
#include <sys/sysctl.h>
@@ -301,42 +302,6 @@ strip_color (const char *text, int len, int flags)
return new_str;
}
static int
hexcolor_component (const char *s, int avail, guint32 *rgb)
{
int i;
guint32 value = 0;
if (avail < 6)
return FALSE;
for (i = 0; i < 6; i++)
{
if (!g_ascii_isxdigit (s[i]))
return FALSE;
value = (value << 4) | g_ascii_xdigit_value (s[i]);
}
if (rgb)
*rgb = value;
return TRUE;
}
// Parses the parameters of a \004 (hex color) code: RRGGBB[,RRGGBB].
int
hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg)
{
if (has_bg)
*has_bg = FALSE;
if (!hexcolor_component (s, avail, fg))
return 0;
if (avail >= 7 && s[6] == ',' && hexcolor_component (s + 7, avail - 7, bg))
{
if (has_bg)
*has_bg = TRUE;
return 13;
}
return 6;
}
/* CL: strip_color2 strips src and writes the output at dst; pass the same pointer
in both arguments to strip in place. */
int