Changeset ebf0128
- Timestamp:
- Jul 11, 2009, 1:14:34 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 2f21a41
- Parents:
- 7d25006
- git-author:
- Karl Ramm <kcr@1ts.org> (06/11/09 11:18:42)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:34)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
editwin.c
r7d25006 rebf0128 6 6 7 7 static const char fileIdent[] = "$Id$"; 8 9 #define VALID_EXCURSION (0x9a2b4729) 10 11 typedef struct oe_excursion_struct { /*noproto*/ 12 int valid; 13 int index; 14 int goal_column; 15 int lock; 16 struct oe_excursion_struct *next; 17 } oe_excursion; 8 18 9 19 struct _owl_editwin { /*noproto*/ … … 15 25 int goal_column; 16 26 int topindex; 27 int cursorx; 17 28 int winlines, wincols, fillcol, wrapcol; 18 29 WINDOW *curswin; … … 21 32 int dotsend; 22 33 int echochar; 34 oe_excursion *excursions; 23 35 24 36 char *command; … … 27 39 }; 28 40 29 typedef struct { /*noproto*/30 int index;31 int goal_column;32 int lock;33 } oe_excursion;34 41 35 42 static void oe_reframe(owl_editwin *e); 36 43 static void oe_save_excursion(owl_editwin *e, oe_excursion *x); 44 static void oe_release_excursion(owl_editwin *e, oe_excursion *x); 37 45 static void oe_restore_excursion(owl_editwin *e, oe_excursion *x); 46 static int oe_count_glyphs(char *s); 47 static int oe_char_width(gunichar c, int column); 38 48 static int oe_find_display_line(owl_editwin *e, int *x, int index); 49 static void oe_insert_char(owl_editwin *e, gunichar c); 39 50 static int owl_editwin_limit_maxcols(int v, int maxv); 40 51 static int owl_editwin_check_dotsend(owl_editwin *e); 41 52 static int owl_editwin_is_char_in(owl_editwin *e, char *set); 42 53 static gunichar owl_editwin_get_char_at_point(owl_editwin *e); 43 static void owl_editwin_replace(owl_editwin *e, int count, char *s); 44 static int oe_count_glyphs(char *s); 54 static int owl_editwin_replace(owl_editwin *e, int count, char *s); 45 55 46 56 #define INCR 4096 … … 67 77 static inline void oe_set_index(owl_editwin *e, int index) 68 78 { 79 if (index != e->index) { 80 e->goal_column = -1; 81 e->cursorx = -1; 82 } 69 83 e->index = index; 70 e->goal_column = -1;71 84 } 72 85 … … 83 96 oe_set_index(e, 0); 84 97 e->goal_column = -1; 85 e->topindex=0; 86 e->winlines=winlines; 87 e->wincols=wincols; 88 e->fillcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxfillcols(&g)); 89 e->wrapcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxwrapcols(&g)); 90 e->curswin=win; 98 e->cursorx = -1; 99 e->topindex = 0; 100 e->excursions = NULL; 101 owl_editwin_set_curswin(e, win, winlines, wincols); 91 102 e->style=style; 92 103 if ((style!=OWL_EDITWIN_STYLE_MULTILINE) && … … 185 196 static int owl_editwin_limit_maxcols(int v, int maxv) 186 197 { 198 /* maxv > 5 ? MAX(v, vax) : v */ 187 199 if (maxv > 5 && v > maxv) { 188 200 return(maxv); … … 282 294 x->goal_column = e->goal_column; 283 295 x->lock = e->lock; 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 { 304 oe_excursion *p; 305 306 x->valid = 0; 307 if (e->excursions == NULL) 308 /* XXX huh. */ ; 309 else if (e->excursions == x) 310 e->excursions = x->next; 311 else { 312 for (p = e->excursions; p->next != NULL; p = p->next) 313 if (p->next == x) { 314 p->next = p->next->next; 315 break; 316 } 317 /* and if we ran off the end? XXX */ 318 } 284 319 } 285 320 286 321 static void oe_restore_excursion(owl_editwin *e, oe_excursion *x) 287 322 { 288 oe_set_index(e, x->index); 289 e->goal_column = x->goal_column; 290 e->lock = x->lock; 323 if (x->valid == VALID_EXCURSION) { 324 oe_set_index(e, x->index); 325 e->goal_column = x->goal_column; 326 e->lock = x->lock; 327 328 oe_release_excursion(e, x); 329 } 291 330 } 292 331 … … 316 355 } 317 356 357 static int oe_char_width(gunichar c, int column) 358 { 359 int cw; 360 361 if (c == 9) /* TAB */ 362 return TABSIZE - column % TABSIZE; 363 364 cw = mk_wcwidth(c); 365 366 if (cw < 0) /* control characters */ 367 cw = 0; 368 369 return cw; 370 } 371 318 372 static int oe_find_display_line(owl_editwin *e, int *x, int index) 319 373 { 320 374 int width = 0, cw; 321 gunichar c = -1;375 gunichar c; 322 376 char *p; 323 377 … … 331 385 332 386 /* figure out how wide it is */ 333 if (c == 9) /* TAB */ 334 cw = TABSIZE - width % TABSIZE; 335 else 336 cw = mk_wcwidth(c); 337 if (cw < 0) /* control characters */ 338 cw = 0; 387 cw = oe_char_width(c, width); 339 388 340 389 if (width + cw > e->wincols) { … … 434 483 435 484 wmove(e->curswin, y, x); 485 e->cursorx = x; 486 436 487 wnoutrefresh(e->curswin); 437 488 if (update == 1) … … 439 490 } 440 491 441 static void owl_editwin_replace(owl_editwin *e, int replace, char *s) 442 { /* replace count characters at the point with s */ 443 int start, end, i, free, need, size; 492 /* replace count characters at the point with s, returning the change in size */ 493 static int owl_editwin_replace(owl_editwin *e, int replace, char *s) 494 { 495 int start, end, i, free, need, size, change; 444 496 char *p; 497 oe_excursion *x; 445 498 446 499 if (!g_utf8_validate(s, -1, NULL)) { 447 500 owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string."); 448 return ;501 return 0; 449 502 } 450 503 … … 465 518 if (p == NULL) { 466 519 /* XXX signal impending doom somehow and don't do anything */ 467 return ;520 return 0; 468 521 } 469 522 e->buff = p; … … 473 526 memmove(e->buff + start + strlen(s), e->buff + end, e->bufflen + 1 - end); 474 527 memcpy(e->buff + start, s, strlen(s)); 475 e->bufflen += start - end + strlen(s); 528 change = start - end + strlen(s); 529 e->bufflen += change; 476 530 e->index += strlen(s); 531 532 /* fix up any saved points after the replaced area */ 533 for (x = e->excursions; x != NULL; x = x->next) 534 if (x->index > start) { 535 if (x->index < end) 536 x->index = end; 537 else 538 x->index += change; 539 } 540 541 return change; 477 542 } 478 543 … … 977 1042 } 978 1043 1044 static void oe_insert_char(owl_editwin *e, gunichar c) 1045 { 1046 char tmp[7]; 1047 1048 if (c == '\r') /* translate CRs to NLs */ 1049 c = '\n'; 1050 1051 if (!g_unichar_iscntrl(c) || c == '\n' || c== '\n' ) { 1052 memset(tmp, 0, 7); 1053 1054 if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 1055 return; 1056 } 1057 1058 g_unichar_to_utf8(c, tmp); 1059 owl_editwin_replace(e, 0, tmp); 1060 } 1061 } 1062 979 1063 void owl_editwin_process_char(owl_editwin *e, owl_input j) 980 1064 { 981 char tmp[7];982 983 1065 if (j.ch == ERR) 984 1066 return; 985 1067 /* Ignore ncurses control characters. */ 986 1068 if (j.ch < 0x100) { 987 if (!(g_unichar_iscntrl(j.uch) && (j.uch != 10) && (j.uch != 13)) || j.uch==9 ) { 988 memset(tmp, 0, 7); 989 990 /* \r is \n */ 991 if (j.uch == '\r') { 992 j.uch = '\n'; 993 } 994 995 if (j.uch == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) { 996 return; 997 } 998 999 g_unichar_to_utf8(j.uch, tmp); 1000 owl_editwin_replace(e, 0, tmp); 1001 } 1069 oe_insert_char(e, j.uch); 1002 1070 } 1003 1071 }
Note: See TracChangeset
for help on using the changeset viewer.