Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmpdcurses/pdcurses/instr.c
3153 views
1
/* PDCurses */
2
3
#include <curspriv.h>
4
5
/*man-start**************************************************************
6
7
instr
8
-----
9
10
### Synopsis
11
12
int instr(char *str);
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);
20
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);
29
30
### Description
31
32
These functions take characters (or wide characters) from the current
33
or specified position in the window, and return them as a string in
34
str (or wstr). Attributes are ignored. The functions with n as the
35
last argument return a string at most n characters long.
36
37
### Return Value
38
39
Upon successful completion, innstr(), mvinnstr(), mvwinnstr() and
40
winnstr() return the number of characters actually read into the
41
string; instr(), mvinstr(), mvwinstr() and winstr() return OK.
42
Otherwise, all these functions return ERR.
43
44
### Portability
45
X/Open ncurses NetBSD
46
instr Y Y Y
47
winstr Y Y Y
48
mvinstr Y Y Y
49
mvwinstr Y Y Y
50
innstr Y Y Y
51
winnstr Y Y Y
52
mvinnstr Y Y Y
53
mvwinnstr Y Y Y
54
inwstr Y Y Y
55
winwstr Y Y Y
56
mvinwstr Y Y Y
57
mvwinwstr Y Y Y
58
innwstr Y Y Y
59
winnwstr Y Y Y
60
mvinnwstr Y Y Y
61
mvwinnwstr Y Y Y
62
63
**man-end****************************************************************/
64
65
int winnstr(WINDOW *win, char *str, int n)
66
{
67
#ifdef PDC_WIDE
68
wchar_t wstr[513];
69
70
if (n < 0 || n > 512)
71
n = 512;
72
73
if (winnwstr(win, wstr, n) == ERR)
74
return ERR;
75
76
return PDC_wcstombs(str, wstr, n);
77
#else
78
chtype *src;
79
int i;
80
81
PDC_LOG(("winnstr() - called: n %d \n", n));
82
83
if (!win || !str)
84
return ERR;
85
86
if (n < 0 || (win->_curx + n) > win->_maxx)
87
n = win->_maxx - win->_curx;
88
89
src = win->_y[win->_cury] + win->_curx;
90
91
for (i = 0; i < n; i++)
92
str[i] = src[i] & A_CHARTEXT;
93
94
str[i] = '\0';
95
96
return i;
97
#endif
98
}
99
100
int instr(char *str)
101
{
102
PDC_LOG(("instr() - called: string=\"%s\"\n", str));
103
104
return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
105
}
106
107
int winstr(WINDOW *win, char *str)
108
{
109
PDC_LOG(("winstr() - called: \n"));
110
111
return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
112
}
113
114
int mvinstr(int y, int x, char *str)
115
{
116
PDC_LOG(("mvinstr() - called: y %d x %d \n", y, x));
117
118
if (move(y, x) == ERR)
119
return ERR;
120
121
return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
122
}
123
124
int mvwinstr(WINDOW *win, int y, int x, char *str)
125
{
126
PDC_LOG(("mvwinstr() - called: y %d x %d \n", y, x));
127
128
if (wmove(win, y, x) == ERR)
129
return ERR;
130
131
return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
132
}
133
134
int innstr(char *str, int n)
135
{
136
PDC_LOG(("innstr() - called: n %d \n", n));
137
138
return winnstr(stdscr, str, n);
139
}
140
141
int mvinnstr(int y, int x, char *str, int n)
142
{
143
PDC_LOG(("mvinnstr() - called: y %d x %d n %d \n", y, x, n));
144
145
if (move(y, x) == ERR)
146
return ERR;
147
148
return winnstr(stdscr, str, n);
149
}
150
151
int mvwinnstr(WINDOW *win, int y, int x, char *str, int n)
152
{
153
PDC_LOG(("mvwinnstr() - called: y %d x %d n %d \n", y, x, n));
154
155
if (wmove(win, y, x) == ERR)
156
return ERR;
157
158
return winnstr(win, str, n);
159
}
160
161
#ifdef PDC_WIDE
162
int winnwstr(WINDOW *win, wchar_t *wstr, int n)
163
{
164
chtype *src;
165
int i;
166
167
PDC_LOG(("winnstr() - called: n %d \n", n));
168
169
if (!win || !wstr)
170
return ERR;
171
172
if (n < 0 || (win->_curx + n) > win->_maxx)
173
n = win->_maxx - win->_curx;
174
175
src = win->_y[win->_cury] + win->_curx;
176
177
for (i = 0; i < n; i++)
178
wstr[i] = src[i] & A_CHARTEXT;
179
180
wstr[i] = L'\0';
181
182
return i;
183
}
184
185
int inwstr(wchar_t *wstr)
186
{
187
PDC_LOG(("inwstr() - called\n"));
188
189
return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
190
}
191
192
int winwstr(WINDOW *win, wchar_t *wstr)
193
{
194
PDC_LOG(("winwstr() - called\n"));
195
196
return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
197
}
198
199
int mvinwstr(int y, int x, wchar_t *wstr)
200
{
201
PDC_LOG(("mvinwstr() - called\n"));
202
203
if (move(y, x) == ERR)
204
return ERR;
205
206
return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
207
}
208
209
int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr)
210
{
211
PDC_LOG(("mvwinstr() - called\n"));
212
213
if (wmove(win, y, x) == ERR)
214
return ERR;
215
216
return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
217
}
218
219
int innwstr(wchar_t *wstr, int n)
220
{
221
PDC_LOG(("innwstr() - called\n"));
222
223
return winnwstr(stdscr, wstr, n);
224
}
225
226
int mvinnwstr(int y, int x, wchar_t *wstr, int n)
227
{
228
PDC_LOG(("mvinnstr() - called\n"));
229
230
if (move(y, x) == ERR)
231
return ERR;
232
233
return winnwstr(stdscr, wstr, n);
234
}
235
236
int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n)
237
{
238
PDC_LOG(("mvwinnwstr() - called\n"));
239
240
if (wmove(win, y, x) == ERR)
241
return ERR;
242
243
return winnwstr(win, wstr, n);
244
}
245
#endif
246
247