Changeset 28a5ebd in mainline for kernel/generic/src/console


Ignore:
Timestamp:
2020-06-18T15:39:50Z (6 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.

Location:
kernel/generic/src/console
Files:
4 edited

Legend:

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

    r4f663f3e r28a5ebd  
    6565 *
    6666 */
    67 void indev_push_character(indev_t *indev, wchar_t ch)
     67void indev_push_character(indev_t *indev, char32_t ch)
    6868{
    6969        assert(indev);
     
    9292 *
    9393 */
    94 wchar_t indev_pop_character(indev_t *indev)
     94char32_t indev_pop_character(indev_t *indev)
    9595{
    9696        if (atomic_load(&haltstate)) {
     
    117117        waitq_sleep(&indev->wq);
    118118        irq_spinlock_lock(&indev->lock, true);
    119         wchar_t ch = indev->buffer[(indev->index - indev->counter) %
     119        char32_t ch = indev->buffer[(indev->index - indev->counter) %
    120120            INDEV_BUFLEN];
    121121        indev->counter--;
  • kernel/generic/src/console/console.c

    r4f663f3e r28a5ebd  
    5959
    6060#define KIO_PAGES    8
    61 #define KIO_LENGTH   (KIO_PAGES * PAGE_SIZE / sizeof(wchar_t))
     61#define KIO_LENGTH   (KIO_PAGES * PAGE_SIZE / sizeof(char32_t))
    6262
    6363/** Kernel log cyclic buffer */
    64 wchar_t kio[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE)));
     64char32_t kio[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE)));
    6565
    6666/** Kernel log initialized */
     
    9595};
    9696
    97 static void stdout_write(outdev_t *, wchar_t);
     97static void stdout_write(outdev_t *, char32_t);
    9898static void stdout_redraw(outdev_t *);
    9999static void stdout_scroll_up(outdev_t *);
     
    148148}
    149149
    150 static void stdout_write(outdev_t *dev, wchar_t ch)
     150static void stdout_write(outdev_t *dev, char32_t ch)
    151151{
    152152        list_foreach(dev->list, link, outdev_t, sink) {
     
    261261        buf[offset] = 0;
    262262
    263         wchar_t ch;
     263        char32_t ch;
    264264        while ((ch = indev_pop_character(indev)) != '\n') {
    265265                if (ch == '\b') {
    266266                        if (count > 0) {
    267267                                /* Space, backspace, space */
    268                                 putwchar('\b');
    269                                 putwchar(' ');
    270                                 putwchar('\b');
     268                                putuchar('\b');
     269                                putuchar(' ');
     270                                putuchar('\b');
    271271
    272272                                count--;
     
    277277
    278278                if (chr_encode(ch, buf, &offset, buflen - 1) == EOK) {
    279                         putwchar(ch);
     279                        putuchar(ch);
    280280                        count++;
    281281                        buf[offset] = 0;
     
    287287
    288288/** Get character from input device & echo it to screen */
    289 wchar_t getc(indev_t *indev)
    290 {
    291         wchar_t ch = indev_pop_character(indev);
    292         putwchar(ch);
     289char32_t getc(indev_t *indev)
     290{
     291        char32_t ch = indev_pop_character(indev);
     292        putuchar(ch);
    293293        return ch;
    294294}
     
    324324        /* Print characters that weren't printed earlier */
    325325        while (kio_stored > 0) {
    326                 wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH];
     326                char32_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH];
    327327                kio_stored--;
    328328
     
    344344 * The caller is required to hold kio_lock
    345345 */
    346 void kio_push_char(const wchar_t ch)
     346void kio_push_char(const char32_t ch)
    347347{
    348348        kio[(kio_start + kio_len) % KIO_LENGTH] = ch;
     
    360360}
    361361
    362 void putwchar(const wchar_t ch)
     362void putuchar(const char32_t ch)
    363363{
    364364        bool ordy = ((stdout) && (stdout->op->write));
     
    377377                 * for possible future output.
    378378                 *
    379                  * The early_putwchar() function is used to output
     379                 * The early_putuchar() function is used to output
    380380                 * the character for low-level debugging purposes.
    381381                 * Note that the early_putc() function might be
    382382                 * a no-op on certain hardware configurations.
    383383                 */
    384                 early_putwchar(ch);
     384                early_putuchar(ch);
    385385        }
    386386
  • 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)
  • kernel/generic/src/console/prompt.c

    r4f663f3e r28a5ebd  
    5656
    5757        while (true) {
    58                 wchar_t answer = indev_pop_character(indev);
     58                char32_t answer = indev_pop_character(indev);
    5959
    6060                if ((answer == 'y') || (answer == 'Y')) {
     
    8787        printf("--More--");
    8888        while (true) {
    89                 wchar_t continue_showing_hints = indev_pop_character(indev);
     89                char32_t continue_showing_hints = indev_pop_character(indev);
    9090                /* Display a full page again? */
    9191                if ((continue_showing_hints == 'y') ||
Note: See TracChangeset for help on using the changeset viewer.