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


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/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
Note: See TracChangeset for help on using the changeset viewer.