Changeset a35b458 in mainline for uspace/app/tetris


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 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.

Location:
uspace/app/tetris
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tetris/scores.c

    r3061bc1 ra35b458  
    9898{
    9999        int i;
    100        
     100
    101101        clear_screen();
    102102        moveto(10, 0);
    103103        printf("\tRank \tLevel \tName\t                     points\n");
    104104        printf("\t========================================================\n");
    105        
     105
    106106        for (i = 0; i < NUMSPOTS - 1; i++)
    107107                printf("\t%6d %6d %-16s %20d\n",
    108108                    i + 1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score);
    109        
     109
    110110        if (!firstgame) {
    111111                printf("\t========================================================\n");
     
    113113                    scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score);
    114114        }
    115        
     115
    116116        printf("\n\n\n\n\tPress any key to return to main menu.");
    117117        getchar();
     
    125125        cons_event_t ev;
    126126        kbd_event_t *kev;
    127        
     127
    128128        clear_screen();
    129129        moveto(10, 10);
     
    133133        i = 6;
    134134        off = 6;
    135        
     135
    136136        moveto(10 , 28);
    137137        printf("%s%.*s", scores[NUMSPOTS - 1].hs_name, MAXLOGNAME-i,
    138138            "........................................");
    139        
     139
    140140        while (1) {
    141141                console_flush(console);
    142142                if (!console_get_event(console, &ev))
    143143                        exit(1);
    144                
     144
    145145                if (ev.type != CEV_KEY || ev.ev.key.type == KEY_RELEASE)
    146146                        continue;
    147                
     147
    148148                kev = &ev.ev.key;
    149                
     149
    150150                if (kev->key == KC_ENTER || kev->key == KC_NENTER)
    151151                        break;
    152                
     152
    153153                if (kev->key == KC_BACKSPACE) {
    154154                        if (i > 0) {
    155155                                wchar_t uc;
    156                                
     156
    157157                                --i;
    158158                                while (off > 0) {
     
    164164                                                break;
    165165                                }
    166                                
     166
    167167                                scores[NUMSPOTS - 1].hs_name[off] = '\0';
    168168                        }
     
    176176                        }
    177177                }
    178                
     178
    179179                moveto(10, 28);
    180180                printf("%s%.*s", scores[NUMSPOTS - 1].hs_name, MAXLOGNAME - i,
    181181                    "........................................");
    182182        }
    183        
     183
    184184        scores[NUMSPOTS - 1].hs_score = score;
    185185        scores[NUMSPOTS - 1].hs_level = level;
    186        
     186
    187187        i = NUMSPOTS - 1;
    188188        while ((i > 0) && (scores[i - 1].hs_score < score))
    189189                i--;
    190        
     190
    191191        for (j = NUMSPOTS - 2; j > i; j--)
    192192                copyhiscore(j, j-1);
    193        
     193
    194194        copyhiscore(i, NUMSPOTS - 1);
    195195}
     
    235235                return;
    236236        }
    237        
     237
    238238        cnt = fwrite(scores, sizeof(struct highscore), NUMSPOTS, f);
    239239        rc = fclose(f);
  • uspace/app/tetris/screen.c

    r3061bc1 ra35b458  
    147147        sysarg_t ccap;
    148148        errno_t rc = console_get_color_cap(console, &ccap);
    149        
     149
    150150        if (rc != EOK)
    151151                return false;
    152        
     152
    153153        return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB);
    154154}
     
    160160{
    161161        winsize_t ws;
    162        
     162
    163163        Rows = 0;
    164164        Cols = 0;
    165        
     165
    166166        if (get_display_size(&ws) == 0) {
    167167                Rows = ws.ws_row;
     
    170170
    171171        use_color = get_display_color_sup();
    172        
     172
    173173        if ((Rows < MINROWS) || (Cols < MINCOLS)) {
    174174                char smallscr[55];
    175                
     175
    176176                snprintf(smallscr, sizeof(smallscr),
    177177                    "the screen is too small (must be at least %dx%d)",
     
    180180        }
    181181        isset = 1;
    182        
     182
    183183        scr_clear();
    184184}
     
    196196        if (isset)
    197197                scr_end();
    198        
     198
    199199        fprintf(stderr, "aborting: %s", why);
    200200        abort();
     
    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/app/tetris/shapes.c

    r3061bc1 ra35b458  
    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/app/tetris/tetris.c

    r3061bc1 ra35b458  
    9797        int i;
    9898        cell *p = board;
    99        
     99
    100100        for (i = B_SIZE; i; i--)
    101101                *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 0x0000ff : 0x000000;
     
    112112        int base;
    113113        cell *p;
    114        
     114
    115115        for (i = A_FIRST; i < A_LAST; i++) {
    116116                base = i * B_COLS + 1;
     
    121121                                rows++;
    122122                                memset(&board[base], 0, sizeof(cell) * (B_COLS - 2));
    123                                
     123
    124124                                scr_update();
    125125                                tsleep();
    126                                
     126
    127127                                while (--base != 0)
    128128                                        board[base + B_COLS] = board[base];
    129                                
     129
    130130                                scr_update();
    131131                                tsleep();
    132                                
     132
    133133                                break;
    134134                        }
    135135                }
    136136        }
    137        
     137
    138138        switch (rows) {
    139139        case 1:
     
    159159        int i;
    160160        int j = rand() % 4;
    161        
     161
    162162        for (i = 0; i < j; i++)
    163163                tmp = &shapes[classic ? tmp->rotc : tmp->rot];
    164        
     164
    165165        return (tmp);
    166166}
     
    169169{
    170170        struct timeval tv;
    171        
     171
    172172        gettimeofday(&tv, NULL);
    173173        srand(tv.tv_sec + tv.tv_usec / 100000);
     
    179179        moveto(5, 10);
    180180        puts("Tetris\n\n");
    181        
     181
    182182        moveto(8, 10);
    183183        printf("Level = %d (press keys 1 - 9 to change)", level);
     
    201201        while (1) {
    202202                int i = getchar();
    203                
     203
    204204                switch(i) {
    205205                        case 'p':
     
    248248        int j;
    249249        int ch;
    250        
     250
    251251        console = console_init(stdin, stdout);
    252        
     252
    253253        keys = "jkl pq";
    254        
     254
    255255        classic = 0;
    256256        showpreview = 1;
    257        
     257
    258258        while ((ch = getopt(argc, argv, "ck:ps")) != -1)
    259259                switch(ch) {
     
    279279                        usage();
    280280                }
    281        
     281
    282282        argc -= optind;
    283283        argv += optind;
    284        
     284
    285285        if (argc)
    286286                usage();
    287        
     287
    288288        for (i = 0; i <= 5; i++) {
    289289                for (j = i + 1; j <= 5; j++) {
     
    293293                        }
    294294                }
    295                
     295
    296296                if (keys[i] == ' ')
    297297                        str_cpy(key_write[i], sizeof(key_write[i]), "<space>");
     
    301301                }
    302302        }
    303        
     303
    304304        snprintf(key_msg, sizeof(key_msg),
    305305            "%s - left   %s - rotate   %s - right   %s - drop   %s - pause   %s - quit",
    306306            key_write[0], key_write[1], key_write[2], key_write[3],
    307307            key_write[4], key_write[5]);
    308        
     308
    309309        scr_init();
    310310        if (loadscores() != EOK)
     
    313313        while (tetris_menu(&level)) {
    314314                fallrate = 1000000 / level;
    315                
     315
    316316                scr_clear();
    317317                setup_board();
    318                
     318
    319319                srandomdev();
    320320                scr_set();
    321                
     321
    322322                pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
    323323                nextshape = randshape();
    324324                curshape = randshape();
    325                
     325
    326326                scr_msg(key_msg, 1);
    327                
     327
    328328                while (1) {
    329329                        place(curshape, pos, 1);
     
    339339                                        continue;
    340340                                }
    341                                
     341
    342342                                /*
    343343                                 * Put up the current shape `permanently',
     
    347347                                score++;
    348348                                elide();
    349                                
     349
    350350                                /*
    351351                                 * Choose a new shape.  If it does not fit,
     
    355355                                nextshape = randshape();
    356356                                pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
    357                                
     357
    358358                                if (!fits_in(curshape, pos))
    359359                                        break;
    360                                
    361                                 continue;
    362                         }
    363                        
     360
     361                                continue;
     362                        }
     363
    364364                        /*
    365365                         * Handle command keys.
     
    369369                                break;
    370370                        }
    371                        
     371
    372372                        if (c == keys[4]) {
    373373                                static char msg[] =
    374374                                    "paused - press RETURN to continue";
    375                                
     375
    376376                                place(curshape, pos, 1);
    377377                                do {
     
    381381                                        console_flush(console);
    382382                                } while (!twait());
    383                                
     383
    384384                                scr_msg(msg, 0);
    385385                                scr_msg(key_msg, 1);
     
    387387                                continue;
    388388                        }
    389                        
     389
    390390                        if (c == keys[0]) {
    391391                                /* move left */
     
    394394                                continue;
    395395                        }
    396                        
     396
    397397                        if (c == keys[1]) {
    398398                                /* turn */
    399399                                const struct shape *new =
    400400                                    &shapes[classic ? curshape->rotc : curshape->rot];
    401                                
     401
    402402                                if (fits_in(new, pos))
    403403                                        curshape = new;
    404404                                continue;
    405405                        }
    406                        
     406
    407407                        if (c == keys[2]) {
    408408                                /* move right */
     
    411411                                continue;
    412412                        }
    413                        
     413
    414414                        if (c == keys[3]) {
    415415                                /* move to bottom */
     
    420420                                continue;
    421421                        }
    422                        
     422
    423423                        if (c == '\f') {
    424424                                scr_clear();
     
    426426                        }
    427427                }
    428                
     428
    429429                scr_clear();
    430430                loadscores();
     
    433433                score = 0;
    434434        }
    435        
     435
    436436        scr_clear();
    437437        printf("\nGame over.\n");
    438438        scr_end();
    439        
     439
    440440        return 0;
    441441}
Note: See TracChangeset for help on using the changeset viewer.