From: Mischa POSLAWSKY Date: Tue, 27 Feb 2007 11:08:11 +0000 (+0100) Subject: code indenting/alignment fixes X-Git-Url: http://git.shiar.net/netris.git/commitdiff_plain/5902d7f327fcf57d2b1a47f1b4a3aa98f4ab08a8 code indenting/alignment fixes --- diff --git a/board.c b/board.c index c3a8d5c..7946d57 100644 --- a/board.c +++ b/board.c @@ -146,8 +146,8 @@ unsigned char GetBlock(int scr, int y, int x) void SetBlock(int scr, int y, int x, unsigned char type) { - if (y >= 0 && y < Players[scr].boardHeight && - x >= 0 && x < Players[scr].boardWidth) { + if (y >= 0 && y < Players[scr].boardHeight + && x >= 0 && x < Players[scr].boardWidth) { board[scr][y][x] = type; changed[scr][y] |= 1 << x; } @@ -237,7 +237,7 @@ int MovePiece(int scr, int deltaY, int deltaX) EraseShape(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); result = ShapeFits(Players[scr].curShape, scr, Players[scr].curY + deltaY, - Players[scr].curX + deltaX); + Players[scr].curX + deltaX); if (result) { Players[scr].curY += deltaY; Players[scr].curX += deltaX; @@ -268,7 +268,7 @@ int RotatePiece(int scr, int dir) } //try to fit if it doesn't if (result) Players[scr].curShape = newshape; PlotShape(Players[scr].curShape, scr, - Players[scr].curY, Players[scr].curX, scr == me); + Players[scr].curY, Players[scr].curX, scr == me); return result; } //RotatePiece @@ -279,7 +279,7 @@ int DropPiece(int scr) EraseShape(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); while (ShapeFits(Players[scr].curShape, scr, - Players[scr].curY - 1, Players[scr].curX)) { + Players[scr].curY - 1, Players[scr].curX)) { Players[scr].curY--; count++; } diff --git a/curses.c b/curses.c index aab808d..e7f18c4 100644 --- a/curses.c +++ b/curses.c @@ -86,14 +86,14 @@ void InitScreens(void) char type; short color; } myColorTable[] = { - { BT_white, COLOR_WHITE }, - { BT_blue, COLOR_BLUE }, - { BT_magenta, COLOR_MAGENTA }, - { BT_cyan, COLOR_CYAN }, - { BT_yellow, COLOR_YELLOW }, - { BT_green, COLOR_GREEN }, - { BT_red, COLOR_RED }, - { BT_none, 0 } + { BT_white, COLOR_WHITE }, + { BT_blue, COLOR_BLUE }, + { BT_magenta, COLOR_MAGENTA }, + { BT_cyan, COLOR_CYAN }, + { BT_yellow, COLOR_YELLOW }, + { BT_green, COLOR_GREEN }, + { BT_red, COLOR_RED }, + { BT_none, 0 } }; //myColorTable int i = 0; @@ -103,36 +103,36 @@ void InitScreens(void) } //I've never worked on a color-changable terminal, so no idea.. for (i = 0; myColorTable[i].type != BT_none; ++i) init_pair(myColorTable[i].type, COLOR_BLACK, - myColorTable[i].color); + myColorTable[i].color); } //haveColor #else haveColor = 0; #endif - AtExit(CleanupScreens); //restore everything when done + AtExit(CleanupScreens); //restore everything when done RestoreSignals(NULL, &oldMask); - cbreak(); //no line buffering + cbreak(); //no line buffering noecho(); -// keypad(stdscr, TRUE); //get arrow/functionkeys 'n stuff +// keypad(stdscr, TRUE); //get arrow/functionkeys 'n stuff OutputTermStr(term_vi, 0); - AddEventGen(&keyGen); //key handler - signal(SIGWINCH, CatchWinCh); //handle window resize + AddEventGen(&keyGen); //key handler + signal(SIGWINCH, CatchWinCh); //handle window resize // ioctl(STDIN_FILENO, KDSKBMODE, K_MEDIUMRAW); - standend(); //normal text + standend(); //normal text memset(messages, 0, sizeof(messages)); //empty messages { int i; for (i = 0; i 0) { if (game == GT_onePlayer) @@ -728,8 +728,9 @@ int main(int argc, char **argv) // ReadConf(optarg); // else ReadConf(CONFIG_FILE); - while ((ch = getopt_long(argc, argv, - "hHRk:c:n:odDSCap:i:l:t:", options, NULL)) != -1) + while ((ch = getopt_long( + argc, argv, "hHRk:c:n:odDSCap:i:l:t:", options, NULL + )) != -1) HandleOption(ch, optarg); if (optind < argc) { Usage(); @@ -737,7 +738,7 @@ int main(int argc, char **argv) } // WriteConf(); - InitScreens(); //setup screen + InitScreens(); //setup screen if (game == GT_classicTwo) { spied = 1; InitiateConnection(hostStr, port); diff --git a/inet.c b/inet.c index 8da9956..8f1f453 100644 --- a/inet.c +++ b/inet.c @@ -114,11 +114,11 @@ void HandShake(void) { static struct { int playerflags; - int maxplayers; //1 - int started; //2 - int continuous; //3 - long seed; //4 - int initspeed; //5 + int maxplayers; //1 + int started; //2 + int continuous; //3 + long seed; //4 + int initspeed; //5 } data; memcpy(&data, event.u.net.data, event.u.net.size); diff --git a/netris.h b/netris.h index cab651c..72e2522 100644 --- a/netris.h +++ b/netris.h @@ -29,9 +29,9 @@ #include #include -#define version_string "0.8" +#define version_string "0.8" -#ifdef NOEXT //prevent re-declaration +#ifdef NOEXT //prevent re-declaration # define EXT #else # define EXT extern @@ -58,10 +58,10 @@ typedef long netint4; #define ntoh4(x) ntohl(x) /* Protocol versions */ -#define MAJOR_VERSION 1 -#define PROTOCOL_VERSION 4 +#define MAJOR_VERSION 1 +#define PROTOCOL_VERSION 4 -#define DEFAULT_PORT 9284 /* Very arbitrary */ +#define DEFAULT_PORT 9284 /* Very arbitrary */ #define CONFIG_FILE "netris.conf" @@ -69,16 +69,16 @@ typedef long netint4; //#define DEFAULT_KEYS "4685 2fp^lq" #define DEFAULT_KEYS "dcaf b^fp^lq" -#define MAX_BOARD_WIDTH 32 -#define MAX_BOARD_HEIGHT 64 -#define MAX_SCREENS 9 //8 players +#define MAX_BOARD_WIDTH 32 +#define MAX_BOARD_HEIGHT 64 +#define MAX_SCREENS 9 //8 players /* Event masks */ -#define EM_alarm 000001 -#define EM_key 000002 -#define EM_net 000004 -#define EM_connect 000020 -#define EM_any 000777 +#define EM_alarm 000001 +#define EM_key 000002 +#define EM_net 000004 +#define EM_connect 000020 +#define EM_any 000777 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType; typedef enum _BlockTypeA { @@ -93,33 +93,33 @@ typedef enum _MyEventType { E_none, E_alarm, E_key, E_connect, E_net, E_lostConn } MyEventType; typedef enum _NetPacketType { - NP_endConn, //client/server quits - NP_byeBye, //unused atm - NP_error, //handshake error - NP_hello, //check versions - NP_gamedata, //game options - - NP_start, //game ok to start - NP_pause, //player (un)pauses - NP_stop, //game ended - NP_newPlayer, //add new player - NP_team, //player switched teams - NP_argghhh, //player died - NP_part, //player left - - NP_msg, //chat message - - NP_newPiece, //new piece info - NP_rotright, //rotate piece clockwise - NP_rotleft, //rotate piece counterclockwise - NP_left, //move piece left - NP_right, //move piece right - NP_down, //move piece one down - NP_drop, //drop piece to bottom - NP_clear, //line cleared - NP_insertJunk, //player added junk - - NP_giveJunk //player has to add junk + NP_endConn, //client/server quits + NP_byeBye, //unused atm + NP_error, //handshake error + NP_hello, //check versions + NP_gamedata, //game options + + NP_start, //game ok to start + NP_pause, //player (un)pauses + NP_stop, //game ended + NP_newPlayer, //add new player + NP_team, //player switched teams + NP_argghhh, //player died + NP_part, //player left + + NP_msg, //chat message + + NP_newPiece, //new piece info + NP_rotright, //rotate piece clockwise + NP_rotleft, //rotate piece counterclockwise + NP_left, //move piece left + NP_right, //move piece right + NP_down, //move piece one down + NP_drop, //drop piece to bottom + NP_clear, //line cleared + NP_insertJunk, //player added junk + + NP_giveJunk //player has to add junk } NetPacketType; typedef struct { @@ -162,7 +162,7 @@ typedef struct _Shape { } Shape; /* NP_startConn flags */ -#define SCF_paused 1 +#define SCF_paused 1 typedef struct { int alive; @@ -178,23 +178,23 @@ typedef struct { long score; int pieces, lines, adds; } score; - char host[256]; //last + char host[256]; //last } _Player; EXT _Player Players[MAX_SCREENS]; EXT short me; EXT short maxPlayer; EXT int spied; //in player.flags -#define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */ -#define SPEEDINC 1.2 -#define SPEEDMINIMUM 40000 +#define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */ +#define SPEEDINC 1.2 +#define SPEEDMINIMUM 40000 typedef struct { - int gravity; //1 - int started; //2 - int continuous; //3 - long seed; //4 - int initspeed; //5 + int gravity; //1 + int started; //2 + int continuous; //3 + long seed; //4 + int initspeed; //5 int speed; } _Game; EXT _Game Game; diff --git a/server.c b/server.c index 7d63e02..11c42e3 100644 --- a/server.c +++ b/server.c @@ -38,18 +38,18 @@ #define HEADER_SIZE sizeof(netint4[3]) static struct option options[] = { - { "wait", 0, 0, 'w' }, - { "port", 1, 0, 'p' }, - { "quadra", 1, 0, 'q' }, - { "min-players",1, 0, 'm' }, - { "max-players",1, 0, 'x' }, - { "continuous", 1, 0, 'c' }, - { "speed", 1, 0, 'i' }, - { "seed", 1, 0, 's' }, - { "verbose", 0, 0, 'v' }, - { "info", 0, 0, 'H' }, - { "help", 0, 0, 'h' }, - { 0, 0, 0, 0 } + { "wait", 0, 0, 'w' }, + { "port", 1, 0, 'p' }, + { "quadra", 1, 0, 'q' }, + { "min-players", 1, 0, 'm' }, + { "max-players", 1, 0, 'x' }, + { "continuous", 1, 0, 'c' }, + { "speed", 1, 0, 'i' }, + { "seed", 1, 0, 's' }, + { "verbose", 0, 0, 'v' }, + { "info", 0, 0, 'H' }, + { "help", 0, 0, 'h' }, + { 0, 0, 0, 0 } }; static char minplayers = 2; @@ -105,7 +105,7 @@ void SCloseNet(short playa) if (netGen[playa].fd >= 0) { if (Players[playa].alive >= 0) { SendPacketTo(playa, 0, NP_endConn, 0, NULL); - do{} while (WaitMyEvent(&event, EM_net) != E_lostConn); + do {} while (WaitMyEvent(&event, EM_net) != E_lostConn); } //say bye to player close(netGen[playa].fd); netGen[playa].fd = -1; @@ -188,7 +188,7 @@ static MyEventType ConnGenFunc(EventGenRec *gen, MyEvent *event) sprintf(Players[new].host, "%s", inet_ntoa(addr.sin_addr)); if (addr.sin_family == AF_INET) { host = gethostbyaddr((void *)&addr.sin_addr, - sizeof(struct in_addr), AF_INET); + sizeof(struct in_addr), AF_INET); if (host) { strncpy(Players[new].host, host->h_name, sizeof(Players[new].host) - 1); @@ -221,7 +221,7 @@ int StartServer(void) int paused = 1; int i; char teams[10][7] = { "", "Green", "Cyan", "Blue", "Purple", - "Red", "Grey", "White", "*Orange" }; + "Red", "Grey", "White", "*Orange" }; do { switch (WaitMyEvent(&event, EM_any)) { @@ -251,7 +251,7 @@ int StartServer(void) major = ntoh4(versiondata[0]); protocolVersion = ntoh4(versiondata[1]); if (major != MAJOR_VERSION - || protocolVersion != PROTOCOL_VERSION) { + || protocolVersion != PROTOCOL_VERSION) { snprintf(data, sizeof(data), "Version mismatch: received %d.%d", major, protocolVersion); @@ -365,7 +365,7 @@ int StartServer(void) sendtoall: // if (event.u.net.type >= NP_pause) if (event.u.net.type >= NP_rotright - && Game.started < 2) + && Game.started < 2) break; for (i = 1; i < MAX_SCREENS; i++) if (i != event.u.net.sender) @@ -424,27 +424,27 @@ int StartServer(void) void SHeader(void) { fprintf(stderr, - "NETRIS Server %s\t(c) 2002 Shiar \n\n", - version_string); + "NETRIS Server %s\t(c) 2002 Shiar \n\n", + version_string); } void SUsage(void) { SHeader(); fprintf(stderr, - "Usage: netris \n" - "\n" - " -h, --help\t\tPrint this usage information\n" - " -H, --info\t\tShow distribution and warranty information\n" - "\n" - " -p, --port \tSet port number (default is %d)\n" - "\n" - " -s, --seed \tStart with given random seed\n" - " -i, --speed \tSet the initial step-down interval, in seconds\n" - " -m, --min-players <2>\tNumber of players required before starting the game\n" - " -x, --max-players <8>\tMaximum number of players allowed in the game\n" - " -c, --continuous\tDon'n quit the game\n" - "\n", DEFAULT_PORT); + "Usage: netris \n" + "\n" + " -h, --help\t\tPrint this usage information\n" + " -H, --info\t\tShow distribution and warranty information\n" + "\n" + " -p, --port \tSet port number (default is %d)\n" + "\n" + " -s, --seed \tStart with given random seed\n" + " -i, --speed \tSet the initial step-down interval, in seconds\n" + " -m, --min-players <2>\tNumber of players required before starting the game\n" + " -x, --max-players <8>\tMaximum number of players allowed in the game\n" + " -c, --continuous\tDon'n quit the game\n" + "\n", DEFAULT_PORT); } void WriteConf(void) @@ -466,36 +466,36 @@ void WriteConf(void) void HandleOption(char tag, char *value) { switch (tag) { - case 'v': //verbose + case 'v': //verbose verbose = 1; break; - case 'p': //port + case 'p': //port port = atoi(value); break; - case 'c': //min-players + case 'c': //min-players Game.continuous = atoi(value); break; - case 'm': //min-players + case 'm': //min-players minplayers = atoi(value); break; - case 'x': //max-players + case 'x': //max-players maxplayers = atoi(value); if (maxplayers >= MAX_SCREENS) maxplayers = MAX_SCREENS; break; - case 'q': //quadra-style gravity + case 'q': //quadra-style gravity Game.gravity ^= 1; break; - case 'i': //speed (of level 1) + case 'i': //speed (of level 1) Game.initspeed = atof(value) * 1e6; break; - case 's': //seed + case 's': //seed Game.seed = atoi(value); break; - case 'H': //info + case 'H': //info SHeader(); DistInfo(); exit(0); - case 'h': //help + case 'h': //help SUsage(); exit(0); default: break; @@ -516,8 +516,8 @@ void ReadConf(char *filename) if ((ch = strchr(buf, '#'))) *ch = '\0'; // truncate string from # char for (i = strlen(buf)-1; i >= 0; i--) - if (buf[i] == ' ' || buf[i] == '\t' - || buf[i] == '\n' || buf[i] == 13) + if (buf[i] == ' ' || buf[i] == '\t' + || buf[i] == '\n' || buf[i] == 13) buf[i] = '\0'; else break; @@ -564,8 +564,9 @@ int main(int argc, char **argv) // ReadConf(optarg); // else ReadConf(CONFIG_FILE); - while ((ch = getopt_long(argc, argv, - "hHvqp:i:s:c:m:x:", options, NULL)) != -1) + while ((ch = getopt_long( + argc, argv, "hHvqp:i:s:c:m:x:", options, NULL + )) != -1) HandleOption(ch, optarg); if (optind < argc) { SUsage(); @@ -595,7 +596,7 @@ int main(int argc, char **argv) die("socket"); val1 = 1; setsockopt(connGen.fd, SOL_SOCKET, SO_REUSEADDR, - (void *)&val1, sizeof(val1)); + (void *)&val1, sizeof(val1)); if (bind(connGen.fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) die("bind"); if (listen(connGen.fd, 1) < 0) diff --git a/util.c b/util.c index 791a007..306c197 100644 --- a/util.c +++ b/util.c @@ -34,7 +34,7 @@ static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event); static EventGenRec alarmGen = - { &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm }; + { &alarmGen, 0, FT_read, -1, AlarmGenFunc, EM_alarm }; static EventGenRec *nextGen = &alarmGen; static int myRandSeed = 1; @@ -56,80 +56,80 @@ void AtExit(void (*handler)(void)) void Header(void) { fprintf(stderr, - "NETRIS %s\t(c) 1994-1996,1999 Mark H. Weaver \n" - " \t(c) 2002 Shiar \n\n", - version_string); + "NETRIS %s\t(c) 1994-1996,1999 Mark H. Weaver \n" + " \t(c) 2002 Shiar \n\n", + version_string); } //Header void Usage(void) { Header(); fprintf(stderr, - "Usage: netris \n" - "\n" - " -h, --help\t\tPrint this usage information\n" - " -H, --info\t\tShow distribution and warranty information\n" - " -R, --rules\t\tShow game rules\n" - "\n" - " -S, --slowterm\tDisable inverse/bold/color for slow terminals\n" - " -a, --ascii\t\tUse ascii characters\n" - " -C, --color=0\t\tDisable color\n" - "\n" - " -c, --connect \tInitiate connection\n" - " -p, --port \tSet port number (default is %d)\n" - "\n" - " -t, --team \tJoin a team (don't receive lines from your teammates)\n" - " -l, --level \tBegin at a higher level (can be used as handicap)\n" - " -k, --keys \tRemap keys (default is \"%s\" for cursors)\n" - " -d, --dropmode\tDrops go into drop mode\n" - " -D, --instadrop\tInstant drop\n" - "\n" - " -r, --robot \tExecute program to control the game instead of keyboard\n" - " -F, --fair-robot\tUse fair robot interface\n" - "\n", DEFAULT_PORT, DEFAULT_KEYS); + "Usage: netris \n" + "\n" + " -h, --help\t\tPrint this usage information\n" + " -H, --info\t\tShow distribution and warranty information\n" + " -R, --rules\t\tShow game rules\n" + "\n" + " -S, --slowterm\tDisable inverse/bold/color for slow terminals\n" + " -a, --ascii\t\tUse ascii characters\n" + " -C, --color=0\t\tDisable color\n" + "\n" + " -c, --connect \tInitiate connection\n" + " -p, --port \tSet port number (default is %d)\n" + "\n" + " -t, --team \tJoin a team (don't receive lines from your teammates)\n" + " -l, --level \tBegin at a higher level (can be used as handicap)\n" + " -k, --keys \tRemap keys (default is \"%s\" for cursors)\n" + " -d, --dropmode\tDrops go into drop mode\n" + " -D, --instadrop\tInstant drop\n" + "\n" + " -r, --robot \tExecute program to control the game instead of keyboard\n" + " -F, --fair-robot\tUse fair robot interface\n" + "\n", DEFAULT_PORT, DEFAULT_KEYS); } void DistInfo(void) { fprintf(stderr, - "This program is free software; you can redistribute it and/or modify\n" - "it under the terms of the GNU General Public License as published by\n" - "the Free Software Foundation; either version 2 of the License, or\n" - "(at your option) any later version.\n" - "\n" - "This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n" - "\n" - "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"); + "This program is free software; you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation; either version 2 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "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"); } //DistInfo void Rules(void) { Header(); fprintf(stderr, - "One player mode\n" - "---------------\n" - "Good old Tetris. Scoring is like on the GameBoy version (so try to\n" - "remove as many lines at once as you can). After removing ten lines\n" - "you go to the next level, which will be faster thus making the game\n" - "harder to play.\n" - "\n" - "Two player mode\n" - "---------------\n" - "It's just like normal T*tris except that when you clear more than\n" - "one row with a single piece, the other player receives penalty lines\n" - "For clearing 2, 3 or 4 rows, respectively 1, 2 or 4 junk rows will\n" - "be added to the bottom of your opponent's board respectively.\n" - "The junk rows have exactly one empty column, which will line up for\n" - "multiple rows.\n" - "\n" - "The longest surviving player wins the game.\n" - "\n"); + "One player mode\n" + "---------------\n" + "Good old Tetris. Scoring is like on the GameBoy version (so try to\n" + "remove as many lines at once as you can). After removing ten lines\n" + "you go to the next level, which will be faster thus making the game\n" + "harder to play.\n" + "\n" + "Two player mode\n" + "---------------\n" + "It's just like normal T*tris except that when you clear more than\n" + "one row with a single piece, the other player receives penalty lines\n" + "For clearing 2, 3 or 4 rows, respectively 1, 2 or 4 junk rows will\n" + "be added to the bottom of your opponent's board respectively.\n" + "The junk rows have exactly one empty column, which will line up for\n" + "multiple rows.\n" + "\n" + "The longest surviving player wins the game.\n" + "\n"); } //Rules ///////////// RANDOM ///////////// @@ -374,7 +374,7 @@ MyEventType WaitMyEvent(MyEvent *event, int mask) tv.tv_sec = 0; tv.tv_usec = (retry && !anyReady) ? 500000 : 0; result = select(FD_SETSIZE, &fds[FT_read], &fds[FT_write], - &fds[FT_except], anyReady ? &tv : NULL); + &fds[FT_except], anyReady ? &tv : NULL); } else { if (retry && !anyReady) @@ -383,9 +383,10 @@ MyEventType WaitMyEvent(MyEvent *event, int mask) } gen = nextGen; do { - if ((gen->mask & mask) - && (gen->ready || (result > 0 && gen->fd >= 0 - && FD_ISSET(gen->fd, &fds[gen->fdType])))) { + if ((gen->mask & mask) && (gen->ready || ( + result > 0 && gen->fd >= 0 + && FD_ISSET(gen->fd, &fds[gen->fdType]) + ))) { gen->ready = 0; event->type = gen->func(gen, event); if (event->type != E_none) {