code cosmetics
authorMischa POSLAWSKY <netris@shiar.org>
Tue, 27 Feb 2007 14:34:29 +0000 (15:34 +0100)
committerMischa POSLAWSKY <netris@shiar.org>
Tue, 27 Feb 2007 14:34:29 +0000 (15:34 +0100)
board.c
curses.c
game.c
inet.c
server.c
util.c

diff --git a/board.c b/board.c
index c6c4837e5975b5430911f90e9dacb0d957531a98..9044f7844c5723aedd993d6feeaee8a6a45eb495 100644 (file)
--- a/board.c
+++ b/board.c
@@ -94,10 +94,10 @@ int ShapeIterate(char s, int scr, int y, int x, ShapeDrawFunc func)
        int i, j, result;
        char type, rotation;
 
-       type = s/4;
-       rotation = s&3;
-       for (i = 0; i<4; i++)
-               for (j = 0; j<4; j++)
+       type = s / 4;
+       rotation = s & 3;
+       for (i = 0; i < 4; i++)
+               for (j = 0; j < 4; j++)
                        if (shapes[type][rotation][i][j])
                                if (result = func(scr, y-i, x+j, shapes[type][rotation][i][j]))
                                        return result;
@@ -112,9 +112,10 @@ char ChooseOption(float options[7])
        int i;
        float total = 0, val;
 
-       for (i = 0; i<7; i++) total += options[i];
-       val = Random(0, 32767)/32768.0*total;
-       for (i = 0; i<7; i++) if ((val -= options[i])<0) return i<<2;
+       for (i = 0; i < 7; i++) total += options[i];
+       val = Random(0, 32767) / 32768.0 * total;
+       for (i = 0; i < 7; i++) if ((val -= options[i]) < 0)
+               return i << 2;
        return 0;
 }
 
@@ -319,7 +320,7 @@ int CheckFall(int scr)
        unsigned char z;
 
        if (!Game.gravity) return 0;
-       for (y = Players[scr].boardHeight-1; y > 0; y--)
+       for (y = Players[scr].boardHeight - 1; y > 0; y--)
                for (x = 0; x < Players[scr].boardWidth; x++) {
                        if (((z = GetBlock(scr, y, x)) > BT_none) && ((z & 160) == 0)) {
                        //doesn't stick left/up => topleft block
@@ -362,7 +363,7 @@ int ClearFullLines(int scr)
                        from++; //skip
                        for (x = 0; x<Players[scr].boardWidth; x++) {
                                SetBlock(scr, from, x, GetBlock(scr, from, x)&239);
-                               if (from>1)
+                               if (from > 1)
                                        SetBlock(scr, from-2, x, GetBlock(scr, from-2, x)&223);
                        } //don't stick blocks to line which we'll remove
                } //full lines
index bece8392af0c572edc6a3374705674ace491e80d..a8af702707003f2818f91c49aea763d7310d1815 100644 (file)
--- a/curses.c
+++ b/curses.c
 #endif
 
 static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec keyGen =
-//             { NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key };
-               { NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key };
+static EventGenRec keyGen = {
+//     NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key
+       NULL, 0, FT_read, STDIN_FILENO, KeyGenFunc, EM_key
+};
 
 static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS];
 static int boardSize[MAX_SCREENS];
@@ -51,12 +52,12 @@ WINDOW *msgwin;
 static int haveColor;
 int PlayerDisp[MAX_SCREENS];
 
-#define MSG_HEIGHT 64 //max history
+#define MSG_HEIGHT 64  //max history
 char *message[MSG_HEIGHT];
 char messages[MSG_HEIGHT][MSG_WIDTH];
 
-static char *term_vi;  /* String to make cursor invisible */
-static char *term_ve;  /* String to make cursor visible */
+static char *term_vi;  /* String to make cursor invisible */
+static char *term_ve;  /* String to make cursor visible */
 
 void InitScreens(void)
 {
@@ -178,12 +179,12 @@ void GetTermcapInfo(void)
                        "vt100", "vt101", "vt102",
                        "vt200", "vt220", "vt300",
                        "vt320", "vt400", "vt420",
-                       "screen", "xterm", NULL };
+                       "screen", "xterm", NULL
+               };
                int i;
 
                for (i = 0; vts[i]; i++)
