Changeset a35b458 in mainline for uspace/lib/clui/tinput.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/lib/clui/tinput.c

    r3061bc1 ra35b458  
    7575{
    7676        tinput_t *ti;
    77        
     77
    7878        ti = calloc(1, sizeof(tinput_t));
    7979        if (ti == NULL)
    8080                return NULL;
    81        
     81
    8282        tinput_init(ti);
    8383        return ti;
     
    107107        if (!dbuf)
    108108                return;
    109        
     109
    110110        size_t sa;
    111111        size_t sb;
    112112        tinput_sel_get_bounds(ti, &sa, &sb);
    113        
     113
    114114        tinput_console_set_lpos(ti, ti->text_coord + start);
    115115        console_set_style(ti->console, STYLE_NORMAL);
    116        
     116
    117117        size_t p = start;
    118118        if (p < sa) {
     
    122122                p = sa;
    123123        }
    124        
     124
    125125        if (p < sb) {
    126126                console_flush(ti->console);
    127127                console_set_style(ti->console, STYLE_SELECTED);
    128                
     128
    129129                memcpy(dbuf, ti->buffer + p,
    130130                    (sb - p) * sizeof(wchar_t));
     
    133133                p = sb;
    134134        }
    135        
     135
    136136        console_flush(ti->console);
    137137        console_set_style(ti->console, STYLE_NORMAL);
    138        
     138
    139139        if (p < ti->nc) {
    140140                memcpy(dbuf, ti->buffer + p,
     
    143143                printf("%ls", dbuf);
    144144        }
    145        
     145
    146146        for (p = 0; p < pad; p++)
    147147                putchar(' ');
    148        
     148
    149149        console_flush(ti->console);
    150150
     
    188188{
    189189        sysarg_t col0, row0;
    190        
     190
    191191        if (console_get_pos(ti->console, &col0, &row0) != EOK)
    192192                return EIO;
    193        
     193
    194194        ti->prompt_coord = row0 * ti->con_cols + col0;
    195195        ti->text_coord = ti->prompt_coord + str_length(ti->prompt);
     
    206206        if (ti->nc == INPUT_MAX_SIZE)
    207207                return;
    208        
     208
    209209        unsigned new_width = LIN_TO_COL(ti, ti->text_coord) + ti->nc + 1;
    210210        if (new_width % ti->con_cols == 0) {
     
    216216                }
    217217        }
    218        
     218
    219219        size_t i;
    220220        for (i = ti->nc; i > ti->pos; i--)
    221221                ti->buffer[i] = ti->buffer[i - 1];
    222        
     222
    223223        ti->buffer[ti->pos] = c;
    224224        ti->pos += 1;
     
    226226        ti->buffer[ti->nc] = '\0';
    227227        ti->sel_start = ti->pos;
    228        
     228
    229229        tinput_display_tail(ti, ti->pos - 1, 0);
    230230        tinput_update_origin(ti);
     
    237237        if (ilen == 0)
    238238                return;
    239        
     239
    240240        unsigned new_width = LIN_TO_COL(ti, ti->text_coord) + ti->nc + ilen;
    241241        unsigned new_height = (new_width / ti->con_cols) + 1;
     
    244244                return;
    245245        }
    246        
     246
    247247        if (ti->nc > 0) {
    248248                size_t i;
     
    250250                        ti->buffer[i + ilen - 1] = ti->buffer[i - 1];
    251251        }
    252        
     252
    253253        size_t off = 0;
    254254        size_t i = 0;
     
    257257                if (c == '\0')
    258258                        break;
    259                
     259
    260260                /* Filter out non-printable chars. */
    261261                if (c < 32)
    262262                        c = 32;
    263                
     263
    264264                ti->buffer[ti->pos + i] = c;
    265265                i++;
    266266        }
    267        
     267
    268268        ti->pos += ilen;
    269269        ti->nc += ilen;
    270270        ti->buffer[ti->nc] = '\0';
    271271        ti->sel_start = ti->pos;
    272        
     272
    273273        tinput_display_tail(ti, ti->pos - ilen, 0);
    274274        tinput_update_origin(ti);
     
    282282                return;
    283283        }
    284        
     284
    285285        if (ti->pos == 0)
    286286                return;
    287        
     287
    288288        size_t i;
    289289        for (i = ti->pos; i < ti->nc; i++)
    290290                ti->buffer[i - 1] = ti->buffer[i];
    291        
     291
    292292        ti->pos -= 1;
    293293        ti->nc -= 1;
    294294        ti->buffer[ti->nc] = '\0';
    295295        ti->sel_start = ti->pos;
    296        
     296
    297297        tinput_display_tail(ti, ti->pos, 1);
    298298        tinput_position_caret(ti);
     
    305305                return;
    306306        }
    307        
     307
    308308        if (ti->pos == ti->nc)
    309309                return;
    310        
     310
    311311        ti->pos += 1;
    312312        ti->sel_start = ti->pos;
    313        
     313
    314314        tinput_backspace(ti);
    315315}
     
    318318{
    319319        tinput_pre_seek(ti, shift_held);
    320        
     320
    321321        if (dir == seek_forward) {
    322322                if (ti->pos < ti->nc)
     
    326326                        ti->pos -= 1;
    327327        }
    328        
     328
    329329        tinput_post_seek(ti, shift_held);
    330330}
     
    333333{
    334334        tinput_pre_seek(ti, shift_held);
    335        
     335
    336336        if (dir == seek_forward) {
    337337                if (ti->pos == ti->nc)
    338338                        return;
    339                
     339
    340340                while (true) {
    341341                        ti->pos += 1;
    342                        
     342
    343343                        if (ti->pos == ti->nc)
    344344                                break;
    345                        
     345
    346346                        if ((ti->buffer[ti->pos - 1] == ' ') &&
    347347                            (ti->buffer[ti->pos] != ' '))
     
    351351                if (ti->pos == 0)
    352352                        return;
    353                
     353
    354354                while (true) {
    355355                        ti->pos -= 1;
    356                        
     356
    357357                        if (ti->pos == 0)
    358358                                break;
    359                        
     359
    360360                        if (ti->buffer[ti->pos - 1] == ' ' &&
    361361                            ti->buffer[ti->pos] != ' ')
    362362                                break;
    363363                }
    364        
    365         }
    366        
     364
     365        }
     366
    367367        tinput_post_seek(ti, shift_held);
    368368}
     
    371371{
    372372        tinput_pre_seek(ti, shift_held);
    373        
     373
    374374        if (dir == seek_forward) {
    375375                if (ti->pos + ti->con_cols <= ti->nc)
     
    379379                        ti->pos = ti->pos - ti->con_cols;
    380380        }
    381        
     381
    382382        tinput_post_seek(ti, shift_held);
    383383}
     
    403403{
    404404        tinput_pre_seek(ti, shift_held);
    405        
     405
    406406        if (dir == seek_backward)
    407407                ti->pos = 0;
    408408        else
    409409                ti->pos = ti->nc;
    410        
     410
    411411        tinput_post_seek(ti, shift_held);
    412412}
     
    431431                ti->sel_start = ti->pos;
    432432        }
    433        
     433
    434434        tinput_position_caret(ti);
    435435}
     
    443443                        free(ti->history[HISTORY_LEN]);
    444444        }
    445        
     445
    446446        size_t i;
    447447        for (i = ti->hnum; i > 1; i--)
    448448                ti->history[i] = ti->history[i - 1];
    449        
     449
    450450        ti->history[1] = str_dup(str);
    451        
     451
    452452        if (ti->history[0] != NULL) {
    453453                free(ti->history[0]);
     
    492492        size_t sa;
    493493        size_t sb;
    494        
     494
    495495        tinput_sel_get_bounds(ti, &sa, &sb);
    496496        if (sa == sb)
    497497                return;
    498        
     498
    499499        memmove(ti->buffer + sa, ti->buffer + sb,
    500500            (ti->nc - sb) * sizeof(wchar_t));
    501        
     501
    502502        ti->pos = ti->sel_start = sa;
    503503        ti->nc -= (sb - sa);
    504504        ti->buffer[ti->nc] = '\0';
    505        
     505
    506506        tinput_display_tail(ti, sa, sb - sa);
    507507        tinput_position_caret(ti);
     
    512512        size_t sa;
    513513        size_t sb;
    514        
     514
    515515        tinput_sel_get_bounds(ti, &sa, &sb);
    516        
     516
    517517        char *str;
    518        
     518
    519519        if (sb < ti->nc) {
    520520                wchar_t tmp_c = ti->buffer[sb];
     
    524524        } else
    525525                str = wstr_to_astr(ti->buffer + sa);
    526        
     526
    527527        if (str == NULL)
    528528                goto error;
    529        
     529
    530530        if (clipboard_put_str(str) != EOK)
    531531                goto error;
    532        
     532
    533533        free(str);
    534534        return;
    535        
     535
    536536error:
    537537        /* TODO: Give the user some kind of warning. */
     
    543543        char *str;
    544544        errno_t rc = clipboard_get_str(&str);
    545        
     545
    546546        if ((rc != EOK) || (str == NULL)) {
    547547                /* TODO: Give the user some kind of warning. */
    548548                return;
    549549        }
    550        
     550
    551551        tinput_insert_string(ti, str);
    552552        free(str);
     
    562562                        return;
    563563        }
    564        
     564
    565565        if (ti->history[ti->hpos] != NULL) {
    566566                free(ti->history[ti->hpos]);
    567567                ti->history[ti->hpos] = NULL;
    568568        }
    569        
     569
    570570        ti->history[ti->hpos] = tinput_get_str(ti);
    571571        ti->hpos += offs;
    572        
     572
    573573        int pad = (int) ti->nc - str_length(ti->history[ti->hpos]);
    574574        if (pad < 0)
    575575                pad = 0;
    576        
     576
    577577        tinput_set_str(ti, ti->history[ti->hpos]);
    578578        tinput_display_tail(ti, 0, pad);
     
    620620        for (i = 0; i < cnum; i++)
    621621                max_width = max(max_width, str_width(compl[i]));
    622        
     622
    623623        unsigned int cols = max(1, (ti->con_cols + 1) / (max_width + 1));
    624624        unsigned int padding = 0;
     
    628628        unsigned int col_width = max_width + padding / cols;
    629629        unsigned int rows = cnum / cols + ((cnum % cols) != 0);
    630        
     630
    631631        unsigned int row, col;
    632        
     632
    633633        for (row = 0; row < rows; row++) {
    634634                unsigned int display_col = 0;
     
    786786        if (ti->prompt != NULL)
    787787                free(ti->prompt);
    788        
     788
    789789        ti->prompt = str_dup(prompt);
    790790        if (ti->prompt == NULL)
    791791                return ENOMEM;
    792        
     792
    793793        return EOK;
    794794}
     
    815815            ((kev->mods & (KM_ALT | KM_SHIFT)) == 0))
    816816                tinput_key_ctrl(ti, kev);
    817        
     817
    818818        if (((kev->mods & KM_SHIFT) != 0) &&
    819819            ((kev->mods & (KM_CTRL | KM_ALT)) == 0))
    820820                tinput_key_shift(ti, kev);
    821        
     821
    822822        if (((kev->mods & KM_CTRL) != 0) &&
    823823            ((kev->mods & KM_SHIFT) != 0) &&
    824824            ((kev->mods & KM_ALT) == 0))
    825825                tinput_key_ctrl_shift(ti, kev);
    826        
     826
    827827        if ((kev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)
    828828                tinput_key_unmod(ti, kev);
    829        
     829
    830830        if (kev->c >= ' ') {
    831831                tinput_sel_delete(ti);
     
    868868        if (console_get_size(ti->console, &ti->con_cols, &ti->con_rows) != EOK)
    869869                return EIO;
    870        
     870
    871871        tinput_set_str(ti, istr);
    872872
     
    874874        ti->done = false;
    875875        ti->exit_clui = false;
    876        
     876
    877877        if (tinput_display(ti) != EOK)
    878878                return EIO;
    879        
     879
    880880        while (!ti->done) {
    881881                console_flush(ti->console);
    882                
     882
    883883                cons_event_t ev;
    884884                if (!console_get_event(ti->console, &ev))
    885885                        return EIO;
    886                
     886
    887887                switch (ev.type) {
    888888                case CEV_KEY:
     
    897897                }
    898898        }
    899        
     899
    900900        if (ti->exit_clui)
    901901                return ENOENT;
    902        
     902
    903903        ti->pos = ti->nc;
    904904        tinput_position_caret(ti);
    905905        putchar('\n');
    906        
     906
    907907        char *str = tinput_get_str(ti);
    908908        if (str_cmp(str, "") != 0)
    909909                tinput_history_insert(ti, str);
    910        
     910
    911911        ti->hpos = 0;
    912        
     912
    913913        *dstr = str;
    914914        return EOK;
Note: See TracChangeset for help on using the changeset viewer.