source: trunk/minix/lib/curses/prntscan.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 4.4 KB
Line 
1#include <string.h>
2#include <curses.h>
3#include "curspriv.h"
4
5static char printscanbuf[513]; /* buffer used during I/O */
6
7/****************************************************************/
8/* Wprintw(win,fmt,args) does a printf() in window 'win'. */
9/****************************************************************/
10int wprintw(WINDOW *win, const char *fmt, ...)
11{
12 va_list args;
13
14 va_start(args, fmt);
15 vsprintf(printscanbuf, fmt, args);
16 if (waddstr(win, printscanbuf) == ERR) return(ERR);
17 return(strlen(printscanbuf));
18}
19
20/****************************************************************/
21/* Printw(fmt,args) does a printf() in stdscr. */
22/****************************************************************/
23int printw(const char *fmt, ...)
24{
25 va_list args;
26
27 va_start(args, fmt);
28 vsprintf(printscanbuf, fmt, args);
29 if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
30 return(strlen(printscanbuf));
31} /* printw */
32
33/****************************************************************/
34/* Mvprintw(fmt,args) moves the stdscr cursor to a new posi- */
35/* tion, then does a printf() in stdscr. */
36/****************************************************************/
37int mvprintw(int y, int x, const char *fmt, ...)
38{
39 va_list args;
40
41 va_start(args, fmt);
42 if (wmove(stdscr, y, x) == ERR) return(ERR);
43 vsprintf(printscanbuf, fmt, args);
44 if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
45 return(strlen(printscanbuf));
46}
47
48/****************************************************************/
49/* Mvwprintw(win,fmt,args) moves the window 'win's cursor to */
50/* A new position, then does a printf() in window 'win'. */
51/****************************************************************/
52int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
53{
54 va_list args;
55
56 va_start(args, fmt);
57 if (wmove(win, y, x) == ERR) return(ERR);
58 vsprintf(printscanbuf, fmt, args);
59 if (waddstr(win, printscanbuf) == ERR) return(ERR);
60 return(strlen(printscanbuf));
61} /* mvwprintw */
62
63/****************************************************************/
64/* Wscanw(win,fmt,args) gets a string via window 'win', then */
65/* Scans the string using format 'fmt' to extract the values */
66/* And put them in the variables pointed to the arguments. */
67/****************************************************************/
68int wscanw(WINDOW *win, const char *fmt, ...)
69{
70 va_list args;
71
72 va_start(args, fmt);
73 wrefresh(win); /* set cursor */
74 if (wgetstr(win, printscanbuf) == ERR) /* get string */
75 return(ERR);
76 return(vsscanf(printscanbuf, fmt, args));
77} /* wscanw */
78
79/****************************************************************/
80/* Scanw(fmt,args) gets a string via stdscr, then scans the */
81/* String using format 'fmt' to extract the values and put them */
82/* In the variables pointed to the arguments. */
83/****************************************************************/
84int scanw(const char *fmt, ...)
85{
86 va_list args;
87
88 va_start(args, fmt);
89 wrefresh(stdscr); /* set cursor */
90 if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
91 return(ERR);
92 return(vsscanf(printscanbuf, fmt, args));
93} /* scanw */
94
95/****************************************************************/
96/* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi- */
97/* Tion, then gets a string via stdscr and scans the string */
98/* Using format 'fmt' to extract the values and put them in the */
99/* Variables pointed to the arguments. */
100/****************************************************************/
101int mvscanw(int y, int x, const char *fmt, ...)
102{
103 va_list args;
104
105 va_start(args, fmt);
106 if (wmove(stdscr, y, x) == ERR) return(ERR);
107 wrefresh(stdscr); /* set cursor */
108 if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
109 return(ERR);
110 return(vsscanf(printscanbuf, fmt, args));
111} /* mvscanw */
112
113/****************************************************************/
114/* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a */
115/* New position, then gets a string via 'win' and scans the */
116/* String using format 'fmt' to extract the values and put them */
117/* In the variables pointed to the arguments. */
118/****************************************************************/
119int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
120{
121 va_list args;
122
123 va_start(args, fmt);
124 if (wmove(win, y, x) == ERR) return(ERR);
125 wrefresh(win); /* set cursor */
126 if (wgetstr(win, printscanbuf) == ERR) /* get string */
127 return(ERR);
128 return(vsscanf(printscanbuf, fmt, args));
129} /* mvwscanw */
Note: See TracBrowser for help on using the repository browser.