Changeset 28a5ebd in mainline for uspace/srv/hid/input/layout/cz.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
  • uspace/srv/hid/input/layout/cz.c

    r4f663f3e r28a5ebd  
    4545static errno_t cz_create(layout_t *);
    4646static void cz_destroy(layout_t *);
    47 static wchar_t cz_parse_ev(layout_t *, kbd_event_t *ev);
     47static char32_t cz_parse_ev(layout_t *, kbd_event_t *ev);
    4848
    4949enum m_state {
     
    6363};
    6464
    65 static wchar_t map_lcase[] = {
     65static char32_t map_lcase[] = {
    6666        [KC_Q] = 'q',
    6767        [KC_W] = 'w',
     
    9494};
    9595
    96 static wchar_t map_ucase[] = {
     96static char32_t map_ucase[] = {
    9797        [KC_Q] = 'Q',
    9898        [KC_W] = 'W',
     
    125125};
    126126
    127 static wchar_t map_not_shifted[] = {
     127static char32_t map_not_shifted[] = {
    128128        [KC_BACKTICK] = ';',
    129129
     
    141141};
    142142
    143 static wchar_t map_shifted[] = {
     143static char32_t map_shifted[] = {
    144144        [KC_1] = '1',
    145145        [KC_2] = '2',
     
    167167};
    168168
    169 static wchar_t map_ns_nocaps[] = {
     169static char32_t map_ns_nocaps[] = {
    170170        [KC_2] = L'ě',
    171171        [KC_3] = L'š',
     
    182182};
    183183
    184 static wchar_t map_ns_caps[] = {
     184static char32_t map_ns_caps[] = {
    185185        [KC_2] = L'Ě',
    186186        [KC_3] = L'Š',
     
    197197};
    198198
    199 static wchar_t map_neutral[] = {
     199static char32_t map_neutral[] = {
    200200        [KC_BACKSPACE] = '\b',
    201201        [KC_TAB] = '\t',
     
    210210};
    211211
    212 static wchar_t map_numeric[] = {
     212static char32_t map_numeric[] = {
    213213        [KC_N7] = '7',
    214214        [KC_N8] = '8',
     
    225225};
    226226
    227 static wchar_t map_hacek_lcase[] = {
     227static char32_t map_hacek_lcase[] = {
    228228        [KC_E] = L'ě',
    229229        [KC_R] = L'ř',
     
    239239};
    240240
    241 static wchar_t map_hacek_ucase[] = {
     241static char32_t map_hacek_ucase[] = {
    242242        [KC_E] = L'Ě',
    243243        [KC_R] = L'Ř',
     
    253253};
    254254
    255 static wchar_t map_carka_lcase[] = {
     255static char32_t map_carka_lcase[] = {
    256256        [KC_E] = L'é',
    257257        [KC_U] = L'ú',
     
    264264};
    265265
    266 static wchar_t map_carka_ucase[] = {
     266static char32_t map_carka_ucase[] = {
    267267        [KC_E] = L'É',
    268268        [KC_U] = L'Ú',
     
    275275};
    276276
    277 static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
     277static char32_t translate(unsigned int key, char32_t *map, size_t map_length)
    278278{
    279279        if (key >= map_length)
     
    282282}
    283283
    284 static wchar_t parse_ms_hacek(layout_cz_t *cz_state, kbd_event_t *ev)
    285 {
    286         wchar_t c;
     284static char32_t parse_ms_hacek(layout_cz_t *cz_state, kbd_event_t *ev)
     285{
     286        char32_t c;
    287287
    288288        cz_state->mstate = ms_start;
     
    293293
    294294        if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
    295                 c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t));
     295                c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(char32_t));
    296296        else
    297                 c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t));
     297                c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(char32_t));
    298298
    299299        return c;
    300300}
    301301
    302 static wchar_t parse_ms_carka(layout_cz_t *cz_state, kbd_event_t *ev)
    303 {
    304         wchar_t c;
     302static char32_t parse_ms_carka(layout_cz_t *cz_state, kbd_event_t *ev)
     303{
     304        char32_t c;
    305305
    306306        cz_state->mstate = ms_start;
     
    311311
    312312        if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
    313                 c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t));
     313                c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(char32_t));
    314314        else
    315                 c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t));
     315                c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(char32_t));
    316316
    317317        return c;
    318318}
    319319
    320 static wchar_t parse_ms_start(layout_cz_t *cz_state, kbd_event_t *ev)
    321 {
    322         wchar_t c;
     320static char32_t parse_ms_start(layout_cz_t *cz_state, kbd_event_t *ev)
     321{
     322        char32_t c;
    323323
    324324        /* Produce no characters when Ctrl or Alt is pressed. */
     
    335335        }
    336336
    337         c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
     337        c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_t));
    338338        if (c != 0)
    339339                return c;
     
    341341        if ((ev->mods & KM_SHIFT) == 0) {
    342342                if ((ev->mods & KM_CAPS_LOCK) != 0)
    343                         c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t));
     343                        c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(char32_t));
    344344                else
    345                         c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t));
     345                        c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(char32_t));
    346346
    347347                if (c != 0)
     
    350350
    351351        if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
    352                 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
     352                c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char32_t));
    353353        else
    354                 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
     354                c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char32_t));
    355355
    356356        if (c != 0)
     
    358358
    359359        if ((ev->mods & KM_SHIFT) != 0)
    360                 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
     360                c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
    361361        else
    362                 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
     362                c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
    363363
    364364        if (c != 0)
     
    366366
    367367        if ((ev->mods & KM_NUM_LOCK) != 0)
    368                 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
     368                c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
    369369        else
    370370                c = 0;
     
    409409}
    410410
    411 static wchar_t cz_parse_ev(layout_t *state, kbd_event_t *ev)
     411static char32_t cz_parse_ev(layout_t *state, kbd_event_t *ev)
    412412{
    413413        layout_cz_t *cz_state = (layout_cz_t *) state->layout_priv;
Note: See TracChangeset for help on using the changeset viewer.