diff options
Diffstat (limited to 'all_unicode_chars')
-rw-r--r-- | all_unicode_chars/all_unicode_chars.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/all_unicode_chars/all_unicode_chars.c b/all_unicode_chars/all_unicode_chars.c new file mode 100644 index 0000000..33099b1 --- /dev/null +++ b/all_unicode_chars/all_unicode_chars.c @@ -0,0 +1,54 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <unistd.h> +#include <errno.h> +#include <locale.h> +#include <string.h> +#include <uchar.h> +#include <wchar.h> + +int main( int argc, char *args[] ){ + setlocale( LC_ALL, "" ); + fprintf( stdout, "Buffer size: %llu\n", (0xFFFF - (0x00A0 - 0x007F)) * 4 ); + uint16_t char_buffer[(0xFFFF - (0x00A0 - 0x007F)) * 4] = {0}; + memset( (void*)&char_buffer, 0, (0xFFFF - (0x00A0 - 0x007F)) * 4 ); + uint16_t current_char = 0x0020; + size_t char_bytes = 0; + char mbstr[sizeof(wchar_t)] = {0}; + memset( (void*)&mbstr, 0, sizeof(wchar_t) ); + size_t b_size = 0; + mbstate_t *m_state = NULL; + for ( ; current_char < 0xFFFF; current_char++ ){ + if ( current_char > 0x007F && current_char < 0x00A0 ) + current_char = 0x00A0; + if ( (b_size = wcrtomb((char*)&mbstr, (wchar_t)current_char, m_state)) == (size_t)-1 ) + continue; + wmemmove( (void*)&char_buffer[char_bytes], (const void*)&mbstr, b_size ); + memset( (void*)&mbstr, 0, b_size ); + char_bytes += b_size; + } + fprintf( stdout, "Copied %llu bytes into buffer\n", char_bytes ); + b_size = 0; + m_state = NULL; + memset( (void*)&mbstr, 0, sizeof(mbstr) ); + FILE *output = fopen( "unicode_chars.txt", "w" ); + if ( output == NULL ){ + fprintf( stderr, "Error: %s\n", strerror(errno) ); + exit( EXIT_FAILURE ); + } + ssize_t char_written = 0; + if ( (char_written = (ssize_t)fwrite((void*)&char_buffer, sizeof(uint16_t), char_bytes, output)) < 0 ){ + fclose( output ); + fprintf( stderr, "Error writing file: %s\n", strerror(errno) ); + exit( EXIT_FAILURE ); + } + fclose( output ); + fprintf( stdout, "%llu bytes written into unicode_chars.txt\n", char_written ); + memset( (void*)&char_buffer, 0, sizeof(char_buffer) ); + output = NULL; + current_char = 0x0020; + char_written = 0; + char_bytes = 0; + exit( EXIT_SUCCESS ); +} |