gnome-games r8236 - trunk/gnibbles
- From: thomashpa svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8236 - trunk/gnibbles
- Date: Tue, 4 Nov 2008 01:05:36 +0000 (UTC)
Author: thomashpa
Date: Tue Nov 4 01:05:36 2008
New Revision: 8236
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8236&view=rev
Log:
check return value of fgets. Also clean up function wrt tabs/spaces
Modified:
trunk/gnibbles/gnibbles.c
Modified: trunk/gnibbles/gnibbles.c
==============================================================================
--- trunk/gnibbles/gnibbles.c (original)
+++ trunk/gnibbles/gnibbles.c Tue Nov 4 01:05:36 2008
@@ -256,9 +256,10 @@
if ((in = fopen (filename, "r")) == NULL) {
char *message =
g_strdup_printf (_
- ("Gnibbles couldn't load level file:\n%s\n\n"
- "Please check your Gnibbles installation"), filename);
+ ("Gnibbles couldn't load level file:\n%s\n\n"
+ "Please check your Gnibbles installation"), filename);
gnibbles_error (window, message);
+ g_free (message);
}
g_free (filename);
@@ -274,33 +275,41 @@
boni = gnibbles_boni_new ();
for (i = 0; i < BOARDHEIGHT; i++) {
- fgets (tmpboard, sizeof (tmpboard), in);
+ if (!fgets (tmpboard, sizeof (tmpboard), in)) {
+ char *message =
+ g_strdup_printf (_
+ ("Level file appears to be damaged:\n%s\n\n"
+ "Please check your Gnibbles installation"), filename);
+ gnibbles_error (window, message);
+ g_free (message);
+ break;
+ }
for (j = 0; j < BOARDWIDTH; j++) {
board[j][i] = tmpboard[j];
switch (board[j][i]) {
case 'm':
- board[j][i] = 'a';
- if (count < properties->numworms)
- gnibbles_worm_set_start (worms[count++], j, i, WORMUP);
- break;
+ board[j][i] = 'a';
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMUP);
+ break;
case 'n':
- board[j][i] = 'a';
- if (count < properties->numworms)
- gnibbles_worm_set_start (worms[count++], j, i, WORMLEFT);
- break;
+ board[j][i] = 'a';
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMLEFT);
+ break;
case 'o':
- board[j][i] = 'a';
- if (count < properties->numworms)
- gnibbles_worm_set_start (worms[count++], j, i, WORMDOWN);
- break;
+ board[j][i] = 'a';
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMDOWN);
+ break;
case 'p':
- board[j][i] = 'a';
- if (count < properties->numworms)
- gnibbles_worm_set_start (worms[count++], j, i, WORMRIGHT);
- break;
+ board[j][i] = 'a';
+ if (count < properties->numworms)
+ gnibbles_worm_set_start (worms[count++], j, i, WORMRIGHT);
+ break;
case 'Q':
- gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
- break;
+ gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
+ break;
case 'R':
case 'S':
case 'T':
@@ -310,9 +319,9 @@
case 'X':
case 'Y':
case 'Z':
- gnibbles_warpmanager_add_warp
- (warpmanager, j - 1, i - 1, -board[j][i], 0);
- break;
+ gnibbles_warpmanager_add_warp
+ (warpmanager, j - 1, i - 1, -board[j][i], 0);
+ break;
case 'r':
case 's':
case 't':
@@ -322,22 +331,22 @@
case 'x':
case 'y':
case 'z':
- gnibbles_warpmanager_add_warp
- (warpmanager, -(board[j][i] - 'a' + 'A'), 0, j, i);
- board[j][i] = EMPTYCHAR;
- break;
+ gnibbles_warpmanager_add_warp
+ (warpmanager, -(board[j][i] - 'a' + 'A'), 0, j, i);
+ board[j][i] = EMPTYCHAR;
+ break;
}
/* Warpmanager draws the warp points. Everything else gets drawn here. */
if (board[j][i] >= 'a')
- gnibbles_draw_pixmap_buffer (board[j][i] - 'a', j, i);
+ gnibbles_draw_pixmap_buffer (board[j][i] - 'a', j, i);
}
}
gdk_draw_drawable (GDK_DRAWABLE (drawing_area->window),
- drawing_area->style->
- fg_gc[GTK_WIDGET_STATE (drawing_area)], buffer_pixmap, 0,
- 0, 0, 0, BOARDWIDTH * properties->tilesize,
- BOARDHEIGHT * properties->tilesize);
+ drawing_area->style->
+ fg_gc[GTK_WIDGET_STATE (drawing_area)], buffer_pixmap, 0,
+ 0, 0, 0, BOARDWIDTH * properties->tilesize,
+ BOARDHEIGHT * properties->tilesize);
fclose (in);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]