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