From 6a874e031ef811ea6ebb9f46a27b14e8852d41cf Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 7 Sep 2003 16:29:29 +0000 Subject: [PATCH] Added -Wall parameter to the compilation and fixed the tons of warnings. The result is a rather massive cleanup. --- Makefile | 4 ++-- server.c | 25 +++++++++++++------------ sockets.c | 7 ++++--- tetrinet.c | 28 +++++++++++++++------------- tetris.c | 14 +++++--------- tetris.h | 2 ++ tty.c | 27 +++++++++++---------------- xwin.c | 26 +++++++++++--------------- 8 files changed, 63 insertions(+), 70 deletions(-) diff --git a/Makefile b/Makefile index b5d6543..9018ba3 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ CC = cc -CFLAGS = -O2 -I/usr/include/ncurses -DHAVE_IPV6 -g +CFLAGS = -O2 -I/usr/include/ncurses -DHAVE_IPV6 -g -Wall OBJS = sockets.o tetrinet.o tetris.o tty.o xwin.o ### If you want to have -server tetrinet client option, comment the two lines ### above and uncomment this instead. -# CFLAGS = -O2 -I/usr/include/ncurses -DHAVE_IPV6 -g -DBUILTIN_SERVER +# CFLAGS = -O2 -I/usr/include/ncurses -DHAVE_IPV6 -g -DBUILTIN_SERVER -Wall # OBJS = server.o sockets.o tetrinet.o tetris.o tty.o xwin.o ######## diff --git a/server.c b/server.c index edf2285..7b3cdc9 100644 --- a/server.c +++ b/server.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include "tetrinet.h" #include "tetris.h" #include "server.h" @@ -106,38 +108,38 @@ void read_config(void) if (!s) { continue; } else if (strcmp(s, "linuxmode") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) linuxmode = atoi(s); } else if (strcmp(s, "ipv6_only") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) ipv6_only = atoi(s); } else if (strcmp(s, "averagelevels") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) level_average = atoi(s); } else if (strcmp(s, "classic") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) old_mode = atoi(s); } else if (strcmp(s, "initiallevel") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) initial_level = atoi(s); } else if (strcmp(s, "levelinc") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) level_inc = atoi(s); } else if (strcmp(s, "linesperlevel") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) lines_per_level = atoi(s); } else if (strcmp(s, "pieces") == 0) { i = 0; while (i < 7 && (s = strtok(NULL, " "))) piecefreq[i++] = atoi(s); } else if (strcmp(s, "specialcapacity") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) special_capacity = atoi(s); } else if (strcmp(s, "specialcount") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) special_count = atoi(s); } else if (strcmp(s, "speciallines") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) special_lines = atoi(s); } else if (strcmp(s, "specials") == 0) { i = 0; @@ -234,7 +236,6 @@ static void send_to(int player, const char *format, ...) { va_list args; char buf[1024]; - int i; va_start(args, format); vsnprintf(buf, sizeof(buf), format, args); @@ -396,7 +397,7 @@ static void sort_winlist() static void player_loses(int player) { - int i, j, order, end = 1, winner = -1, second, third; + int i, j, order, end = 1, winner = -1, second = -1, third = -1; if (player < 1 || player > 6 || player_socks[player-1] < 0) return; diff --git a/sockets.c b/sockets.c index 9c979cb..fecc362 100644 --- a/sockets.c +++ b/sockets.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "sockets.h" #include "tetrinet.h" @@ -71,7 +72,7 @@ char *sgets(char *buf, int len, int s) struct timeval tv; gettimeofday(&tv, NULL); fprintf(logfile, "[%d.%03d] <<< %s\n", - tv.tv_sec, tv.tv_usec/1000, buf); + (int) tv.tv_sec, (int) tv.tv_usec/1000, buf); fflush(logfile); } } @@ -94,7 +95,7 @@ int sputs(const char *str, int s) struct timeval tv; gettimeofday(&tv, NULL); fprintf(logfile, "[%d.%03d] >>> %s\n", - tv.tv_sec, tv.tv_usec/1000, str); + (int) tv.tv_sec, (int) tv.tv_usec/1000, str); } } if (*str != 0) { @@ -134,7 +135,7 @@ int conn(const char *host, int port, char ipbuf[4]) struct hostent *hp; struct sockaddr_in sa; #endif - int sock; + int sock = -1; #ifdef HAVE_IPV6 snprintf(service, sizeof(service), "%d", port); diff --git a/tetrinet.c b/tetrinet.c index ba9bc87..5a9a0fc 100644 --- a/tetrinet.c +++ b/tetrinet.c @@ -7,7 +7,9 @@ /*************************************************************************/ #include +#include #include +#include #include #include "tetrinet.h" #include "io.h" @@ -93,7 +95,7 @@ void parse(char *buf) io->setup_winlist(); } else if (strcmp(cmd, tetrifast ? ")#)(!@(*3" : "playernum") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) my_playernum = atoi(s); /* Note: players[my_playernum-1] is set in init() */ /* But that doesn't work when joining other channel. */ @@ -205,24 +207,24 @@ void parse(char *buf) } else if (strcmp(cmd, tetrifast ? "*******" : "newgame") == 0) { int i; - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) /* stack height */; - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) initial_level = atoi(s); - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) lines_per_level = atoi(s); - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) level_inc = atoi(s); - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) special_lines = atoi(s); - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) special_count = atoi(s); - if (s = strtok(NULL, " ")) { + if ((s = strtok(NULL, " "))) { special_capacity = atoi(s); if (special_capacity > MAX_SPECIALS) special_capacity = MAX_SPECIALS; } - if (s = strtok(NULL, " ")) { + if ((s = strtok(NULL, " "))) { memset(piecefreq, 0, sizeof(piecefreq)); while (*s) { i = *s - '1'; @@ -231,7 +233,7 @@ void parse(char *buf) s++; } } - if (s = strtok(NULL, " ")) { + if ((s = strtok(NULL, " "))) { memset(specialfreq, 0, sizeof(specialfreq)); while (*s) { i = *s - '1'; @@ -240,9 +242,9 @@ void parse(char *buf) s++; } } - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) level_average = atoi(s); - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) old_mode = atoi(s); lines = 0; for (i = 0; i < 6; i++) @@ -274,7 +276,7 @@ void parse(char *buf) not_playing_game = 1; } else if (strcmp(cmd, "pause") == 0) { - if (s = strtok(NULL, " ")) + if ((s = strtok(NULL, " "))) game_paused = atoi(s); if (game_paused) { io->draw_text(BUFFER_PLINE, "*** The Game Has Been Paused"); diff --git a/tetris.c b/tetris.c index ba005ea..34bfe5a 100644 --- a/tetris.c +++ b/tetris.c @@ -248,7 +248,7 @@ static int piece_overlaps(int x, int y, int rot) * erase the piece rather than drawing it. */ -static int draw_piece(int draw) +static void draw_piece(int draw) { Field *f = &fields[my_playernum-1]; char c = draw ? current_piece % 5 + 1 : 0; @@ -497,9 +497,8 @@ void step_down(void) { Field *f = &fields[my_playernum-1]; PieceData *pd = &piecedata[current_piece][current_rotation]; - int x = current_x - pd->hot_x; int y = current_y - pd->hot_y; - int i, j, ynew, ok; + int ynew; draw_piece(0); ynew = current_y+1; @@ -686,7 +685,7 @@ void do_special(const char *type, int from, int to) } } else if (*type == 'r') { - int i, tries; + int i; for (i = 0; i < 10; i++) { x = rand() % FIELD_WIDTH; @@ -795,8 +794,6 @@ static void gmsg_move(int how) static void gmsg_enter(void) { - char buf[1024]; - if (*gmsg_buffer) { if (strncasecmp(gmsg_buffer, "/me ", 4) == 0) sockprintf(server_sock, "gmsg * %s %s", players[my_playernum-1], gmsg_buffer+4); @@ -867,7 +864,6 @@ static const char special_chars[] = "acnrsbgqo"; void tetris_input(int c) { - Field *f = &fields[my_playernum-1]; PieceData *pd = &piecedata[current_piece][current_rotation]; int x = current_x - pd->hot_x; int y = current_y - pd->hot_y; @@ -1024,8 +1020,8 @@ void tetris_input(int c) if (specials[0] == -1) break; sockprintf(server_sock, "sb %d %c %d", - c, special_chars[specials[0]], my_playernum); - buf[0] = special_chars[specials[0]]; + c, special_chars[(int) specials[0]], my_playernum); + buf[0] = special_chars[(int) specials[0]]; buf[1] = 0; do_special(buf, my_playernum, c); if (special_capacity > 1) diff --git a/tetris.h b/tetris.h index 488ee85..167ae84 100644 --- a/tetris.h +++ b/tetris.h @@ -58,6 +58,8 @@ extern int current_piece, current_rotation; extern void init_shapes(void); extern int get_shape(int piece, int rotation, char buf[4][4]); +extern void new_game(void); + extern void new_piece(void); extern void step_down(void); extern void do_special(const char *type, int from, int to); diff --git a/tty.c b/tty.c index 0562042..f4f635d 100644 --- a/tty.c +++ b/tty.c @@ -4,6 +4,8 @@ * Text terminal I/O routines. */ +#define _GNU_SOURCE /* strsignal() - FIXME!!! --pasky */ + #include #include #include @@ -320,7 +322,7 @@ static void draw_text(int bufnum, const char *s) char str[1024]; /* hopefully scrwidth < 1024 */ const char *t; int indent = 0; - int x, y; + int x = 0, y = 0; TextBuffer *buf; switch (bufnum) { @@ -473,10 +475,6 @@ static const int field_text_coord[2] = {0,47}; static int tile_chars[15] = { ' ','#','#','#','#','#','a','c','n','r','s','b','g','q','o' }; -static int attdef_size; -static int attdef_line; -static char **attdef_text; - /* Are we redrawing the entire display? */ static int field_redraw = 0; @@ -665,7 +663,6 @@ static void draw_own_field(void) /* XXX: Code duplication with tetris.c:draw_piece(). --pasky */ if (playing_game && cast_shadow) { - int x = current_x - piecedata[current_piece][current_rotation].hot_x; int y = current_y - piecedata[current_piece][current_rotation].hot_y; char *shape = (char *) piecedata[current_piece][current_rotation].shape; int i, j; @@ -686,7 +683,7 @@ static void draw_own_field(void) y0 = own_coord[1]; for (y = 0; y < 22; y++) { for (x = 0; x < 12; x++) { - int c = tile_chars[(*f)[y][x]]; + int c = tile_chars[(int) (*f)[y][x]]; if (playing_game && cast_shadow) { PieceData *piece = &piecedata[current_piece][current_rotation]; @@ -736,7 +733,7 @@ static void draw_other_field(int player) for (y = 0; y < 22; y++) { move(y0+y, x0); for (x = 0; x < 12; x++) { - addch(tile_chars[(*f)[y][x]]); + addch(tile_chars[(int) (*f)[y][x]]); } } if (gmsg_inputwin) { @@ -772,13 +769,13 @@ static void draw_status(void) for (i = 0; i < 4; i++) { if (wide_screen) { move(y+j*2, x+i*2); - addch(tile_chars[shape[j][i]]); - addch(tile_chars[shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); move(y+j*2+1, x+i*2); - addch(tile_chars[shape[j][i]]); - addch(tile_chars[shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); } else - addch(tile_chars[shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); } } } @@ -848,7 +845,7 @@ static const char *msgs[][2] = { static void draw_attdef(const char *type, int from, int to) { int i, width; - char *s, buf[512]; + char buf[512]; width = other_coord[4][0] - attdef_coord[0] - 1; for (i = 0; msgs[i][0]; i++) { @@ -946,8 +943,6 @@ static void clear_gmsg_input(void) static void setup_partyline(void) { - int i; - close_textwin(&gmsgbuf); close_textwin(&attdefbuf); clear(); diff --git a/xwin.c b/xwin.c index 1f1c119..0cd4e84 100644 --- a/xwin.c +++ b/xwin.c @@ -4,6 +4,8 @@ * Text terminal I/O routines. */ +#define _GNU_SOURCE /* strsignal() - FIXME!!! --pasky */ + #include #include #include @@ -310,7 +312,7 @@ static void draw_text(int bufnum, const char *s) char str[1024]; /* hopefully scrwidth < 1024 */ const char *t; int indent = 0; - int x, y; + int x = 0, y = 0; TextBuffer *buf; switch (bufnum) { @@ -463,10 +465,6 @@ static const int field_text_coord[2] = {0,47}; static int tile_chars[15] = { ' ','#','#','#','#','#','a','c','n','r','s','b','g','q','o' }; -static int attdef_size; -static int attdef_line; -static char **attdef_text; - /* Are we redrawing the entire display? */ static int field_redraw = 0; @@ -655,7 +653,7 @@ static void draw_own_field(void) y0 = own_coord[1]; for (y = 0; y < 22; y++) { for (x = 0; x < 12; x++) { - int c = tile_chars[(*f)[y][x]]; + int c = tile_chars[(int) (*f)[y][x]]; mvaddch(y0+y*2, x0+x*2, c); addch(c); mvaddch(y0+y*2+1, x0+x*2, c); @@ -691,7 +689,7 @@ static void draw_other_field(int player) for (y = 0; y < 22; y++) { move(y0+y, x0); for (x = 0; x < 12; x++) - addch(tile_chars[(*f)[y][x]]); + addch(tile_chars[(int) (*f)[y][x]]); } if (gmsg_inputwin) { delwin(gmsg_inputwin); @@ -726,13 +724,13 @@ static void draw_status(void) for (i = 0; i < 4; i++) { if (wide_screen) { move(y+j*2, x+i*2); - addch(tile_chars[shape[j][i]]); - addch(tile_chars[shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); move(y+j*2+1, x+i*2); - addch(tile_chars[shape[j][i]]); - addch(tile_chars[shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); } else - addch(tile_chars[shape[j][i]]); + addch(tile_chars[(int) shape[j][i]]); } } } @@ -802,7 +800,7 @@ static const char *msgs[][2] = { static void draw_attdef(const char *type, int from, int to) { int i, width; - char *s, buf[512]; + char buf[512]; width = other_coord[4][0] - attdef_coord[0] - 1; for (i = 0; msgs[i][0]; i++) { @@ -900,8 +898,6 @@ static void clear_gmsg_input(void) static void setup_partyline(void) { - int i; - close_textwin(&gmsgbuf); close_textwin(&attdefbuf); clear(); -- 2.11.4.GIT