Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmpdcurses/pdcurses/addstr.c
3153 views
1
/* PDCurses */
2
3
#include <curspriv.h>
4
5
/*man-start**************************************************************
6
7
addstr
8
------
9
10
### Synopsis
11
12
int addstr(const char *str);
13
int addnstr(const char *str, int n);
14
int waddstr(WINDOW *win, const char *str);
15
int waddnstr(WINDOW *win, const char *str, int n);
16
int mvaddstr(int y, int x, const char *str);
17
int mvaddnstr(int y, int x, const char *str, int n);
18
int mvwaddstr(WINDOW *win, int y, int x, const char *str);
19
int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);
20
21
int addwstr(const wchar_t *wstr);
22
int addnwstr(const wchar_t *wstr, int n);
23
int waddwstr(WINDOW *win, const wchar_t *wstr);
24
int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
25
int mvaddwstr(int y, int x, const wchar_t *wstr);
26
int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
27
int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
28
int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
29
30
### Description
31
32
These routines write all the characters of the null-terminated string
33
str or wide-character string wstr to the given window. The
34
functionality is similar to calling waddch() once for each character
35
in the string; except that, when PDCurses is built with wide-
36
character support enabled, the narrow-character functions treat the
37
string as a multibyte string in the current locale, and convert it.
38
The routines with n as the last argument write at most n characters;
39
if n is negative, then the entire string will be added.
40
41
### Return Value
42
43
All functions return OK or ERR.
44
45
### Portability
46
X/Open ncurses NetBSD
47
addstr Y Y Y
48
waddstr Y Y Y
49
mvaddstr Y Y Y
50
mvwaddstr Y Y Y
51
addnstr Y Y Y
52
waddnstr Y Y Y
53
mvaddnstr Y Y Y
54
mvwaddnstr Y Y Y
55
addwstr Y Y Y
56
waddwstr Y Y Y
57
mvaddwstr Y Y Y
58
mvwaddwstr Y Y Y
59
addnwstr Y Y Y
60
waddnwstr Y Y Y
61
mvaddnwstr Y Y Y
62
mvwaddnwstr Y Y Y
63
64
**man-end****************************************************************/
65
66
int waddnstr(WINDOW *win, const char *str, int n)
67
{
68
int i = 0;
69
70
PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));
71
72
if (!win || !str)
73
return ERR;
74
75
while (str[i] && (i < n || n < 0))
76
{
77
#ifdef PDC_WIDE
78
wchar_t wch;
79
int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);
80
81
if (retval <= 0)
82
return OK;
83
84
i += retval;
85
#else
86
chtype wch = (unsigned char)(str[i++]);
87
#endif
88
if (waddch(win, wch) == ERR)
89
return ERR;
90
}
91
92
return OK;
93
}
94
95
int addstr(const char *str)
96
{
97
PDC_LOG(("addstr() - called: string=\"%s\"\n", str));
98
99
return waddnstr(stdscr, str, -1);
100
}
101
102
int addnstr(const char *str, int n)
103
{
104
PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n));
105
106
return waddnstr(stdscr, str, n);
107
}
108
109
int waddstr(WINDOW *win, const char *str)
110
{
111
PDC_LOG(("waddstr() - called: string=\"%s\"\n", str));
112
113
return waddnstr(win, str, -1);
114
}
115
116
int mvaddstr(int y, int x, const char *str)
117
{
118
PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
119
120
if (move(y, x) == ERR)
121
return ERR;
122
123
return waddnstr(stdscr, str, -1);
124
}
125
126
int mvaddnstr(int y, int x, const char *str, int n)
127
{
128
PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
129
y, x, str, n));
130
131
if (move(y, x) == ERR)
132
return ERR;
133
134
return waddnstr(stdscr, str, n);
135
}
136
137
int mvwaddstr(WINDOW *win, int y, int x, const char *str)
138
{
139
PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str));
140
141
if (wmove(win, y, x) == ERR)
142
return ERR;
143
144
return waddnstr(win, str, -1);
145
}
146
147
int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n)
148
{
149
PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
150
y, x, str, n));
151
152
if (wmove(win, y, x) == ERR)
153
return ERR;
154
155
return waddnstr(win, str, n);
156
}
157
158
#ifdef PDC_WIDE
159
int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
160
{
161
int i = 0;
162
163
PDC_LOG(("waddnwstr() - called\n"));
164
165
if (!win || !wstr)
166
return ERR;
167
168
while (wstr[i] && (i < n || n < 0))
169
{
170
chtype wch = wstr[i++];
171
172
if (waddch(win, wch) == ERR)
173
return ERR;
174
}
175
176
return OK;
177
}
178
179
int addwstr(const wchar_t *wstr)
180
{
181
PDC_LOG(("addwstr() - called\n"));
182
183
return waddnwstr(stdscr, wstr, -1);
184
}
185
186
int addnwstr(const wchar_t *wstr, int n)
187
{
188
PDC_LOG(("addnwstr() - called\n"));
189
190
return waddnwstr(stdscr, wstr, n);
191
}
192
193
int waddwstr(WINDOW *win, const wchar_t *wstr)
194
{
195
PDC_LOG(("waddwstr() - called\n"));
196
197
return waddnwstr(win, wstr, -1);
198
}
199
200
int mvaddwstr(int y, int x, const wchar_t *wstr)
201
{
202
PDC_LOG(("mvaddstr() - called\n"));
203
204
if (move(y, x) == ERR)
205
return ERR;
206
207
return waddnwstr(stdscr, wstr, -1);
208
}
209
210
int mvaddnwstr(int y, int x, const wchar_t *wstr, int n)
211
{
212
PDC_LOG(("mvaddnstr() - called\n"));
213
214
if (move(y, x) == ERR)
215
return ERR;
216
217
return waddnwstr(stdscr, wstr, n);
218
}
219
220
int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr)
221
{
222
PDC_LOG(("mvwaddstr() - called\n"));
223
224
if (wmove(win, y, x) == ERR)
225
return ERR;
226
227
return waddnwstr(win, wstr, -1);
228
}
229
230
int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
231
{
232
PDC_LOG(("mvwaddnstr() - called\n"));
233
234
if (wmove(win, y, x) == ERR)
235
return ERR;
236
237
return waddnwstr(win, wstr, n);
238
}
239
#endif
240
241