чување 860cae35d1bda8c94f250d8e15a8e77c6a1b063b
родитељ a9e96234bfc5a104b1328b28f047b990cc67736b
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Tue, 10 Mar 2026 12:48:06 +0100
Convert wchar_t constants to uint32_t
Diffstat:
измењених датотека: 2, додавања: 12(+), брисања: 11(-)
diff --git a/TODO b/TODO
@@ -1,6 +1,6 @@
TODO
====
-[ ] Convert wchar_t constants to uint32_t
+[x] Convert wchar_t constants to uint32_t
[x] Check if argument is a file or something else
diff --git a/dtree.c b/dtree.c
@@ -23,6 +23,7 @@
" any later version. Copyright (C) 2023-2026 Strahinya Radich.\n" \
" See the file LICENSE for exact copyright and license " \
"details.")
+#define U32(c) ((u32)(0x00000000 | (c)))
struct Node {
int level;
@@ -59,16 +60,16 @@ static const int string_to_symbol_set[] = {
};
static const u32 tree_symbols[][5] = {
[TREE_SYMBOLS_ASCII] = {
- (u32)L'`', (u32)L'+', (u32)L'-',
- (u32)L'|', (u32)L' '
+ U32('`'), U32('+'), U32('-'),
+ U32('|'), U32(' ')
},
[TREE_SYMBOLS_SINGLE] = {
- (u32)L'\u2514', (u32)L'\u251c', (u32)L'\u2500',
- (u32)L'\u2502', (u32)L' '
+ U32(0x2514), U32(0x251c), U32(0x2500),
+ U32(0x2502), U32(' ')
},
[TREE_SYMBOLS_DOUBLE] = {
- (u32)L'\u255a', (u32)L'\u2560', (u32)L'\u2550',
- (u32)L'\u2551', (u32)L' '
+ U32(0x255a), U32(0x2560), U32(0x2550),
+ U32(0x2551), U32(' ')
}
};
/* clang-format on */
@@ -212,7 +213,7 @@ print_indent(void)
while (*ppindent)
{
- len = u32_char_to_u8(u8ch, *ppindent);
+ len = u32_rune_to_u8(u8ch, *ppindent);
u8ch[len] = 0;
printf("%s ", u8ch);
ppindent++;
@@ -233,12 +234,12 @@ print_node(const struct Node* node)
size_t len;
if (!node->next)
- len = u32_char_to_u8(u8ch, tree_symbols[symbol_set][0]);
+ len = u32_rune_to_u8(u8ch, tree_symbols[symbol_set][0]);
else
- len = u32_char_to_u8(u8ch, tree_symbols[symbol_set][1]);
+ len = u32_rune_to_u8(u8ch, tree_symbols[symbol_set][1]);
u8ch[len] = 0;
printf("%s", u8ch);
- len = u32_char_to_u8(u8ch, tree_symbols[symbol_set][2]);
+ len = u32_rune_to_u8(u8ch, tree_symbols[symbol_set][2]);
u8ch[len] = 0;
printf("%s%s", u8ch, u8ch);
}