Ignore:
Timestamp:
2020-06-18T15:39:50Z (4 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce52c333
Parents:
4f663f3e
Message:

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/kconsole.c

    r4f663f3e r28a5ebd  
    8686LIST_INITIALIZE(cmd_list);      /**< Command list. */
    8787
    88 static wchar_t history[KCONSOLE_HISTORY][MAX_CMDLINE] = { };
     88static char32_t history[KCONSOLE_HISTORY][MAX_CMDLINE] = { };
    8989static size_t history_pos = 0;
    9090
     
    156156
    157157/** Print count times a character */
    158 _NO_TRACE static void print_cc(wchar_t ch, size_t count)
     158_NO_TRACE static void print_cc(char32_t ch, size_t count)
    159159{
    160160        size_t i;
    161161        for (i = 0; i < count; i++)
    162                 putwchar(ch);
     162                putuchar(ch);
    163163}
    164164
     
    290290}
    291291
    292 _NO_TRACE static cmd_info_t *parse_cmd(const wchar_t *cmdline)
     292_NO_TRACE static cmd_info_t *parse_cmd(const char32_t *cmdline)
    293293{
    294294        size_t start = 0;
     
    331331}
    332332
    333 _NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev,
     333_NO_TRACE static char32_t *clever_readline(const char *prompt, indev_t *indev,
    334334    char *tmp)
    335335{
     
    337337
    338338        size_t position = 0;
    339         wchar_t *current = history[history_pos];
     339        char32_t *current = history[history_pos];
    340340        current[0] = 0;
    341341
    342342        while (true) {
    343                 wchar_t ch = indev_pop_character(indev);
     343                char32_t ch = indev_pop_character(indev);
    344344
    345345                if (ch == '\n') {
    346346                        /* Enter */
    347                         putwchar(ch);
     347                        putuchar(ch);
    348348                        break;
    349349                }
     
    356356                        if (wstr_remove(current, position - 1)) {
    357357                                position--;
    358                                 putwchar('\b');
     358                                putuchar('\b');
    359359                                printf("%ls ", current + position);
    360360                                print_cc('\b', wstr_length(current) - position + 1);
     
    369369                        for (; (current[position] != 0) && (!isspace(current[position]));
    370370                            position++)
    371                                 putwchar(current[position]);
     371                                putuchar(current[position]);
    372372
    373373                        /*
     
    464464                        /* Left */
    465465                        if (position > 0) {
    466                                 putwchar('\b');
     466                                putuchar('\b');
    467467                                position--;
    468468                        }
     
    473473                        /* Right */
    474474                        if (position < wstr_length(current)) {
    475                                 putwchar(current[position]);
     475                                putuchar(current[position]);
    476476                                position++;
    477477                        }
     
    646646        size_t offset = *start;
    647647        size_t prev = *start;
    648         wchar_t ch;
     648        char32_t ch;
    649649
    650650        while ((ch = str_decode(cmdline, &offset, size)) != 0) {
     
    825825
    826826        while (true) {
    827                 wchar_t *tmp = clever_readline((char *) prompt, stdin, buffer);
     827                char32_t *tmp = clever_readline((char *) prompt, stdin, buffer);
    828828                size_t len = wstr_length(tmp);
    829829                if (!len)
Note: See TracChangeset for help on using the changeset viewer.