-                       if (!strcmp(term, vts[i]))
-                       {
+                       if (!strcmp(term, vts[i])) {
                                term_vi = "\033[?25l";
                                term_ve = "\033[?25h";
                                break;
@@ -391,9 +392,9 @@ void Messagetype(char c, int x, char *s)
                mvwaddch(msgwin, messageHeight-1, (x+1) % (messageWidth-1), ' ');
        } //escape
        else {
-               if (c == 13 || c==127) //enter/backspace
+               if (c == 13 || c == 127) //enter/backspace
                        mvwaddch(msgwin, messageHeight - 1, (x+2) % (messageWidth-1),
-                               x>=messageWidth-3 ? s[x - messageWidth + 3] : ' ');
+                               x >= messageWidth-3 ? s[x - messageWidth + 3] : ' ');
                else //any character
                        mvwaddch(msgwin, messageHeight - 1, x % (messageWidth-1), c);
                mvwaddch(msgwin, messageHeight - 1, (x+1) % (messageWidth-1), '_');
@@ -499,8 +500,8 @@ void PlotBlock1S(int y, int x, unsigned char type)
 }
 void PlotBlock(int scr, int y, int x, unsigned char type)
 {
-       if (y >= 0 && y < Players[scr].boardVisible &&
-               x >= 0 && x < Players[scr].boardWidth) {
+       if (y >= 0 && y < Players[scr].boardVisible
+        && x >= 0 && x < Players[scr].boardWidth) {
                if (boardSize[scr] > 1)
                        PlotBlock1(boardYPos[scr] - y, boardXPos[scr] + 2*x, type);
                else
@@ -599,10 +600,10 @@ void ScheduleFullRedraw(void)
 
 void CatchWinCh(int sig)
 { //handle window resize
-       endwin();    //exit curses
-       refresh();    //and reinit display (with different sizes)
+       endwin();      //exit curses
+       refresh();     //and reinit display (with different sizes)
        InitFields();  //manually redraw everything
-       refresh();    //refresh
+       refresh();     //refresh
 }
 
 static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event)
diff --git a/game.c b/game.c
index f26e07a556e1a6f9ca7592a3dc04e7449c043d97..d7214dc9eaa921c1ad883a678be6289c17d21a75 100644 (file)
--- a/game.c
+++ b/game.c
@@ -52,14 +52,17 @@ static struct option options[] = {
        { 0,                    0, 0,  0 }
 };
 
-enum { KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down,
-               KT_faster, KT_pause, KT_redraw, KT_quit, KT_numKeys };
+enum {
+       KT_left, KT_right, KT_rotright, KT_rotleft, KT_drop, KT_down,
+       KT_faster, KT_pause, KT_redraw, KT_quit, KT_numKeys
+};
 
 static char *keyNames[KT_numKeys+1] = {
        "Left", "Right", "RotRight", "RotLeft", "Drop", "Down",
-       "Faster", "Pause", "Redraw", "Quit", NULL };
+       "Faster", "Pause", "Redraw", "Quit", NULL
+};
 
-_Sets Sets = {7, 0, 1, 1, 1}; //Sets
+_Sets Sets = {7, 0, 1, 1, 1};
 
 static char keyTable[KT_numKeys+1];
 
@@ -159,16 +162,21 @@ void HandleOption(char tag, char *value)
                        else Sets.standout = 0;
                        break;
                case 'k':       //keys
-                       MapKeys(value); break;
+                       MapKeys(value);
+                       break;
                case 'H':       //info
                        Header();
-                       DistInfo(); exit(0);
+                       DistInfo();
+                       exit(0);
                case 'R':       //rules
-                       Rules(); exit(0);
+                       Rules();
+                       exit(0);
                case 'h':       //help
-                       Usage(); exit(0);
+                       Usage();
+                       exit(0);
                default:
-                       Usage(); exit(1);
+                       Usage();
+                       exit(1);
        }
 }
 
@@ -185,7 +193,7 @@ void ReadConf(char *filename)
                while (fgets(buf, 512, file_in) != NULL) {
                        if ((ch = strchr(buf, '#')))
                                *ch = '\0'; // truncate string from # char
-                       for (i = strlen(buf)-1; i >= 0; i--)
+                       for (i = strlen(buf) - 1; i >= 0; i--)
                                if (buf[i] == ' ' || buf[i] == '\n' || buf[i] == '\t' || buf[i] == 13)
                                        buf[i] = '\0';
                                else break;
@@ -372,7 +380,7 @@ void OneGame(void)
                                        if (!Sets.dropmode) gameStatus = 1; //instadrop
                                }
                                else gameStatus = 1; //dropped
-                               dropMode = Sets.dropmode>1;
+                               dropMode = Sets.dropmode > 1;
                                break;
                        case KT_faster:
                                if (game != GT_onePlayer) break;
