Changeset a35b458 in mainline for uspace/dist/src/c/demos/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/dist/src/c/demos/tetris
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/dist/src/c/demos/tetris/scores.c

    r3061bc1 ra35b458  
    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 ra35b458  
    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 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/dist/src/c/demos/tetris/tetris.c

    r3061bc1 ra35b458  
    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}
Note: See TracChangeset for help on using the changeset viewer.