]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_scanw.c
ncurses 6.1 - patch 20190810
[ncurses.git] / ncurses / base / lib_scanw.c
index b8a5a227a1a9929a8be2232ee754c17ac46d84e9..26a47d1abf559771582a8dbad0d7410c6c955592 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_scanw.c,v 1.11 2001/06/30 23:39:41 tom Exp $")
+MODULE_ID("$Id: lib_scanw.c,v 1.18 2019/01/19 15:46:25 tom Exp $")
 
 NCURSES_EXPORT(int)
-vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp)
+vwscanw(WINDOW *win, const char *fmt, va_list argp)
 {
     char buf[BUFSIZ];
+    int code = ERR;
 
-    if (wgetnstr(win, buf, sizeof(buf) - 1) == ERR)
-       return (ERR);
+    if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) {
+       if ((code = vsscanf(buf, fmt, argp)) == EOF) {
+           code = ERR;
+       }
+    }
 
-    return (vsscanf(buf, fmt, argp));
+    return code;
 }
 
 NCURSES_EXPORT(int)
-scanw(NCURSES_CONST char *fmt,...)
+vw_scanw(WINDOW *win, const char *fmt, va_list argp)
+{
+    char buf[BUFSIZ];
+    int code = ERR;
+
+    if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) {
+       if ((code = vsscanf(buf, fmt, argp)) == EOF) {
+           code = ERR;
+       }
+    }
+
+    return code;
+}
+
+NCURSES_EXPORT(int)
+scanw(const char *fmt, ...)
 {
     int code;
     va_list ap;
@@ -62,45 +81,45 @@ scanw(NCURSES_CONST char *fmt,...)
     T(("scanw(\"%s\",...) called", fmt));
 
     va_start(ap, fmt);
-    code = vwscanw(stdscr, fmt, ap);
+    code = vw_scanw(stdscr, fmt, ap);
     va_end(ap);
     return (code);
 }
 
 NCURSES_EXPORT(int)
-wscanw(WINDOW *win, NCURSES_CONST char *fmt,...)
+wscanw(WINDOW *win, const char *fmt, ...)
 {
     int code;
     va_list ap;
 
-    T(("wscanw(%p,\"%s\",...) called", win, fmt));
+    T(("wscanw(%p,\"%s\",...) called", (void *) win, fmt));
 
     va_start(ap, fmt);
-    code = vwscanw(win, fmt, ap);
+    code = vw_scanw(win, fmt, ap);
     va_end(ap);
     return (code);
 }
 
 NCURSES_EXPORT(int)
-mvscanw(int y, int x, NCURSES_CONST char *fmt,...)
+mvscanw(int y, int x, const char *fmt, ...)
 {
     int code;
     va_list ap;
 
     va_start(ap, fmt);
-    code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR;
+    code = (move(y, x) == OK) ? vw_scanw(stdscr, fmt, ap) : ERR;
     va_end(ap);
     return (code);
 }
 
 NCURSES_EXPORT(int)
-mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...)
+mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
 {
     int code;
     va_list ap;
 
     va_start(ap, fmt);
-    code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR;
+    code = (wmove(win, y, x) == OK) ? vw_scanw(win, fmt, ap) : ERR;
     va_end(ap);
     return (code);
 }