Basic utf8 output idk

This commit is contained in:
NukeBird 2025-12-04 16:52:03 +03:00
parent f1f44f0d6d
commit 7ac2113e60
3 changed files with 59 additions and 23 deletions

View file

@ -2,27 +2,57 @@
#include <windows.h> #include <windows.h>
#include "axl_string.h" #include "axl_string.h"
i8 axl_putchar(i32 c) i32 axl_putchar(i32 c)
{ {
HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE); u8 buf[4];
int len = 0;
if(console_handle == INVALID_HANDLE_VALUE)
{
return AXL_EOF;
}
i8 char_to_write = (i8)c;
DWORD bytes_written = 0;
BOOL status = WriteConsoleA(console_handle, &char_to_write, 1, if (c <= 0x7F)
&bytes_written, NULL); {
buf[0] = (u8)c;
if(!status || bytes_written != 1) len = 1;
}
else if (c <= 0x07FF)
{
buf[0] = 0xC0 | (u8)(c >> 6);
buf[1] = 0x80 | (u8)(c & 0x3F);
len = 2;
}
else if (c <= 0xFFFF)
{
buf[0] = 0xE0 | (u8)(c >> 12);
buf[1] = 0x80 | (u8)((c >> 6) & 0x3F);
buf[2] = 0x80 | (u8)(c & 0x3F);
len = 3;
}
else if (c <= 0x10FFFF)
{
buf[0] = 0xF0 | (u8)(c >> 18);
buf[1] = 0x80 | (u8)((c >> 12) & 0x3F);
buf[2] = 0x80 | (u8)((c >> 6) & 0x3F);
buf[3] = 0x80 | (u8)(c & 0x3F);
len = 4;
}
else
{ {
return AXL_EOF; return AXL_EOF;
} }
return char_to_write; HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
if (console_handle == INVALID_HANDLE_VALUE)
{
return AXL_EOF;
}
DWORD bytes_written = 0;
BOOL status = WriteConsoleA(console_handle, buf, len, &bytes_written, NULL);
if (!status || bytes_written != (DWORD)len)
{
return AXL_EOF;
}
return c;
} }
i32 axl_puts(const i8* str) i32 axl_puts(const i8* str)

View file

@ -4,7 +4,7 @@
#define AXL_EOF -1 #define AXL_EOF -1
#define AXL_SUCCESS 0 #define AXL_SUCCESS 0
i8 axl_putchar(i32 c); i32 axl_putchar(i32 c);
i32 axl_puts(const i8* str); i32 axl_puts(const i8* str);
#endif // !AXL_IO_H #endif // !AXL_IO_H

18
main.c
View file

@ -1,15 +1,21 @@
#include "axl.h" #include "axl.h"
#include <windows.h>
int _start(void) int _start(void)
{ {
SetConsoleOutputCP(CP_UTF8);
axl_init(); axl_init();
axl_puts("Potato activated"); axl_puts("Привет, мир!");
axl_puts("Quack quack motherducker"); axl_puts("Hello, world!");
axl_puts("Meowdy partner"); axl_puts("Bonjour le monde!");
axl_puts("I am a meat popsicle"); axl_puts("Hola mundo!");
axl_puts("My spoon is too big"); axl_puts("こんにちは世界!");
axl_puts("Blin!"); axl_puts("你好世界!");
axl_puts("안녕하세요 세계!");
axl_puts("สวัสดีชาวโลก!");
axl_puts("नमस्ते दुनिया!");
axl_puts("مرحبا بالعالم!");
void* fds = axl_malloc(83); void* fds = axl_malloc(83);