mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-10-16 18:27:13 +00:00
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:
@@ -43,6 +43,7 @@
|
|||||||
<ClInclude Include="typedef.h" />
|
<ClInclude Include="typedef.h" />
|
||||||
<ClInclude Include="url.h" />
|
<ClInclude Include="url.h" />
|
||||||
<ClInclude Include="userlist.h" />
|
<ClInclude Include="userlist.h" />
|
||||||
|
<ClInclude Include="hexcolor.h" />
|
||||||
<ClInclude Include="util.h" />
|
<ClInclude Include="util.h" />
|
||||||
<ClInclude Include="zoitechat-plugin.h" />
|
<ClInclude Include="zoitechat-plugin.h" />
|
||||||
<ClInclude Include="zoitechat.h" />
|
<ClInclude Include="zoitechat.h" />
|
||||||
@@ -79,6 +80,7 @@
|
|||||||
<ClCompile Include="tree.c" />
|
<ClCompile Include="tree.c" />
|
||||||
<ClCompile Include="url.c" />
|
<ClCompile Include="url.c" />
|
||||||
<ClCompile Include="userlist.c" />
|
<ClCompile Include="userlist.c" />
|
||||||
|
<ClCompile Include="hexcolor.c" />
|
||||||
<ClCompile Include="util.c" />
|
<ClCompile Include="util.c" />
|
||||||
<ClCompile Include="zoitechat.c" />
|
<ClCompile Include="zoitechat.c" />
|
||||||
<ClCompile Include="theme-service.c" />
|
<ClCompile Include="theme-service.c" />
|
||||||
|
|||||||
@@ -98,6 +98,9 @@
|
|||||||
<ClInclude Include="userlist.h">
|
<ClInclude Include="userlist.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="hexcolor.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="util.h">
|
<ClInclude Include="util.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -202,6 +205,9 @@
|
|||||||
<ClCompile Include="userlist.c">
|
<ClCompile Include="userlist.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="hexcolor.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="util.c">
|
<ClCompile Include="util.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* ZoiteChat
|
||||||
|
* Parsing of \004 (hex color) formatting codes: RRGGBB[,RRGGBB].
|
||||||
|
* Kept free of other application dependencies so the xtext widget tests can
|
||||||
|
* compile it on its own.
|
||||||
|
* Distributed under GPL-2.0-or-later; see COPYING. */
|
||||||
|
|
||||||
|
#include "hexcolor.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/* ZoiteChat
|
||||||
|
* Parsing of \004 (hex color) formatting codes: RRGGBB[,RRGGBB].
|
||||||
|
* See https://modern.ircdocs.horse/formatting
|
||||||
|
* Distributed under GPL-2.0-or-later; see COPYING. */
|
||||||
|
|
||||||
|
#ifndef ZOITECHAT_HEXCOLOR_H
|
||||||
|
#define ZOITECHAT_HEXCOLOR_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
/* Parses the parameters following a \004 byte. Returns the number of bytes
|
||||||
|
* consumed (6 or 13), or 0 if no valid RRGGBB follows. fg, bg and has_bg
|
||||||
|
* may be NULL. */
|
||||||
|
int hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -25,6 +25,7 @@ common_sources = [
|
|||||||
'tree.c',
|
'tree.c',
|
||||||
'url.c',
|
'url.c',
|
||||||
'userlist.c',
|
'userlist.c',
|
||||||
|
'hexcolor.c',
|
||||||
'util.c'
|
'util.c'
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -201,6 +202,7 @@ test('Emoji Data Tests', emoji_data_tests,
|
|||||||
hexcolor_tests = executable('hexcolor_tests',
|
hexcolor_tests = executable('hexcolor_tests',
|
||||||
[
|
[
|
||||||
'tests/test-hexcolor.c',
|
'tests/test-hexcolor.c',
|
||||||
|
'hexcolor.c',
|
||||||
'util.c',
|
'util.c',
|
||||||
],
|
],
|
||||||
include_directories: [config_h_include, include_directories('.')],
|
include_directories: [config_h_include, include_directories('.')],
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "../hexcolor.h"
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+1
-36
@@ -47,6 +47,7 @@
|
|||||||
#include "zoitechatc.h"
|
#include "zoitechatc.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "hexcolor.h"
|
||||||
|
|
||||||
#if defined (__FreeBSD__) || defined (__APPLE__)
|
#if defined (__FreeBSD__) || defined (__APPLE__)
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
@@ -301,42 +302,6 @@ strip_color (const char *text, int len, int flags)
|
|||||||
return new_str;
|
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
|
/* CL: strip_color2 strips src and writes the output at dst; pass the same pointer
|
||||||
in both arguments to strip in place. */
|
in both arguments to strip in place. */
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ void util_exec (const char *cmd);
|
|||||||
#define STRIP_ALL 7
|
#define STRIP_ALL 7
|
||||||
gchar *strip_color (const char *text, int len, int flags);
|
gchar *strip_color (const char *text, int len, int flags);
|
||||||
int strip_color2 (const char *src, int len, char *dst, int flags);
|
int strip_color2 (const char *src, int len, char *dst, int flags);
|
||||||
int hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg);
|
|
||||||
int strip_hidden_attribute (char *src, char *dst);
|
int strip_hidden_attribute (char *src, char *dst);
|
||||||
char *errorstring (int err);
|
char *errorstring (int err);
|
||||||
int waitline (int sok, char *buf, int bufsize, int);
|
int waitline (int sok, char *buf, int bufsize, int);
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ test('Emoji Font Tests', emoji_font_tests,
|
|||||||
)
|
)
|
||||||
|
|
||||||
xtext_tests = executable('xtext_tests',
|
xtext_tests = executable('xtext_tests',
|
||||||
'tests/test-xtext.c',
|
['tests/test-xtext.c', '../common/hexcolor.c'],
|
||||||
include_directories: [config_h_include],
|
include_directories: [config_h_include],
|
||||||
dependencies: [gtk_dep],
|
dependencies: [gtk_dep],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "../common/zoitechat.h"
|
#include "../common/zoitechat.h"
|
||||||
#include "../common/fe.h"
|
#include "../common/fe.h"
|
||||||
#include "../common/util.h"
|
#include "../common/util.h"
|
||||||
|
#include "../common/hexcolor.h"
|
||||||
#include "../common/zoitechatc.h"
|
#include "../common/zoitechatc.h"
|
||||||
#include "../common/url.h"
|
#include "../common/url.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user