Lines Matching defs:gr
24 grid_reader_start(struct grid_reader *gr, struct grid *gd, u_int cx, u_int cy)
26 gr->gd = gd;
27 gr->cx = cx;
28 gr->cy = cy;
33 grid_reader_get_cursor(struct grid_reader *gr, u_int *cx, u_int *cy)
35 *cx = gr->cx;
36 *cy = gr->cy;
41 grid_reader_line_length(struct grid_reader *gr)
43 return (grid_line_length(gr->gd, gr->cy));
48 grid_reader_cursor_right(struct grid_reader *gr, int wrap, int all)
54 px = gr->gd->sx;
56 px = grid_reader_line_length(gr);
58 if (wrap && gr->cx >= px && gr->cy < gr->gd->hsize + gr->gd->sy - 1) {
59 grid_reader_cursor_start_of_line(gr, 0);
60 grid_reader_cursor_down(gr);
61 } else if (gr->cx < px) {
62 gr->cx++;
63 while (gr->cx < px) {
64 grid_get_cell(gr->gd, gr->cx, gr->cy, &gc);
67 gr->cx++;
74 grid_reader_cursor_left(struct grid_reader *gr, int wrap)
78 while (gr->cx > 0) {
79 grid_get_cell(gr->gd, gr->cx, gr->cy, &gc);
82 gr->cx--;
84 if (gr->cx == 0 && gr->cy > 0 &&
86 grid_get_line(gr->gd, gr->cy - 1)->flags & GRID_LINE_WRAPPED)) {
87 grid_reader_cursor_up(gr);
88 grid_reader_cursor_end_of_line(gr, 0, 0);
89 } else if (gr->cx > 0)
90 gr->cx--;
95 grid_reader_cursor_down(struct grid_reader *gr)
99 if (gr->cy < gr->gd->hsize + gr->gd->sy - 1)
100 gr->cy++;
101 while (gr->cx > 0) {
102 grid_get_cell(gr->gd, gr->cx, gr->cy, &gc);
105 gr->cx--;
111 grid_reader_cursor_up(struct grid_reader *gr)
115 if (gr->cy > 0)
116 gr->cy--;
117 while (gr->cx > 0) {
118 grid_get_cell(gr->gd, gr->cx, gr->cy, &gc);
121 gr->cx--;
127 grid_reader_cursor_start_of_line(struct grid_reader *gr, int wrap)
130 while (gr->cy > 0 &&
131 grid_get_line(gr->gd, gr->cy - 1)->flags &
133 gr->cy--;
135 gr->cx = 0;
140 grid_reader_cursor_end_of_line(struct grid_reader *gr, int wrap, int all)
145 yy = gr->gd->hsize + gr->gd->sy - 1;
146 while (gr->cy < yy && grid_get_line(gr->gd, gr->cy)->flags &
148 gr->cy++;
151 gr->cx = gr->gd->sx;
153 gr->cx = grid_reader_line_length(gr);
158 grid_reader_handle_wrap(struct grid_reader *gr, u_int *xx, u_int *yy)
165 while (gr->cx > *xx) {
166 if (gr->cy == *yy)
168 grid_reader_cursor_start_of_line(gr, 0);
169 grid_reader_cursor_down(gr);
171 if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
172 *xx = gr->gd->sx - 1;
174 *xx = grid_reader_line_length(gr);
181 grid_reader_in_set(struct grid_reader *gr, const char *set)
183 return (grid_in_set(gr->gd, gr->cx, gr->cy, set));
188 grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
193 if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
194 xx = gr->gd->sx - 1;
196 xx = grid_reader_line_length(gr);
197 yy = gr->gd->hsize + gr->gd->sy - 1;
209 if (!grid_reader_handle_wrap(gr, &xx, &yy))
211 if (!grid_reader_in_set(gr, WHITESPACE)) {
212 if (grid_reader_in_set(gr, separators)) {
214 gr->cx++;
215 while (grid_reader_handle_wrap(gr, &xx, &yy) &&
216 grid_reader_in_set(gr, separators) &&
217 !grid_reader_in_set(gr, WHITESPACE));
220 gr->cx++;
221 while (grid_reader_handle_wrap(gr, &xx, &yy) &&
222 !(grid_reader_in_set(gr, separators) ||
223 grid_reader_in_set(gr, WHITESPACE)));
226 while (grid_reader_handle_wrap(gr, &xx, &yy) &&
227 (width = grid_reader_in_set(gr, WHITESPACE)))
228 gr->cx += width;
233 grid_reader_cursor_next_word_end(struct grid_reader *gr, const char *separators)
238 if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
239 xx = gr->gd->sx - 1;
241 xx = grid_reader_line_length(gr);
242 yy = gr->gd->hsize + gr->gd->sy - 1;
255 while (grid_reader_handle_wrap(gr, &xx, &yy)) {
256 if (grid_reader_in_set(gr, WHITESPACE))
257 gr->cx++;
258 else if (grid_reader_in_set(gr, separators)) {
260 gr->cx++;
261 while (grid_reader_handle_wrap(gr, &xx, &yy) &&
262 grid_reader_in_set(gr, separators) &&
263 !grid_reader_in_set(gr, WHITESPACE));
267 gr->cx++;
268 while (grid_reader_handle_wrap(gr, &xx, &yy) &&
269 !(grid_reader_in_set(gr, WHITESPACE) ||
270 grid_reader_in_set(gr, separators)));
278 grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
284 if (already || grid_reader_in_set(gr, WHITESPACE)) {
286 if (gr->cx > 0) {
287 gr->cx--;
288 if (!grid_reader_in_set(gr, WHITESPACE)) {
290 !grid_reader_in_set(gr, separators);
294 if (gr->cy == 0)
296 grid_reader_cursor_up(gr);
297 grid_reader_cursor_end_of_line(gr, 0, 0);
300 if (stop_at_eol && gr->cx > 0) {
301 oldx = gr->cx;
302 gr->cx--;
303 at_eol = grid_reader_in_set(gr,
305 gr->cx = oldx;
314 word_is_letters = !grid_reader_in_set(gr, separators);
318 oldx = gr->cx;
319 oldy = gr->cy;
320 if (gr->cx == 0) {
321 if (gr->cy == 0 ||
322 (~grid_get_line(gr->gd, gr->cy - 1)->flags &
325 grid_reader_cursor_up(gr);
326 grid_reader_cursor_end_of_line(gr, 0, 1);
328 if (gr->cx > 0)
329 gr->cx--;
330 } while (!grid_reader_in_set(gr, WHITESPACE) &&
331 word_is_letters != grid_reader_in_set(gr, separators));
332 gr->cx = oldx;
333 gr->cy = oldy;
352 grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
357 px = gr->cx;
358 yy = gr->gd->hsize + gr->gd->sy - 1;
360 for (py = gr->cy; py <= yy; py++) {
361 xx = grid_line_length(gr->gd, py);
363 grid_get_cell(gr->gd, px, py, &gc);
365 gr->cx = px;
366 gr->cy = py;
373 !(grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED))
382 grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc)
387 xx = gr->cx + 1;
389 for (py = gr->cy + 1; py > 0; py--) {
391 grid_get_cell(gr->gd, px - 1, py - 1, &gc);
393 gr->cx = px - 1;
394 gr->cy = py - 1;
400 !(grid_get_line(gr->gd, py - 2)->flags & GRID_LINE_WRAPPED))
402 xx = grid_line_length(gr->gd, py - 2);
409 grid_reader_cursor_back_to_indentation(struct grid_reader *gr)
414 yy = gr->gd->hsize + gr->gd->sy - 1;
415 oldx = gr->cx;
416 oldy = gr->cy;
417 grid_reader_cursor_start_of_line(gr, 1);
419 for (py = gr->cy; py <= yy; py++) {
420 xx = grid_line_length(gr->gd, py);
422 grid_get_cell(gr->gd, px, py, &gc);
426 gr->cx = px;
427 gr->cy = py;
431 if (~grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED)
434 gr->cx = oldx;
435 gr->cy = oldy;