@@ -463,11 +471,11 @@ void OneGame(void)
                        netint4 data[3];
                        short column;
 
-                       if (Players[me].alive<=0) break;
+                       if (Players[me].alive <= 0) break;
                        memcpy(data, net.data, sizeof(data[0]));
                        column = Random(0, Players[me].boardWidth);
                        Message("\\%d%s sends %d lines",
-                               Players[net.uid].team>7 ? 7 : Players[net.uid].team,
+                               Players[net.uid].team > 7 ? 7 : Players[net.uid].team,
                                Players[net.uid].name, data[0]);
                        lastadd = net.uid;
                        InsertJunk(me, Players[net.uid].team, data[0], column);
@@ -481,7 +489,7 @@ void OneGame(void)
                case NP_msg:
                {
                        Message("<\\%d%s\\7> %s",
-                               Players[net.uid].team>7 ? 7 : Players[net.uid].team,
+                               Players[net.uid].team > 7 ? 7 : Players[net.uid].team,
                                Players[net.uid].name, net.data, net.type);
                        break;
                } //chat
@@ -492,30 +500,30 @@ void OneGame(void)
                        Game.started = 2;
                        paused = 0;
                        Message("The game has started");
-                       for (i = 1; i<MAX_SCREENS; i++) if (Players[i].alive>0)
+                       for (i = 1; i < MAX_SCREENS; i++) if (Players[i].alive > 0)
                                ShowPause(i);
                        break;
                } //start game
                case NP_stop:
                {
-                       if (Game.started>1) {
+                       if (Game.started > 1) {
                                int winner;
                                float timer;
                                int i;
 
                                Message("The game has ended");
-                               timer = CurTimeval()/1e6;
-                               if (timer>5) {
-                                       for (i = MAX_SCREENS-1; i>0; i--) if (Players[i].alive>=0) {
+                               timer = CurTimeval() / 1e6;
+                               if (timer > 5) {
+                                       for (i = MAX_SCREENS-1; i > 0; i--) if (Players[i].alive >= 0) {
                                                Message("\\%d%10s%6.1fp%5.1fa",
-                                                       Players[i].team>7 ? 7 : Players[i].team, Players[i].name,
-                                                       Players[i].score.pieces/timer*60,
-                                                       Players[i].score.adds/timer*60);
-                                               if (Players[i].alive>0) winner = i;
+                                                       Players[i].team > 7 ? 7 : Players[i].team, Players[i].name,
+                                                       Players[i].score.pieces / timer * 60,
+                                                       Players[i].score.adds / timer * 60);
+                                               if (Players[i].alive > 0) winner = i;
                                        } //show player stats
                                if (winner)
                                        Message("%s won after %0.0f'%02d\"",
-                                               Players[winner].name, timer/60, (int)timer%60);
+                                               Players[winner].name, timer / 60, (int)timer % 60);
                                } //show game stats
                                Message(NULL);
                        } //game was playing
@@ -524,7 +532,7 @@ void OneGame(void)
                        {
                                int i;
 
-                               for (i = 1; i<MAX_SCREENS; i++) if (Players[i].alive>=0) {
+                               for (i = 1; i < MAX_SCREENS; i++) if (Players[i].alive >= 0) {
                                        Players[i].alive = 1;
                                        Players[i].flags |= SCF_paused;
                                } //reset players
@@ -546,12 +554,12 @@ void OneGame(void)
                        memcpy(&Players[net.uid], net.data, net.size);
                        ClearField(net.uid);
                        InitFields();
-                       if (Players[net.uid].team>7)
+                       if (Players[net.uid].team > 7)
                                Message("%s joined the game", Players[net.uid].name);
                        else
                                Message("%s joined %s team", Players[net.uid].name,
                                        teams[Players[net.uid].team]);
-                       if (Players[net.uid].flags&SCF_paused) {
+                       if (Players[net.uid].flags & SCF_paused) {
                                checkPaused();
                        } //player has paused
 //                     DrawField(net.uid);
@@ -564,7 +572,7 @@ void OneGame(void)
                        char s[20];
 
                        Players[net.uid].flags ^= SCF_paused;
-                       if (Game.started>1)
+                       if (Game.started > 1)
                                strcpy(s, Players[net.uid].flags&SCF_paused
                                        ? "paused the game" : "unpaused the game");
                        else
@@ -593,13 +601,13 @@ void OneGame(void)
                        memcpy(&i, net.data, sizeof(i));
                        Players[net.uid].alive = 0;
                        if (i == me) Message("\\%dYou fragged %s",
-                                       Players[me].team>7 ? 7 : Players[me].team, Players[net.uid].name);
+                                       Players[me].team > 7 ? 7 : Players[me].team, Players[net.uid].name);
                        else if (i==net.uid)
                                Message("\\%d%s died",
-                                       Players[i].team>7 ? 7 : Players[i].team, Players[i].name);
+                                       Players[i].team > 7 ? 7 : Players[i].team, Players[i].name);
                        else
                                Message("\\%d%s fragged %s",
-                                       Players[i].team>7 ? 7 : Players[i].team, Players[i].name,
+                                       Players[i].team > 7 ? 7 : Players[i].team, Players[i].name,
                                        Players[net.uid].name);
                        checkPaused();
                        ShowPause(net.uid);
diff --git a/inet.c b/inet.c
index ca3230c9fbd162cb5db623b210b1ec0463fc0385..6dcb0aac4a59030f5d64ff34ae9d1cffdcb577db 100644 (file)
--- a/inet.c
+++ b/inet.c
@@ -37,8 +37,9 @@
 #define HEADER_SIZE3 sizeof(netint4[3])
 
 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
-EventGenRec netGen =
-       { NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE3 };
+EventGenRec netGen = {
+       NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE3
+};
 
 
 static sigjmp_buf close_env;
index 3d6453c691d669d983557bdd633a66fab0689adf..4c6582b4bdb47766e130e415b5706a9e9c3e0e31 100644 (file)
--- a/server.c
+++ b/server.c
@@ -61,15 +61,18 @@ struct sockaddr_in addr;
 
 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
 static EventGenRec netGen[MAX_SCREENS] = {
-       { NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE } };
+       { NULL, 0, FT_read, -1, NetGenFunc, EM_net, 0, "\0", 0, HEADER_SIZE }
+};
 
 static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec alarmGen =
-       { &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm };
+static EventGenRec alarmGen = {
+       &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm
+};
 
 static MyEventType ConnGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec connGen =
-       { NULL, 0, FT_read, -1, ConnGenFunc, EM_connect };
+static EventGenRec connGen = {
+       NULL, 0, FT_read, -1, ConnGenFunc, EM_connect
+};
 
 static EventGenRec *nextGen = &alarmGen;
 
@@ -220,8 +223,10 @@ int StartServer(void)
        int playersReady = 0;
        int paused = 1;
        int i;
-       char teams[10][7] = { "", "Green", "Cyan", "Blue", "Purple",
-                             "Red", "Grey", "White", "*Orange" };
+       char teams[10][7] = {
+               "", "Green", "Cyan", "Blue", "Purple",
+               "Red", "Grey", "White", "*Orange"
+       };
 
        do {
                switch (WaitMyEvent(&event, EM_any)) {
diff --git a/util.c b/util.c
index fc70d5780af06069091e2ad0ecbdb5a8afa5b1b3..4f702e6c223aa28b2f11e4268a5d4a16d6b72b49 100644 (file)
--- a/util.c
+++ b/util.c
@@ -33,8 +33,9 @@
 #include "util.h"
 
 static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event);
-static EventGenRec alarmGen =
-       { &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm };
+static EventGenRec alarmGen = {
+       &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm
+};
 static EventGenRec *nextGen = &alarmGen;
 
 static int myRandSeed = 1;
@@ -58,7 +59,8 @@ void Header(void)
        fprintf(stderr,
                "NETRIS %s\t(c) 1994-1996,1999 Mark H. Weaver <mhw@netris.org>\n"
                "          \t(c) 2002 Shiar <shiar@shiar.org>\n\n",
-               version_string);
+               version_string
+       );
 }
 
 void Usage(void)
@@ -86,7 +88,8 @@ void Usage(void)
                "\n"
                "  -r, --robot <cmd>\tExecute program to control the game instead of keyboard\n"
                "  -F, --fair-robot\tUse fair robot interface\n"
-               "\n", DEFAULT_PORT, DEFAULT_KEYS);
+               "\n", DEFAULT_PORT, DEFAULT_KEYS
+       );
 }
 
 void DistInfo(void)
@@ -105,7 +108,8 @@ void DistInfo(void)
                "You should have received a copy of the GNU General Public License\n"
                "along with this program; if not, write to the Free Software\n"
                "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
-               "\n");
+               "\n"
+       );
 }
 
 void Rules(void)
@@ -129,7 +133,8 @@ void Rules(void)
                "multiple rows.\n"
                "\n"
                "The longest surviving player wins the game.\n"
-               "\n");
+               "\n"
+       );
 }
 
 ///////////// RANDOM /////////////