Changeset 8565a42 in mainline for uspace/dist/src


Ignore:
Timestamp:
2018-03-02T20:34:50Z (8 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
uspace/dist/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/dist/src/bithenge/gif/gif.bh

    r3061bc1 r8565a42  
    8686        .width <- word;
    8787        .height <- word;
    88        
     88
    8989        <- struct {
    9090                .use_local_color_map <- bit;
     
    9393                .bits_per_pixel <- (in + 1) <- uint_be(3);
    9494        } <- bits_be <- known_length(1);
    95        
     95
    9696        if (.use_local_color_map) {
    9797                .local_color_map <- gif_color_map_from_bits_per_pixel(.bits_per_pixel);
    9898        }
    99        
     99
    100100        .lzw_initial_size <- uint8;
    101101        .lzw_data <- generic_data_block;
  • uspace/dist/src/c/demos/edit/edit.c

    r3061bc1 r8565a42  
    8888         */
    8989        int ideal_column;
    90        
     90
    9191        char *previous_search;
    9292        bool previous_search_reverse;
     
    532532                pane.rflags |= REDRAW_TEXT;
    533533        }
    534        
     534
    535535        if (update_ideal_column)
    536536                pane.ideal_column = c_new.column;
    537        
     537
    538538        caret_update();
    539539}
     
    608608        const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";
    609609        char *fname;
    610        
     610
    611611        fname = prompt("Save As", old_fname);
    612612        if (fname == NULL) {
     
    815815
    816816        /* Clear the remaining rows if file is short. */
    817        
     817
    818818        int i;
    819819        sysarg_t j;
     
    905905                                console_flush(con);
    906906                        }
    907        
     907
    908908                        if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    909909                                console_flush(con);
     
    911911                                console_flush(con);
    912912                        }
    913        
     913
    914914                        c = str_decode(row_buf, &pos, size);
    915915                        if (c != '\t') {
     
    966966        int n = printf(" %d, %d (%d): File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
    967967            "Ctrl-E Save As", coord.row, coord.column, last_row, fname);
    968        
     968
    969969        int pos = scr_columns - 1 - n;
    970970        printf("%*s", pos, "");
     
    11511151        coord.row = row;
    11521152        coord.column = column;
    1153        
     1153
    11541154        spt_t pt;
    11551155        sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
    1156        
     1156
    11571157        caret_move(pt, select, true);
    11581158}
     
    11961196{
    11971197        char *sline;
    1198        
     1198
    11991199        sline = prompt("Go to line", "");
    12001200        if (sline == NULL) {
     
    12021202                return;
    12031203        }
    1204        
     1204
    12051205        char *endptr;
    12061206        int line = strtol(sline, &endptr, 10);
     
    12111211        }
    12121212        free(sline);
    1213        
     1213
    12141214        caret_move_absolute(line, pane.ideal_column, dir_before, false);
    12151215}
     
    12701270{
    12711271        char *pattern;
    1272        
     1272
    12731273        const char *prompt_text = "Find next";
    12741274        if (reverse)
    12751275                prompt_text = "Find previous";
    1276        
     1276
    12771277        const char *default_value = "";
    12781278        if (pane.previous_search)
    12791279                default_value = pane.previous_search;
    1280        
     1280
    12811281        pattern = prompt(prompt_text, default_value);
    12821282        if (pattern == NULL) {
     
    12841284                return;
    12851285        }
    1286        
     1286
    12871287        if (pane.previous_search)
    12881288                free(pane.previous_search);
    12891289        pane.previous_search = pattern;
    12901290        pane.previous_search_reverse = reverse;
    1291        
     1291
    12921292        search(pattern, reverse);
    12931293}
     
    12991299                return;
    13001300        }
    1301        
     1301
    13021302        search(pane.previous_search, pane.previous_search_reverse);
    13031303}
     
    13061306{
    13071307        status_display("Searching...");
    1308        
     1308
    13091309        spt_t sp, producer_pos;
    13101310        tag_get_pt(&pane.caret_pos, &sp);
    1311        
     1311
    13121312        /* Start searching on the position before/after caret */
    13131313        if (!reverse) {
     
    13181318        }
    13191319        producer_pos = sp;
    1320        
     1320
    13211321        search_ops_t ops = search_spt_ops;
    13221322        if (reverse)
    13231323                ops = search_spt_reverse_ops;
    1324        
     1324
    13251325        search_t *search = search_init(pattern, &producer_pos, ops, reverse);
    13261326        if (search == NULL) {
     
    13281328                return;
    13291329        }
    1330        
     1330
    13311331        match_t match;
    13321332        errno_t rc = search_next_match(search, &match);
     
    13351335                search_fini(search);
    13361336        }
    1337        
     1337
    13381338        if (match.end) {
    13391339                status_display("Match found.");
     
    13561356                status_display("Not found.");
    13571357        }
    1358        
     1358
    13591359        search_fini(search);
    13601360}
     
    16491649        console_set_pos(con, 0, scr_rows - 1);
    16501650        console_set_style(con, STYLE_INVERTED);
    1651        
     1651
    16521652        int pos = -(scr_columns - 3);
    16531653        printf(" %*s ", pos, str);
  • uspace/dist/src/c/demos/edit/search.c

    r3061bc1 r8565a42  
    4848        if (search == NULL)
    4949                return NULL;
    50        
     50
    5151        wchar_t *p = str_to_awstr(pattern);
    5252        if (p == NULL) {
     
    5454                return NULL;
    5555        }
    56        
     56
    5757        search->pattern_length = wstr_length(p);
    58        
     58
    5959        if (reverse) {
    6060                /* Reverse the pattern */
     
    6767                }
    6868        }
    69        
     69
    7070        search->pattern = p;
    71        
     71
    7272        search->client_data = client_data;
    7373        search->ops = ops;
     
    7878                return NULL;
    7979        }
    80        
     80
    8181        search->pattern_pos = 0;
    82        
     82
    8383        search->back_table[0] = -1;
    8484        search->back_table[1] = 0;
     
    100100                }
    101101        }
    102        
     102
    103103        return search;
    104104}
     
    107107{
    108108        search_equals_fn eq = s->ops.equals;
    109        
     109
    110110        wchar_t cur_char;
    111111        errno_t rc = EOK;
     
    128128                }
    129129        }
    130        
     130
    131131        match->end = NULL;
    132132        match->length = 0;
    133        
     133
    134134        return rc;
    135135}
     
    139139        free(search->pattern);
    140140        free(search->back_table);
    141        
     141
    142142}
    143143
  • uspace/dist/src/c/demos/edit/sheet.c

    r3061bc1 r8565a42  
    263263        coord.row = row;
    264264        coord.column = 65536;
    265        
     265
    266266        sheet_get_cell_pt(sh, &coord, dir_before, &pt);
    267267        spt_get_coord(&pt, &coord);
  • uspace/dist/src/c/demos/tetris/scores.c

    r3061bc1 r8565a42  
    9999{
    100100        int i;
    101        
     101
    102102        clear_screen();
    103103        moveto(10, 0);
    104104        printf("\tRank \tLevel \tName\t                     points\n");
    105105        printf("\t========================================================\n");
    106        
     106
    107107        for (i = 0; i < NUMSPOTS - 1; i++)
    108108                printf("\t%6d %6d %-16s %20d\n",
    109109                    i + 1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score);
    110        
     110
    111111        if (!firstgame) {
    112112                printf("\t========================================================\n");
     
    114114                    scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score);
    115115        }
    116        
     116
    117117        printf("\n\n\n\n\tPress any key to return to main menu.");
    118118        getchar();
     
    126126        cons_event_t ev;
    127127        kbd_event_t *kev;
    128        
     128
    129129        clear_screen();
    130130        moveto(10, 10);
     
    134134        i = 6;
    135135        off = 6;
    136        
     136
    137137        moveto(10 , 28);
    138138        printf("%s%.*s", scores[NUMSPOTS - 1].hs_name, MAXLOGNAME-i,
    139139            "........................................");
    140        
     140
    141141        while (1) {
    142142                console_flush(console);
    143143                if (!console_get_event(console, &ev))
    144144                        exit(1);
    145                
     145
    146146                if (ev.type != CEV_KEY || ev.ev.key.type == KEY_RELEASE)
    147147                        continue;
    148                
     148
    149149                kev = &ev.ev.key;
    150                
     150
    151151                if (kev->key == KC_ENTER || kev->key == KC_NENTER)
    152152                        break;
    153                
     153
    154154                if (kev->key == KC_BACKSPACE) {
    155155                        if (i > 0) {
    156156                                wchar_t uc;
    157                                
     157
    158158                                --i;
    159159                                while (off > 0) {
     
    165165                                                break;
    166166                                }
    167                                
     167
    168168                                scores[NUMSPOTS - 1].hs_name[off] = '\0';
    169169                        }
     
    177177                        }
    178178                }
    179                
     179
    180180                moveto(10, 28);
    181181                printf("%s%.*s", scores[NUMSPOTS - 1].hs_name, MAXLOGNAME - i,
    182182                    "........................................");
    183183        }
    184        
     184
    185185        scores[NUMSPOTS - 1].hs_score = score;
    186186        scores[NUMSPOTS - 1].hs_level = level;
    187        
     187
    188188        i = NUMSPOTS - 1;
    189189        while ((i > 0) && (scores[i - 1].hs_score < score))
    190190                i--;
    191        
     191
    192192        for (j = NUMSPOTS - 2; j > i; j--)
    193193                copyhiscore(j, j-1);
    194        
     194
    195195        copyhiscore(i, NUMSPOTS - 1);
    196196}
     
    236236                return;
    237237        }
    238        
     238
    239239        cnt = fwrite(scores, sizeof(struct highscore), NUMSPOTS, f);
    240240        rc = fclose(f);
  • uspace/dist/src/c/demos/tetris/screen.c

    r3061bc1 r8565a42  
    148148        sysarg_t ccap;
    149149        errno_t rc = console_get_color_cap(console, &ccap);
    150        
     150
    151151        if (rc != EOK)
    152152                return false;
    153        
     153
    154154        return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB);
    155155}
     
    161161{
    162162        winsize_t ws;
    163        
     163
    164164        Rows = 0;
    165165        Cols = 0;
    166        
     166
    167167        if (get_display_size(&ws) == 0) {
    168168                Rows = ws.ws_row;
     
    171171
    172172        use_color = get_display_color_sup();
    173        
     173
    174174        if ((Rows < MINROWS) || (Cols < MINCOLS)) {
    175175                char smallscr[55];
    176                
     176
    177177                snprintf(smallscr, sizeof(smallscr),
    178178                    "the screen is too small (must be at least %dx%d)",
     
    181181        }
    182182        isset = 1;
    183        
     183
    184184        scr_clear();
    185185}
     
    197197        if (isset)
    198198                scr_end();
    199        
     199
    200200        errx(1, "aborting: %s", why);
    201201}
     
    213213        int j;
    214214        int ccol;
    215        
     215
    216216        /* Always leave cursor after last displayed point */
    217217        curscreen[D_LAST * B_COLS - 1] = -1;
    218        
     218
    219219        if (score != curscore) {
    220220                moveto(0, 0);
     
    222222                curscore = score;
    223223        }
    224        
     224
    225225        /* Draw preview of next pattern */
    226226        if ((showpreview) && (nextshape != lastshape)) {
     
    228228                static int r = 5, c = 2;
    229229                int tr, tc, t;
    230                
     230
    231231                lastshape = nextshape;
    232                
     232
    233233                /* Clean */
    234234                resume_normal();
     
    241241                moveto(r + 2, c - 1);
    242242                putstr("          ");
    243                
     243
    244244                moveto(r - 3, c - 2);
    245245                putstr("Next shape:");
    246                
     246
    247247                /* Draw */
    248248                start_standout(nextshape->color);
     
    252252                        t = c + r * B_COLS;
    253253                        t += nextshape->off[i];
    254                        
     254
    255255                        tr = t / B_COLS;
    256256                        tc = t % B_COLS;
    257                        
     257
    258258                        moveto(tr, 2*tc);
    259259                        putstr("  ");
     
    261261                resume_normal();
    262262        }
    263        
     263
    264264        bp = &board[D_FIRST * B_COLS];
    265265        sp = &curscreen[D_FIRST * B_COLS];
     
    269269                        if (*sp == (so = *bp))
    270270                                continue;
    271                        
     271
    272272                        *sp = so;
    273273                        if (i != ccol) {
     
    278278                                moveto(RTOD(j), CTOD(i));
    279279                        }
    280                        
     280
    281281                        if (so != cur_so) {
    282282                                if (so)
     
    287287                        }
    288288                        putstr("  ");
    289                        
     289
    290290                        ccol = i + 1;
    291291                        /*
     
    297297                         * the next cell is a different color.
    298298                         */
    299                        
     299
    300300                        if ((i > STOP) || (sp[1] != bp[1]) || (so != bp[1]))
    301301                                continue;
    302                        
     302
    303303                        if (sp[2] != bp[2])
    304304                                sp[1] = -1;
     
    309309                }
    310310        }
    311        
     311
    312312        if (cur_so)
    313313                resume_normal();
    314        
     314
    315315        console_flush(console);
    316316}
     
    323323{
    324324        int l = str_size(s);
    325        
     325
    326326        moveto(Rows - 2, ((Cols - l) >> 1) - 1);
    327        
     327
    328328        if (set)
    329329                putstr(s);
     
    341341{
    342342        suseconds_t timeout = fallrate;
    343        
     343
    344344        while (timeout > 0) {
    345345                cons_event_t event;
    346                
     346
    347347                if (!console_get_event_timeout(console, &event, &timeout))
    348348                        break;
     
    359359         * and increase speed.
    360360         */
    361        
     361
    362362        if (timeleft <= 0) {
    363363                faster();
    364364                timeleft = fallrate;
    365365        }
    366        
     366
    367367        /*
    368368         * Wait to see if there is any input. If so, take it and
     
    371371         * make timeleft zero and return -1.
    372372         */
    373        
     373
    374374        wchar_t c = 0;
    375        
     375
    376376        while (c == 0) {
    377377                cons_event_t event;
    378                
     378
    379379                if (!console_get_event_timeout(console, &event, &timeleft)) {
    380380                        timeleft = 0;
    381381                        return -1;
    382382                }
    383                
     383
    384384                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
    385385                        c = event.ev.key.c;
    386386        }
    387        
     387
    388388        return (int) c;
    389389}
     
    395395{
    396396        wchar_t c = 0;
    397        
     397
    398398        while (c == 0) {
    399399                cons_event_t event;
    400                
     400
    401401                if (!console_get_event(console, &event))
    402402                        return -1;
    403                
     403
    404404                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
    405405                        c = event.ev.key.c;
    406406        }
    407        
     407
    408408        return (int) c;
    409409}
  • uspace/dist/src/c/demos/tetris/shapes.c

    r3061bc1 r8565a42  
    9696{
    9797        const int *o = shape->off;
    98        
     98
    9999        if ((board[pos]) || (board[pos + *o++]) || (board[pos + *o++]) ||
    100100            (board[pos + *o]))
    101101                return 0;
    102        
     102
    103103        return 1;
    104104}
     
    111111{
    112112        const int *o = shape->off;
    113        
     113
    114114        board[pos] = onoff ? shape->color : 0x000000;
    115115        board[pos + *o++] = onoff ? shape->color : 0x000000;
  • uspace/dist/src/c/demos/tetris/tetris.c

    r3061bc1 r8565a42  
    9898        int i;
    9999        cell *p = board;
    100        
     100
    101101        for (i = B_SIZE; i; i--)
    102102                *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 0x0000ff : 0x000000;
     
    113113        int base;
    114114        cell *p;
    115        
     115
    116116        for (i = A_FIRST; i < A_LAST; i++) {
    117117                base = i * B_COLS + 1;
     
    122122                                rows++;
    123123                                memset(&board[base], 0, sizeof(cell) * (B_COLS - 2));
    124                                
     124
    125125                                scr_update();
    126126                                tsleep();
    127                                
     127
    128128                                while (--base != 0)
    129129                                        board[base + B_COLS] = board[base];
    130                                
     130
    131131                                scr_update();
    132132                                tsleep();
    133                                
     133
    134134                                break;
    135135                        }
    136136                }
    137137        }
    138        
     138
    139139        switch (rows) {
    140140        case 1:
     
    160160        int i;
    161161        int j = rand() % 4;
    162        
     162
    163163        for (i = 0; i < j; i++)
    164164                tmp = &shapes[classic ? tmp->rotc : tmp->rot];
    165        
     165
    166166        return (tmp);
    167167}
     
    170170{
    171171        struct timeval tv;
    172        
     172
    173173        gettimeofday(&tv, NULL);
    174174        srand(tv.tv_sec + tv.tv_usec / 100000);
     
    180180        moveto(5, 10);
    181181        puts("Tetris\n\n");
    182        
     182
    183183        moveto(8, 10);
    184184        printf("Level = %d (press keys 1 - 9 to change)", level);
     
    202202        while (1) {
    203203                int i = getchar();
    204                
     204
    205205                switch(i) {
    206206                        case 'p':
     
    249249        int j;
    250250        int ch;
    251        
     251
    252252        console = console_init(stdin, stdout);
    253        
     253
    254254        keys = "jkl pq";
    255        
     255
    256256        classic = 0;
    257257        showpreview = 1;
    258        
     258
    259259        while ((ch = getopt(argc, argv, "ck:ps")) != -1)
    260260                switch(ch) {
     
    280280                        usage();
    281281                }
    282        
     282
    283283        argc -= optind;
    284284        argv += optind;
    285        
     285
    286286        if (argc)
    287287                usage();
    288        
     288
    289289        for (i = 0; i <= 5; i++) {
    290290                for (j = i + 1; j <= 5; j++) {
     
    292292                                errx(1, "%s", "duplicate command keys specified.");
    293293                }
    294                
     294
    295295                if (keys[i] == ' ')
    296296                        str_cpy(key_write[i], sizeof(key_write[i]), "<space>");
     
    300300                }
    301301        }
    302        
     302
    303303        snprintf(key_msg, sizeof(key_msg),
    304304            "%s - left   %s - rotate   %s - right   %s - drop   %s - pause   %s - quit",
    305305            key_write[0], key_write[1], key_write[2], key_write[3],
    306306            key_write[4], key_write[5]);
    307        
     307
    308308        scr_init();
    309309        if (loadscores() != EOK)
     
    312312        while (tetris_menu(&level)) {
    313313                fallrate = 1000000 / level;
    314                
     314
    315315                scr_clear();
    316316                setup_board();
    317                
     317
    318318                srandomdev();
    319319                scr_set();
    320                
     320
    321321                pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
    322322                nextshape = randshape();
    323323                curshape = randshape();
    324                
     324
    325325                scr_msg(key_msg, 1);
    326                
     326
    327327                while (1) {
    328328                        place(curshape, pos, 1);
     
    338338                                        continue;
    339339                                }
    340                                
     340
    341341                                /*
    342342                                 * Put up the current shape `permanently',
     
    346346                                score++;
    347347                                elide();
    348                                
     348
    349349                                /*
    350350                                 * Choose a new shape.  If it does not fit,
     
    354354                                nextshape = randshape();
    355355                                pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
    356                                
     356
    357357                                if (!fits_in(curshape, pos))
    358358                                        break;
    359                                
    360                                 continue;
    361                         }
    362                        
     359
     360                                continue;
     361                        }
     362
    363363                        /*
    364364                         * Handle command keys.
     
    368368                                break;
    369369                        }
    370                        
     370
    371371                        if (c == keys[4]) {
    372372                                static char msg[] =
    373373                                    "paused - press RETURN to continue";
    374                                
     374
    375375                                place(curshape, pos, 1);
    376376                                do {
     
    380380                                        console_flush(console);
    381381                                } while (!twait());
    382                                
     382
    383383                                scr_msg(msg, 0);
    384384                                scr_msg(key_msg, 1);
     
    386386                                continue;
    387387                        }
    388                        
     388
    389389                        if (c == keys[0]) {
    390390                                /* move left */
     
    393393                                continue;
    394394                        }
    395                        
     395
    396396                        if (c == keys[1]) {
    397397                                /* turn */
    398398                                const struct shape *new =
    399399                                    &shapes[classic ? curshape->rotc : curshape->rot];
    400                                
     400
    401401                                if (fits_in(new, pos))
    402402                                        curshape = new;
    403403                                continue;
    404404                        }
    405                        
     405
    406406                        if (c == keys[2]) {
    407407                                /* move right */
     
    410410                                continue;
    411411                        }
    412                        
     412
    413413                        if (c == keys[3]) {
    414414                                /* move to bottom */
     
    419419                                continue;
    420420                        }
    421                        
     421
    422422                        if (c == '\f') {
    423423                                scr_clear();
     
    425425                        }
    426426                }
    427                
     427
    428428                scr_clear();
    429429                loadscores();
     
    432432                score = 0;
    433433        }
    434        
     434
    435435        scr_clear();
    436436        printf("\nGame over.\n");
    437437        scr_end();
    438        
     438
    439439        return 0;
    440440}
  • uspace/dist/src/c/demos/top/screen.c

    r3061bc1 r8565a42  
    9898{
    9999        screen_style_normal();
    100        
     100
    101101        if (clear) {
    102102                console_flush(console);
    103103                console_clear(console);
    104104        }
    105        
     105
    106106        screen_moveto(0, 0);
    107107}
     
    112112        sysarg_t rows;
    113113        screen_get_size(&cols, &rows);
    114        
     114
    115115        sysarg_t c;
    116116        sysarg_t r;
    117117        screen_get_pos(&c, &r);
    118        
     118
    119119        sysarg_t i;
    120120        for (i = c + 1; i < cols; i++)
    121121                puts(" ");
    122        
     122
    123123        if (r + 1 < rows)
    124124                puts("\n");
     
    128128{
    129129        console = console_init(stdin, stdout);
    130        
     130
    131131        console_flush(console);
    132132        console_cursor_visibility(console, false);
    133        
     133
    134134        screen_restart(true);
    135135}
     
    141141
    142142        screen_restart(true);
    143        
     143
    144144        console_flush(console);
    145145        console_cursor_visibility(console, true);
     
    149149{
    150150        printf("%3" PRIu64 ".", ffloat.upper / ffloat.lower);
    151        
     151
    152152        unsigned int i;
    153153        uint64_t rest = (ffloat.upper % ffloat.lower) * 10;
     
    156156                rest = (rest % ffloat.lower) * 10;
    157157        }
    158        
     158
    159159        printf("%%");
    160160}
     
    165165        sysarg_t rows;
    166166        screen_get_size(&cols, &rows);
    167        
     167
    168168        sysarg_t c;
    169169        sysarg_t r;
    170170        screen_get_pos(&c, &r);
    171        
     171
    172172        if (c < cols) {
    173173                int pos = cols - c - 1;
     
    183183            data->hours, data->minutes, data->seconds,
    184184            data->udays, data->uhours, data->uminutes, data->useconds);
    185        
     185
    186186        size_t i;
    187187        for (i = 0; i < data->load_count; i++) {
     
    189189                stats_print_load_fragment(data->load[i], 2);
    190190        }
    191        
     191
    192192        screen_newline();
    193193}
     
    208208        size_t other = 0;
    209209        size_t invalid = 0;
    210        
     210
    211211        size_t i;
    212212        for (i = 0; i < data->threads_count; i++) {
    213213                total++;
    214                
     214
    215215                switch (data->threads[i].state) {
    216216                case Running:
     
    234234                }
    235235        }
    236        
     236
    237237        printf("threads: %zu total, %zu running, %zu ready, "
    238238            "%zu sleeping, %zu lingering, %zu other, %zu invalid",
     
    250250                        char busy_suffix;
    251251                        char idle_suffix;
    252                        
     252
    253253                        order_suffix(data->cpus[i].busy_cycles, &busy, &busy_suffix);
    254254                        order_suffix(data->cpus[i].idle_cycles, &idle, &idle_suffix);
    255                        
     255
    256256                        printf("cpu%u (%4" PRIu16 " MHz): busy cycles: "
    257257                            "%" PRIu64 "%c, idle cycles: %" PRIu64 "%c",
     
    264264                } else
    265265                        printf("cpu%u inactive", data->cpus[i].id);
    266                
     266
    267267                screen_newline();
    268268        }
     
    279279        const char *used_suffix;
    280280        const char *free_suffix;
    281        
     281
    282282        bin_order_suffix(data->physmem->total, &total, &total_suffix, false);
    283283        bin_order_suffix(data->physmem->unavail, &unavail, &unavail_suffix, false);
    284284        bin_order_suffix(data->physmem->used, &used, &used_suffix, false);
    285285        bin_order_suffix(data->physmem->free, &free, &free_suffix, false);
    286        
     286
    287287        printf("memory: %" PRIu64 "%s total, %" PRIu64 "%s unavail, %"
    288288            PRIu64 "%s used, %" PRIu64 "%s free", total, total_suffix,
     
    304304        sysarg_t rows;
    305305        screen_get_size(&cols, &rows);
    306        
    307         screen_newline();
    308        
     306
     307        screen_newline();
     308
    309309        printf("Operation modes:");
    310310        screen_newline();
    311        
     311
    312312        printf(" t .. tasks statistics");
    313313        screen_newline();
    314        
     314
    315315        printf(" i .. IPC statistics");
    316316        screen_newline();
    317        
     317
    318318        printf(" e .. exceptions statistics");
    319319        screen_newline();
    320        
     320
    321321        printf("      a .. toggle display of all/hot exceptions");
    322322        screen_newline();
     
    329329        printf("Other keys:");
    330330        screen_newline();
    331        
     331
    332332        printf(" s .. choose column to sort by");
    333333        screen_newline();
    334        
     334
    335335        printf(" r .. toggle reversed sorting");
    336336        screen_newline();
    337        
     337
    338338        printf(" q .. quit");
    339339        screen_newline();
    340        
     340
    341341        sysarg_t col;
    342342        sysarg_t row;
    343343        screen_get_pos(&col, &row);
    344        
     344
    345345        while (row < rows) {
    346346                screen_newline();
     
    379379        sysarg_t rows;
    380380        screen_get_size(&cols, &rows);
    381        
     381
    382382        sysarg_t col;
    383383        sysarg_t row;
    384384        screen_get_pos(&col, &row);
    385        
     385
    386386        size_t i;
    387387        for (i = 0; (i < table->num_fields) && (row < rows); i++) {
     
    440440                }
    441441        }
    442        
     442
    443443        while (row < rows) {
    444444                screen_newline();
     
    452452        sysarg_t rows;
    453453        screen_get_size(&cols, &rows);
    454        
     454
    455455        sysarg_t col;
    456456        sysarg_t row;
     
    463463                row++;
    464464        }
    465        
     465
    466466        while (row < rows) {
    467467                screen_newline();
     
    493493        print_physmem_info(data);
    494494        print_warning();
    495        
     495
    496496        switch (screen_mode) {
    497497        case SCREEN_TABLE:
     
    506506                print_help();
    507507        }
    508        
     508
    509509        console_flush(console);
    510510}
     
    526526        vsnprintf(warning_text, warning_text_size, fmt, args);
    527527        va_end(args);
    528        
     528
    529529        warning_timeleft = 2 * USEC_COUNT;
    530530
     
    542542         * Reset timeleft whenever it is not positive.
    543543         */
    544        
     544
    545545        if (timeleft <= 0)
    546546                timeleft = sec * USEC_COUNT;
    547        
     547
    548548        /*
    549549         * Wait to see if there is any input. If so, take it and
     
    552552         * make timeleft zero and return -1.
    553553         */
    554        
     554
    555555        wchar_t c = 0;
    556        
     556
    557557        while (c == 0) {
    558558                cons_event_t event;
    559                
     559
    560560                warning_timeleft -= timeleft;
    561561                if (!console_get_event_timeout(console, &event, &timeleft)) {
     
    564564                }
    565565                warning_timeleft += timeleft;
    566                
     566
    567567                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
    568568                        c = event.ev.key.c;
    569569        }
    570        
     570
    571571        return (int) c;
    572572}
  • uspace/dist/src/c/demos/top/top.c

    r3061bc1 r8565a42  
    152152        target->table.num_fields = 0;
    153153        target->table.fields = NULL;
    154        
     154
    155155        /* Get current time */
    156156        struct timeval time;
    157157        gettimeofday(&time, NULL);
    158        
     158
    159159        target->hours = (time.tv_sec % DAY) / HOUR;
    160160        target->minutes = (time.tv_sec % HOUR) / MINUTE;
    161161        target->seconds = time.tv_sec % MINUTE;
    162        
     162
    163163        /* Get uptime */
    164164        struct timeval uptime;
    165165        getuptime(&uptime);
    166        
     166
    167167        target->udays = uptime.tv_sec / DAY;
    168168        target->uhours = (uptime.tv_sec % DAY) / HOUR;
    169169        target->uminutes = (uptime.tv_sec % HOUR) / MINUTE;
    170170        target->useconds = uptime.tv_sec % MINUTE;
    171        
     171
    172172        /* Get load */
    173173        target->load = stats_get_load(&(target->load_count));
    174174        if (target->load == NULL)
    175175                return "Cannot get system load";
    176        
     176
    177177        /* Get CPUs */
    178178        target->cpus = stats_get_cpus(&(target->cpus_count));
    179179        if (target->cpus == NULL)
    180180                return "Cannot get CPUs";
    181        
     181
    182182        target->cpus_perc =
    183183            (perc_cpu_t *) calloc(target->cpus_count, sizeof(perc_cpu_t));
    184184        if (target->cpus_perc == NULL)
    185185                return "Not enough memory for CPU utilization";
    186        
     186
    187187        /* Get tasks */
    188188        target->tasks = stats_get_tasks(&(target->tasks_count));
    189189        if (target->tasks == NULL)
    190190                return "Cannot get tasks";
    191        
     191
    192192        target->tasks_perc =
    193193            (perc_task_t *) calloc(target->tasks_count, sizeof(perc_task_t));
    194194        if (target->tasks_perc == NULL)
    195195                return "Not enough memory for task utilization";
    196        
     196
    197197        /* Get threads */
    198198        target->threads = stats_get_threads(&(target->threads_count));
    199199        if (target->threads == NULL)
    200200                return "Cannot get threads";
    201        
     201
    202202        /* Get Exceptions */
    203203        target->exceptions = stats_get_exceptions(&(target->exceptions_count));
    204204        if (target->exceptions == NULL)
    205205                return "Cannot get exceptions";
    206        
     206
    207207        target->exceptions_perc =
    208208            (perc_exc_t *) calloc(target->exceptions_count, sizeof(perc_exc_t));
    209209        if (target->exceptions_perc == NULL)
    210210                return "Not enough memory for exception utilization";
    211        
     211
    212212        /* Get physical memory */
    213213        target->physmem = stats_get_physmem();
    214214        if (target->physmem == NULL)
    215215                return "Cannot get physical memory";
    216        
     216
    217217        target->ucycles_diff = calloc(target->tasks_count,
    218218            sizeof(uint64_t));
    219219        if (target->ucycles_diff == NULL)
    220220                return "Not enough memory for user utilization";
    221        
     221
    222222        /* Allocate memory for computed values */
    223223        target->kcycles_diff = calloc(target->tasks_count,
     
    225225        if (target->kcycles_diff == NULL)
    226226                return "Not enough memory for kernel utilization";
    227        
     227
    228228        target->ecycles_diff = calloc(target->exceptions_count,
    229229            sizeof(uint64_t));
    230230        if (target->ecycles_diff == NULL)
    231231                return "Not enough memory for exception cycles utilization";
    232        
     232
    233233        target->ecount_diff = calloc(target->exceptions_count,
    234234            sizeof(uint64_t));
    235235        if (target->ecount_diff == NULL)
    236236                return "Not enough memory for exception count utilization";
    237        
     237
    238238        return NULL;
    239239}
     
    249249        /* For each CPU: Compute total cycles and divide it between
    250250           user and kernel */
    251        
     251
    252252        size_t i;
    253253        for (i = 0; i < new_data->cpus_count; i++) {
     
    257257                    new_data->cpus[i].busy_cycles - old_data->cpus[i].busy_cycles;
    258258                uint64_t sum = idle + busy;
    259                
     259
    260260                FRACTION_TO_FLOAT(new_data->cpus_perc[i].idle, idle * 100, sum);
    261261                FRACTION_TO_FLOAT(new_data->cpus_perc[i].busy, busy * 100, sum);
    262262        }
    263        
     263
    264264        /* For all tasks compute sum and differencies of all cycles */
    265        
     265
    266266        uint64_t virtmem_total = 0;
    267267        uint64_t resmem_total = 0;
    268268        uint64_t ucycles_total = 0;
    269269        uint64_t kcycles_total = 0;
    270        
     270
    271271        for (i = 0; i < new_data->tasks_count; i++) {
    272272                /* Match task with the previous instance */
    273                
     273
    274274                bool found = false;
    275275                size_t j;
     
    280280                        }
    281281                }
    282                
     282
    283283                if (!found) {
    284284                        /* This is newly borned task, ignore it */
     
    287287                        continue;
    288288                }
    289                
     289
    290290                new_data->ucycles_diff[i] =
    291291                    new_data->tasks[i].ucycles - old_data->tasks[j].ucycles;
    292292                new_data->kcycles_diff[i] =
    293293                    new_data->tasks[i].kcycles - old_data->tasks[j].kcycles;
    294                
     294
    295295                virtmem_total += new_data->tasks[i].virtmem;
    296296                resmem_total += new_data->tasks[i].resmem;
     
    298298                kcycles_total += new_data->kcycles_diff[i];
    299299        }
    300        
     300
    301301        /* For each task compute percential change */
    302        
     302
    303303        for (i = 0; i < new_data->tasks_count; i++) {
    304304                FRACTION_TO_FLOAT(new_data->tasks_perc[i].virtmem,
     
    311311                    new_data->kcycles_diff[i] * 100, kcycles_total);
    312312        }
    313        
     313
    314314        /* For all exceptions compute sum and differencies of cycles */
    315        
     315
    316316        uint64_t ecycles_total = 0;
    317317        uint64_t ecount_total = 0;
    318        
     318
    319319        for (i = 0; i < new_data->exceptions_count; i++) {
    320320                /*
     
    323323                 * usually disappear, but it does not hurt.
    324324                 */
    325                
     325
    326326                bool found = false;
    327327                size_t j;
     
    332332                        }
    333333                }
    334                
     334
    335335                if (!found) {
    336336                        /* This is a new exception, ignore it */
     
    339339                        continue;
    340340                }
    341                
     341
    342342                new_data->ecycles_diff[i] =
    343343                    new_data->exceptions[i].cycles - old_data->exceptions[j].cycles;
    344344                new_data->ecount_diff[i] =
    345345                    new_data->exceptions[i].count - old_data->exceptions[i].count;
    346                
     346
    347347                ecycles_total += new_data->ecycles_diff[i];
    348348                ecount_total += new_data->ecount_diff[i];
    349349        }
    350        
     350
    351351        /* For each exception compute percential change */
    352        
     352
    353353        for (i = 0; i < new_data->exceptions_count; i++) {
    354354                FRACTION_TO_FLOAT(new_data->exceptions_perc[i].cycles,
     
    363363        field_t *fa = (field_t *)a + sort_column;
    364364        field_t *fb = (field_t *)b + sort_column;
    365        
     365
    366366        if (fa->type > fb->type)
    367367                return 1 * sort_reverse;
     
    535535        if (target->load != NULL)
    536536                free(target->load);
    537        
     537
    538538        if (target->cpus != NULL)
    539539                free(target->cpus);
    540        
     540
    541541        if (target->cpus_perc != NULL)
    542542                free(target->cpus_perc);
    543        
     543
    544544        if (target->tasks != NULL)
    545545                free(target->tasks);
    546        
     546
    547547        if (target->tasks_perc != NULL)
    548548                free(target->tasks_perc);
    549        
     549
    550550        if (target->threads != NULL)
    551551                free(target->threads);
    552        
     552
    553553        if (target->exceptions != NULL)
    554554                free(target->exceptions);
    555        
     555
    556556        if (target->exceptions_perc != NULL)
    557557                free(target->exceptions_perc);
    558        
     558
    559559        if (target->physmem != NULL)
    560560                free(target->physmem);
    561        
     561
    562562        if (target->ucycles_diff != NULL)
    563563                free(target->ucycles_diff);
    564        
     564
    565565        if (target->kcycles_diff != NULL)
    566566                free(target->kcycles_diff);
    567        
     567
    568568        if (target->ecycles_diff != NULL)
    569569                free(target->ecycles_diff);
    570        
     570
    571571        if (target->ecount_diff != NULL)
    572572                free(target->ecount_diff);
     
    581581        data_t data_prev;
    582582        const char *ret = NULL;
    583        
     583
    584584        screen_init();
    585585        printf("Reading initial data...\n");
    586        
     586
    587587        if ((ret = read_data(&data)) != NULL)
    588588                goto out;
    589        
     589
    590590        /* Compute some rubbish to have initialised values */
    591591        compute_percentages(&data, &data);
    592        
     592
    593593        /* And paint screen until death */
    594594        while (true) {
     
    601601                                goto out;
    602602                        }
    603                        
     603
    604604                        compute_percentages(&data_prev, &data);
    605605                        free_data(&data_prev);
     
    671671                print_data(&data);
    672672        }
    673        
     673
    674674out:
    675675        screen_done();
    676676        free_data(&data);
    677        
     677
    678678        if (ret != NULL) {
    679679                fprintf(stderr, "%s: %s\n", NAME, ret);
    680680                return 1;
    681681        }
    682        
     682
    683683        return 0;
    684684}
  • uspace/dist/src/c/demos/top/top.h

    r3061bc1 r8565a42  
    112112        time_t minutes;
    113113        time_t seconds;
    114        
     114
    115115        sysarg_t udays;
    116116        sysarg_t uhours;
    117117        sysarg_t uminutes;
    118118        sysarg_t useconds;
    119        
     119
    120120        size_t load_count;
    121121        load_t *load;
    122        
     122
    123123        size_t cpus_count;
    124124        stats_cpu_t *cpus;
    125125        perc_cpu_t *cpus_perc;
    126        
     126
    127127        size_t tasks_count;
    128128        stats_task_t *tasks;
    129129        perc_task_t *tasks_perc;
    130        
     130
    131131        size_t threads_count;
    132132        stats_thread_t *threads;
    133        
     133
    134134        size_t exceptions_count;
    135135        stats_exc_t *exceptions;
    136136        perc_exc_t *exceptions_perc;
    137        
     137
    138138        stats_physmem_t *physmem;
    139        
     139
    140140        uint64_t *ucycles_diff;
    141141        uint64_t *kcycles_diff;
Note: See TracChangeset for help on using the changeset viewer.