1 /* Public Domain Curses */
5 RCSID("$Id: instr.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
13 int innstr(char *str, int n);
14 int winstr(WINDOW *win, char *str);
15 int winnstr(WINDOW *win, char *str, int n);
16 int mvinstr(int y, int x, char *str);
17 int mvinnstr(int y, int x, char *str, int n);
18 int mvwinstr(WINDOW *win, int y, int x, char *str);
19 int mvwinnstr(WINDOW *win, int y, int x, char *str, int n);
21 int inwstr(wchar_t *wstr);
22 int innwstr(wchar_t *wstr, int n);
23 int winwstr(WINDOW *win, wchar_t *wstr);
24 int winnwstr(WINDOW *win, wchar_t *wstr, int n);
25 int mvinwstr(int y, int x, wchar_t *wstr);
26 int mvinnwstr(int y, int x, wchar_t *wstr, int n);
27 int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr);
28 int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n);
31 These functions take characters (or wide characters) from the
32 current or specified position in the window, and return them as
33 a string in str (or wstr). Attributes are ignored. The functions
34 with n as the last argument return a string at most n characters
38 Upon successful completion, innstr(), mvinnstr(), mvwinnstr()
39 and winnstr() return the number of characters actually read into
40 the string; instr(), mvinstr(), mvwinstr() and winstr() return
41 OK. Otherwise, all these functions return ERR.
43 Portability X/Open BSD SYS V
61 **man-end****************************************************************/
63 int winnstr(WINDOW
*win
, char *str
, int n
)
71 if (winnwstr(win
, wstr
, n
) == ERR
)
74 return PDC_wcstombs(str
, wstr
, n
);
79 PDC_LOG(("winnstr() - called: n %d \n", n
));
84 if (n
< 0 || (win
->_curx
+ n
) > win
->_maxx
)
85 n
= win
->_maxx
- win
->_curx
;
87 src
= win
->_y
[win
->_cury
] + win
->_curx
;
89 for (i
= 0; i
< n
; i
++)
90 str
[i
] = src
[i
] & A_CHARTEXT
;
100 PDC_LOG(("instr() - called: string=\"%s\"\n", str
));
102 return (ERR
== winnstr(stdscr
, str
, stdscr
->_maxx
)) ? ERR
: OK
;
105 int winstr(WINDOW
*win
, char *str
)
107 PDC_LOG(("winstr() - called: \n"));
109 return (ERR
== winnstr(win
, str
, win
->_maxx
)) ? ERR
: OK
;
112 int mvinstr(int y
, int x
, char *str
)
114 PDC_LOG(("mvinstr() - called: y %d x %d \n", y
, x
));
116 if (move(y
, x
) == ERR
)
119 return (ERR
== winnstr(stdscr
, str
, stdscr
->_maxx
)) ? ERR
: OK
;
122 int mvwinstr(WINDOW
*win
, int y
, int x
, char *str
)
124 PDC_LOG(("mvwinstr() - called: y %d x %d \n", y
, x
));
126 if (wmove(win
, y
, x
) == ERR
)
129 return (ERR
== winnstr(win
, str
, win
->_maxx
)) ? ERR
: OK
;
132 int innstr(char *str
, int n
)
134 PDC_LOG(("innstr() - called: n %d \n", n
));
136 return winnstr(stdscr
, str
, n
);
139 int mvinnstr(int y
, int x
, char *str
, int n
)
141 PDC_LOG(("mvinnstr() - called: y %d x %d n %d \n", y
, x
, n
));
143 if (move(y
, x
) == ERR
)
146 return winnstr(stdscr
, str
, n
);
149 int mvwinnstr(WINDOW
*win
, int y
, int x
, char *str
, int n
)
151 PDC_LOG(("mvwinnstr() - called: y %d x %d n %d \n", y
, x
, n
));
153 if (wmove(win
, y
, x
) == ERR
)
156 return winnstr(win
, str
, n
);
160 int winnwstr(WINDOW
*win
, wchar_t *wstr
, int n
)
165 PDC_LOG(("winnstr() - called: n %d \n", n
));
170 if (n
< 0 || (win
->_curx
+ n
) > win
->_maxx
)
171 n
= win
->_maxx
- win
->_curx
;
173 src
= win
->_y
[win
->_cury
] + win
->_curx
;
175 for (i
= 0; i
< n
; i
++)
176 wstr
[i
] = src
[i
] & A_CHARTEXT
;
183 int inwstr(wchar_t *wstr
)
185 PDC_LOG(("inwstr() - called\n"));
187 return (ERR
== winnwstr(stdscr
, wstr
, stdscr
->_maxx
)) ? ERR
: OK
;
190 int winwstr(WINDOW
*win
, wchar_t *wstr
)
192 PDC_LOG(("winwstr() - called\n"));
194 return (ERR
== winnwstr(win
, wstr
, win
->_maxx
)) ? ERR
: OK
;
197 int mvinwstr(int y
, int x
, wchar_t *wstr
)
199 PDC_LOG(("mvinwstr() - called\n"));
201 if (move(y
, x
) == ERR
)
204 return (ERR
== winnwstr(stdscr
, wstr
, stdscr
->_maxx
)) ? ERR
: OK
;
207 int mvwinwstr(WINDOW
*win
, int y
, int x
, wchar_t *wstr
)
209 PDC_LOG(("mvwinstr() - called\n"));
211 if (wmove(win
, y
, x
) == ERR
)
214 return (ERR
== winnwstr(win
, wstr
, win
->_maxx
)) ? ERR
: OK
;
217 int innwstr(wchar_t *wstr
, int n
)
219 PDC_LOG(("innwstr() - called\n"));
221 return winnwstr(stdscr
, wstr
, n
);
224 int mvinnwstr(int y
, int x
, wchar_t *wstr
, int n
)
226 PDC_LOG(("mvinnstr() - called\n"));
228 if (move(y
, x
) == ERR
)
231 return winnwstr(stdscr
, wstr
, n
);
234 int mvwinnwstr(WINDOW
*win
, int y
, int x
, wchar_t *wstr
, int n
)
236 PDC_LOG(("mvwinnwstr() - called\n"));
238 if (wmove(win
, y
, x
) == ERR
)
241 return winnwstr(win
, wstr
, n
);