summaryrefslogtreecommitdiffstats
path: root/src/intrfn.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2012-01-01 18:44:44 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2012-01-01 18:44:44 +0100
commit7b769570102a1ef5323145123df86f22d2b97b13 (patch)
tree3fd7b0751ba95db9cbf58e8319a2c3d618bd5bc0 /src/intrfn.c
parente4429ca8c24234160bd28c05ad00d89633879640 (diff)
Add WINDOW *window argument to get_string()
Diffstat (limited to 'src/intrfn.c')
-rw-r--r--src/intrfn.c121
1 files changed, 61 insertions, 60 deletions
diff --git a/src/intrfn.c b/src/intrfn.c
index a3a32ba..8df69a7 100644
--- a/src/intrfn.c
+++ b/src/intrfn.c
@@ -86,70 +86,69 @@ extern int intr_nbr_line;
static int wmenuUpdate(WINDOW *window, const int yinfo, int y, int x, const struct MenuItem *menuItems, const unsigned int itemLength, const char *available, const int menuType, unsigned int current);
static int wgetch_nodelay(WINDOW *window);
-int get_string(char *str, const int len, const char *def)
+int get_string(WINDOW *window, char *str, const int len, const char *def)
{
- int c;
- int i = 0;
- int x, y;
- int use_def = FALSE;
- curs_set(1);
- getyx(stdscr, y, x);
- wclrtoeol(stdscr);
- str[0] = 0;
+ int c;
+ int i = 0;
+ int x, y;
+ int use_def = FALSE;
+ curs_set(1);
+ getyx(window, y, x);
+ str[0] = 0;
- if (def != NULL) {
- mvwaddstr(stdscr,y, x, def);
- wmove(stdscr,y, x);
- use_def = TRUE;
- }
+ if (def != NULL) {
+ mvwaddstr(window,y, x, def);
+ wmove(window,y, x);
+ use_def = TRUE;
+ }
- wrefresh(stdscr);
- while ((c = wgetch(stdscr)) != '\n' && c != key_CR
+ wrefresh(window);
+ while ((c = wgetch(window)) != '\n' && c != key_CR
#ifdef PADENTER
- && c!= PADENTER
+ && c!= PADENTER
#endif
- )
- {
- switch (c) {
- /* escape is generated by enter from keypad */
- /*
- case key_ESC:
- wmove(stdscr,y, x);
- wclrtoeol(stdscr);
- curs_set(0);
- wrefresh(stdscr);
- return GS_key_ESCAPE;
- */
- case KEY_DC:
- case KEY_BACKSPACE:
- if (i > 0) {
- str[--i] = 0;
- mvaddch(y, x+i, ' ');
- wmove(stdscr,y, x+i);
- } else if (use_def) {
- wclrtoeol(stdscr);
- use_def = FALSE;
- }
- break;
- default:
- if (i < len && isprint(c)) {
- mvaddch(y, x+i, c);
- if (use_def) {
- wclrtoeol(stdscr);
- use_def = FALSE;
- }
- str[i++] = c;
- str[i] = 0;
- }
- }
- wrefresh(stdscr);
+ )
+ {
+ switch (c) {
+ /* escape is generated by enter from keypad */
+ /*
+ case key_ESC:
+ wmove(window,y, x);
+ wclrtoeol(window);
+ curs_set(0);
+ wrefresh(window);
+ return GS_key_ESCAPE;
+ */
+ case KEY_DC:
+ case KEY_BACKSPACE:
+ if (i > 0) {
+ str[--i] = 0;
+ mvwaddch(window, y, x+i, ' ');
+ wmove(window,y, x+i);
+ } else if (use_def) {
+ wclrtoeol(window);
+ use_def = FALSE;
+ }
+ break;
+ default:
+ if (i < len && isprint(c)) {
+ mvwaddch(window, y, x+i, c);
+ if (use_def) {
+ wclrtoeol(window);
+ use_def = FALSE;
+ }
+ str[i++] = c;
+ str[i] = 0;
+ }
}
- curs_set(0);
- wrefresh(stdscr);
- if (use_def)
- return GS_DEFAULT;
- else
- return i;
+ wrefresh(window);
+ }
+ curs_set(0);
+ wrefresh(window);
+ if (use_def)
+ return GS_DEFAULT;
+ else
+ return i;
}
static int wgetch_nodelay(WINDOW *window)
@@ -555,8 +554,9 @@ unsigned long long int ask_number(const unsigned long long int val_cur, const un
va_end(ap);
waddstr(stdscr, res);
waddstr(stdscr, res2);
+ wclrtoeol(stdscr);
sprintf(def, "%llu", val_cur);
- if (get_string(response, sizeof(response), def) > 0)
+ if (get_string(stdscr, response, sizeof(response), def) > 0)
{
unsigned long int tmp_val;
#ifdef HAVE_ATOLL
@@ -1224,7 +1224,8 @@ char *ask_log_location(const char*filename)
wbkgdset(stdscr,' ' | COLOR_PAIR(0));
wmove(stdscr,9,0);
wprintw(stdscr,"to abort log file creation.\n");
- if (get_string(response, sizeof(response), NULL) > 0)
+ wclrtoeol(stdscr);
+ if (get_string(stdscr, response, sizeof(response), NULL) > 0)
return response;
return NULL;
}