summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-10-23 00:57:08 +0200
committeralex <alex@ASUS>2018-10-23 00:57:08 +0200
commit82b2af381e68f04b3c4e924c92f3301de6b1b861 (patch)
tree6c81b195800b73dfdfb93e97fd963b10f6226e9e
parentf757fdbb017d5d77e0319c85844a750e557bc54b (diff)
Fix bugs: now use printf(%s, str) instead of printf(str)
-rw-r--r--libalx/inc/alx_input.hpp77
-rw-r--r--libalx/inc/alx_ncur.h12
-rw-r--r--libalx/inc/alx_ncur.hpp113
-rw-r--r--libalx/src/alx_input.c2
-rw-r--r--libalx/src/alx_ncur.c55
5 files changed, 208 insertions, 51 deletions
diff --git a/libalx/inc/alx_input.hpp b/libalx/inc/alx_input.hpp
new file mode 100644
index 0000000..0228133
--- /dev/null
+++ b/libalx/inc/alx_input.hpp
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * Copyright (C) 2017 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef ALX_INPUT_HPP
+ # define ALX_INPUT_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+ #include <math.h>
+ #include <stdarg.h>
+ #include <stdbool.h>
+ #include <stdint.h>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ int alx_sscan_dbl (double *dest,
+ double m,
+ double def,
+ double M,
+ const char *str);
+
+ int alx_sscan_int (int64_t *dest,
+ double m,
+ int64_t def,
+ double M,
+ const char *str);
+
+ int alx_sscan_fname (const char *fpath,
+ char *fname,
+ bool exist,
+ const char *str);
+
+ double alx_getdbl (double m,
+ double def,
+ double M,
+ const char *formatA,
+ const char *formatB,
+ ...);
+
+ int64_t alx_getint (double m,
+ int64_t def,
+ double M,
+ const char *formatA,
+ const char *formatB,
+ ...);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* alx_input.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/libalx/inc/alx_ncur.h b/libalx/inc/alx_ncur.h
index f1a774f..b3f2860 100644
--- a/libalx/inc/alx_ncur.h
+++ b/libalx/inc/alx_ncur.h
@@ -53,8 +53,7 @@
double m,
double def,
double M,
- const char *format,
- ...);
+ const char *help);
int64_t alx_w_getint (int w,
int r,
@@ -62,16 +61,14 @@
double m,
int64_t def,
double M,
- const char *format,
- ...);
+ const char *help);
void alx_w_getstr (char *dest,
int destsize,
int w,
int r,
const char *title,
- const char *format,
- ...);
+ const char *help);
void alx_w_getfname (const char *fpath,
char *fname,
@@ -79,8 +76,7 @@
int w,
int r,
const char *title,
- const char *format,
- ...);
+ const char *help);
void alx_ncur_prn_title (WINDOW *win,
const char *title);
diff --git a/libalx/inc/alx_ncur.hpp b/libalx/inc/alx_ncur.hpp
new file mode 100644
index 0000000..676b64b
--- /dev/null
+++ b/libalx/inc/alx_ncur.hpp
@@ -0,0 +1,113 @@
+/******************************************************************************
+ * Copyright (C) 2017 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef ALX_NCUR_HPP
+ # define ALX_NCUR_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ /* int64_t */
+ #include <cstdint>
+
+/* Packages ------------------------------------------------------------------*/
+ /* WINDOW */
+ #include <ncurses.h>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+ struct Alx_Menu {
+ int r;
+ int c;
+ char *t;
+ };
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void alx_start_curses (void);
+ void alx_pause_curses (void);
+ void alx_resume_curses (void);
+ void alx_end_curses (void);
+ void alx_win_del (WINDOW *win);
+
+ int alx_menu (int h,
+ int w,
+ int N,
+ struct Alx_Menu mnu[],
+ const char *str);
+
+ int alx_menu_2 (WINDOW *win,
+ int N,
+ struct Alx_Menu mnu[],
+ const char *str);
+
+ double alx_w_getdbl (int w,
+ int r,
+ const char *title,
+ double m,
+ double def,
+ double M,
+ const char *help);
+
+ int64_t alx_w_getint (int w,
+ int r,
+ const char *title,
+ double m,
+ int64_t def,
+ double M,
+ const char *help);
+
+ void alx_w_getstr (char *dest,
+ int destsize,
+ int w,
+ int r,
+ const char *title,
+ const char *help);
+
+ void alx_w_getfname (const char *fpath,
+ char *fname,
+ bool exist,
+ int w,
+ int r,
+ const char *title,
+ const char *help);
+
+ void alx_ncur_prn_title (WINDOW *win,
+ const char *title);
+
+ void alx_ncur_prn_subtitle (WINDOW *win,
+ const char *subtitle);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* alx_ncur.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/libalx/src/alx_input.c b/libalx/src/alx_input.c
index 0c52cb9..214e145 100644
--- a/libalx/src/alx_input.c
+++ b/libalx/src/alx_input.c
@@ -134,7 +134,7 @@ int alx_sscan_fname (const char *fpath, char *fname, bool exist, const char *str
}
if (!err) {
- snprintf(fname, FILENAME_MAX, buff);
+ snprintf(fname, FILENAME_MAX, "%s", buff);
}
return err;
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c
index c059488..cdb683d 100644
--- a/libalx/src/alx_ncur.c
+++ b/libalx/src/alx_ncur.c
@@ -11,7 +11,6 @@
* * * * * * * * * */
#include <ncurses.h>
#include <inttypes.h>
- #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
/* strlen() */
@@ -153,12 +152,8 @@ int alx_menu_2 (WINDOW *win,
double alx_w_getdbl (int w, int r, const char *title,
double m, double def, double M,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -197,10 +192,10 @@ double alx_w_getdbl (int w, int r, const char *title,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
wprintw(win2, "Introduce a real number [%lf U %lf] (default %lf)", m, M, def);
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -216,20 +211,13 @@ double alx_w_getdbl (int w, int r, const char *title,
alx_win_del(win2);
alx_win_del(win1);
- /* End varargs */
- va_end(args);
-
return R;
}
int64_t alx_w_getint (int w, int r, const char *title,
double m, int64_t def, double M,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -268,10 +256,10 @@ int64_t alx_w_getint (int w, int r, const char *title,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
wprintw(win2, "Introduce an integer number [%lf U %lf] (default %"PRIi64")", m, M, def);
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -287,20 +275,13 @@ int64_t alx_w_getint (int w, int r, const char *title,
alx_win_del(win2);
alx_win_del(win1);
- /* End varargs */
- va_end(args);
-
return Z;
}
void alx_w_getstr (char *dest, int destsize,
int w, int r, const char *title,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -339,10 +320,10 @@ void alx_w_getstr (char *dest, int destsize,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
waddstr(win2, "Introduce a string");
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -356,19 +337,12 @@ void alx_w_getstr (char *dest, int destsize,
alx_win_del(win3);
alx_win_del(win2);
alx_win_del(win1);
-
- /* End varargs */
- va_end(args);
}
void alx_w_getfname (const char *fpath, char *fname, bool exist,
int w, int r, const char *title,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -407,10 +381,10 @@ void alx_w_getfname (const char *fpath, char *fname, bool exist,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
waddstr(win2, "Introduce a file name");
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -424,9 +398,6 @@ void alx_w_getfname (const char *fpath, char *fname, bool exist,
alx_win_del(win3);
alx_win_del(win2);
alx_win_del(win1);
-
- /* End varargs */
- va_end(args);
}
void alx_ncur_prn_title (WINDOW *win, const char *title)
@@ -641,7 +612,7 @@ static void loop_w_getstr (char *dest, int destsize, WINDOW *win)
}
if (!err) {
- snprintf(dest, destsize, buff);
+ snprintf(dest, destsize, "%s", buff);
}
}