X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_scanw.c;h=1ed36a5213296212581d90a07d32180c2dbef9ba;hp=637aa46ece01ab0921bb18216e9428f9999a1eb9;hb=d6c65d287166c3105ece4a5e3f3ec7af5a5f26a3;hpb=03f728e5bb3630a54fffc4a2ff2f8dbfcce9088e diff --git a/ncurses/base/lib_scanw.c b/ncurses/base/lib_scanw.c index 637aa46e..1ed36a52 100644 --- a/ncurses/base/lib_scanw.c +++ b/ncurses/base/lib_scanw.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2009,2011 Free Software Foundation, Inc. * + * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 1998-2009,2011 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 * @@ -40,21 +41,40 @@ #include -MODULE_ID("$Id: lib_scanw.c,v 1.13 2011/10/22 16:31:35 tom Exp $") +MODULE_ID("$Id: lib_scanw.c,v 1.19 2020/02/02 23:34:34 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, (int) 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,13 +82,13 @@ 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; @@ -76,31 +96,31 @@ wscanw(WINDOW *win, NCURSES_CONST char *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); }