Changeset a35b458 in mainline for uspace/srv/hid/console/console.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    r3061bc1 ra35b458  
    6262        atomic_t refcnt;      /**< Connection reference count */
    6363        prodcons_t input_pc;  /**< Incoming keyboard events */
    64        
     64
    6565        /**
    6666         * Not yet sent bytes of last char event.
     
    6868        char char_remains[UTF8_CHAR_BUFFER_SIZE];
    6969        size_t char_remains_len;  /**< Number of not yet sent bytes. */
    70        
     70
    7171        fibril_mutex_t mtx;  /**< Lock protecting mutable fields */
    72        
     72
    7373        size_t index;           /**< Console index */
    7474        service_id_t dsid;      /**< Service handle */
    75        
     75
    7676        sysarg_t cols;         /**< Number of columns */
    7777        sysarg_t rows;         /**< Number of rows */
    7878        console_caps_t ccaps;  /**< Console capabilities */
    79        
     79
    8080        chargrid_t *frontbuf;    /**< Front buffer */
    8181        frontbuf_handle_t fbid;  /**< Front buffer handle */
     
    162162        fibril_mutex_lock(&switch_mtx);
    163163        fibril_mutex_lock(&cons->mtx);
    164        
     164
    165165        if ((active) && (cons == active_console)) {
    166166                output_update(output_sess, cons->fbid);
    167167                output_cursor_update(output_sess, cons->fbid);
    168168        }
    169        
     169
    170170        fibril_mutex_unlock(&cons->mtx);
    171171        fibril_mutex_unlock(&switch_mtx);
     
    176176        fibril_mutex_lock(&switch_mtx);
    177177        fibril_mutex_lock(&cons->mtx);
    178        
     178
    179179        if ((active) && (cons == active_console))
    180180                output_cursor_update(output_sess, cons->fbid);
    181        
     181
    182182        fibril_mutex_unlock(&cons->mtx);
    183183        fibril_mutex_unlock(&switch_mtx);
     
    188188        fibril_mutex_lock(&switch_mtx);
    189189        fibril_mutex_lock(&cons->mtx);
    190        
     190
    191191        if ((active) && (cons == active_console)) {
    192192                output_damage(output_sess, cons->fbid, 0, 0, cons->cols,
     
    194194                output_cursor_update(output_sess, cons->fbid);
    195195        }
    196        
     196
    197197        fibril_mutex_unlock(&cons->mtx);
    198198        fibril_mutex_unlock(&switch_mtx);
     
    208208                if (console_kcon())
    209209                        active = false;
    210                
     210
    211211                return;
    212212        }
    213        
     213
    214214        if (index > CONSOLE_COUNT)
    215215                return;
    216        
     216
    217217        console_t *cons = &consoles[index];
    218        
     218
    219219        fibril_mutex_lock(&switch_mtx);
    220        
     220
    221221        if (cons == active_console) {
    222222                fibril_mutex_unlock(&switch_mtx);
    223223                return;
    224224        }
    225        
     225
    226226        active_console = cons;
    227        
     227
    228228        fibril_mutex_unlock(&switch_mtx);
    229        
     229
    230230        cons_damage(cons);
    231231}
     
    236236        output_claim(output_sess);
    237237        cons_damage(active_console);
    238        
     238
    239239        return EOK;
    240240}
     
    244244        active = false;
    245245        output_yield(output_sess);
    246        
     246
    247247        return EOK;
    248248}
     
    261261                        return ENOMEM;
    262262                }
    263                
     263
    264264                link_initialize(&event->link);
    265265                event->type = type;
     
    267267                event->mods = mods;
    268268                event->c = c;
    269                
     269
    270270                prodcons_produce(&active_console->input_pc,
    271271                    &event->link);
    272272        }
    273        
     273
    274274        return EOK;
    275275}
     
    295295{
    296296        sysarg_t updated = 0;
    297        
    298         fibril_mutex_lock(&cons->mtx);
    299        
     297
     298        fibril_mutex_lock(&cons->mtx);
     299
    300300        switch (ch) {
    301301        case '\n':
     
    313313                updated = chargrid_putchar(cons->frontbuf, ch, true);
    314314        }
    315        
    316         fibril_mutex_unlock(&cons->mtx);
    317        
     315
     316        fibril_mutex_unlock(&cons->mtx);
     317
    318318        if (updated > 1)
    319319                cons_update(cons);
     
    325325        chargrid_set_cursor_visibility(cons->frontbuf, visible);
    326326        fibril_mutex_unlock(&cons->mtx);
    327        
     327
    328328        cons_update_cursor(cons);
    329329}
     
    344344        console_t *cons = srv_to_console(srv);
    345345        size_t pos = 0;
    346        
     346
    347347        /*
    348348         * Read input from keyboard and copy it to the buffer.
     
    355355                        bbuf[pos] = cons->char_remains[0];
    356356                        pos++;
    357                        
     357
    358358                        /* Unshift the array. */
    359359                        for (size_t i = 1; i < cons->char_remains_len; i++)
    360360                                cons->char_remains[i - 1] = cons->char_remains[i];
    361                        
     361
    362362                        cons->char_remains_len--;
    363363                }
    364                
     364
    365365                /* Still not enough? Then get another key from the queue. */
    366366                if (pos < size) {
    367367                        link_t *link = prodcons_consume(&cons->input_pc);
    368368                        kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
    369                        
     369
    370370                        /* Accept key presses of printable chars only. */
    371371                        if ((event->type == KEY_PRESS) && (event->c != 0)) {
     
    374374                                cons->char_remains_len = str_size(cons->char_remains);
    375375                        }
    376                        
     376
    377377                        free(event);
    378378                }
    379379        }
    380        
     380
    381381        *nread = size;
    382382        return EOK;
     
    390390        while (off < size)
    391391                cons_write_char(cons, str_decode(data, &off, size));
    392        
     392
    393393        *nwritten = size;
    394394        return EOK;
     
    398398{
    399399        console_t *cons = srv_to_console(srv);
    400        
     400
    401401        cons_update(cons);
    402402}
     
    405405{
    406406        console_t *cons = srv_to_console(srv);
    407        
     407
    408408        fibril_mutex_lock(&cons->mtx);
    409409        chargrid_clear(cons->frontbuf);
    410410        fibril_mutex_unlock(&cons->mtx);
    411        
     411
    412412        cons_update(cons);
    413413}
     
    416416{
    417417        console_t *cons = srv_to_console(srv);
    418        
     418
    419419        fibril_mutex_lock(&cons->mtx);
    420420        chargrid_set_cursor(cons->frontbuf, col, row);
    421421        fibril_mutex_unlock(&cons->mtx);
    422        
     422
    423423        cons_update_cursor(cons);
    424424}
     
    427427{
    428428        console_t *cons = srv_to_console(srv);
    429        
     429
    430430        fibril_mutex_lock(&cons->mtx);
    431431        chargrid_get_cursor(cons->frontbuf, col, row);
    432432        fibril_mutex_unlock(&cons->mtx);
    433        
     433
    434434        return EOK;
    435435}
     
    438438{
    439439        console_t *cons = srv_to_console(srv);
    440        
     440
    441441        fibril_mutex_lock(&cons->mtx);
    442442        *cols = cons->cols;
    443443        *rows = cons->rows;
    444444        fibril_mutex_unlock(&cons->mtx);
    445        
     445
    446446        return EOK;
    447447}
     
    450450{
    451451        console_t *cons = srv_to_console(srv);
    452        
     452
    453453        fibril_mutex_lock(&cons->mtx);
    454454        *ccaps = cons->ccaps;
    455455        fibril_mutex_unlock(&cons->mtx);
    456        
     456
    457457        return EOK;
    458458}
     
    461461{
    462462        console_t *cons = srv_to_console(srv);
    463        
     463
    464464        fibril_mutex_lock(&cons->mtx);
    465465        chargrid_set_style(cons->frontbuf, style);
     
    471471{
    472472        console_t *cons = srv_to_console(srv);
    473        
     473
    474474        fibril_mutex_lock(&cons->mtx);
    475475        chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr);
     
    481481{
    482482        console_t *cons = srv_to_console(srv);
    483        
     483
    484484        fibril_mutex_lock(&cons->mtx);
    485485        chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);
     
    490490{
    491491        console_t *cons = srv_to_console(srv);
    492        
     492
    493493        cons_set_cursor_vis(cons, visible);
    494494}
     
    499499        link_t *link = prodcons_consume(&cons->input_pc);
    500500        kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link);
    501        
     501
    502502        event->type = CEV_KEY;
    503503        event->ev.key = *kevent;
    504        
     504
    505505        free(kevent);
    506506        return EOK;
     
    510510{
    511511        console_t *cons = NULL;
    512        
     512
    513513        for (size_t i = 0; i < CONSOLE_COUNT; i++) {
    514514                if (consoles[i].dsid == (service_id_t) IPC_GET_ARG2(*icall)) {
     
    517517                }
    518518        }
    519        
     519
    520520        if (cons == NULL) {
    521521                async_answer_0(iid, ENOENT);
    522522                return;
    523523        }
    524        
     524
    525525        if (atomic_postinc(&cons->refcnt) == 0)
    526526                cons_set_cursor_vis(cons, true);
    527        
     527
    528528        con_conn(iid, icall, &cons->srvs);
    529529}
     
    533533        async_sess_t *sess;
    534534        service_id_t dsid;
    535        
     535
    536536        errno_t rc = loc_service_get_id(svc, &dsid, 0);
    537537        if (rc != EOK) {
     
    546546                return EIO;
    547547        }
    548        
     548
    549549        rc = input_open(sess, &input_ev_ops, NULL, &input);
    550550        if (rc != EOK) {
     
    554554                return rc;
    555555        }
    556        
     556
    557557        return EOK;
    558558}
     
    562562        async_sess_t *sess;
    563563        service_id_t dsid;
    564        
     564
    565565        errno_t rc = loc_service_get_id(svc, &dsid, 0);
    566566        if (rc == EOK) {
     
    573573        } else
    574574                return NULL;
    575        
     575
    576576        return sess;
    577577}
     
    583583        if (rc != EOK)
    584584                return false;
    585        
     585
    586586        /* Connect to output service */
    587587        output_sess = output_connect(output_svc);
    588588        if (output_sess == NULL)
    589589                return false;
    590        
     590
    591591        /* Register server */
    592592        async_set_fallback_port_handler(client_connection, NULL);
     
    597597                return false;
    598598        }
    599        
     599
    600600        output_get_dimensions(output_sess, &cols, &rows);
    601601        output_set_style(output_sess, STYLE_NORMAL);
    602        
     602
    603603        console_caps_t ccaps;
    604604        output_get_caps(output_sess, &ccaps);
    605        
     605
    606606        /*
    607607         * Inititalize consoles only if there are
     
    615615                        prodcons_initialize(&consoles[i].input_pc);
    616616                        consoles[i].char_remains_len = 0;
    617                        
     617
    618618                        consoles[i].cols = cols;
    619619                        consoles[i].rows = rows;
     
    621621                        consoles[i].frontbuf =
    622622                            chargrid_create(cols, rows, CHARGRID_FLAG_SHARED);
    623                        
     623
    624624                        if (consoles[i].frontbuf == NULL) {
    625625                                printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
    626626                                return false;
    627627                        }
    628                        
     628
    629629                        consoles[i].fbid = output_frontbuf_create(output_sess,
    630630                            consoles[i].frontbuf);
     
    633633                                return false;
    634634                        }
    635                        
     635
    636636                        con_srvs_init(&consoles[i].srvs);
    637637                        consoles[i].srvs.ops = &con_ops;
    638638                        consoles[i].srvs.sarg = &consoles[i];
    639                        
     639
    640640                        char vc[LOC_NAME_MAXLEN + 1];
    641641                        snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
    642                        
     642
    643643                        if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
    644644                                printf("%s: Unable to register device %s\n", NAME, vc);
     
    646646                        }
    647647                }
    648                
     648
    649649                input_activate(input);
    650650        }
    651        
     651
    652652        return true;
    653653}
     
    664664                return -1;
    665665        }
    666        
     666
    667667        printf("%s: HelenOS Console service\n", NAME);
    668        
     668
    669669        if (!console_srv_init(argv[1], argv[2]))
    670670                return -1;
    671        
     671
    672672        printf("%s: Accepting connections\n", NAME);
    673673        task_retval(0);
    674674        async_manager();
    675        
     675
    676676        /* Never reached */
    677677        return 0;
Note: See TracChangeset for help on using the changeset viewer.