summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandroColomar <colomar.6.4.3@gmail.com>2019-01-07 05:00:51 +0100
committerAlejandroColomar <colomar.6.4.3@gmail.com>2019-01-07 05:00:51 +0100
commit98ce1841e943568ace3b42571d448a0fa09dff18 (patch)
treed3437759ac897b8b03fc085013bc501b69d3744f
parent4263106c125fba1791b5f78184812fdc11a0d394 (diff)
Fix style
m---------libalx0
-rw-r--r--modules/menu/src/menu_clui.c177
-rw-r--r--modules/menu/src/menu_gui.c2
-rw-r--r--modules/menu/src/menu_tui.c99
4 files changed, 159 insertions, 119 deletions
diff --git a/libalx b/libalx
-Subproject a088b2ec37f0c1b868eaa336a62bee65fbf42c6
+Subproject 207eade1bd19c0934da8f64571a1bff58a2d29f
diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c
index e7c057b..8657dfe 100644
--- a/modules/menu/src/menu_clui.c
+++ b/modules/menu/src/menu_clui.c
@@ -6,19 +6,16 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
/* INFINITY */
#include <math.h>
/* srand() */
#include <stdlib.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* libalx --------------------------------------------------------------------*/
#include "alx_input.h"
+/* Project -------------------------------------------------------------------*/
#include "about.h"
#include "game_iface.h"
// #include "save.h"
@@ -60,51 +57,73 @@ static void menu_clui_start (void);
void menu_clui (void)
{
char buff [BUFF_SIZE];
- char ch;
+ char c;
- ch = 'n';
+ c = 'n';
printf("Read 'Disclaimer of warranty'? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ if (sscanf(buff, " %c", &c) != 1) {
+ goto err_sscanf;
+ }
+ if (c == 'y' || c == 'Y') {
+ printf(" >yes\n");
print_share_file(SHARE_DISCLAIMER);
} else {
- puts (" >NO");
+ printf(" >NO\n");
}
- ch = 'n';
+ c = 'n';
printf("Read 'License'? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ if (sscanf(buff, " %c", &c) != 1) {
+ goto err_sscanf;
+ }
+ if (c == 'y' || c == 'Y') {
+ printf(" >yes\n");
print_share_file(SHARE_LICENSE);
} else {
- puts (" >NO");
+ printf(" >NO\n");
}
#if 0
printf("Game interface? (NCURSES/text): ");
- scanf(" %c%*s ", &ch);
- if (ch == 't' || ch == 'T') {
- puts (" >text");
+ scanf(" %c%*s ", &c);
+ if (c == 't' || c == 'T') {
+ printf(" >text\n");
// FIXME
} else {
- puts (" >NCURSES");
+ printf(" >NCURSES\n");
// FIXME
}
#endif
- ch = 'n';
+ c = 'n';
printf("New game or load game? (NEW/load): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'l' || ch == 'L') {
- puts (" >load");
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ if (sscanf(buff, " %c", &c) != 1) {
+ goto err_sscanf;
+ }
+ if (c == 'l' || c == 'L') {
+ printf(" >load\n");
menu_clui_load();
} else {
- puts (" >NEW");
+ printf(" >NEW\n");
menu_clui_rand();
}
+
+ return;
+
+
+err_fgets:
+ printf("fgets() error\n");
+ exit(EXIT_FAILURE);
+err_sscanf:
+ printf("sscanf() error\n");
+ exit(EXIT_FAILURE);
}
@@ -113,52 +132,70 @@ void menu_clui (void)
******************************************************************************/
static void menu_clui_rand (void)
{
+ int seed;
+ char buff [BUFF_SIZE];
+ char c;
+
/* Random */
start_mode = START_RAND;
- char buff [BUFF_SIZE];
- char ch;
-
- ch = 'n';
+ c = 'n';
printf("Set seed for random generator? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- int seed;
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ if (sscanf(buff, " %c", &c) != 1) {
+ goto err_sscanf;
+ }
+ if (c == 'y' || c == 'Y') {
+ printf(" >yes\n");
seed = alx_getint(-INFINITY, 1, INFINITY, "Seed:", NULL);
srand(seed);
} else {
- puts (" >NO");
+ printf(" >NO\n");
}
- ch = 'b';
+ c = 'b';
printf("Level? (BEGINNER/intermediate/(expert)/custom): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'i' || ch == 'I') {
- puts (" >intermediate");
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ if (sscanf(buff, " %c", &c) != 1) {
+ goto err_sscanf;
+ }
+ if (c == 'i' || c == 'I') {
+ printf(" >intermediate\n");
menu_iface_variables.level = GAME_IFACE_LEVEL_INTERMEDIATE;
menu_clui_start();
- } else if (ch == 'e' || ch == 'E') {
- puts (" >expert");
+ } else if (c == 'e' || c == 'E') {
+ printf(" >expert\n");
menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT_INV;
menu_clui_start();
- } else if (ch == 'c' || ch == 'C') {
- puts (" >custom");
+ } else if (c == 'c' || c == 'C') {
+ printf(" >custom\n");
menu_iface_variables.level = GAME_IFACE_LEVEL_CUSTOM;
menu_clui_custom();
} else {
- puts (" >BEGINNER");
+ printf(" >BEGINNER\n");
menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER;
menu_clui_start();
}
+
+ return;
+
+
+err_fgets:
+ printf("fgets() error\n");
+ exit(EXIT_FAILURE);
+err_sscanf:
+ printf("sscanf() error\n");
+ exit(EXIT_FAILURE);
}
static void menu_clui_custom (void)
{
- /* Random */
+
start_mode = START_RAND;
menu_iface_variables.rows = alx_getint(2, menu_iface_variables.rows, ROWS_CLUI_MAX, "Rows:", NULL);
@@ -170,7 +207,7 @@ static void menu_clui_custom (void)
static void menu_clui_load (void)
{
- /* Load */
+
start_mode = START_LOAD;
#if 0
/* File name */ // FIXME
@@ -181,25 +218,39 @@ static void menu_clui_load (void)
static void menu_clui_start (void)
{
- puts(" >>START:");
- start_switch();
-
char buff [BUFF_SIZE];
- char ch;
+ char c;
+
+ printf(" >>START:\n");
+ start_switch();
- ch = 'm';
+ c = 'm';
printf("Play again? (MENU/play/exit): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'p' || ch == 'P') {
- puts (" >play");
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ if (sscanf(buff, " %c", &c) != 1) {
+ goto err_sscanf;
+ }
+ if (c == 'p' || c == 'P') {
+ printf(" >play\n");
menu_clui_start();
- } else if (ch == 'e' || ch == 'E') {
- puts (" >exit!");
+ } else if (c == 'e' || c == 'E') {
+ printf(" >exit!\n");
} else {
- puts (" >MENU");
+ printf(" >MENU\n");
menu_clui();
}
+
+ return;
+
+
+err_fgets:
+ printf("fgets() error\n");
+ exit(EXIT_FAILURE);
+err_sscanf:
+ printf("sscanf() error\n");
+ exit(EXIT_FAILURE);
}
diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c
index fbd684b..3318e9f 100644
--- a/modules/menu/src/menu_gui.c
+++ b/modules/menu/src/menu_gui.c
@@ -325,7 +325,7 @@ static void callback_entry_int (GtkWidget *widget,
entry = ((struct Entry_int_Data *)data);
str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
- err = alx_sscan_int64(&Z, entry->min, entry->def, entry->max, str);
+ err = alx_sscan_i64(&Z, entry->min, entry->def, entry->max, str);
if (err) {
(void)snprintf(buff, LINE_SIZE, "Error %i", err);
diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c
index e675b25..d9e9cc1 100644
--- a/modules/menu/src/menu_tui.c
+++ b/modules/menu/src/menu_tui.c
@@ -66,16 +66,19 @@ static void menu_tui_verbose (void);
******************************************************************************/
void menu_tui (void)
{
+ int h;
+ int w;
+ int N;
+ bool wh;
+ int sw;
+
alx_resume_curses();
/* Menu dimensions & options */
- int h;
- int w;
h = 10;
w = 34;
- int N;
N = 4;
- struct Alx_Menu mnu[4] = {
+ static const struct Alx_Menu mnu[4] = {
{7, 4, "[0] Exit program"},
{2, 4, "[1] Continue"},
{4, 4, "[2] Disclaimer of warranty"},
@@ -83,8 +86,6 @@ void menu_tui (void)
};
/* Menu */
- bool wh;
- int sw;
wh = true;
while (wh) {
/* Menu loop */
@@ -95,18 +96,15 @@ void menu_tui (void)
case 0:
wh = false;
break;
-
case 1:
menu_tui_continue();
break;
-
case 2:
alx_pause_curses();
print_share_file(SHARE_DISCLAIMER);
getchar();
alx_resume_curses();
break;
-
case 3:
alx_pause_curses();
print_share_file(SHARE_LICENSE);
@@ -125,23 +123,26 @@ void menu_tui (void)
******************************************************************************/
static void menu_tui_continue (void)
{
- /* Hi scores tmp string */
char str [BUFF_SIZE_TEXT];
-
- /* Menu dimensions & options */
WINDOW *win;
int h;
int w;
int r;
int c;
+ int N;
+ int w2;
+ int r2;
+ bool wh;
+ int sw;
+
+ /* Menu dimensions & options */
h = 18;
w = 50;
r = 1;
c = (80 - w) / 2;
- int N;
/* N = 7 if DEVEL option is enabled */
N = 6;
- struct Alx_Menu mnu[6] = {
+ static const struct Alx_Menu mnu[6] = {
{11, 4, "[0] Back"},
{2, 4, "[1] Start"},
{4, 4, "[2] Select map"},
@@ -152,15 +153,11 @@ static void menu_tui_continue (void)
};
/* Input box */
- int w2;
- int r2;
w2 = w - 8;
r2 = r + h - 5;
- char *txt[] = {"File name:"};
+ static const char *txt[] = {"File name:"};
/* Menu */
- bool wh;
- int sw;
wh = true;
while (wh) {
/* Menu loop */
@@ -175,31 +172,26 @@ static void menu_tui_continue (void)
alx_win_del(win);
wh = false;
break;
-
case 1:
alx_win_del(win);
alx_pause_curses();
start_switch();
alx_resume_curses();
break;
-
case 2:
alx_win_del(win);
menu_tui_select();
break;
-
case 3:
alx_win_del(win);
menu_tui_level();
break;
-
case 4:
save_clr();
alx_w_getfname(saved_path, saved_name, true, w2, r2,
txt[0], NULL);
alx_win_del(win);
break;
-
case 5:
alx_win_del(win);
alx_pause_curses();
@@ -220,26 +212,27 @@ static void menu_tui_continue (void)
static void menu_tui_select (void)
{
- /* Menu dimensions & options */
WINDOW *win;
int h;
int w;
int r;
int c;
+ int N;
+ int sw;
+
+ /* Menu dimensions & options */
h = 9;
w = 70;
r = 1;
c = (80 - w) / 2;
- int N;
N = 3;
- struct Alx_Menu mnu[3] = {
+ static const struct Alx_Menu mnu[3] = {
{6, 4, "[0] Back"},
{2, 4, "[1] New map"},
{4, 4, "[2] Load map"}
};
/* Menu loop */
- int sw;
win = newwin(h, w, r, c);
mvwprintw(win, mnu[2].r, mnu[2].c, "%s (File: \"%s\")", mnu[1].t, saved_name);
wrefresh(win);
@@ -251,7 +244,6 @@ static void menu_tui_select (void)
case 1:
start_mode = START_RAND;
break;
-
case 2:
start_mode = START_LOAD;
break;
@@ -261,14 +253,16 @@ static void menu_tui_select (void)
static void menu_tui_level (void)
{
- /* Menu dimensions & options */
int h;
int w;
+ int N;
+ int sw;
+
+ /* Menu dimensions & options */
h = 10;
w = 70;
- int N;
N = 5;
- struct Alx_Menu mnu[5] = {
+ static const struct Alx_Menu mnu[5] = {
{7, 4, "[0] Back"},
{2, 4, "[1] Beginner"},
{3, 4, "[2] Intermediate"},
@@ -277,7 +271,6 @@ static void menu_tui_level (void)
};
/* Menu loop */
- int sw;
sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:");
/* Selection */
@@ -304,19 +297,24 @@ static void menu_tui_level (void)
static void menu_tui_custom (void)
{
- /* Menu dimensions & options */
WINDOW *win;
int h;
int w;
int r;
int c;
+ int N;
+ int w2;
+ int r2;
+ bool wh;
+ int sw;
+
+ /* Menu dimensions & options */
h = 16;
w = 76;
r = 1;
c = (80 - w) / 2;
- int N;
N = 4;
- struct Alx_Menu mnu[4] = {
+ static const struct Alx_Menu mnu[4] = {
{8, 4, "[0] Back"},
{2, 4, "[1] Change rows:"},
{4, 4, "[2] Change columns:"},
@@ -324,11 +322,9 @@ static void menu_tui_custom (void)
};
/* Input box */
- int w2;
- int r2;
w2 = w - 8;
r2 = r + h - 5;
- char *txt[] = {
+ static const char *txt[] = {
"Rows:",
"Columns:",
"Proportion:"
@@ -338,8 +334,6 @@ static void menu_tui_custom (void)
win = newwin(h, w, r, c);
/* Menu loop */
- bool wh;
- int sw;
wh = true;
while (wh) {
mvwprintw(win, mnu[1].r, mnu[1].c, "%s rows\t\t(%i)",
@@ -357,17 +351,14 @@ static void menu_tui_custom (void)
case 0:
wh = false;
break;
-
case 1:
menu_iface_variables.rows = alx_w_getint(w2, r2,
txt[sw - 1], 2, menu_iface_variables.rows, ROWS_TUI_MAX, NULL);
break;
-
case 2:
menu_iface_variables.cols = alx_w_getint(w2, r2,
txt[sw - 1], 2, menu_iface_variables.cols, COLS_TUI_MAX, NULL);
break;
-
case 3:
menu_iface_variables.p = alx_w_getdbl(w2, r2,
txt[sw - 1], 0, menu_iface_variables.p, 1, NULL);
@@ -376,7 +367,6 @@ static void menu_tui_custom (void)
}
- /* Cleanup */
alx_win_del(win);
}
#if 0
@@ -387,32 +377,33 @@ static void menu_tui_devel (void)
int w;
int r;
int c;
+ int N;
+ int w2;
+ int r2;
+ bool wh;
+ int sw;
+ int seed;
+
h = 12;
w = 50;
r = 1;
c = (80 - w) / 2;
- int N;
N = 2;
- struct Alx_Menu mnu[2] = {
+ static const struct Alx_Menu mnu[2] = {
{5, 4, "[0] Back"},
{2, 4, "[1] Change seed (srand)"}
};
/* Input box */
- int w2;
- int r2;
w2 = w - 8;
r2 = r + h - 5;
- char *txt[] = {"Seed:"};
+ static const char *txt[] = {"Seed:"};
/* Menu */
win = newwin(h, w, r, c);
/* Menu loop */
- bool wh;
- int sw;
wh = true;
- int seed;
while (wh) {
/* Selection */
sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:");
@@ -421,7 +412,6 @@ static void menu_tui_devel (void)
case 0:
wh = false;
break;
-
case 1:
seed = alx_w_getint(w2, r2, txt[0],
-INFINITY, 1, INFINITY, NULL);
@@ -430,7 +420,6 @@ static void menu_tui_devel (void)
}
}
- /* Cleanup */
alx_win_del(win);
}
#endif