pdcurses/addchstr.c

changeset 97
2d43f05b284c
equal deleted inserted replaced
96:5314ebdcb38d 97:2d43f05b284c
1 /* Public Domain Curses */
2
3 #include <curspriv.h>
4
5 RCSID("$Id: addchstr.c,v 1.43 2008/07/13 16:08:17 wmcbrine Exp $")
6
7 /*man-start**************************************************************
8
9 Name: addchstr
10
11 Synopsis:
12 int addchstr(const chtype *ch);
13 int addchnstr(const chtype *ch, int n);
14 int waddchstr(WINDOW *win, const chtype *ch);
15 int waddchnstr(WINDOW *win, const chtype *ch, int n);
16 int mvaddchstr(int y, int x, const chtype *ch);
17 int mvaddchnstr(int y, int x, const chtype *ch, int n);
18 int mvwaddchstr(WINDOW *, int y, int x, const chtype *ch);
19 int mvwaddchnstr(WINDOW *, int y, int x, const chtype *ch, int n);
20
21 int add_wchstr(const cchar_t *wch);
22 int add_wchnstr(const cchar_t *wch, int n);
23 int wadd_wchstr(WINDOW *win, const cchar_t *wch);
24 int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n);
25 int mvadd_wchstr(int y, int x, const cchar_t *wch);
26 int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n);
27 int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch);
28 int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch,
29 int n);
30
31 Description:
32 These routines write a chtype or cchar_t string directly into
33 the window structure, starting at the current or specified
34 position. The four routines with n as the last argument copy at
35 most n elements, but no more than will fit on the line. If n =
36 -1 then the whole string is copied, up to the maximum number
37 that will fit on the line.
38
39 The cursor position is not advanced. These routines do not check
40 for newline or other special characters, nor does any line
41 wrapping occur.
42
43 Return Value:
44 All functions return OK or ERR.
45
46 Portability X/Open BSD SYS V
47 addchstr Y - 4.0
48 waddchstr Y - 4.0
49 mvaddchstr Y - 4.0
50 mvwaddchstr Y - 4.0
51 addchnstr Y - 4.0
52 waddchnstr Y - 4.0
53 mvaddchnstr Y - 4.0
54 mvwaddchnstr Y - 4.0
55 add_wchstr Y
56 wadd_wchstr Y
57 mvadd_wchstr Y
58 mvwadd_wchstr Y
59 add_wchnstr Y
60 wadd_wchnstr Y
61 mvadd_wchnstr Y
62 mvwadd_wchnstr Y
63
64 **man-end****************************************************************/
65
66 #include <string.h>
67
68 int waddchnstr(WINDOW *win, const chtype *ch, int n)
69 {
70 int y, x, maxx, minx;
71 chtype *ptr;
72
73 PDC_LOG(("waddchnstr() - called: win=%p n=%d\n", win, n));
74
75 if (!win || !ch || !n || n < -1)
76 return ERR;
77
78 x = win->_curx;
79 y = win->_cury;
80 ptr = &(win->_y[y][x]);
81
82 if (n == -1 || n > win->_maxx - x)
83 n = win->_maxx - x;
84
85 minx = win->_firstch[y];
86 maxx = win->_lastch[y];
87
88 for (; n && *ch; n--, x++, ptr++, ch++)
89 {
90 if (*ptr != *ch)
91 {
92 if (x < minx || minx == _NO_CHANGE)
93 minx = x;
94
95 if (x > maxx)
96 maxx = x;
97
98 PDC_LOG(("y %d x %d minx %d maxx %d *ptr %x *ch"
99 " %x firstch: %d lastch: %d\n",
100 y, x, minx, maxx, *ptr, *ch,
101 win->_firstch[y], win->_lastch[y]));
102
103 *ptr = *ch;
104 }
105 }
106
107 win->_firstch[y] = minx;
108 win->_lastch[y] = maxx;
109
110 return OK;
111 }
112
113 int addchstr(const chtype *ch)
114 {
115 PDC_LOG(("addchstr() - called\n"));
116
117 return waddchnstr(stdscr, ch, -1);
118 }
119
120 int addchnstr(const chtype *ch, int n)
121 {
122 PDC_LOG(("addchnstr() - called\n"));
123
124 return waddchnstr(stdscr, ch, n);
125 }
126
127 int waddchstr(WINDOW *win, const chtype *ch)
128 {
129 PDC_LOG(("waddchstr() - called: win=%p\n", win));
130
131 return waddchnstr(win, ch, -1);
132 }
133
134 int mvaddchstr(int y, int x, const chtype *ch)
135 {
136 PDC_LOG(("mvaddchstr() - called: y %d x %d\n", y, x));
137
138 if (move(y, x) == ERR)
139 return ERR;
140
141 return waddchnstr(stdscr, ch, -1);
142 }
143
144 int mvaddchnstr(int y, int x, const chtype *ch, int n)
145 {
146 PDC_LOG(("mvaddchnstr() - called: y %d x %d n %d\n", y, x, n));
147
148 if (move(y, x) == ERR)
149 return ERR;
150
151 return waddchnstr(stdscr, ch, n);
152 }
153
154 int mvwaddchstr(WINDOW *win, int y, int x, const chtype *ch)
155 {
156 PDC_LOG(("mvwaddchstr() - called:\n"));
157
158 if (wmove(win, y, x) == ERR)
159 return ERR;
160
161 return waddchnstr(win, ch, -1);
162 }
163
164 int mvwaddchnstr(WINDOW *win, int y, int x, const chtype *ch, int n)
165 {
166 PDC_LOG(("mvwaddchnstr() - called: y %d x %d n %d \n", y, x, n));
167
168 if (wmove(win, y, x) == ERR)
169 return ERR;
170
171 return waddchnstr(win, ch, n);
172 }
173
174 #ifdef PDC_WIDE
175 int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n)
176 {
177 PDC_LOG(("wadd_wchnstr() - called: win=%p n=%d\n", win, n));
178
179 return waddchnstr(win, wch, n);
180 }
181
182 int add_wchstr(const cchar_t *wch)
183 {
184 PDC_LOG(("add_wchstr() - called\n"));
185
186 return wadd_wchnstr(stdscr, wch, -1);
187 }
188
189 int add_wchnstr(const cchar_t *wch, int n)
190 {
191 PDC_LOG(("add_wchnstr() - called\n"));
192
193 return wadd_wchnstr(stdscr, wch, n);
194 }
195
196 int wadd_wchstr(WINDOW *win, const cchar_t *wch)
197 {
198 PDC_LOG(("wadd_wchstr() - called: win=%p\n", win));
199
200 return wadd_wchnstr(win, wch, -1);
201 }
202
203 int mvadd_wchstr(int y, int x, const cchar_t *wch)
204 {
205 PDC_LOG(("mvadd_wchstr() - called: y %d x %d\n", y, x));
206
207 if (move(y, x) == ERR)
208 return ERR;
209
210 return wadd_wchnstr(stdscr, wch, -1);
211 }
212
213 int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n)
214 {
215 PDC_LOG(("mvadd_wchnstr() - called: y %d x %d n %d\n", y, x, n));
216
217 if (move(y, x) == ERR)
218 return ERR;
219
220 return wadd_wchnstr(stdscr, wch, n);
221 }
222
223 int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch)
224 {
225 PDC_LOG(("mvwadd_wchstr() - called:\n"));
226
227 if (wmove(win, y, x) == ERR)
228 return ERR;
229
230 return wadd_wchnstr(win, wch, -1);
231 }
232
233 int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, int n)
234 {
235 PDC_LOG(("mvwadd_wchnstr() - called: y %d x %d n %d \n", y, x, n));
236
237 if (wmove(win, y, x) == ERR)
238 return ERR;
239
240 return wadd_wchnstr(win, wch, n);
241 }
242 #endif

mercurial