diff options
author | AlejandroColomar <colomar.6.4.3@gmail.com> | 2018-10-28 20:39:48 +0100 |
---|---|---|
committer | AlejandroColomar <colomar.6.4.3@gmail.com> | 2018-10-28 20:39:48 +0100 |
commit | bc83d93362092a8ad1f4e1374b9b7cc58c1decd6 (patch) | |
tree | 085cc8d0586052917c0335d6b7c7ceaf0d8e03dd | |
parent | fdfbd88f25a55502f55ca1bcb94a67c48073f70a (diff) |
Stop using varargs
-rw-r--r-- | libalx/inc/alx_input.h | 11 | ||||
-rw-r--r-- | libalx/inc/alx_input.hpp | 10 | ||||
-rw-r--r-- | libalx/inc/alx_ncur.h | 5 | ||||
-rw-r--r-- | libalx/src/alx_input.c | 37 | ||||
-rw-r--r-- | libalx/src/alx_ncur.c | 20 |
5 files changed, 35 insertions, 48 deletions
diff --git a/libalx/inc/alx_input.h b/libalx/inc/alx_input.h index 0fef5d0..32fe322 100644 --- a/libalx/inc/alx_input.h +++ b/libalx/inc/alx_input.h @@ -13,6 +13,7 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -42,16 +43,14 @@ double alx_getdbl (double m,
double def,
double M,
- const char *formatA,
- const char *formatB,
- ...);
+ const char *title,
+ const char *help);
int64_t alx_getint (double m,
int64_t def,
double M,
- const char *formatA,
- const char *formatB,
- ...);
+ const char *title,
+ const char *help);
/******************************************************************************
diff --git a/libalx/inc/alx_input.hpp b/libalx/inc/alx_input.hpp index 0228133..7fa6a8a 100644 --- a/libalx/inc/alx_input.hpp +++ b/libalx/inc/alx_input.hpp @@ -48,16 +48,14 @@ extern "C" { double alx_getdbl (double m,
double def,
double M,
- const char *formatA,
- const char *formatB,
- ...);
+ const char *title,
+ const char *help);
int64_t alx_getint (double m,
int64_t def,
double M,
- const char *formatA,
- const char *formatB,
- ...);
+ const char *title,
+ const char *help);
/******************************************************************************
diff --git a/libalx/inc/alx_ncur.h b/libalx/inc/alx_ncur.h index b3f2860..004105d 100644 --- a/libalx/inc/alx_ncur.h +++ b/libalx/inc/alx_ncur.h @@ -13,9 +13,12 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
- #include <ncurses.h>
+/* Standard C ----------------------------------------------------------------*/
#include <stdint.h>
+/* Packages ------------------------------------------------------------------*/
+ #include <ncurses.h>
+
/******************************************************************************
******* structs **************************************************************
diff --git a/libalx/src/alx_input.c b/libalx/src/alx_input.c index 214e145..9761932 100644 --- a/libalx/src/alx_input.c +++ b/libalx/src/alx_input.c @@ -6,17 +6,13 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* libalx --------------------------------------------------------------------*/
#include "alx_input.h"
@@ -35,6 +31,7 @@ # define ERR_RANGE_MSG "¡ Number is out of range !"
# define ERR_SSCANF_MSG "¡ sscanf() error !"
+ # define ERR_FPTR_MSG "¡ FILE error !"
# define ERR_FGETS_MSG "¡ fgets() error !"
@@ -148,25 +145,21 @@ int alx_sscan_fname (const char *fpath, char *fname, bool exist, const char *str * value.
*/
double alx_getdbl (double m, double def, double M,
- const char *formatA, const char *formatB, ...)
+ const char *title, const char *help)
{
- va_list args;
- va_start(args, formatB);
-
double R;
- if (formatA != NULL) {
- puts(formatA);
+ if (title != NULL) {
+ puts(title);
}
- if (formatB == NULL) {
+ if (help == NULL) {
printf("Introduce a real number [%lf U %lf] (default %lf):...\t", m, M, def);
} else {
- vprintf(formatB, args);
+ puts(help);
}
R = loop_getdbl(m, def, M);
- va_end(args);
return R;
}
@@ -178,25 +171,21 @@ double alx_getdbl (double m, double def, double M, * value.
*/
int64_t alx_getint (double m, int64_t def, double M,
- const char *formatA, const char *formatB, ...)
+ const char *title, const char *help)
{
- va_list args;
- va_start(args, formatB);
-
int64_t Z;
- if (formatA != NULL) {
- puts(formatA);
+ if (title != NULL) {
+ puts(title);
}
- if (formatB == NULL) {
+ if (help == NULL) {
printf("Introduce an integer number [%lf U %lf] (default %"PRIi64"):...\t", m, M, def);
} else {
- vprintf(formatB, args);
+ puts(help);
}
Z = loop_getint(m, def, M);
- va_end(args);
return Z;
}
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c index cdb683d..1ba5c3c 100644 --- a/libalx/src/alx_ncur.c +++ b/libalx/src/alx_ncur.c @@ -6,10 +6,7 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- #include <ncurses.h>
+/* Standard C ----------------------------------------------------------------*/
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
@@ -18,9 +15,10 @@ /* wchar_t */
#include <wchar.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Packages ------------------------------------------------------------------*/
+ #include <ncurses.h>
+
+/* libalx --------------------------------------------------------------------*/
#include "alx_input.h"
#include "alx_ncur.h"
@@ -42,8 +40,8 @@ # define ERR_RANGE_MSG "¡ Number is out of range !"
# define ERR_SSCANF_MSG "¡ sscanf() error !"
- # define ERR_GETSTR_MSG "¡ wgetstr() error !"
# define ERR_FPTR_MSG "¡ FILE error !"
+ # define ERR_GETSTR_MSG "¡ wgetstr() error !"
/******************************************************************************
@@ -654,12 +652,12 @@ static void manage_w_error (WINDOW *win, int err) case ERR_SSCANF:
mvwaddstr(win, 0, 0, ERR_SSCANF_MSG);
break;
- case ERR_GETSTR:
- mvwaddstr(win, 0, 0, ERR_GETSTR_MSG);
- break;
case ERR_FPTR:
mvwaddstr(win, 0, 0, ERR_FPTR_MSG);
break;
+ case ERR_GETSTR:
+ mvwaddstr(win, 0, 0, ERR_GETSTR_MSG);
+ break;
}
wrefresh(win);
/* Wait for any key */
|