summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandroColomar <colomar.6.4.3@gmail.com>2019-01-07 05:13:35 +0100
committerAlejandroColomar <colomar.6.4.3@gmail.com>2019-01-07 05:13:35 +0100
commit15713d6fe8888aa02fb545cfddabdd22aa06463c (patch)
treeac78902f614ee396912648b1dbad42d74f389e44
parent98ce1841e943568ace3b42571d448a0fa09dff18 (diff)
Fix style
-rw-r--r--modules/ctrl/src/start.c29
-rw-r--r--modules/menu/src/menu_gui.c18
-rw-r--r--modules/menu/src/menu_iface.c5
-rw-r--r--modules/save/src/save.c31
-rw-r--r--modules/save/tmp/Makefile2
5 files changed, 39 insertions, 46 deletions
diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c
index bd0fb94..84ccbc8 100644
--- a/modules/ctrl/src/start.c
+++ b/modules/ctrl/src/start.c
@@ -6,15 +6,11 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
/* errno */
#include <errno.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
/* game() */
#include "game.h"
/* game_iface() */
@@ -46,6 +42,7 @@ static void start_load (void);
******************************************************************************/
void start_switch (void)
{
+
switch (start_mode) {
case START_FOO:
start_foo();
@@ -67,48 +64,40 @@ void start_switch (void)
******************************************************************************/
static void start_foo (void)
{
+
/* empty */
+ ;
}
static void start_rand (void)
{
- /* size & mines */
int level;
int rows;
int cols;
int mines;
- menu_iface_board(&level, &rows, &cols, &mines);
-
- /* user iface init */
bool fail;
- player_iface_init(rows, cols);
-
- /* start position */
int r;
int c;
- fail = player_iface_start(&r, &c);
+ menu_iface_board(&level, &rows, &cols, &mines);
+ player_iface_init(rows, cols);
+ fail = player_iface_start(&r, &c);
if (!fail) {
- /* game init */
game_init_rand(rows, cols, mines, r, c);
-
- /* game iface init */
game_iface_init_rand(level, r, c);
-
/* game loop */
game_iface();
}
- /* user iface cluanup */
player_iface_cleanup();
}
static void start_load (void)
{
- /* size & game init (sets errno) */
int rows;
int cols;
+ /* size & game init (sets errno) */
errno = 0;
game_init_load(&rows, &cols);
diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c
index 3318e9f..18860d2 100644
--- a/modules/menu/src/menu_gui.c
+++ b/modules/menu/src/menu_gui.c
@@ -6,9 +6,7 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <gtk/gtk.h>
/* INFINITY */
#include <math.h>
@@ -19,11 +17,10 @@
/* srand() */
#include <stdlib.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* libalx --------------------------------------------------------------------*/
#include "alx_input.h"
+/* Project -------------------------------------------------------------------*/
#include "about.h"
#include "game_iface.h"
#include "save.h"
@@ -134,25 +131,22 @@ static void menu_gui_verbose (void);
******************************************************************************/
void menu_gui_init (void)
{
- /* Window */
+ char title [LINE_SIZE];
+
window_gui = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- /* Quit */
g_signal_connect(window_gui, "delete-event", G_CALLBACK(delete_window), NULL);
g_signal_connect(window_gui, "destroy", G_CALLBACK(destroy_window), NULL);
/* Title. PROG_VERSION defined in Makefile */
- char title [LINE_SIZE];
(void)snprintf(title, LINE_SIZE, "mine-sweeper %s", PROG_VERSION);
gtk_window_set_title(GTK_WINDOW(window_gui), title);
-
- /* Border */
gtk_container_set_border_width(GTK_CONTAINER(window_gui), 20);
}
void menu_gui_cleanup (void)
{
- /* Destroy window */
+
gtk_widget_destroy(window_gui);
}
diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c
index 2fd89e4..23eeb73 100644
--- a/modules/menu/src/menu_iface.c
+++ b/modules/menu/src/menu_iface.c
@@ -38,6 +38,7 @@ struct Menu_Iface_Variables menu_iface_variables;
******************************************************************************/
void menu_iface_init (void)
{
+
menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER;
menu_iface_variables.rows = 8;
menu_iface_variables.cols = 8;
@@ -46,6 +47,7 @@ void menu_iface_init (void)
void menu_iface_init_iface (void)
{
+
switch (menu_iface_mode) {
case MENU_IFACE_CLUI:
break;
@@ -61,6 +63,7 @@ void menu_iface_init_iface (void)
void menu_iface_cleanup (void)
{
+
switch (menu_iface_mode) {
case MENU_IFACE_CLUI:
break;
@@ -76,6 +79,7 @@ void menu_iface_cleanup (void)
void menu_iface_board (int *level, int *rows, int *cols, int *mines)
{
+
*level = menu_iface_variables.level;
/* size & number of mines */
@@ -118,6 +122,7 @@ void menu_iface_board (int *level, int *rows, int *cols, int *mines)
void menu_iface (void)
{
+
start_mode = START_RAND;
if (!flag_exit) {
diff --git a/modules/save/src/save.c b/modules/save/src/save.c
index a9a54e3..d1b49ae 100644
--- a/modules/save/src/save.c
+++ b/modules/save/src/save.c
@@ -45,6 +45,7 @@
******************************************************************************/
void save_init (void)
{
+
if (snprintf(home_path, FILENAME_MAX, "%s/",
getenv(ENV_HOME)) >= FILENAME_MAX) {
goto err_path;
@@ -59,23 +60,27 @@ void save_init (void)
}
saved_name[0] = '\0';
- int err;
- err = mkdir(user_game_path, 0700);
-
- if (!err) {
- mkdir(saved_path, 0700);
- } else {
-
+ if (mkdir(user_game_path, 0700)) {
switch (errno) {
case EACCES:
printf("err = EACCES");
exit(EXIT_FAILURE);
- break;
-
case EEXIST:
/* OK */
- break;
-
+ return;
+ default:
+ printf("WTF?!");
+ exit(EXIT_FAILURE);
+ }
+ }
+ if (mkdir(saved_path, 0700)) {
+ switch (errno) {
+ case EACCES:
+ printf("err = EACCES");
+ exit(EXIT_FAILURE);
+ case EEXIST:
+ /* OK */
+ return;
default:
printf("WTF?!");
exit(EXIT_FAILURE);
@@ -93,6 +98,7 @@ err_path:
void save_clr (void)
{
+
if (snprintf(saved_path, FILENAME_MAX, "%s/%s/",
home_path, USER_SAVED_DIR) >= FILENAME_MAX) {
goto err_path;
@@ -111,7 +117,6 @@ void load_game_file (void)
{
char file_name [FILENAME_MAX];
FILE *fp;
-
int i;
int j;
@@ -164,6 +169,7 @@ void save_game_file (char *filepath)
FILE *fp;
int i;
int j;
+ bool x;
/* Don't change saved_name variable if not in default dir */
if (filepath != NULL) {
@@ -179,7 +185,6 @@ void save_game_file (char *filepath)
player_iface_save_name(filepath, saved_name, FILENAME_MAX);
/* Look for an unused name of the type 'name_XXX.mine'. */
- bool x;
x = true;
for (i = 0; x; i++) {
if (filepath == NULL) {
diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile
index 4fc63d8..c096cb0 100644
--- a/modules/save/tmp/Makefile
+++ b/modules/save/tmp/Makefile
@@ -46,7 +46,7 @@ all: $(ALL)
save_mod.o: $(_ALL)
@echo " LD $@"
$(Q)$(LD) -r $^ -o $@
-
+
save.s: $(SAVE_DEPS)
@echo " CC $@"