diff options
author | alex <alex@ASUS> | 2018-09-06 19:04:42 +0200 |
---|---|---|
committer | alex <alex@ASUS> | 2018-09-06 19:04:42 +0200 |
commit | 025406b5d8b906fd10a2ff5060268f4c2d7dddf1 (patch) | |
tree | 94cd2ea8c65deb53f6b602f26cd979c44c9647d6 | |
parent | a1baa64d1e2f8907aa7da703d257f1e5cc763ab9 (diff) |
Fix file name bugs
-rw-r--r-- | libalx/src/alx_getnum.c | 4 | ||||
-rw-r--r-- | libalx/src/alx_ncur.c | 27 | ||||
-rw-r--r-- | modules/game/inc/game.h | 8 | ||||
-rw-r--r-- | modules/game/src/game.c | 4 | ||||
-rw-r--r-- | modules/menu/src/menu_tui.c | 3 | ||||
-rw-r--r-- | modules/menu/src/parser.c | 3 | ||||
-rw-r--r-- | modules/save/inc/save.h | 5 | ||||
-rw-r--r-- | modules/save/src/save.c | 28 |
8 files changed, 53 insertions, 29 deletions
diff --git a/libalx/src/alx_getnum.c b/libalx/src/alx_getnum.c index b050f5d..3bfa22f 100644 --- a/libalx/src/alx_getnum.c +++ b/libalx/src/alx_getnum.c @@ -123,7 +123,7 @@ static double loop_getdbl (double m, double def, double M) if (x == NULL) {
err = ERR_FGETS;
- } else if (sscanf(buff, "%lf", &R) != 1) {
+ } else if (sscanf(buff, " %lf", &R) != 1) {
err = ERR_SSCANF;
} else if (R < m || R > M) {
err = ERR_RANGE;
@@ -151,7 +151,7 @@ static int64_t loop_getint (double m, int64_t def, double M) if (x == NULL) {
err = ERR_FGETS;
- } else if (sscanf(buff, "%"SCNi64, &Z) != 1) {
+ } else if (sscanf(buff, " %"SCNi64, &Z) != 1) {
err = ERR_SSCANF;
} else if (Z < m || Z > M) {
err = ERR_RANGE;
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c index 9181e5d..9febf2f 100644 --- a/libalx/src/alx_ncur.c +++ b/libalx/src/alx_ncur.c @@ -31,6 +31,7 @@ # define MAX_TRIES (2)
+ # define ERR_OK (0)
# define ERR_RANGE (1)
# define ERR_SSCANF (2)
# define ERR_GETSTR (3)
@@ -559,6 +560,7 @@ static double loop_w_getdbl (WINDOW *win, wclear(win);
wrefresh(win);
+ err = ERR_OK;
if (x == ERR) {
err = ERR_GETSTR;
} else if (sscanf(buff, "%lf", &R) != 1) {
@@ -587,17 +589,18 @@ static int64_t loop_w_getint (WINDOW *win, for (i = 0; i < MAX_TRIES; i++) {
echo();
- x = mvwgetnstr(win, 0, 0, buff, BUFF_SIZE);
+ x = mvwgetnstr(win, 0, 0, buff, BUFF_SIZE);
noecho();
wclear(win);
wrefresh(win);
+ err = ERR_OK;
if (x == ERR) {
- err = ERR_GETSTR;
+ err = ERR_GETSTR;
} else if (sscanf(buff, "%"SCNi64, &Z) != 1) {
- err = ERR_SSCANF;
+ err = ERR_SSCANF;
} else if (Z < m || Z > M) {
- err = ERR_RANGE;
+ err = ERR_RANGE;
} else {
break;
}
@@ -618,13 +621,14 @@ static void loop_w_getstr (char *str, WINDOW *win) for (i = 0; i < MAX_TRIES; i++) {
echo();
- x = mvwgetnstr(win, 0, 0, buff, BUFF_SIZE);
+ x = mvwgetnstr(win, 0, 0, buff, BUFF_SIZE);
noecho();
wclear(win);
wrefresh(win);
+ err = ERR_OK;
if (x == ERR) {
- err = ERR_GETSTR;
+ err = ERR_GETSTR;
} else {
break;
}
@@ -642,6 +646,7 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist, {
int i;
char buff [FILENAME_MAX];
+ char buff2 [FILENAME_MAX];
char file_path [FILENAME_MAX];
int x;
int err;
@@ -649,16 +654,20 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist, for (i = 0; i < MAX_TRIES; i++) {
echo();
- x = mvwgetnstr(win, 0, 0, buff, FILENAME_MAX);
+ x = mvwgetnstr(win, 0, 0, buff, FILENAME_MAX);
noecho();
wclear(win);
wrefresh(win);
+ err = ERR_OK;
if (x == ERR) {
err = ERR_GETSTR;
+ } else if (sscanf(buff, " %s ", buff2) != 1) {
+ err = ERR_SSCANF;
} else {
strcpy(file_path, fpath);
- strcat(file_path, buff);
+ strcat(file_path, buff2);
+
fp = fopen(file_path, "r");
if (exist) {
@@ -682,7 +691,7 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist, }
if (!err) {
- strcpy(fname, buff);
+ strcpy(fname, buff2);
}
}
diff --git a/modules/game/inc/game.h b/modules/game/inc/game.h index 69182fa..9a97b86 100644 --- a/modules/game/inc/game.h +++ b/modules/game/inc/game.h @@ -13,6 +13,14 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
+/* * * * * * * * * *
+ * * * Standard * * * * * *
+ * * * * * * * * * */
+ #include <stdbool.h>
+
+/* * * * * * * * * *
+ * * * Other * * * * * * *
+ * * * * * * * * * */
/* ยก Need to include these in the Makefile ! */
/* ROWS_MAX & COLS_MAX */
#include "game_iface.h"
diff --git a/modules/game/src/game.c b/modules/game/src/game.c index 9587246..1f414cb 100644 --- a/modules/game/src/game.c +++ b/modules/game/src/game.c @@ -9,6 +9,8 @@ /* * * * * * * * * *
* * * Standard * * * * * *
* * * * * * * * * */
+ /* bool */
+ #include <stdbool.h>
/* rand() */
#include <stdlib.h>
/* time_t & clock() & time() */
@@ -87,7 +89,7 @@ void game_init_rand (int rows, int cols, int mines, void game_init_load (int *rows, int *cols)
{
- load_game_file(NULL, NULL);
+ load_game_file();
game_board.state = GAME_STATE_PLAYING;
diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 1692490..43e4b92 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -187,7 +187,8 @@ static void menu_tui_continue (void) break;
case 4:
- alx_w_getfname(USER_SAVED_DIR, saved_name, true, w2, r2,
+ save_clr();
+ alx_w_getfname(saved_path, saved_name, true, w2, r2,
txt[0], NULL);
alx_win_del(win);
break;
diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index 10123c5..8449e59 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -176,7 +176,8 @@ static void parse_file (char* argument) } else {
fclose(fp);
- strcat(saved_name, argument);
+ strcpy(saved_path, "");
+ strcpy(saved_name, argument);
}
}
diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index 9a4eb0c..ca1721b 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -13,6 +13,8 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
+ /* bool */
+ #include <stdbool.h>
/* FILENAME_MAX */
#include <stdio.h>
@@ -45,7 +47,8 @@ extern char saved_name [FILENAME_MAX]; ******* functions ************************************************************
******************************************************************************/
void save_init (void);
-void load_game_file (char *filepath, char *filename);
+void save_clr (void);
+void load_game_file (void);
void save_game_file (char *filepath);
diff --git a/modules/save/src/save.c b/modules/save/src/save.c index f2c60e3..af18609 100644 --- a/modules/save/src/save.c +++ b/modules/save/src/save.c @@ -63,8 +63,7 @@ void save_init (void) strcat(saved_path, USER_SAVED_DIR);
strcat(saved_path, "/");
- strcpy(saved_name, SAVED_NAME_DEFAULT);
- strcat(saved_name, FILE_EXTENSION);
+ strcpy(saved_name, "");
int err;
#if defined OS_LINUX
@@ -98,7 +97,15 @@ void save_init (void) }
}
-void load_game_file (char *filepath, char *filename)
+void save_clr (void)
+{
+ strcpy(saved_path, home_path);
+ strcat(saved_path, "/");
+ strcat(saved_path, USER_SAVED_DIR);
+ strcat(saved_path, "/");
+}
+
+void load_game_file (void)
{
char file_name [FILENAME_MAX];
FILE *fp;
@@ -106,16 +113,8 @@ void load_game_file (char *filepath, char *filename) int i;
int j;
- if (filepath == NULL) {
- strcpy(file_name, saved_path);
- } else {
- strcpy(file_name, filepath);
- }
- if (filename == NULL) {
- strcat(file_name, saved_name);
- } else {
- strcat(file_name, filename);
- }
+ strcpy(file_name, saved_path);
+ strcat(file_name, saved_name);
fp = fopen(file_name, "r");
if (fp) {
@@ -159,7 +158,8 @@ void save_game_file (char *filepath) w = 70;
r = 10;
- /* Default name */
+ /* Default path & name */
+ save_clr();
strcpy(saved_name, SAVED_NAME_DEFAULT);
/* Request file name */
|