Changeset 28a5ebd in mainline for uspace/dist/src/c/demos/edit


Ignore:
Timestamp:
2020-06-18T15:39:50Z (5 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/dist/src/c/demos/edit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/dist/src/c/demos/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;
     
    847847        coord_t rbc, rec;
    848848        char row_buf[ROW_BUF_SIZE];
    849         wchar_t c;
     849        char32_t c;
    850850        size_t pos, size;
    851851        int s_column;
     
    10521052
    10531053/** Insert a character at caret position. */
    1054 static void insert_char(wchar_t c)
     1054static void insert_char(char32_t c)
    10551055{
    10561056        spt_t pt;
     
    12821282
    12831283/* Search operations */
    1284 static errno_t search_spt_producer(void *data, wchar_t *ret)
     1284static errno_t search_spt_producer(void *data, char32_t *ret)
    12851285{
    12861286        assert(data != NULL);
     
    12911291}
    12921292
    1293 static errno_t search_spt_reverse_producer(void *data, wchar_t *ret)
     1293static errno_t search_spt_reverse_producer(void *data, char32_t *ret)
    12941294{
    12951295        assert(data != NULL);
     
    15101510        char *str;
    15111511        size_t off;
    1512         wchar_t c;
     1512        char32_t c;
    15131513        errno_t rc;
    15141514
     
    16061606}
    16071607
    1608 static wchar_t get_first_wchar(const char *str)
     1608static char32_t get_first_wchar(const char *str)
    16091609{
    16101610        size_t offset = 0;
     
    16271627                return false;
    16281628
    1629         wchar_t first_char = get_first_wchar(ch);
     1629        char32_t first_char = get_first_wchar(ch);
    16301630        switch (first_char) {
    16311631        case ' ':
     
    16531653                return false;
    16541654
    1655         wchar_t first_char = get_first_wchar(ch);
     1655        char32_t first_char = get_first_wchar(ch);
    16561656        switch (first_char) {
    16571657        case ',':
  • uspace/dist/src/c/demos/edit/search.c

    r4f663f3e r28a5ebd  
    4949                return NULL;
    5050
    51         wchar_t *p = str_to_awstr(pattern);
     51        char32_t *p = str_to_awstr(pattern);
    5252        if (p == NULL) {
    5353                free(search);
     
    6262                half = search->pattern_length / 2;
    6363                for (pos = 0; pos < half; pos++) {
    64                         wchar_t tmp = p[pos];
     64                        char32_t tmp = p[pos];
    6565                        p[pos] = p[search->pattern_length - pos - 1];
    6666                        p[search->pattern_length - pos - 1] = tmp;
     
    106106        search_equals_fn eq = s->ops.equals;
    107107
    108         wchar_t cur_char;
     108        char32_t cur_char;
    109109        errno_t rc = EOK;
    110110        while ((rc = s->ops.producer(s->client_data, &cur_char)) == EOK && cur_char > 0) {
     
    140140}
    141141
    142 bool char_exact_equals(const wchar_t a, const wchar_t b)
     142bool char_exact_equals(const char32_t a, const char32_t b)
    143143{
    144144        return a == b;
  • uspace/dist/src/c/demos/edit/search.h

    r4f663f3e r28a5ebd  
    4141struct search;
    4242typedef struct search search_t;
    43 typedef bool (*search_equals_fn)(const wchar_t, const wchar_t);
    44 typedef errno_t (*search_producer_fn)(void *, wchar_t *);
     43typedef bool (*search_equals_fn)(const char32_t, const char32_t);
     44typedef errno_t (*search_producer_fn)(void *, char32_t *);
    4545typedef errno_t (*search_mark_fn)(void *, void **);
    4646typedef void (*search_mark_free_fn)(void *);
     
    5858} search_ops_t;
    5959
    60 extern bool char_exact_equals(const wchar_t, const wchar_t);
     60extern bool char_exact_equals(const char32_t, const char32_t);
    6161extern search_t *search_init(const char *, void *, search_ops_t, bool);
    6262extern errno_t search_next_match(search_t *, match_t *);
  • uspace/dist/src/c/demos/edit/search_impl.h

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

    r4f663f3e r28a5ebd  
    193193        size_t copy_sz;
    194194        size_t off, prev;
    195         wchar_t c;
     195        char32_t c;
    196196
    197197        spp = sh->data + spos->b_off;
     
    220220{
    221221        size_t cur_pos, prev_pos;
    222         wchar_t c;
     222        char32_t c;
    223223        coord_t cc;
    224224
     
    289289        size_t off;
    290290        coord_t cc;
    291         wchar_t c;
     291        char32_t c;
    292292        sheet_t *sh;
    293293
     
    318318
    319319/** Get a character at spt and return next spt */
    320 wchar_t spt_next_char(spt_t spt, spt_t *next)
    321 {
    322         wchar_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
     320char32_t spt_next_char(spt_t spt, spt_t *next)
     321{
     322        char32_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
    323323        if (next)
    324324                *next = spt;
     
    326326}
    327327
    328 wchar_t spt_prev_char(spt_t spt, spt_t *prev)
    329 {
    330         wchar_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
     328char32_t spt_prev_char(spt_t spt, spt_t *prev)
     329{
     330        char32_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
    331331        if (prev)
    332332                *prev = spt;
  • uspace/dist/src/c/demos/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 *);
Note: See TracChangeset for help on using the changeset viewer.