Changeset 28a5ebd in mainline for uspace/app


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:
uspace/app
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r4f663f3e r28a5ebd  
    154154}
    155155
    156 static void paged_char(wchar_t c)
     156static void paged_char(char32_t c)
    157157{
    158158        if (last_char_was_newline && number) {
     
    160160                printf("%6u  ", lineno);
    161161        }
    162         putwchar(c);
     162        putuchar(c);
    163163        last_char_was_newline = c == '\n';
    164164        if (paging_enabled) {
     
    269269                                        paged_char(((count + i + 1) & 0xf) == 0 ? '\n' : ' ');
    270270                                } else {
    271                                         wchar_t c = str_decode(buff, &offset, bytes);
     271                                        char32_t c = str_decode(buff, &offset, bytes);
    272272                                        if (c == 0) {
    273273                                                /* Reached end of string */
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    r4f663f3e r28a5ebd  
    108108                while (true) {
    109109                        size_t prev_off = off;
    110                         wchar_t cur_char = str_decode(path, &off, STR_NO_LIMIT);
     110                        char32_t cur_char = str_decode(path, &off, STR_NO_LIMIT);
    111111                        if ((cur_char == 0) || (cur_char == U_SPECIAL)) {
    112112                                break;
  • uspace/app/bdsh/cmds/modules/printf/printf.c

    r4f663f3e r28a5ebd  
    6868 * @param arg string with data to print.
    6969 */
    70 static int print_arg(wchar_t ch, const char *arg)
     70static int print_arg(char32_t ch, const char *arg)
    7171{
    7272        switch (ch) {
     
    9393 * @param ch  Control character.
    9494 */
    95 static int process_ctl(wchar_t ch)
     95static int process_ctl(char32_t ch)
    9696{
    9797        switch (ch) {
     
    120120        char *fmt;
    121121        size_t pos, fmt_sz;
    122         wchar_t ch;
     122        char32_t ch;
    123123        bool esc_flag = false;
    124124        unsigned int carg;     // Current argument
     
    170170                                break;
    171171                        }
    172                         putwchar(ch);
     172                        putuchar(ch);
    173173                        break;
    174174
    175175                emit:
    176                         putwchar(ch);
     176                        putuchar(ch);
    177177                        esc_flag = false;
    178178                }
  • uspace/app/bdsh/compl.c

    r4f663f3e r28a5ebd  
    4444#include "util.h"
    4545
    46 static errno_t compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state);
     46static errno_t compl_init(char32_t *text, size_t pos, size_t *cstart, void **state);
    4747static errno_t compl_get_next(void *state, char **compl);
    4848static void compl_fini(void *state);
     
    9494 * Set up iterators in completion object, based on current token.
    9595 */
    96 static errno_t compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state)
     96static errno_t compl_init(char32_t *text, size_t pos, size_t *cstart, void **state)
    9797{
    9898        compl_t *cs = NULL;
  • uspace/app/bdsh/tok.c

    r4f663f3e r28a5ebd  
    3636
    3737/* Forward declarations of static functions */
    38 static wchar_t tok_get_char(tokenizer_t *);
    39 static wchar_t tok_look_char(tokenizer_t *);
    40 static errno_t tok_push_char(tokenizer_t *, wchar_t);
     38static char32_t tok_get_char(tokenizer_t *);
     39static char32_t tok_look_char(tokenizer_t *);
     40static errno_t tok_push_char(tokenizer_t *, char32_t);
    4141static errno_t tok_push_token(tokenizer_t *);
    4242static bool tok_pending_chars(tokenizer_t *);
     
    9292{
    9393        errno_t rc;
    94         wchar_t next_char;
     94        char32_t next_char;
    9595
    9696        /* Read the input line char by char and append tokens */
     
    182182{
    183183        errno_t rc;
    184         wchar_t next_char;
     184        char32_t next_char;
    185185
    186186        while ((next_char = tok_look_char(tok)) != 0) {
     
    214214
    215215/** Get a char from input, advancing the input position */
    216 wchar_t tok_get_char(tokenizer_t *tok)
     216char32_t tok_get_char(tokenizer_t *tok)
    217217{
    218218        tok->in_char_offset++;
     
    221221
    222222/** Get a char from input, while staying on the same input position */
    223 wchar_t tok_look_char(tokenizer_t *tok)
     223char32_t tok_look_char(tokenizer_t *tok)
    224224{
    225225        size_t old_offset = tok->in_offset;
    226226        size_t old_char_offset = tok->in_char_offset;
    227         wchar_t ret = tok_get_char(tok);
     227        char32_t ret = tok_get_char(tok);
    228228        tok->in_offset = old_offset;
    229229        tok->in_char_offset = old_char_offset;
     
    232232
    233233/** Append a char to the end of the current token */
    234 errno_t tok_push_char(tokenizer_t *tok, wchar_t ch)
     234errno_t tok_push_char(tokenizer_t *tok, char32_t ch)
    235235{
    236236        return chr_encode(ch, tok->outbuf, &tok->outbuf_offset, tok->outbuf_size);
  • uspace/app/edit/edit.c

    r4f663f3e r28a5ebd  
    147147static void pane_caret_display(void);
    148148
    149 static void insert_char(wchar_t c);
     149static void insert_char(char32_t c);
    150150static void delete_char_before(void);
    151151static void delete_char_after(void);
     
    630630        kbd_event_t *kev;
    631631        char *str;
    632         wchar_t buffer[INFNAME_MAX_LEN + 1];
     632        char32_t buffer[INFNAME_MAX_LEN + 1];
    633633        int max_len;
    634634        int nc;
     
    670670                                default:
    671671                                        if (kev->c >= 32 && nc < max_len) {
    672                                                 putwchar(kev->c);
     672                                                putuchar(kev->c);
    673673                                                console_flush(con);
    674674                                                buffer[nc++] = kev->c;
     
    696696{
    697697        FILE *f;
    698         wchar_t c;
     698        char32_t c;
    699699        char buf[BUF_SIZE];
    700700        int bcnt;
     
    850850        coord_t rbc, rec;
    851851        char row_buf[ROW_BUF_SIZE];
    852         wchar_t c;
     852        char32_t c;
    853853        size_t pos, size;
    854854        int s_column;
     
    10551055
    10561056/** Insert a character at caret position. */
    1057 static void insert_char(wchar_t c)
     1057static void insert_char(char32_t c)
    10581058{
    10591059        spt_t pt;
     
    12851285
    12861286/* Search operations */
    1287 static errno_t search_spt_producer(void *data, wchar_t *ret)
     1287static errno_t search_spt_producer(void *data, char32_t *ret)
    12881288{
    12891289        assert(data != NULL);
     
    12941294}
    12951295
    1296 static errno_t search_spt_reverse_producer(void *data, wchar_t *ret)
     1296static errno_t search_spt_reverse_producer(void *data, char32_t *ret)
    12971297{
    12981298        assert(data != NULL);
     
    15131513        char *str;
    15141514        size_t off;
    1515         wchar_t c;
     1515        char32_t c;
    15161516        errno_t rc;
    15171517
     
    16091609}
    16101610
    1611 static wchar_t get_first_wchar(const char *str)
     1611static char32_t get_first_wchar(const char *str)
    16121612{
    16131613        size_t offset = 0;
     
    16301630                return false;
    16311631
    1632         wchar_t first_char = get_first_wchar(ch);
     1632        char32_t first_char = get_first_wchar(ch);
    16331633        switch (first_char) {
    16341634        case ' ':
     
    16561656                return false;
    16571657
    1658         wchar_t first_char = get_first_wchar(ch);
     1658        char32_t first_char = get_first_wchar(ch);
    16591659        switch (first_char) {
    16601660        case ',':
  • uspace/app/edit/search.c

    r4f663f3e r28a5ebd  
    5050                return NULL;
    5151
    52         wchar_t *p = str_to_awstr(pattern);
     52        char32_t *p = str_to_awstr(pattern);
    5353        if (p == NULL) {
    5454                free(search);
     
    6363                half = search->pattern_length / 2;
    6464                for (pos = 0; pos < half; pos++) {
    65                         wchar_t tmp = p[pos];
     65                        char32_t tmp = p[pos];
    6666                        p[pos] = p[search->pattern_length - pos - 1];
    6767                        p[search->pattern_length - pos - 1] = tmp;
     
    107107        search_equals_fn eq = s->ops.equals;
    108108
    109         wchar_t cur_char;
     109        char32_t cur_char;
    110110        errno_t rc = EOK;
    111111        while ((rc = s->ops.producer(s->client_data, &cur_char)) == EOK && cur_char > 0) {
     
    141141}
    142142
    143 bool char_exact_equals(const wchar_t a, const wchar_t b)
     143bool char_exact_equals(const char32_t a, const char32_t b)
    144144{
    145145        return a == b;
  • uspace/app/edit/search.h

    r4f663f3e r28a5ebd  
    4242struct search;
    4343typedef struct search search_t;
    44 typedef bool (*search_equals_fn)(const wchar_t, const wchar_t);
    45 typedef errno_t (*search_producer_fn)(void *, wchar_t *);
     44typedef bool (*search_equals_fn)(const char32_t, const char32_t);
     45typedef errno_t (*search_producer_fn)(void *, char32_t *);
    4646typedef errno_t (*search_mark_fn)(void *, void **);
    4747typedef void (*search_mark_free_fn)(void *);
     
    5959} search_ops_t;
    6060
    61 extern bool char_exact_equals(const wchar_t, const wchar_t);
     61extern bool char_exact_equals(const char32_t, const char32_t);
    6262extern search_t *search_init(const char *, void *, search_ops_t, bool);
    6363extern errno_t search_next_match(search_t *, match_t *);
  • uspace/app/edit/search_impl.h

    r4f663f3e r28a5ebd  
    4343        /* Note: This structure is opaque for the user. */
    4444
    45         wchar_t *pattern;
     45        char32_t *pattern;
    4646        size_t pattern_length;
    4747        ssize_t *back_table;
  • uspace/app/edit/sheet.c

    r4f663f3e r28a5ebd  
    195195        size_t copy_sz;
    196196        size_t off, prev;
    197         wchar_t c;
     197        char32_t c;
    198198
    199199        spp = sh->data + spos->b_off;
     
    222222{
    223223        size_t cur_pos, prev_pos;
    224         wchar_t c;
     224        char32_t c;
    225225        coord_t cc;
    226226
     
    291291        size_t off;
    292292        coord_t cc;
    293         wchar_t c;
     293        char32_t c;
    294294        sheet_t *sh;
    295295
     
    320320
    321321/** Get a character at spt and return next spt */
    322 wchar_t spt_next_char(spt_t spt, spt_t *next)
    323 {
    324         wchar_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
     322char32_t spt_next_char(spt_t spt, spt_t *next)
     323{
     324        char32_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
    325325        if (next)
    326326                *next = spt;
     
    328328}
    329329
    330 wchar_t spt_prev_char(spt_t spt, spt_t *prev)
    331 {
    332         wchar_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
     330char32_t spt_prev_char(spt_t spt, spt_t *prev)
     331{
     332        char32_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
    333333        if (prev)
    334334                *prev = spt;
  • uspace/app/edit/sheet.h

    r4f663f3e r28a5ebd  
    101101extern void spt_get_coord(spt_t const *, coord_t *);
    102102extern bool spt_equal(spt_t const *, spt_t const *);
    103 extern wchar_t spt_next_char(spt_t, spt_t *);
    104 extern wchar_t spt_prev_char(spt_t, spt_t *);
     103extern char32_t spt_next_char(spt_t, spt_t *);
     104extern char32_t spt_prev_char(spt_t, spt_t *);
    105105
    106106extern void sheet_place_tag(sheet_t *, spt_t const *, tag_t *);
  • uspace/app/kio/kio.c

    r4f663f3e r28a5ebd  
    5656        link_t link;
    5757        size_t length;
    58         wchar_t *data;
     58        char32_t *data;
    5959} item_t;
    6060
     
    6262
    6363/* Pointer to kio area */
    64 static wchar_t *kio = (wchar_t *) AS_AREA_ANY;
     64static char32_t *kio = (char32_t *) AS_AREA_ANY;
    6565static size_t kio_length;
    6666
     
    7777 *
    7878 */
    79 static void producer(size_t length, wchar_t *data)
     79static void producer(size_t length, char32_t *data)
    8080{
    8181        item_t *item = (item_t *) malloc(sizeof(item_t));
     
    8383                return;
    8484
    85         size_t sz = sizeof(wchar_t) * length;
    86         wchar_t *buf = (wchar_t *) malloc(sz);
     85        size_t sz = sizeof(char32_t) * length;
     86        char32_t *buf = (char32_t *) malloc(sz);
    8787        if (buf == NULL) {
    8888                free(item);
     
    121121
    122122                for (size_t i = 0; i < item->length; i++)
    123                         putwchar(item->data[i]);
     123                        putuchar(item->data[i]);
    124124
    125125                if (log != NULL) {
    126126                        for (size_t i = 0; i < item->length; i++)
    127                                 fputwc(item->data[i], log);
     127                                fputuc(item->data[i], log);
    128128
    129129                        fflush(log);
     
    202202
    203203        size_t size = pages * PAGE_SIZE;
    204         kio_length = size / sizeof(wchar_t);
     204        kio_length = size / sizeof(char32_t);
    205205
    206206        rc = physmem_map(faddr, pages, AS_AREA_READ | AS_AREA_CACHEABLE,
  • uspace/app/netecho/netecho.c

    r4f663f3e r28a5ebd  
    7171}
    7272
    73 static void send_char(wchar_t c)
     73static void send_char(char32_t c)
    7474{
    7575        char cbuf[STR_BOUNDS(1)];
  • uspace/app/nterm/nterm.c

    r4f663f3e r28a5ebd  
    5858}
    5959
    60 static void send_char(wchar_t c)
     60static void send_char(char32_t c)
    6161{
    6262        char cbuf[STR_BOUNDS(1)];
  • uspace/app/sbi/src/builtin/bi_char.c

    r4f663f3e r28a5ebd  
    9090        }
    9191
    92         str = os_chr_to_astr((wchar_t) char_val);
     92        str = os_chr_to_astr((char32_t) char_val);
    9393
    9494        /* Ownership of str is transferred. */
  • uspace/app/sbi/src/os/helenos.c

    r4f663f3e r28a5ebd  
    9494        size_t i;
    9595        size_t size;
    96         wchar_t c;
     96        char32_t c;
    9797
    9898        assert(start + length <= str_length(str));
     
    155155        size_t offset;
    156156        int i;
    157         wchar_t c = 0;
     157        char32_t c = 0;
    158158
    159159        if (index < 0)
     
    178178 * @return              Newly allocated string.
    179179 */
    180 char *os_chr_to_astr(wchar_t chr)
     180char *os_chr_to_astr(char32_t chr)
    181181{
    182182        char *str;
  • uspace/app/sbi/src/os/os.h

    r4f663f3e r28a5ebd  
    3838size_t os_str_length(const char *str);
    3939errno_t os_str_get_char(const char *str, int index, int *out_char);
    40 char *os_chr_to_astr(wchar_t chr);
     40char *os_chr_to_astr(char32_t chr);
    4141void os_input_disp_help(void);
    4242errno_t os_input_line(const char *prompt, char **ptr);
  • uspace/app/sbi/src/os/posix.c

    r4f663f3e r28a5ebd  
    164164 * @return              Newly allocated string.
    165165 */
    166 char *os_chr_to_astr(wchar_t chr)
     166char *os_chr_to_astr(char32_t chr)
    167167{
    168168        char *str;
  • uspace/app/sysinfo/sysinfo.c

    r4f663f3e r28a5ebd  
    5656
    5757        while (offset < size) {
    58                 wchar_t c = str_decode(data, &offset, size);
     58                char32_t c = str_decode(data, &offset, size);
    5959                printf("%lc", (wint_t) c);
    6060        }
  • uspace/app/tester/print/print4.c

    r4f663f3e r28a5ebd  
    2929#include <stdio.h>
    3030#include <stddef.h>
    31 #include <wchar.h>
     31#include <uchar.h>
    3232#include "../tester.h"
    3333
  • uspace/app/tetris/scores.c

    r4f663f3e r28a5ebd  
    154154                if (kev->key == KC_BACKSPACE) {
    155155                        if (i > 0) {
    156                                 wchar_t uc;
     156                                char32_t uc;
    157157
    158158                                --i;
  • uspace/app/tetris/screen.c

    r4f663f3e r28a5ebd  
    371371         */
    372372
    373         wchar_t c = 0;
     373        char32_t c = 0;
    374374
    375375        while (c == 0) {
     
    393393int twait(void)
    394394{
    395         wchar_t c = 0;
     395        char32_t c = 0;
    396396
    397397        while (c == 0) {
  • uspace/app/top/screen.c

    r4f663f3e r28a5ebd  
    551551         */
    552552
    553         wchar_t c = 0;
     553        char32_t c = 0;
    554554
    555555        while (c == 0) {
Note: See TracChangeset for help on using the changeset viewer.