[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <unistd.h> |
---|
| 4 | #include <string.h> |
---|
[10b866d] | 5 | #include <ctype.h> |
---|
[7d4fbcd] | 6 | |
---|
[ebf0128] | 7 | #define VALID_EXCURSION (0x9a2b4729) |
---|
| 8 | |
---|
[a88f35a] | 9 | typedef struct _owl_editwin_excursion { /*noproto*/ |
---|
[ebf0128] | 10 | int valid; |
---|
| 11 | int index; |
---|
[16cfd12a] | 12 | int mark; |
---|
[ebf0128] | 13 | int goal_column; |
---|
| 14 | int lock; |
---|
[a88f35a] | 15 | struct _owl_editwin_excursion *next; |
---|
[ebf0128] | 16 | } oe_excursion; |
---|
| 17 | |
---|
[a556caa] | 18 | struct _owl_editwin { /*noproto*/ |
---|
| 19 | char *buff; |
---|
| 20 | owl_history *hist; |
---|
| 21 | int bufflen; |
---|
| 22 | int allocated; |
---|
| 23 | int index; |
---|
[16cfd12a] | 24 | int mark; |
---|
[a60edf2] | 25 | char *killbuf; |
---|
[a556caa] | 26 | int goal_column; |
---|
| 27 | int topindex; |
---|
[ebf0128] | 28 | int cursorx; |
---|
[a556caa] | 29 | int winlines, wincols, fillcol, wrapcol; |
---|
| 30 | WINDOW *curswin; |
---|
| 31 | int style; |
---|
| 32 | int lock; |
---|
| 33 | int dotsend; |
---|
| 34 | int echochar; |
---|
[ebf0128] | 35 | oe_excursion *excursions; |
---|
[a556caa] | 36 | |
---|
| 37 | void (*callback)(struct _owl_editwin*); |
---|
[1b1cd2c] | 38 | void (*destroy_cbdata)(void *); |
---|
[a556caa] | 39 | void *cbdata; |
---|
| 40 | }; |
---|
| 41 | |
---|
[e20d8179] | 42 | static void oe_reframe(owl_editwin *e); |
---|
[bab52da] | 43 | static void oe_save_excursion(owl_editwin *e, oe_excursion *x); |
---|
[ebf0128] | 44 | static void oe_release_excursion(owl_editwin *e, oe_excursion *x); |
---|
[bab52da] | 45 | static void oe_restore_excursion(owl_editwin *e, oe_excursion *x); |
---|
[a60edf2] | 46 | static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x); |
---|
[ebf0128] | 47 | static int oe_char_width(gunichar c, int column); |
---|
[16cfd12a] | 48 | static int oe_region_width(owl_editwin *e, int start, int end, int width); |
---|
[bab52da] | 49 | static int oe_find_display_line(owl_editwin *e, int *x, int index); |
---|
[ebf0128] | 50 | static void oe_insert_char(owl_editwin *e, gunichar c); |
---|
[bab52da] | 51 | static int owl_editwin_limit_maxcols(int v, int maxv); |
---|
| 52 | static int owl_editwin_check_dotsend(owl_editwin *e); |
---|
[e19eb97] | 53 | static int owl_editwin_is_char_in(owl_editwin *e, const char *set); |
---|
[bab52da] | 54 | static gunichar owl_editwin_get_char_at_point(owl_editwin *e); |
---|
[e19eb97] | 55 | static int owl_editwin_replace_internal(owl_editwin *e, int replace, const char *s); |
---|
| 56 | static const char *oe_copy_buf(owl_editwin *e, const char *buf, int len); |
---|
[a60edf2] | 57 | static int oe_copy_region(owl_editwin *e); |
---|
[77f605d] | 58 | static char *oe_chunk(owl_editwin *e, int start, int end); |
---|
[1b1cd2c] | 59 | static void oe_destroy_cbdata(owl_editwin *e); |
---|
[bab52da] | 60 | |
---|
[5b5f3e6] | 61 | #define INCR 4096 |
---|
[7d4fbcd] | 62 | |
---|
[a556caa] | 63 | #define WHITESPACE " \n\t" |
---|
| 64 | |
---|
[38cc669] | 65 | static owl_editwin *owl_editwin_allocate(void) |
---|
[bab52da] | 66 | { |
---|
[8321cb7] | 67 | owl_editwin *e; |
---|
| 68 | e = owl_malloc(sizeof(owl_editwin)); |
---|
| 69 | memset(e, 0, sizeof(*e)); |
---|
| 70 | return e; |
---|
[a556caa] | 71 | } |
---|
| 72 | |
---|
[30bb10a] | 73 | void owl_editwin_delete(owl_editwin *e) |
---|
[6211c76] | 74 | { |
---|
| 75 | owl_free(e->buff); |
---|
| 76 | owl_free(e->killbuf); |
---|
| 77 | /* just in case someone forgot to clean up */ |
---|
| 78 | while (e->excursions) { |
---|
| 79 | oe_release_excursion(e, e->excursions); |
---|
| 80 | } |
---|
[38cc669] | 81 | oe_destroy_cbdata(e); |
---|
[6211c76] | 82 | |
---|
| 83 | owl_free(e); |
---|
| 84 | } |
---|
| 85 | |
---|
[bab52da] | 86 | static inline void oe_set_index(owl_editwin *e, int index) |
---|
| 87 | { |
---|
[ebf0128] | 88 | if (index != e->index) { |
---|
| 89 | e->goal_column = -1; |
---|
| 90 | e->cursorx = -1; |
---|
| 91 | } |
---|
[521bc84] | 92 | e->index = index; |
---|
| 93 | } |
---|
| 94 | |
---|
[7f0c26f] | 95 | static inline void oe_set_mark(owl_editwin *e, int mark) |
---|
| 96 | { |
---|
| 97 | e->mark = mark; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | void owl_editwin_set_mark(owl_editwin *e) |
---|
| 101 | { |
---|
| 102 | oe_set_mark(e, e->index); |
---|
| 103 | /* owl_function_makemsg("Mark set."); */ |
---|
| 104 | } |
---|
| 105 | |
---|
[38cc669] | 106 | static void _owl_editwin_init(owl_editwin *e, |
---|
| 107 | WINDOW *win, |
---|
| 108 | int winlines, |
---|
| 109 | int wincols, |
---|
| 110 | int style, |
---|
| 111 | owl_history *hist) |
---|
[c9334b1] | 112 | { |
---|
[e20d8179] | 113 | e->buff=owl_malloc(INCR); |
---|
[7d4fbcd] | 114 | e->buff[0]='\0'; |
---|
| 115 | e->bufflen=0; |
---|
[10b866d] | 116 | e->hist=hist; |
---|
[7d4fbcd] | 117 | e->allocated=INCR; |
---|
[521bc84] | 118 | oe_set_index(e, 0); |
---|
[7f0c26f] | 119 | oe_set_mark(e, -1); |
---|
[a60edf2] | 120 | if (e->killbuf != NULL) |
---|
[27f6487] | 121 | owl_free(e->killbuf); |
---|
[a60edf2] | 122 | e->killbuf = NULL; |
---|
[a556caa] | 123 | e->goal_column = -1; |
---|
[ebf0128] | 124 | e->cursorx = -1; |
---|
| 125 | e->topindex = 0; |
---|
| 126 | e->excursions = NULL; |
---|
| 127 | owl_editwin_set_curswin(e, win, winlines, wincols); |
---|
[7d4fbcd] | 128 | e->style=style; |
---|
| 129 | if ((style!=OWL_EDITWIN_STYLE_MULTILINE) && |
---|
| 130 | (style!=OWL_EDITWIN_STYLE_ONELINE)) { |
---|
| 131 | e->style=OWL_EDITWIN_STYLE_MULTILINE; |
---|
| 132 | } |
---|
| 133 | e->lock=0; |
---|
| 134 | e->dotsend=0; |
---|
[c9334b1] | 135 | e->echochar='\0'; |
---|
[e74c01c] | 136 | |
---|
[7d4fbcd] | 137 | if (win) werase(win); |
---|
| 138 | } |
---|
| 139 | |
---|
[38cc669] | 140 | owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist) |
---|
| 141 | { |
---|
| 142 | owl_editwin *e = owl_editwin_allocate(); |
---|
| 143 | |
---|
| 144 | _owl_editwin_init(e, win, winlines, wincols, style, hist); |
---|
| 145 | return e; |
---|
| 146 | } |
---|
| 147 | |
---|
[c9334b1] | 148 | void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols) |
---|
| 149 | { |
---|
[7d4fbcd] | 150 | e->curswin=w; |
---|
| 151 | e->winlines=winlines; |
---|
| 152 | e->wincols=wincols; |
---|
[9a6cc40] | 153 | e->fillcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxfillcols(&g)); |
---|
| 154 | e->wrapcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxwrapcols(&g)); |
---|
[7d4fbcd] | 155 | } |
---|
| 156 | |
---|
[c9334b1] | 157 | /* echo the character 'ch' for each normal character keystroke, |
---|
| 158 | * excepting locktext. This is useful for entering passwords etc. If |
---|
| 159 | * ch=='\0' characters are echo'd normally |
---|
| 160 | */ |
---|
| 161 | void owl_editwin_set_echochar(owl_editwin *e, int ch) |
---|
| 162 | { |
---|
| 163 | e->echochar=ch; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | WINDOW *owl_editwin_get_curswin(owl_editwin *e) |
---|
| 167 | { |
---|
[060b3b4] | 168 | return(e->curswin); |
---|
[7d4fbcd] | 169 | } |
---|
| 170 | |
---|
[c9334b1] | 171 | owl_history *owl_editwin_get_history(owl_editwin *e) |
---|
| 172 | { |
---|
[060b3b4] | 173 | return(e->hist); |
---|
[10b866d] | 174 | } |
---|
| 175 | |
---|
[c9334b1] | 176 | void owl_editwin_set_dotsend(owl_editwin *e) |
---|
| 177 | { |
---|
[7d4fbcd] | 178 | e->dotsend=1; |
---|
| 179 | } |
---|
| 180 | |
---|
[bab52da] | 181 | void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*)) |
---|
| 182 | { |
---|
[e74c01c] | 183 | e->callback = cb; |
---|
| 184 | } |
---|
| 185 | |
---|
[bab52da] | 186 | void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin*) |
---|
| 187 | { |
---|
[e74c01c] | 188 | return e->callback; |
---|
| 189 | } |
---|
| 190 | |
---|
[1b1cd2c] | 191 | static void oe_destroy_cbdata(owl_editwin *e) { |
---|
| 192 | if (e->destroy_cbdata) |
---|
| 193 | e->destroy_cbdata(e->cbdata); |
---|
| 194 | e->cbdata = NULL; |
---|
| 195 | e->destroy_cbdata = NULL; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | void owl_editwin_set_cbdata(owl_editwin *e, void *data, void (*destroy)(void *)) |
---|
[bab52da] | 199 | { |
---|
[1b1cd2c] | 200 | oe_destroy_cbdata(e); |
---|
[e74c01c] | 201 | e->cbdata = data; |
---|
[1b1cd2c] | 202 | e->destroy_cbdata = destroy; |
---|
[e74c01c] | 203 | } |
---|
| 204 | |
---|
[a556caa] | 205 | void *owl_editwin_get_cbdata(owl_editwin *e) { |
---|
[e74c01c] | 206 | return e->cbdata; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void owl_editwin_do_callback(owl_editwin *e) { |
---|
| 210 | void (*cb)(owl_editwin*); |
---|
| 211 | cb=owl_editwin_get_callback(e); |
---|
| 212 | if(!cb) { |
---|
| 213 | owl_function_error("Internal error: No editwin callback!"); |
---|
| 214 | } else { |
---|
[af1920fd] | 215 | /* owl_function_error("text: |%s|", owl_editwin_get_text(e)); */ |
---|
[e74c01c] | 216 | cb(e); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
[bab52da] | 220 | static int owl_editwin_limit_maxcols(int v, int maxv) |
---|
[c9334b1] | 221 | { |
---|
[ebf0128] | 222 | /* maxv > 5 ? MAX(v, vax) : v */ |
---|
[d36f2cb] | 223 | if (maxv > 5 && v > maxv) { |
---|
[060b3b4] | 224 | return(maxv); |
---|
[d36f2cb] | 225 | } else { |
---|
[060b3b4] | 226 | return(v); |
---|
[d36f2cb] | 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
[c9334b1] | 230 | /* set text to be 'locked in' at the beginning of the buffer, any |
---|
| 231 | * previous text (including locked text) will be overwritten |
---|
| 232 | */ |
---|
[e19eb97] | 233 | void owl_editwin_set_locktext(owl_editwin *e, const char *text) |
---|
[c9334b1] | 234 | { |
---|
[521bc84] | 235 | oe_set_index(e, 0); |
---|
[5b5f3e6] | 236 | e->lock = 0; |
---|
| 237 | owl_editwin_replace(e, e->bufflen, text); |
---|
| 238 | e->buff[e->bufflen] = 0; |
---|
| 239 | e->lock=e->bufflen; |
---|
[521bc84] | 240 | oe_set_index(e, e->lock); |
---|
[2ee9e8d] | 241 | owl_editwin_redisplay(e); |
---|
[7d4fbcd] | 242 | } |
---|
| 243 | |
---|
[c9334b1] | 244 | int owl_editwin_get_style(owl_editwin *e) |
---|
| 245 | { |
---|
[7d4fbcd] | 246 | return(e->style); |
---|
| 247 | } |
---|
| 248 | |
---|
[c9334b1] | 249 | /* clear all text except for locktext and put the cursor at the |
---|
| 250 | * beginning |
---|
| 251 | */ |
---|
| 252 | void owl_editwin_clear(owl_editwin *e) |
---|
| 253 | { |
---|
| 254 | |
---|
[6073462] | 255 | int lock = e->lock; |
---|
[10b866d] | 256 | int dotsend=e->dotsend; |
---|
[7d4fbcd] | 257 | char *locktext=NULL; |
---|
[cc6f009] | 258 | char echochar=e->echochar; |
---|
[10b866d] | 259 | |
---|
[6073462] | 260 | if (lock > 0) { |
---|
[5b5f3e6] | 261 | locktext = owl_malloc(lock+1); |
---|
| 262 | strncpy(locktext, e->buff, lock); |
---|
| 263 | locktext[lock] = 0; |
---|
[7d4fbcd] | 264 | } |
---|
| 265 | |
---|
| 266 | owl_free(e->buff); |
---|
[38cc669] | 267 | _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist); |
---|
[7d4fbcd] | 268 | |
---|
| 269 | if (lock > 0) { |
---|
| 270 | owl_editwin_set_locktext(e, locktext); |
---|
| 271 | } |
---|
[10b866d] | 272 | if (dotsend) { |
---|
| 273 | owl_editwin_set_dotsend(e); |
---|
| 274 | } |
---|
[cc6f009] | 275 | if (echochar) { |
---|
| 276 | owl_editwin_set_echochar(e, echochar); |
---|
| 277 | } |
---|
[7d4fbcd] | 278 | |
---|
[5b5f3e6] | 279 | if (locktext) |
---|
| 280 | owl_free(locktext); |
---|
[6073462] | 281 | |
---|
[521bc84] | 282 | oe_set_index(e, lock); |
---|
[7d4fbcd] | 283 | } |
---|
| 284 | |
---|
[c9334b1] | 285 | void owl_editwin_recenter(owl_editwin *e) |
---|
| 286 | { |
---|
[a556caa] | 287 | e->topindex = -1; |
---|
| 288 | } |
---|
[e20d8179] | 289 | |
---|
[a0fbdee] | 290 | static void oe_save_excursion(owl_editwin *e, oe_excursion *x) |
---|
| 291 | { |
---|
| 292 | x->index = e->index; |
---|
[7f0c26f] | 293 | x->mark = e->mark; |
---|
[a0fbdee] | 294 | x->goal_column = e->goal_column; |
---|
| 295 | x->lock = e->lock; |
---|
[ebf0128] | 296 | |
---|
| 297 | x->valid = VALID_EXCURSION; |
---|
| 298 | x->next = e->excursions; |
---|
| 299 | e->excursions = x; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | static void oe_release_excursion(owl_editwin *e, oe_excursion *x) |
---|
| 303 | { |
---|
[a85d225] | 304 | oe_excursion **px; |
---|
[ebf0128] | 305 | |
---|
| 306 | x->valid = 0; |
---|
[a85d225] | 307 | for (px = &e->excursions; *px != NULL; px = &(*px)->next) |
---|
| 308 | if (*px == x) { |
---|
| 309 | *px = x->next; |
---|
| 310 | return; |
---|
| 311 | } |
---|
| 312 | abort(); |
---|
[a0fbdee] | 313 | } |
---|
| 314 | |
---|
| 315 | static void oe_restore_excursion(owl_editwin *e, oe_excursion *x) |
---|
| 316 | { |
---|
[ebf0128] | 317 | if (x->valid == VALID_EXCURSION) { |
---|
| 318 | oe_set_index(e, x->index); |
---|
| 319 | e->goal_column = x->goal_column; |
---|
[7f0c26f] | 320 | e->mark = x->mark; |
---|
[ebf0128] | 321 | e->lock = x->lock; |
---|
| 322 | |
---|
| 323 | oe_release_excursion(e, x); |
---|
| 324 | } |
---|
[a0fbdee] | 325 | } |
---|
| 326 | |
---|
[a60edf2] | 327 | static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x) |
---|
| 328 | { |
---|
| 329 | if (x->valid == VALID_EXCURSION) { |
---|
| 330 | e->mark = x->mark; |
---|
| 331 | |
---|
| 332 | oe_release_excursion(e, x); |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | |
---|
[a88f35a] | 336 | /* External interface to oe_save_excursion */ |
---|
| 337 | owl_editwin_excursion *owl_editwin_begin_excursion(owl_editwin *e) |
---|
| 338 | { |
---|
| 339 | owl_editwin_excursion *x = owl_malloc(sizeof *x); |
---|
| 340 | oe_save_excursion(e, x); |
---|
| 341 | return x; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | void owl_editwin_end_excursion(owl_editwin *e, owl_editwin_excursion *x) |
---|
| 345 | { |
---|
| 346 | oe_restore_excursion(e, x); |
---|
| 347 | owl_free(x); |
---|
| 348 | } |
---|
| 349 | |
---|
[e19eb97] | 350 | static inline const char *oe_next_point(owl_editwin *e, const char *p) |
---|
[e20d8179] | 351 | { |
---|
[e19eb97] | 352 | const char *boundary = e->buff + e->bufflen + 1; |
---|
| 353 | const char *q; |
---|
[e20d8179] | 354 | |
---|
| 355 | q = g_utf8_find_next_char(p, boundary); |
---|
| 356 | while (q && g_unichar_ismark(g_utf8_get_char(q))) |
---|
| 357 | q = g_utf8_find_next_char(q, boundary); |
---|
| 358 | |
---|
| 359 | if (q == p) |
---|
| 360 | return NULL; |
---|
| 361 | return q; |
---|
| 362 | } |
---|
| 363 | |
---|
[e19eb97] | 364 | static inline const char *oe_prev_point(owl_editwin *e, const char *p) |
---|
[e20d8179] | 365 | { |
---|
[e19eb97] | 366 | const char *boundary = e->buff + e->lock; |
---|
[e20d8179] | 367 | |
---|
| 368 | p = g_utf8_find_prev_char(boundary, p); |
---|
| 369 | while (p && g_unichar_ismark(g_utf8_get_char(p))) |
---|
| 370 | p = g_utf8_find_prev_char(boundary, p); |
---|
| 371 | |
---|
| 372 | return p; |
---|
| 373 | } |
---|
| 374 | |
---|
[ebf0128] | 375 | static int oe_char_width(gunichar c, int column) |
---|
| 376 | { |
---|
| 377 | int cw; |
---|
| 378 | |
---|
| 379 | if (c == 9) /* TAB */ |
---|
| 380 | return TABSIZE - column % TABSIZE; |
---|
| 381 | |
---|
| 382 | cw = mk_wcwidth(c); |
---|
| 383 | |
---|
| 384 | if (cw < 0) /* control characters */ |
---|
| 385 | cw = 0; |
---|
| 386 | |
---|
| 387 | return cw; |
---|
| 388 | } |
---|
| 389 | |
---|
[19f765d] | 390 | static int oe_find_display_line(owl_editwin *e, int *x, int index) |
---|
| 391 | { |
---|
| 392 | int width = 0, cw; |
---|
[ebf0128] | 393 | gunichar c; |
---|
[e19eb97] | 394 | const char *p; |
---|
[19f765d] | 395 | |
---|
[77d4402] | 396 | while(1) { |
---|
| 397 | /* note the position of the dot */ |
---|
[2021bea] | 398 | if (x != NULL && index == e->index && width < e->wincols) |
---|
[19f765d] | 399 | *x = width; |
---|
[77d4402] | 400 | |
---|
[19f765d] | 401 | /* get the current character */ |
---|
| 402 | c = g_utf8_get_char(e->buff + index); |
---|
| 403 | |
---|
| 404 | /* figure out how wide it is */ |
---|
[ebf0128] | 405 | cw = oe_char_width(c, width); |
---|
[19f765d] | 406 | |
---|
[77d4402] | 407 | if (width + cw > e->wincols) { |
---|
| 408 | if (x != NULL && *x == width) |
---|
| 409 | *x = -1; |
---|
[19f765d] | 410 | break; |
---|
[77d4402] | 411 | } |
---|
[19f765d] | 412 | width += cw; |
---|
| 413 | |
---|
| 414 | if (c == '\n') { |
---|
[77d4402] | 415 | if (width < e->wincols) |
---|
| 416 | ++index; /* skip the newline */ |
---|
[19f765d] | 417 | break; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | /* find the next character */ |
---|
| 421 | p = oe_next_point(e, e->buff + index); |
---|
| 422 | if (p == NULL) { /* we ran off the end */ |
---|
| 423 | if (x != NULL && e->index > index) |
---|
| 424 | *x = width + 1; |
---|
| 425 | break; |
---|
| 426 | } |
---|
| 427 | index = p - e->buff; |
---|
[cedc95c] | 428 | |
---|
[19f765d] | 429 | } |
---|
| 430 | return index; |
---|
| 431 | } |
---|
| 432 | |
---|
[e20d8179] | 433 | static void oe_reframe(owl_editwin *e) { |
---|
[cedc95c] | 434 | oe_excursion x; |
---|
[460fbe8] | 435 | int goal = 1 + e->winlines / 2; |
---|
[cedc95c] | 436 | int index; |
---|
| 437 | int count = 0; |
---|
| 438 | int n, i; |
---|
| 439 | int last; |
---|
| 440 | |
---|
| 441 | oe_save_excursion(e, &x); |
---|
| 442 | /* step back line-by-line through the buffer until we have >= goal lines of |
---|
| 443 | display text */ |
---|
| 444 | e->lock = 0; /* we can (must) tread on the locktext */ |
---|
| 445 | |
---|
| 446 | last = -1; |
---|
| 447 | while (count < goal) { |
---|
| 448 | index = e->index; |
---|
| 449 | owl_editwin_move_to_beginning_of_line(e); |
---|
| 450 | if (last == e->index) |
---|
| 451 | break; |
---|
| 452 | last = e->index; |
---|
| 453 | for (n = 0, i = e->index; i < index; n++) |
---|
| 454 | i = oe_find_display_line(e, NULL, i); |
---|
| 455 | count += n == 0 ? 1 : n; |
---|
| 456 | if (count < goal) |
---|
| 457 | owl_editwin_point_move(e, -1); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | e->topindex = e->index; |
---|
[521bc84] | 461 | /* if we overshot, backtrack */ |
---|
| 462 | for (n = 0; n < (count - goal); n++) |
---|
| 463 | e->topindex = oe_find_display_line(e, NULL, e->topindex); |
---|
[cedc95c] | 464 | |
---|
| 465 | oe_restore_excursion(e, &x); |
---|
[7d4fbcd] | 466 | } |
---|
| 467 | |
---|
[3e36085] | 468 | static void oe_addnec(owl_editwin *e, int count) |
---|
| 469 | { |
---|
| 470 | int i; |
---|
| 471 | |
---|
| 472 | for (i = 0; i < count; i++) |
---|
| 473 | waddch(e->curswin, e->echochar); |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | static void oe_mvaddnec(owl_editwin *e, int y, int x, int count) |
---|
| 477 | { |
---|
| 478 | wmove(e->curswin, y, x); |
---|
| 479 | oe_addnec(e, count); |
---|
| 480 | } |
---|
| 481 | |
---|
[c9334b1] | 482 | /* regenerate the text on the curses window */ |
---|
[2ee9e8d] | 483 | void owl_editwin_redisplay(owl_editwin *e) |
---|
[c9334b1] | 484 | { |
---|
[19f765d] | 485 | int x = -1, y = -1, t; |
---|
[77d4402] | 486 | int line, index, lineindex, times = 0; |
---|
[7d4fbcd] | 487 | |
---|
[bd1a1ae] | 488 | do { |
---|
[cedc95c] | 489 | werase(e->curswin); |
---|
[36a16fc] | 490 | |
---|
| 491 | if (e->topindex == -1 || e->index < e->topindex) |
---|
[e20d8179] | 492 | oe_reframe(e); |
---|
| 493 | |
---|
[bd1a1ae] | 494 | line = 0; |
---|
| 495 | index = e->topindex; |
---|
| 496 | while(line < e->winlines) { |
---|
| 497 | lineindex = index; |
---|
[19f765d] | 498 | t = -1; |
---|
| 499 | index = oe_find_display_line(e, &t, lineindex); |
---|
| 500 | if (x == -1 && t != -1) |
---|
| 501 | x = t, y = line; |
---|
[3e36085] | 502 | if (index - lineindex) { |
---|
| 503 | if (!e->echochar) |
---|
| 504 | mvwaddnstr(e->curswin, line, 0, |
---|
| 505 | e->buff + lineindex, |
---|
| 506 | index - lineindex); |
---|
| 507 | else { |
---|
| 508 | if(lineindex < e->lock) { |
---|
| 509 | mvwaddnstr(e->curswin, line, 0, |
---|
| 510 | e->buff + lineindex, |
---|
| 511 | MIN(index - lineindex, |
---|
| 512 | e->lock - lineindex)); |
---|
| 513 | if (e->lock < index) |
---|
| 514 | oe_addnec(e, |
---|
| 515 | oe_region_width(e, e->lock, index, |
---|
| 516 | oe_region_width(e, lineindex, e->lock, 0))); |
---|
| 517 | } else |
---|
| 518 | oe_mvaddnec(e, line, 0, oe_region_width(e, line, index, 0)); |
---|
| 519 | } |
---|
| 520 | } |
---|
[bd1a1ae] | 521 | line++; |
---|
[a556caa] | 522 | } |
---|
[19f765d] | 523 | if (x == -1) |
---|
[bd1a1ae] | 524 | e->topindex = -1; /* force a reframe */ |
---|
[77d4402] | 525 | times++; |
---|
| 526 | } while(x == -1 && times < 3); |
---|
[e20d8179] | 527 | |
---|
[19f765d] | 528 | wmove(e->curswin, y, x); |
---|
[ebf0128] | 529 | e->cursorx = x; |
---|
[7d4fbcd] | 530 | } |
---|
| 531 | |
---|
[7f0c26f] | 532 | static inline void oe_fixup(int *target, int start, int end, int change) { |
---|
| 533 | if (*target > start) { |
---|
[0d9c90c] | 534 | if (*target <= end) |
---|
[8459609] | 535 | *target = end + change; |
---|
[7f0c26f] | 536 | else |
---|
| 537 | *target += change; |
---|
| 538 | } |
---|
| 539 | } |
---|
| 540 | |
---|
[e19eb97] | 541 | int owl_editwin_replace_region(owl_editwin *e, const char *s) |
---|
[a88f35a] | 542 | { |
---|
| 543 | oe_excursion x; |
---|
| 544 | int ret; |
---|
[6e58ff2] | 545 | |
---|
| 546 | if (e->mark == -1) { |
---|
| 547 | owl_function_error("The mark is unset, there is no region to replace."); |
---|
| 548 | return 0; |
---|
| 549 | } |
---|
| 550 | |
---|
[5ebc202] | 551 | oe_save_excursion(e, &x); |
---|
[a88f35a] | 552 | |
---|
| 553 | if(e->index > e->mark) { |
---|
| 554 | owl_editwin_exchange_point_and_mark(e); |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | ret = owl_editwin_replace_internal(e, e->mark - e->index, s); |
---|
| 558 | |
---|
| 559 | oe_restore_excursion(e, &x); |
---|
| 560 | |
---|
| 561 | return ret; |
---|
| 562 | } |
---|
| 563 | |
---|
[19a023f] | 564 | /* replace 'replace' characters at the point with s, returning the change in size */ |
---|
[e19eb97] | 565 | int owl_editwin_replace(owl_editwin *e, int replace, const char *s) |
---|
[ebf0128] | 566 | { |
---|
[19a023f] | 567 | int start, end, i; |
---|
[e19eb97] | 568 | const char *p; |
---|
[e9bb404] | 569 | |
---|
[5b5f3e6] | 570 | if (!g_utf8_validate(s, -1, NULL)) { |
---|
| 571 | owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string."); |
---|
[ebf0128] | 572 | return 0; |
---|
[47519e1b] | 573 | } |
---|
| 574 | |
---|
[5b5f3e6] | 575 | start = e->index; |
---|
| 576 | for (i = 0, p = e->buff + start; i < replace && p != NULL; i++) |
---|
| 577 | p = oe_next_point(e, p); |
---|
| 578 | if (p != NULL) |
---|
| 579 | end = p - e->buff; |
---|
| 580 | else |
---|
| 581 | end = e->bufflen; |
---|
| 582 | |
---|
[19a023f] | 583 | return owl_editwin_replace_internal(e, end - start, s); |
---|
| 584 | } |
---|
| 585 | |
---|
[e19eb97] | 586 | static int owl_editwin_replace_internal(owl_editwin *e, int replace, const char *s) |
---|
[19a023f] | 587 | { |
---|
| 588 | int start, end, free, need, size, change; |
---|
| 589 | oe_excursion *x; |
---|
| 590 | |
---|
| 591 | start = e->index; |
---|
| 592 | end = start + replace; |
---|
| 593 | |
---|
[5b5f3e6] | 594 | free = e->allocated - e->bufflen + end - start; |
---|
| 595 | |
---|
| 596 | need = strlen(s) - free; |
---|
| 597 | if (need > 0) { |
---|
| 598 | size = e->allocated + need + INCR - (need % INCR); |
---|
[b644688] | 599 | e->buff = owl_realloc(e->buff, size); |
---|
[5b5f3e6] | 600 | e->allocated = size; |
---|
[47519e1b] | 601 | } |
---|
[e9bb404] | 602 | |
---|
[5b5f3e6] | 603 | memmove(e->buff + start + strlen(s), e->buff + end, e->bufflen + 1 - end); |
---|
| 604 | memcpy(e->buff + start, s, strlen(s)); |
---|
[ebf0128] | 605 | change = start - end + strlen(s); |
---|
| 606 | e->bufflen += change; |
---|
[5b5f3e6] | 607 | e->index += strlen(s); |
---|
[ebf0128] | 608 | |
---|
[7f0c26f] | 609 | /* fix up the mark */ |
---|
[3e36085] | 610 | oe_fixup(&e->mark, start, end, change); |
---|
| 611 | oe_fixup(&e->topindex, start, end, change); |
---|
[ebf0128] | 612 | /* fix up any saved points after the replaced area */ |
---|
[7f0c26f] | 613 | for (x = e->excursions; x != NULL; x = x->next) { |
---|
| 614 | oe_fixup(&x->index, start, end, change); |
---|
[3e36085] | 615 | oe_fixup(&x->mark, start, end, change); |
---|
[7f0c26f] | 616 | } |
---|
[ebf0128] | 617 | |
---|
[c471e85] | 618 | /* recenter if needed */ |
---|
| 619 | if (start <= e->topindex) |
---|
| 620 | owl_editwin_recenter(e); |
---|
| 621 | |
---|
[ebf0128] | 622 | return change; |
---|
[47519e1b] | 623 | } |
---|
| 624 | |
---|
[c9334b1] | 625 | /* linewrap the word just before the cursor. |
---|
| 626 | * returns 0 on success |
---|
| 627 | * returns -1 if we could not wrap. |
---|
| 628 | */ |
---|
[fc2677b] | 629 | static void _owl_editwin_linewrap_word(owl_editwin *e) |
---|
[c9334b1] | 630 | { |
---|
[fc2677b] | 631 | oe_excursion x; |
---|
[84027015] | 632 | gunichar c; |
---|
[7d4fbcd] | 633 | |
---|
[fc2677b] | 634 | oe_save_excursion(e, &x); |
---|
[84027015] | 635 | |
---|
[fc2677b] | 636 | while (owl_editwin_point_move(e, -1)) { |
---|
| 637 | c = owl_editwin_get_char_at_point(e); |
---|
| 638 | if (owl_util_can_break_after(c) || c == '\n') { |
---|
| 639 | if (c != '\n') |
---|
| 640 | owl_editwin_replace(e, c != ' ' ? 0 : 1, "\n"); |
---|
| 641 | break; |
---|
[2d4ff14] | 642 | } |
---|
[7d4fbcd] | 643 | } |
---|
[fc2677b] | 644 | |
---|
| 645 | oe_restore_excursion(e, &x); |
---|
[7d4fbcd] | 646 | } |
---|
| 647 | |
---|
[c9334b1] | 648 | /* delete the character at the current point, following chars |
---|
| 649 | * shift left. |
---|
[e20d8179] | 650 | */ |
---|
[c9334b1] | 651 | void owl_editwin_delete_char(owl_editwin *e) |
---|
| 652 | { |
---|
[5b5f3e6] | 653 | owl_editwin_replace(e, 1, ""); |
---|
[7d4fbcd] | 654 | } |
---|
| 655 | |
---|
[c9334b1] | 656 | /* Swap the character at point with the character at point-1 and |
---|
| 657 | * advance the pointer. If point is at beginning of buffer do |
---|
| 658 | * nothing. If point is after the last character swap point-1 with |
---|
[e20d8179] | 659 | * point-2. (Behaves as observed in tcsh and emacs). |
---|
[c9334b1] | 660 | */ |
---|
| 661 | void owl_editwin_transpose_chars(owl_editwin *e) |
---|
| 662 | { |
---|
[e19eb97] | 663 | const char *middle, *end, *start; |
---|
[65b2173] | 664 | char *tmp; |
---|
[f2e36b5] | 665 | |
---|
[47519e1b] | 666 | if (e->bufflen == 0) return; |
---|
[e20d8179] | 667 | |
---|
[5b5f3e6] | 668 | if (e->index == e->bufflen) |
---|
| 669 | owl_editwin_point_move(e, -1); /* point is after last character */ |
---|
[f2e36b5] | 670 | |
---|
[5b5f3e6] | 671 | if (owl_editwin_at_beginning_of_buffer(e)) |
---|
| 672 | return; /* point is at beginning of buffer, do nothing */ |
---|
[f2e36b5] | 673 | |
---|
[47519e1b] | 674 | /* Transpose two utf-8 unicode glyphs. */ |
---|
[5b5f3e6] | 675 | middle = e->buff + e->index; |
---|
[47519e1b] | 676 | |
---|
[5b5f3e6] | 677 | end = oe_next_point(e, middle); |
---|
| 678 | if (end == NULL) |
---|
[e20d8179] | 679 | return; |
---|
[47519e1b] | 680 | |
---|
[5b5f3e6] | 681 | start = oe_prev_point(e, middle); |
---|
| 682 | if (start == NULL) |
---|
[e20d8179] | 683 | return; |
---|
[47519e1b] | 684 | |
---|
[5b5f3e6] | 685 | tmp = owl_malloc((end - start) + 1); |
---|
| 686 | tmp[(end - start)] = 0; |
---|
| 687 | memcpy(tmp, middle, end - middle); |
---|
| 688 | memcpy(tmp + (end - middle), start, middle - start); |
---|
| 689 | |
---|
| 690 | owl_editwin_point_move(e, -1); |
---|
| 691 | owl_editwin_replace(e, 2, tmp); |
---|
[f2e36b5] | 692 | } |
---|
| 693 | |
---|
[c9334b1] | 694 | /* insert 'string' at the current point, later text is shifted |
---|
| 695 | * right |
---|
| 696 | */ |
---|
[e19eb97] | 697 | void owl_editwin_insert_string(owl_editwin *e, const char *s) |
---|
[c9334b1] | 698 | { |
---|
[5b5f3e6] | 699 | owl_editwin_replace(e, 0, s); |
---|
[7d4fbcd] | 700 | } |
---|
| 701 | |
---|
[a556caa] | 702 | /* We assume index is not set to point to a mid-char */ |
---|
[bab52da] | 703 | static gunichar owl_editwin_get_char_at_point(owl_editwin *e) |
---|
[c9334b1] | 704 | { |
---|
[a556caa] | 705 | return g_utf8_get_char(e->buff + e->index); |
---|
| 706 | } |
---|
[7d4fbcd] | 707 | |
---|
[7f0c26f] | 708 | void owl_editwin_exchange_point_and_mark(owl_editwin *e) { |
---|
| 709 | int tmp; |
---|
| 710 | |
---|
| 711 | if (e->mark != -1) { |
---|
| 712 | tmp = e->mark; |
---|
| 713 | owl_editwin_set_mark(e); |
---|
| 714 | oe_set_index(e, tmp); |
---|
| 715 | } |
---|
| 716 | } |
---|
| 717 | |
---|
[e20d8179] | 718 | int owl_editwin_point_move(owl_editwin *e, int delta) |
---|
[84027015] | 719 | { |
---|
[e19eb97] | 720 | const char *p; |
---|
[19f765d] | 721 | int change, d = 0; |
---|
[a556caa] | 722 | |
---|
| 723 | change = MAX(delta, - delta); |
---|
| 724 | p = e->buff + e->index; |
---|
| 725 | |
---|
| 726 | while (d < change && p != NULL) { |
---|
[e20d8179] | 727 | if (delta > 0) |
---|
| 728 | p = oe_next_point(e, p); |
---|
| 729 | else |
---|
| 730 | p = oe_prev_point(e, p); |
---|
| 731 | if (p != NULL) { |
---|
[521bc84] | 732 | oe_set_index(e, p - e->buff); |
---|
[e20d8179] | 733 | d++; |
---|
[a556caa] | 734 | } |
---|
| 735 | } |
---|
| 736 | |
---|
| 737 | return delta > 0 ? d : -d; |
---|
[84027015] | 738 | } |
---|
| 739 | |
---|
[a556caa] | 740 | int owl_editwin_at_beginning_of_buffer(owl_editwin *e) { |
---|
| 741 | if (e->index == e->lock) |
---|
| 742 | return 1; |
---|
[84027015] | 743 | |
---|
[a556caa] | 744 | return 0; |
---|
| 745 | } |
---|
| 746 | |
---|
| 747 | int owl_at_end_of_buffer(owl_editwin *e) { |
---|
| 748 | if (e->index == e->bufflen) |
---|
| 749 | return 1; |
---|
| 750 | |
---|
| 751 | return 0; |
---|
| 752 | } |
---|
| 753 | |
---|
[e9c6fc8] | 754 | static int owl_editwin_at_beginning_of_line(owl_editwin *e) |
---|
[c9334b1] | 755 | { |
---|
[a0fbdee] | 756 | oe_excursion x; |
---|
[a556caa] | 757 | int ret; |
---|
[47519e1b] | 758 | |
---|
[a556caa] | 759 | if (owl_editwin_at_beginning_of_buffer(e)) |
---|
| 760 | return 1; |
---|
[47519e1b] | 761 | |
---|
[a0fbdee] | 762 | oe_save_excursion(e, &x); |
---|
[a556caa] | 763 | owl_editwin_point_move(e, -1); |
---|
[bab52da] | 764 | ret = (owl_editwin_get_char_at_point(e) == '\n'); |
---|
[a0fbdee] | 765 | oe_restore_excursion(e, &x); |
---|
[a556caa] | 766 | |
---|
| 767 | return ret; |
---|
| 768 | } |
---|
| 769 | |
---|
[e19eb97] | 770 | static int owl_editwin_is_char_in(owl_editwin *e, const char *set) |
---|
[a556caa] | 771 | { |
---|
[e19eb97] | 772 | const char *p; |
---|
[5b5f3e6] | 773 | |
---|
| 774 | for (p = set; *p != 0; p = g_utf8_find_next_char(p, NULL)) |
---|
| 775 | if (owl_editwin_get_char_at_point(e) == g_utf8_get_char(p)) |
---|
[a556caa] | 776 | return 1; |
---|
| 777 | return 0; |
---|
| 778 | } |
---|
| 779 | |
---|
[e19eb97] | 780 | int owl_editwin_move_if_in(owl_editwin *e, int delta, const char *set) |
---|
[a556caa] | 781 | { |
---|
| 782 | int change, distance = 0; |
---|
[e20d8179] | 783 | while (owl_editwin_is_char_in(e, set)) { |
---|
[a556caa] | 784 | change = owl_editwin_point_move(e, delta); |
---|
| 785 | distance += change; |
---|
| 786 | if (change == 0) |
---|
| 787 | break; |
---|
[47519e1b] | 788 | } |
---|
[a556caa] | 789 | return distance; |
---|
| 790 | } |
---|
| 791 | |
---|
[e19eb97] | 792 | int owl_editwin_move_if_not_in(owl_editwin *e, int delta, const char *set) |
---|
[a556caa] | 793 | { |
---|
| 794 | int change, distance = 0; |
---|
[e20d8179] | 795 | while (!owl_editwin_is_char_in(e, set)) { |
---|
[a556caa] | 796 | change = owl_editwin_point_move(e, delta); |
---|
| 797 | distance += change; |
---|
| 798 | if (change == 0) |
---|
| 799 | break; |
---|
[7d4fbcd] | 800 | } |
---|
[a556caa] | 801 | return distance; |
---|
[7d4fbcd] | 802 | } |
---|
| 803 | |
---|
[e20d8179] | 804 | int owl_editwin_move_to_beginning_of_line(owl_editwin *e) |
---|
[47519e1b] | 805 | { |
---|
[a556caa] | 806 | int distance = 0; |
---|
[47519e1b] | 807 | |
---|
[a556caa] | 808 | if (!owl_editwin_at_beginning_of_line(e)) { |
---|
| 809 | /* move off the \n if were at the end of a line */ |
---|
| 810 | distance += owl_editwin_point_move(e, -1); |
---|
| 811 | distance += owl_editwin_move_if_not_in(e, -1, "\n"); |
---|
| 812 | if (distance && !owl_editwin_at_beginning_of_buffer(e)) |
---|
| 813 | distance += owl_editwin_point_move(e, 1); |
---|
[47519e1b] | 814 | } |
---|
[77d4402] | 815 | e->goal_column = 0; /* subtleties */ |
---|
[84027015] | 816 | |
---|
[a556caa] | 817 | return distance; |
---|
| 818 | } |
---|
[e20d8179] | 819 | |
---|
| 820 | int owl_editwin_move_to_end_of_line(owl_editwin *e) |
---|
[a556caa] | 821 | { |
---|
| 822 | return owl_editwin_move_if_not_in(e, 1, "\n"); |
---|
[47519e1b] | 823 | } |
---|
| 824 | |
---|
[e20d8179] | 825 | int owl_editwin_line_move(owl_editwin *e, int delta) |
---|
[c9334b1] | 826 | { |
---|
[d7043b4] | 827 | int goal_column, change, ll, distance; |
---|
| 828 | int count = 0; |
---|
[a556caa] | 829 | |
---|
| 830 | change = MAX(delta, -delta); |
---|
| 831 | |
---|
[d7043b4] | 832 | goal_column = e->goal_column; |
---|
| 833 | distance = owl_editwin_move_to_beginning_of_line(e); |
---|
| 834 | goal_column = goal_column == -1 ? -distance : goal_column; |
---|
[a556caa] | 835 | |
---|
| 836 | while(count < change) { |
---|
| 837 | if (delta > 0) { |
---|
| 838 | distance += owl_editwin_move_if_not_in(e, 1, "\n"); |
---|
| 839 | distance += owl_editwin_point_move(e, 1); |
---|
| 840 | } else { |
---|
| 841 | /* I really want to assert delta < 0 here */ |
---|
| 842 | distance += owl_editwin_point_move(e, -1); /* to the newline on |
---|
| 843 | the previous line */ |
---|
| 844 | distance += owl_editwin_move_to_beginning_of_line(e); |
---|
| 845 | } |
---|
| 846 | count++; |
---|
[7d4fbcd] | 847 | } |
---|
[a556caa] | 848 | |
---|
| 849 | distance += (ll = owl_editwin_move_to_end_of_line(e)); |
---|
| 850 | if (ll > goal_column) |
---|
| 851 | distance += owl_editwin_point_move(e, goal_column - ll); |
---|
| 852 | |
---|
| 853 | e->goal_column = goal_column; |
---|
| 854 | |
---|
| 855 | return distance; |
---|
[7d4fbcd] | 856 | } |
---|
| 857 | |
---|
[c9334b1] | 858 | void owl_editwin_backspace(owl_editwin *e) |
---|
| 859 | { |
---|
[7d4fbcd] | 860 | /* delete the char before the current one |
---|
| 861 | * and shift later chars left |
---|
| 862 | */ |
---|
[a556caa] | 863 | if(owl_editwin_point_move(e, -1)) |
---|
[7d4fbcd] | 864 | owl_editwin_delete_char(e); |
---|
| 865 | } |
---|
| 866 | |
---|
[c9334b1] | 867 | void owl_editwin_key_up(owl_editwin *e) |
---|
| 868 | { |
---|
[a556caa] | 869 | owl_editwin_line_move(e, -1); |
---|
[7d4fbcd] | 870 | } |
---|
| 871 | |
---|
[c9334b1] | 872 | void owl_editwin_key_down(owl_editwin *e) |
---|
| 873 | { |
---|
[a556caa] | 874 | owl_editwin_line_move(e, 1); |
---|
[7d4fbcd] | 875 | } |
---|
| 876 | |
---|
[c9334b1] | 877 | void owl_editwin_key_left(owl_editwin *e) |
---|
| 878 | { |
---|
[a556caa] | 879 | owl_editwin_point_move(e, -1); |
---|
[7d4fbcd] | 880 | } |
---|
| 881 | |
---|
[c9334b1] | 882 | void owl_editwin_key_right(owl_editwin *e) |
---|
| 883 | { |
---|
[a556caa] | 884 | owl_editwin_point_move(e, 1); |
---|
[7d4fbcd] | 885 | } |
---|
| 886 | |
---|
[5b5f3e6] | 887 | int owl_editwin_forward_word(owl_editwin *e) |
---|
[c9334b1] | 888 | { |
---|
[5b5f3e6] | 889 | int distance; |
---|
[7d4fbcd] | 890 | /* if we're starting on a space, find the first non-space */ |
---|
[5b5f3e6] | 891 | distance = owl_editwin_move_if_in(e, 1, WHITESPACE); |
---|
[7d4fbcd] | 892 | |
---|
[a556caa] | 893 | /* now find the end of this word */ |
---|
[5b5f3e6] | 894 | distance += owl_editwin_move_if_not_in(e, 1, WHITESPACE); |
---|
| 895 | |
---|
| 896 | return distance; |
---|
| 897 | } |
---|
| 898 | |
---|
| 899 | void owl_editwin_move_to_nextword(owl_editwin *e) |
---|
| 900 | { |
---|
| 901 | owl_editwin_forward_word(e); |
---|
[7d4fbcd] | 902 | } |
---|
| 903 | |
---|
[c9334b1] | 904 | /* go backwards to the last non-space character |
---|
| 905 | */ |
---|
[5b5f3e6] | 906 | int owl_editwin_backward_word(owl_editwin *e) |
---|
[c9334b1] | 907 | { |
---|
[a0fbdee] | 908 | oe_excursion x; |
---|
[5b5f3e6] | 909 | int distance = 0; |
---|
| 910 | int further = 0; |
---|
[a556caa] | 911 | int beginning; |
---|
| 912 | /* if in middle of word, beginning of word */ |
---|
| 913 | |
---|
| 914 | /* if at beginning of a word, find beginning of previous word */ |
---|
| 915 | |
---|
[e20d8179] | 916 | if (owl_editwin_is_char_in(e, WHITESPACE)) { |
---|
[a556caa] | 917 | /* if in whitespace past end of word, find a word , the find the beginning*/ |
---|
[5b5f3e6] | 918 | distance += owl_editwin_move_if_in(e, -1, WHITESPACE); /* leaves us on the last |
---|
| 919 | character of the word */ |
---|
[a0fbdee] | 920 | oe_save_excursion(e, &x); |
---|
[a556caa] | 921 | /* are we at the beginning of a word? */ |
---|
| 922 | owl_editwin_point_move(e, -1); |
---|
[e20d8179] | 923 | beginning = owl_editwin_is_char_in(e, WHITESPACE); |
---|
[a0fbdee] | 924 | oe_restore_excursion(e, &x); |
---|
[a556caa] | 925 | if (beginning) |
---|
[5b5f3e6] | 926 | return distance; |
---|
[a556caa] | 927 | } else { |
---|
| 928 | /* in the middle of the word; */ |
---|
[a0fbdee] | 929 | oe_save_excursion(e, &x); |
---|
[5b5f3e6] | 930 | further += owl_editwin_point_move(e, -1); |
---|
[e20d8179] | 931 | if (owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */ |
---|
[5b5f3e6] | 932 | distance += owl_editwin_backward_word(e); /* previous case */ |
---|
[8321cb7] | 933 | oe_release_excursion(e, &x); |
---|
[5b5f3e6] | 934 | return distance + further; |
---|
[a556caa] | 935 | } else { |
---|
[a0fbdee] | 936 | oe_restore_excursion(e, &x); |
---|
[7d4fbcd] | 937 | } |
---|
| 938 | } |
---|
[5b5f3e6] | 939 | distance += owl_editwin_move_if_not_in(e, -1, WHITESPACE); |
---|
[a556caa] | 940 | /* will go past */ |
---|
| 941 | if (e->index > e->lock) |
---|
[5b5f3e6] | 942 | distance += owl_editwin_point_move(e, 1); |
---|
| 943 | return distance; |
---|
| 944 | } |
---|
| 945 | |
---|
| 946 | void owl_editwin_move_to_previousword(owl_editwin *e) |
---|
| 947 | { |
---|
| 948 | owl_editwin_backward_word(e); |
---|
[7d4fbcd] | 949 | } |
---|
| 950 | |
---|
[c9334b1] | 951 | void owl_editwin_delete_nextword(owl_editwin *e) |
---|
| 952 | { |
---|
[a0fbdee] | 953 | oe_excursion x; |
---|
[a556caa] | 954 | |
---|
[a0fbdee] | 955 | oe_save_excursion(e, &x); |
---|
[a60edf2] | 956 | oe_set_mark(e, e->index); |
---|
| 957 | owl_editwin_forward_word(e); |
---|
| 958 | owl_editwin_kill_region(e); |
---|
| 959 | oe_restore_mark_only(e, &x); |
---|
[7d4fbcd] | 960 | } |
---|
| 961 | |
---|
[c9334b1] | 962 | void owl_editwin_delete_previousword(owl_editwin *e) |
---|
| 963 | { |
---|
[a60edf2] | 964 | oe_excursion x; |
---|
[b68f9cd] | 965 | |
---|
[a60edf2] | 966 | oe_save_excursion(e, &x); |
---|
| 967 | oe_set_mark(e, e->index); |
---|
| 968 | owl_editwin_backward_word(e); |
---|
| 969 | owl_editwin_kill_region(e); |
---|
| 970 | oe_restore_mark_only(e, &x); |
---|
[b68f9cd] | 971 | } |
---|
| 972 | |
---|
[a556caa] | 973 | void owl_editwin_move_to_line_end(owl_editwin *e) |
---|
[c9334b1] | 974 | { |
---|
[a556caa] | 975 | owl_editwin_move_to_end_of_line(e); |
---|
[7d4fbcd] | 976 | } |
---|
| 977 | |
---|
[a556caa] | 978 | void owl_editwin_delete_to_endofline(owl_editwin *e) |
---|
[c9334b1] | 979 | { |
---|
[a0fbdee] | 980 | oe_excursion x; |
---|
[5b5f3e6] | 981 | int distance; |
---|
[a556caa] | 982 | |
---|
[a0fbdee] | 983 | oe_save_excursion(e, &x); |
---|
[a60edf2] | 984 | owl_editwin_set_mark(e); |
---|
[5b5f3e6] | 985 | distance = owl_editwin_move_to_end_of_line(e); |
---|
[a60edf2] | 986 | if (distance) |
---|
| 987 | owl_editwin_kill_region(e); |
---|
| 988 | else |
---|
| 989 | owl_editwin_replace(e, 1, ""); |
---|
[a0fbdee] | 990 | oe_restore_excursion(e, &x); |
---|
[a60edf2] | 991 | } |
---|
| 992 | |
---|
| 993 | void owl_editwin_yank(owl_editwin *e) |
---|
| 994 | { |
---|
| 995 | if (e->killbuf != NULL) |
---|
| 996 | owl_editwin_replace(e, 0, e->killbuf); |
---|
| 997 | } |
---|
| 998 | |
---|
[e19eb97] | 999 | static const char *oe_copy_buf(owl_editwin *e, const char *buf, int len) |
---|
[a60edf2] | 1000 | { |
---|
| 1001 | char *p; |
---|
| 1002 | |
---|
| 1003 | p = owl_malloc(len + 1); |
---|
| 1004 | |
---|
| 1005 | if (p != NULL) { |
---|
| 1006 | owl_free(e->killbuf); |
---|
| 1007 | e->killbuf = p; |
---|
| 1008 | memcpy(e->killbuf, buf, len); |
---|
| 1009 | e->killbuf[len] = 0; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | return p; |
---|
| 1013 | } |
---|
| 1014 | |
---|
| 1015 | static int oe_copy_region(owl_editwin *e) |
---|
| 1016 | { |
---|
[e19eb97] | 1017 | const char *p; |
---|
[a60edf2] | 1018 | int start, end; |
---|
| 1019 | |
---|
| 1020 | if (e->mark == -1) |
---|
| 1021 | return 0; |
---|
| 1022 | |
---|
| 1023 | start = MIN(e->index, e->mark); |
---|
| 1024 | end = MAX(e->index, e->mark); |
---|
| 1025 | |
---|
| 1026 | p = oe_copy_buf(e, e->buff + start, end - start); |
---|
| 1027 | if (p != NULL) |
---|
| 1028 | return end - start; |
---|
| 1029 | return 0; |
---|
| 1030 | } |
---|
| 1031 | |
---|
| 1032 | void owl_editwin_copy_region_as_kill(owl_editwin *e) |
---|
| 1033 | { |
---|
| 1034 | oe_copy_region(e); |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | void owl_editwin_kill_region(owl_editwin *e) |
---|
| 1038 | { |
---|
| 1039 | if (e->index > e->mark) |
---|
| 1040 | owl_editwin_exchange_point_and_mark(e); |
---|
| 1041 | |
---|
[2184001] | 1042 | owl_editwin_replace_internal(e, oe_copy_region(e), ""); |
---|
[7d4fbcd] | 1043 | } |
---|
| 1044 | |
---|
[c9334b1] | 1045 | void owl_editwin_move_to_line_start(owl_editwin *e) |
---|
| 1046 | { |
---|
[a556caa] | 1047 | owl_editwin_move_to_beginning_of_line(e); |
---|
[7d4fbcd] | 1048 | } |
---|
| 1049 | |
---|
[c9334b1] | 1050 | void owl_editwin_move_to_end(owl_editwin *e) |
---|
| 1051 | { |
---|
[521bc84] | 1052 | oe_set_index(e, e->bufflen); |
---|
[7d4fbcd] | 1053 | } |
---|
| 1054 | |
---|
[c9334b1] | 1055 | void owl_editwin_move_to_top(owl_editwin *e) |
---|
| 1056 | { |
---|
[521bc84] | 1057 | oe_set_index(e, e->lock); |
---|
[7d4fbcd] | 1058 | } |
---|
| 1059 | |
---|
[2fc8397] | 1060 | void owl_editwin_backward_paragraph(owl_editwin *e) |
---|
| 1061 | { |
---|
| 1062 | owl_editwin_point_move(e, -1); |
---|
| 1063 | for (; e->index >= e->lock; owl_editwin_point_move(e, -1)) { |
---|
| 1064 | if (e->index <= e->lock || |
---|
| 1065 | ((e->buff[e->index] == '\n') && (e->buff[e->index - 1]=='\n'))) |
---|
| 1066 | break; |
---|
| 1067 | } |
---|
| 1068 | } |
---|
| 1069 | |
---|
| 1070 | void owl_editwin_forward_paragraph(owl_editwin *e) |
---|
| 1071 | { |
---|
| 1072 | owl_editwin_point_move(e, 1); |
---|
| 1073 | /* scan forward to the start of the next paragraph */ |
---|
| 1074 | for(; e->index < e->bufflen; owl_editwin_point_move(e, 1)) { |
---|
| 1075 | if (e->buff[e->index -1] == '\n' && e->buff[e->index] == '\n') |
---|
| 1076 | break; |
---|
| 1077 | } |
---|
| 1078 | } |
---|
| 1079 | |
---|
[d41294a] | 1080 | int owl_editwin_current_column(owl_editwin *e) |
---|
[c9334b1] | 1081 | { |
---|
[a0fbdee] | 1082 | oe_excursion x; |
---|
[fc2677b] | 1083 | int lineindex; |
---|
[7d4fbcd] | 1084 | |
---|
[a0fbdee] | 1085 | oe_save_excursion(e, &x); |
---|
[fc2677b] | 1086 | owl_editwin_move_to_beginning_of_line(e); |
---|
| 1087 | lineindex = e->index; |
---|
| 1088 | oe_restore_excursion(e, &x); |
---|
| 1089 | return oe_region_width(e, lineindex, e->index, 0); |
---|
| 1090 | } |
---|
[a556caa] | 1091 | |
---|
[fc2677b] | 1092 | void owl_editwin_fill_paragraph(owl_editwin *e) |
---|
| 1093 | { |
---|
| 1094 | oe_excursion x; |
---|
| 1095 | gunichar ch; |
---|
| 1096 | int sentence; |
---|
[7d4fbcd] | 1097 | |
---|
[fc2677b] | 1098 | oe_save_excursion(e, &x); |
---|
[7d4fbcd] | 1099 | |
---|
[fc2677b] | 1100 | /* Mark the end of the paragraph */ |
---|
| 1101 | owl_editwin_forward_paragraph(e); |
---|
| 1102 | /* Skip the trailing newline */ |
---|
| 1103 | owl_editwin_point_move(e, -1); |
---|
| 1104 | owl_editwin_set_mark(e); |
---|
[7d4fbcd] | 1105 | |
---|
[fc2677b] | 1106 | owl_editwin_backward_paragraph(e); |
---|
[7d4fbcd] | 1107 | |
---|
[fc2677b] | 1108 | /* Don't mess with the leading newline */ |
---|
| 1109 | if (owl_editwin_get_char_at_point(e) == '\n') |
---|
| 1110 | owl_editwin_point_move(e, 1); |
---|
[7d4fbcd] | 1111 | |
---|
[fc2677b] | 1112 | /* |
---|
| 1113 | * First pass: Scan forward replacing all series of spaces with ' ' |
---|
| 1114 | * (or nothing after CJK ideograms) |
---|
| 1115 | */ |
---|
| 1116 | sentence = 0; |
---|
| 1117 | for(;e->index < e->mark; owl_editwin_point_move(e, 1)) { |
---|
[50e671c] | 1118 | /* bail if we hit a trailing dot on the buffer */ |
---|
[fc2677b] | 1119 | if (strcmp(e->buff + e->index, "\n.") == 0) { |
---|
| 1120 | owl_editwin_set_mark(e); |
---|
[50e671c] | 1121 | break; |
---|
[7d4fbcd] | 1122 | } |
---|
| 1123 | |
---|
[fc2677b] | 1124 | ch = owl_editwin_get_char_at_point(e); |
---|
[b2c1bd4] | 1125 | |
---|
[fc2677b] | 1126 | if (owl_util_can_break_after(ch) || ch == '\n') { |
---|
| 1127 | if (g_unichar_isspace(ch)) { |
---|
| 1128 | owl_editwin_replace(e, 1, " "); |
---|
| 1129 | } |
---|
| 1130 | |
---|
[f9d257b] | 1131 | if (sentence && g_unichar_isspace(owl_editwin_get_char_at_point(e)) |
---|
| 1132 | && e->index < e->mark) |
---|
[fc2677b] | 1133 | owl_editwin_point_move(e, 1); |
---|
| 1134 | |
---|
| 1135 | while(g_unichar_isspace(owl_editwin_get_char_at_point(e)) |
---|
| 1136 | && e->index < e->mark) { |
---|
| 1137 | owl_editwin_delete_char(e); |
---|
[7d4fbcd] | 1138 | } |
---|
| 1139 | } |
---|
[fc2677b] | 1140 | |
---|
| 1141 | if(ch == '.' || ch == '!' || ch == '?') |
---|
| 1142 | sentence = 1; |
---|
| 1143 | else |
---|
| 1144 | sentence = 0; |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | owl_editwin_backward_paragraph(e); |
---|
| 1148 | |
---|
| 1149 | /* Now go through inserting newlines as needed */ |
---|
| 1150 | while(e->index < e->mark) { |
---|
| 1151 | /* if we've travelled too far, linewrap */ |
---|
[d41294a] | 1152 | if (owl_editwin_current_column(e) >= e->fillcol) |
---|
[fc2677b] | 1153 | _owl_editwin_linewrap_word(e); |
---|
| 1154 | owl_editwin_point_move(e, 1); |
---|
[7d4fbcd] | 1155 | } |
---|
| 1156 | |
---|
[a0fbdee] | 1157 | oe_restore_excursion(e, &x); |
---|
[7d4fbcd] | 1158 | } |
---|
| 1159 | |
---|
[cf83b7a] | 1160 | /* returns true if only whitespace remains */ |
---|
[c9334b1] | 1161 | int owl_editwin_is_at_end(owl_editwin *e) |
---|
| 1162 | { |
---|
[a556caa] | 1163 | return (only_whitespace(e->buff + e->index)); |
---|
[217a43e] | 1164 | } |
---|
| 1165 | |
---|
[bab52da] | 1166 | static int owl_editwin_check_dotsend(owl_editwin *e) |
---|
[c9334b1] | 1167 | { |
---|
[dc7884d] | 1168 | int zdot = 0; |
---|
[72ab15f] | 1169 | oe_excursion x; |
---|
[7d4fbcd] | 1170 | |
---|
| 1171 | if (!e->dotsend) return(0); |
---|
[4ccd92c] | 1172 | if (!owl_editwin_is_at_end(e)) return (0); |
---|
[47519e1b] | 1173 | |
---|
[72ab15f] | 1174 | oe_save_excursion(e, &x); |
---|
| 1175 | |
---|
| 1176 | owl_editwin_point_move(e, -3); |
---|
| 1177 | |
---|
[4ccd92c] | 1178 | if(strncmp(e->buff + e->index, "\n.\n", 3) == 0) { |
---|
[dc7884d] | 1179 | owl_editwin_point_move(e, 1); |
---|
| 1180 | zdot = 1; |
---|
[0509efc] | 1181 | } else if(e->index == e->lock && |
---|
[4ccd92c] | 1182 | strncmp(e->buff + e->index, ".\n", 2) == 0) { |
---|
[0509efc] | 1183 | zdot = 1; |
---|
| 1184 | } |
---|
| 1185 | |
---|
| 1186 | if(zdot) { |
---|
[4ccd92c] | 1187 | owl_editwin_set_mark(e); |
---|
| 1188 | owl_editwin_move_to_end(e); |
---|
| 1189 | owl_editwin_replace_region(e, ""); |
---|
[dc7884d] | 1190 | } |
---|
[72ab15f] | 1191 | |
---|
| 1192 | oe_restore_excursion(e, &x); |
---|
| 1193 | |
---|
| 1194 | return zdot; |
---|
[7d4fbcd] | 1195 | } |
---|
| 1196 | |
---|
[fac5463] | 1197 | void owl_editwin_post_process_char(owl_editwin *e, owl_input j) |
---|
[c9334b1] | 1198 | { |
---|
[a556caa] | 1199 | /* XXX force a redisplay? */ |
---|
[fac5463] | 1200 | if ((j.ch==13 || j.ch==10) && owl_editwin_check_dotsend(e)) { |
---|
[435d6b2] | 1201 | owl_command_edit_done(e); |
---|
[7d4fbcd] | 1202 | return; |
---|
| 1203 | } |
---|
[2ee9e8d] | 1204 | owl_editwin_redisplay(e); |
---|
[7d4fbcd] | 1205 | } |
---|
| 1206 | |
---|
[3e36085] | 1207 | static int oe_region_width(owl_editwin *e, int start, int end, int offset) |
---|
[16cfd12a] | 1208 | { |
---|
[e19eb97] | 1209 | const char *p; |
---|
[3e36085] | 1210 | int width = offset; |
---|
| 1211 | |
---|
[16cfd12a] | 1212 | for(p = e->buff + start; |
---|
| 1213 | p < e->buff + end; |
---|
| 1214 | p = g_utf8_find_next_char(p, NULL)) |
---|
| 1215 | width += oe_char_width(g_utf8_get_char(p), width); |
---|
| 1216 | |
---|
[3e36085] | 1217 | return width - offset; |
---|
[16cfd12a] | 1218 | } |
---|
| 1219 | |
---|
[ebf0128] | 1220 | static void oe_insert_char(owl_editwin *e, gunichar c) |
---|
[fac5463] | 1221 | { |
---|
[16cfd12a] | 1222 | oe_excursion x; |
---|
[5b5f3e6] | 1223 | char tmp[7]; |
---|
[16cfd12a] | 1224 | int replaced = -1; |
---|
[5b5f3e6] | 1225 | |
---|
[ebf0128] | 1226 | if (c == '\r') /* translate CRs to NLs */ |
---|
| 1227 | c = '\n'; |
---|
| 1228 | |
---|
[16cfd12a] | 1229 | if (!g_unichar_iscntrl(c) || c == '\n' || c== '\t' ) { |
---|
[ebf0128] | 1230 | if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { |
---|
| 1231 | return; |
---|
| 1232 | } |
---|
| 1233 | |
---|
[16cfd12a] | 1234 | if (e->cursorx != -1 && e->cursorx + oe_char_width(c, e->cursorx) > e->wrapcol) { |
---|
| 1235 | /* XXX this is actually wrong: |
---|
| 1236 | * + If the line has been been wrapped, we can be past the wrap column but |
---|
| 1237 | * e->cursorx be much smaller. |
---|
| 1238 | * + If the user went back and inserted a bunch of stuff in the middle of |
---|
| 1239 | * the line, there may be more than one word past the wrap column. |
---|
| 1240 | */ |
---|
| 1241 | oe_save_excursion(e, &x); |
---|
| 1242 | |
---|
| 1243 | if (c == ' ' || c == '\t') { |
---|
| 1244 | owl_editwin_point_move(e, -1); |
---|
| 1245 | replaced = -owl_editwin_move_if_in(e, -1, " \t"); |
---|
| 1246 | if (!replaced) { |
---|
| 1247 | c = '\n'; |
---|
| 1248 | replaced = -1; |
---|
| 1249 | } |
---|
| 1250 | } else { |
---|
| 1251 | while(!owl_editwin_at_beginning_of_line(e)) { |
---|
| 1252 | owl_editwin_point_move(e, -1); |
---|
| 1253 | if (owl_util_can_break_after(owl_editwin_get_char_at_point(e))) { |
---|
| 1254 | replaced = -owl_editwin_move_if_in(e, -1, " \t"); |
---|
| 1255 | break; |
---|
| 1256 | } |
---|
| 1257 | } |
---|
| 1258 | if (owl_editwin_at_beginning_of_line(e)) |
---|
| 1259 | replaced = -1; |
---|
| 1260 | } |
---|
| 1261 | if (replaced && !owl_editwin_at_beginning_of_line(e)) |
---|
| 1262 | owl_editwin_point_move(e, 1); |
---|
| 1263 | if (replaced >= 0) { |
---|
| 1264 | owl_editwin_replace(e, replaced, "\n"); |
---|
| 1265 | } |
---|
| 1266 | oe_restore_excursion(e, &x); |
---|
| 1267 | } |
---|
| 1268 | |
---|
| 1269 | if (replaced >= 0 && (c == ' ' || c == '\t')) |
---|
| 1270 | return; /* our work here is done */ |
---|
| 1271 | |
---|
[6c171f1] | 1272 | tmp[g_unichar_to_utf8(c, tmp)] = '\0'; |
---|
[ebf0128] | 1273 | owl_editwin_replace(e, 0, tmp); |
---|
| 1274 | } |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | void owl_editwin_process_char(owl_editwin *e, owl_input j) |
---|
| 1278 | { |
---|
[5b5f3e6] | 1279 | if (j.ch == ERR) |
---|
| 1280 | return; |
---|
[fac5463] | 1281 | /* Ignore ncurses control characters. */ |
---|
[e20d8179] | 1282 | if (j.ch < 0x100) { |
---|
[ebf0128] | 1283 | oe_insert_char(e, j.uch); |
---|
[fac5463] | 1284 | } |
---|
| 1285 | } |
---|
| 1286 | |
---|
[e19eb97] | 1287 | const char *owl_editwin_get_text(owl_editwin *e) |
---|
[c9334b1] | 1288 | { |
---|
[7d4fbcd] | 1289 | return(e->buff+e->lock); |
---|
| 1290 | } |
---|
| 1291 | |
---|
[d41294a] | 1292 | char *owl_editwin_get_region(owl_editwin *e) |
---|
| 1293 | { |
---|
| 1294 | int start, end; |
---|
| 1295 | start = e->index; |
---|
| 1296 | end = e->mark; |
---|
| 1297 | if(start > end) { |
---|
| 1298 | int tmp = end; |
---|
| 1299 | end = start; |
---|
| 1300 | start = tmp; |
---|
| 1301 | } |
---|
| 1302 | |
---|
| 1303 | return oe_chunk(e, start, end); |
---|
| 1304 | } |
---|
| 1305 | |
---|
[77f605d] | 1306 | int owl_editwin_get_echochar(owl_editwin *e) |
---|
| 1307 | { |
---|
[a556caa] | 1308 | return e->echochar; |
---|
| 1309 | } |
---|
[77f605d] | 1310 | |
---|
| 1311 | static char *oe_chunk(owl_editwin *e, int start, int end) |
---|
| 1312 | { |
---|
| 1313 | char *p; |
---|
| 1314 | |
---|
| 1315 | p = owl_malloc(end - start + 1); |
---|
| 1316 | memcpy(p, e->buff + start, end - start); |
---|
| 1317 | p[end - start] = 0; |
---|
| 1318 | |
---|
| 1319 | return p; |
---|
| 1320 | } |
---|
| 1321 | |
---|
[d41294a] | 1322 | /* |
---|
| 1323 | * The only guarantee made about these values is that comparisons |
---|
| 1324 | * between them, as well as comparison between multiple calls to these |
---|
| 1325 | * functions without modifying the editwin in-between, are meaningful. |
---|
| 1326 | */ |
---|
| 1327 | |
---|
| 1328 | int owl_editwin_get_point(owl_editwin *e) |
---|
| 1329 | { |
---|
| 1330 | return e->index; |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | int owl_editwin_get_mark(owl_editwin *e) |
---|
| 1334 | { |
---|
| 1335 | return e->mark; |
---|
| 1336 | } |
---|
| 1337 | |
---|
[2f21a41] | 1338 | |
---|
| 1339 | /* |
---|
| 1340 | * Local Variables: |
---|
| 1341 | * mode:C |
---|
| 1342 | * c-basic-offset:2 |
---|
| 1343 | * End: |
---|
| 1344 | */ |
---|