Changeset 47519e1b


Ignore:
Timestamp:
Jan 2, 2008, 2:42:05 AM (13 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
c60ade2
Parents:
2febcae
Message:
text entry:
* first pass at utf-8 text entry. This is not yet complete, and it certainly has bugs.
  The following is an incomplete list of functions that will probably misbehave if you use them.
  - owl_editwin_move_to_nextword()
  - owl_editwin_move_to_previousword()
  - owl_editwin_delete_nextword()
  - owl_editwin_delete_previousword()
  - owl_editwin_delete_to_endofline()
  - owl_editwin_fill_paragraph()

format text:
* owl_fmtext_curs_waddstr() contract restored to match trunk.
* owl_fmtext_curs_waddstr_without_search() added.

misc:
* Importing Markus Kuhn's wcwidth.c from
  http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
* Change wcwidth() calls to mk_wcwidth()
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • Makefile.in

    r2bdfed9 r47519e1b  
    2626     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    2727     aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
    28      zbuddylist.c muxevents.c popexec.c obarray.c
     28     zbuddylist.c muxevents.c popexec.c obarray.c wcwidth.c
    2929OWL_SRC = owl.c
    3030TESTER_SRC = tester.c
  • editwin.c

    r9a6cc40 r47519e1b  
    143143  e->buffy=0;
    144144  owl_editwin_overwrite_string(e, text);
     145  owl_editwin_overwrite_char(e, '\0');
    145146  e->lock=strlen(text);
    146147  /* if (text[e->lock-1]=='\n') e->lock--; */
    147   e->buffx=x;
    148   e->buffy=y;
     148  /*  e->buffx=x; */
     149  /*  e->buffy=y; */
    149150  owl_editwin_adjust_for_locktext(e);
    150151  owl_editwin_redisplay(e, 0);
     
    251252
    252253  /* start at topline */
    253   ptr1=e->buff;
    254   for (i=0; i<e->topline; i++) {
    255     ptr2=strchr(ptr1, '\n');
     254  ptr1 = e->buff;
     255  for (i = 0; i < e->topline; i++) {
     256    ptr2 = strchr(ptr1, '\n');
    256257    if (!ptr2) {
    257258      /* we're already on the last line */
    258259      break;
    259260    }
    260     ptr1=ptr2+1;
     261    ptr1 = ptr2 + 1;
    261262  }
    262263  /* ptr1 now stores the starting point */
    263264
    264265  /* find the ending point and store it in ptr3 */
    265   ptr2=ptr1;
    266   ptr3=ptr1;
    267   for (i=0; i<e->winlines; i++) {
    268     ptr3=strchr(ptr2, '\n');
     266  ptr2 = ptr1;
     267  ptr3 = ptr1;
     268  for (i = 0; i < e->winlines; i++) {
     269    ptr3 = strchr(ptr2, '\n');
    269270    if (!ptr3) {
    270271      /* we've hit the last line */
    271272      /* print everything to the end */
    272       ptr3=e->buff+e->bufflen-1;
     273      ptr3 = e->buff + e->bufflen - 1;
    273274      ptr3--;
    274275      break;
    275276    }
    276     ptr2=ptr3+1;
    277   }
    278   ptr3+=2;
    279 
    280   buff=owl_malloc(ptr3-ptr1+50);
    281   strncpy(buff, ptr1, ptr3-ptr1);
    282   buff[ptr3-ptr1]='\0';
    283   if (e->echochar=='\0') {
     277    ptr2 = ptr3 + 1;
     278  }
     279  ptr3 += 2;
     280
     281  buff = owl_malloc(ptr3 - ptr1 + 50);
     282  strncpy(buff, ptr1, ptr3 - ptr1);
     283  buff[ptr3 - ptr1] = '\0';
     284  if (e->echochar == '\0') {
    284285    waddstr(e->curswin, buff);
    285286  } else {
    286287    /* translate to echochar, *except* for the locktext */
    287288    int len;
    288     int dolocklen=e->lock-(ptr1-e->buff);
    289 
    290     for (i=0; i<dolocklen; i++) {
     289    int dolocklen = e->lock - (ptr1 - e->buff);
     290
     291    for (i = 0; i < dolocklen; i++) {
    291292      waddch(e->curswin, buff[i]);
    292293    }
    293     len=strlen(buff);
    294     for (i=0; i<len-dolocklen; i++) {
     294    len = strlen(buff);
     295    for (i = 0; i < len-dolocklen; i++) {
    295296      waddch(e->curswin, e->echochar);
    296297    }
    297298  }
    298   wmove(e->curswin, e->buffy-e->topline, e->buffx);
     299  wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e));
    299300  wnoutrefresh(e->curswin);
    300   if (update==1) {
     301  if (update == 1) {
    301302    doupdate();
    302303  }
    303304  owl_free(buff);
     305}
     306
     307/* Remove n bytes at cursor. */
     308void _owl_editwin_remove_bytes(owl_editwin *e, int n) /*noproto*/
     309{
     310  int i = _owl_editwin_get_index_from_xy(e) + n;
     311  for (; i < e->bufflen; i++) {
     312    e->buff[i-n] = e->buff[i];
     313  }
     314 
     315  e->bufflen -= n;
     316  e->buff[e->bufflen] = '\0';
     317}
     318/* Insert n bytes at cursor.*/
     319void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/
     320{
     321  int i, z;
     322 
     323  if ((e->bufflen + n) > (e->allocated - 5)) {
     324    _owl_editwin_addspace(e);
     325  }
     326
     327  e->bufflen += n;
     328  e->buff[e->bufflen] = '\0';
     329 
     330  z = _owl_editwin_get_index_from_xy(e);
     331  for (i = e->bufflen - 1; i > z; i--) {
     332    e->buff[i] = e->buff[i - n];
     333  }
    304334}
    305335
     
    313343  int i, z;
    314344
    315   z=_owl_editwin_get_index_from_xy(e);
     345  z = _owl_editwin_get_index_from_xy(e);
    316346  /* move back and line wrap the previous word */
    317   for (i=z-1; ; i--) {
     347  for (i = z - 1; ; i--) {
    318348    /* move back until you find a space or hit the beginning of the line */
    319     if (e->buff[i]==' ') {
     349    if (e->buff[i] == ' ') {
    320350      /* replace the space with a newline */
    321       e->buff[i]='\n';
     351      e->buff[i] = '\n';
    322352      e->buffy++;
    323       e->buffx=z-i-1;
     353      e->buffx = z - i - 1;
    324354      /* were we on the last line */
    325355      return(0);
    326     } else if (e->buff[i]=='\n' || i<=e->lock) {
    327       /* we hit the begginning of the line or the buffer, we cannot
     356    } else if (e->buff[i] == '\n' || i <= e->lock) {
     357      /* we hit the beginning of the line or the buffer, we cannot
    328358       * wrap.
    329359       */
     
    336366 * characters over)
    337367 */
    338 void owl_editwin_insert_char(owl_editwin *e, char c)
    339 {
    340  
    341   int z, i, ret;
    342 
     368void owl_editwin_insert_char(owl_editwin *e, gunichar c)
     369{
     370  int z, i, ret, len;
     371  char tmp[6];
     372  memset(tmp, '\0', 6);
     373 
    343374  /* \r is \n */
    344   if (c=='\r') {
    345     c='\n';
    346   }
    347 
    348   if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {
     375  if (c == '\r') {
     376    c = '\n';
     377  }
     378
     379  if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
    349380    /* perhaps later this will change some state that allows the string
    350381       to be read */
     
    352383  }
    353384
     385  g_unichar_to_utf8(c, tmp);
     386  len = strlen(tmp);
     387 
    354388  /* make sure there is enough memory for the new text */
    355   if ((e->bufflen+1) > (e->allocated-5)) {
     389  if ((e->bufflen + len) > (e->allocated - 5)) {
    356390    _owl_editwin_addspace(e);
    357391  }
    358392
    359393  /* get the insertion point */
    360   z=_owl_editwin_get_index_from_xy(e);
     394  z = _owl_editwin_get_index_from_xy(e);
    361395
    362396  /* If we're going to insert at the last column do word wrapping, unless it's a \n */
    363   if ((e->buffx+1==e->wrapcol) && (c!='\n')) {
    364     ret=_owl_editwin_linewrap_word(e);
    365     if (ret==-1) {
     397  if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) {
     398    ret = _owl_editwin_linewrap_word(e);
     399    if (ret == -1) {
    366400      /* we couldn't wrap, insert a hard newline instead */
    367401      owl_editwin_insert_char(e, '\n');
     
    369403  }
    370404
    371   z=_owl_editwin_get_index_from_xy(e);
    372405  /* shift all the other characters right */
    373   for (i=e->bufflen; i>z; i--) {
    374     e->buff[i]=e->buff[i-1];
    375   }
    376 
    377   /* insert the new one */
    378   e->buff[z]=c;
     406  _owl_editwin_insert_bytes(e, len);
     407
     408  /* insert the new character */
     409  for(i = 0; i < len; i++) {
     410    e->buff[z + i] = tmp[i];
     411  }
    379412
    380413  /* housekeeping */
    381   e->bufflen++;
    382   e->buff[e->bufflen]='\0';
     414  e->bufflen += len;
     415  e->buff[e->bufflen] = '\0';
    383416
    384417  /* advance the cursor */
    385   if (c=='\n') {
    386     e->buffx=0;
    387     e->buffy++;
    388   } else {
    389     e->buffx++;
    390   }
     418  z += len;
     419  _owl_editwin_set_xy_by_index(e, z);
    391420}
    392421
    393422/* overwrite the character at the current point with 'c' */
    394 void owl_editwin_overwrite_char(owl_editwin *e, char c)
    395 {
    396   int z;
     423void owl_editwin_overwrite_char(owl_editwin *e, gunichar c)
     424{
     425  int z, oldlen, newlen, i;
     426  char tmp[6];
     427  memset(tmp, '\0', 6);
    397428 
    398429  /* \r is \n */
    399   if (c=='\r') {
    400     c='\n';
    401   }
    402 
    403   if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {
     430  if (c == '\r') {
     431    c = '\n';
     432  }
     433
     434  if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
    404435    /* perhaps later this will change some state that allows the string
    405436       to be read */
     
    407438  }
    408439
    409   z=_owl_editwin_get_index_from_xy(e);
    410 
    411   /* only if we are at the end of the buffer do we create new space */
    412   if (z==e->bufflen) {
    413     if ((e->bufflen+1) > (e->allocated-5)) {
    414       _owl_editwin_addspace(e);
    415     }
    416   }
    417  
    418   e->buff[z]=c;
    419 
    420   /* housekeeping if we are at the end of the buffer */
    421   if (z==e->bufflen) {
    422     e->bufflen++;
    423     e->buff[e->bufflen]='\0';
    424   }
     440  g_unichar_to_utf8(c, tmp);
     441  newlen = strlen(tmp);
     442
     443  z = _owl_editwin_get_index_from_xy(e);
     444  {
     445    char *t = g_utf8_find_next_char(e->buff + z, NULL);
     446    oldlen = (t ? (t - (e->buff + z)) : 1);
     447  }
     448
     449  if ((e->bufflen + newlen - oldlen + 1) > (e->allocated - 5)) {
     450    _owl_editwin_addspace(e);
     451  }
     452
     453  if (oldlen > newlen) {
     454    _owl_editwin_remove_bytes(e, oldlen-newlen);
     455  }
     456  else /* oldlen < newlen */ {
     457    _owl_editwin_insert_bytes(e, newlen-oldlen);
     458  }
     459  /* Overwrite the old char*/
     460  for (i = 0; i < newlen; i++) {
     461    e->buff[z+i] = tmp[i];
     462  }
     463       
     464  /* housekeeping */
     465  e->buff[e->bufflen] = '\0';
    425466
    426467  /* advance the cursor */
    427   if (c=='\n') {
    428     e->buffx=0;
    429     e->buffy++;
    430   } else {
    431     e->buffx++;
    432   }
    433 
     468  z += newlen;
     469  _owl_editwin_set_xy_by_index(e, z);
    434470}
    435471
     
    439475void owl_editwin_delete_char(owl_editwin *e)
    440476{
    441   int z, i;
    442 
    443   if (e->bufflen==0) return;
     477  int z;
     478  char *p1, *p2;
     479  gunichar c;
     480
     481  if (e->bufflen == 0) return;
    444482 
    445483  /* get the deletion point */
    446   z=_owl_editwin_get_index_from_xy(e);
    447 
    448   if (z==e->bufflen) return;
    449 
    450   for (i=z; i<e->bufflen; i++) {
    451     e->buff[i]=e->buff[i+1];
    452   }
    453   e->bufflen--;
    454   e->buff[e->bufflen]='\0';
     484  z = _owl_editwin_get_index_from_xy(e);
     485
     486  if (z == e->bufflen) return;
     487
     488  p1 = e->buff + z;
     489  p2 = g_utf8_next_char(p1);
     490  c = g_utf8_get_char(p2);
     491  while (g_unichar_ismark(c)) {
     492    p2 = g_utf8_next_char(p2);
     493    c = g_utf8_get_char(p2);
     494  }
     495  _owl_editwin_remove_bytes(e, p2-p1);
    455496}
    456497
     
    463504{
    464505  int z;
    465   char tmp;
    466 
    467   if (e->bufflen==0) return;
     506  char *p1, *p2, *p3, *tmp;
     507
     508  if (e->bufflen == 0) return;
    468509 
    469510  /* get the cursor point */
    470   z=_owl_editwin_get_index_from_xy(e);
    471 
    472   if (z==e->bufflen) {
     511  z = _owl_editwin_get_index_from_xy(e);
     512
     513  if (z == e->bufflen) {
    473514    /* point is after last character */
    474515    z--;
    475516  } 
    476517
    477   if (z-1 < e->lock) {
     518  if (z - 1 < e->lock) {
    478519    /* point is at beginning of buffer, do nothing */
    479520    return;
    480521  }
    481522
    482   tmp=e->buff[z];
    483   e->buff[z]=e->buff[z-1];
    484   e->buff[z-1]=tmp;
    485   owl_editwin_key_right(e);
     523  /* Transpose two utf-8 unicode glyphs. */
     524  p1 = e->buff + z;
     525
     526  p2 = g_utf8_find_next_char(p1, NULL);
     527  while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) {
     528    p2 = g_utf8_find_next_char(p2, NULL);
     529  }
     530  if (p2 == NULL) return;
     531
     532  p3 = g_utf8_find_prev_char(e->buff, p1);
     533  while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) {
     534    p3 = g_utf8_find_prev_char(p3, NULL);
     535  }
     536  if (p3 == NULL) return;
     537
     538  tmp = owl_malloc(p2 - p3 + 5);
     539  *tmp = '\0';
     540  strncat(tmp, p1, p2 - p1);
     541  strncat(tmp, p3, p1 - p3);
     542  strncpy(p3, tmp, p2 - p3);
     543  owl_free(tmp);
     544  _owl_editwin_set_xy_by_index(e, p3 - e->buff);
    486545}
    487546
     
    491550void owl_editwin_insert_string(owl_editwin *e, char *string)
    492551{
    493   int i, j;
    494 
    495   j=strlen(string);
    496   for (i=0; i<j; i++) {
    497     owl_editwin_insert_char(e, string[i]);
     552  char *p;
     553  gunichar c;
     554  if (!g_utf8_validate(string, -1, NULL)) {
     555    owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string.");
     556    return;
     557  }
     558  p = string;
     559  c = g_utf8_get_char(p);
     560  while (c) {
     561    owl_editwin_process_char(e, c);
     562    p = g_utf8_next_char(p);
     563    c = g_utf8_get_char(p);
    498564  }
    499565}
     
    505571void owl_editwin_overwrite_string(owl_editwin *e, char *string)
    506572{
    507   int i, j;
    508 
    509   j=strlen(string);
    510   for (i=0; i<j; i++) {
    511     owl_editwin_overwrite_char(e, string[i]);
     573  char *p;
     574  gunichar c;
     575
     576  if (!g_utf8_validate(string, -1, NULL)) {
     577    owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string.");
     578    return;
     579  }
     580  p = string;
     581  c = g_utf8_get_char(p);
     582  while (c) {
     583    owl_editwin_overwrite_char(e, c);
     584    p = g_utf8_next_char(p);
     585    c = g_utf8_get_char(p);
    512586  }
    513587}
     
    520594  int i;
    521595  char *ptr1, *ptr2;
    522 
    523   if (e->bufflen==0) return(0);
     596  gunichar c;
     597
     598  if (e->bufflen == 0) return(0);
    524599 
    525600  /* first go to the yth line */
    526   ptr1=e->buff;
    527   for (i=0; i<e->buffy; i++) {
    528     ptr2=strchr(ptr1, '\n');
     601  ptr1 = e->buff;
     602  for (i = 0; i < e->buffy; i++) {
     603    ptr2= strchr(ptr1, '\n');
    529604    if (!ptr2) {
    530605      /* we're already on the last line */
    531606      break;
    532607    }
    533     ptr1=ptr2+1;
    534   }
    535 
    536   /* now go to the xth character */
    537   ptr2=strchr(ptr1, '\n');
    538   if (!ptr2) {
    539     ptr2=e->buff+e->bufflen;
    540   }
    541 
    542   if ((ptr2-ptr1) < e->buffx) {
    543     ptr1=ptr2-1;
    544   } else {
    545     ptr1+=e->buffx;
    546   }
    547 
    548   /* printf("DEBUG: index is %i\r\n", ptr1-e->buff); */
    549   return(ptr1-e->buff);
     608    ptr1 = ptr2 + 1;
     609  }
     610
     611  /* now go to the xth cell */
     612  ptr2 = ptr1;
     613  i = 0;
     614  while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) {
     615    c = g_utf8_get_char(ptr2);
     616    i += (c == '\n' ? 1 : mk_wcwidth(c));
     617    ptr2 = g_utf8_next_char(ptr2);
     618  }
     619  while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) {
     620    ptr2 = g_utf8_next_char(ptr2);
     621  }
     622  if (ptr2 == NULL) return e->bufflen;
     623  return(ptr2 - e->buff);
    550624}
    551625
    552626void _owl_editwin_set_xy_by_index(owl_editwin *e, int index)
    553627{
    554   int z, i;
    555 
    556   z=_owl_editwin_get_index_from_xy(e);
    557   if (index>z) {
    558     for (i=0; i<index-z; i++) {
    559       owl_editwin_key_right(e);
    560     }
    561   } else if (index<z) {
    562     for (i=0; i<z-index; i++) {
    563       owl_editwin_key_left(e);
    564     }
    565   }
     628  char *ptr1, *ptr2, *target;
     629  gunichar c;
     630
     631  e->buffx = 0;
     632  e->buffy = 0;
     633
     634  ptr1 = e->buff;
     635  target = ptr1 + index;
     636  /* target sanitizing */
     637  if ((target[0] & 0x80) && (~target[0] & 0x40)) {
     638    /* middle of a utf-8 character, back up to previous character. */
     639    target = g_utf8_find_prev_char(e->buff, target);
     640  }
     641  c = g_utf8_get_char(target);
     642  while (g_unichar_ismark(c) && target > e->buff) {
     643    /* Adjust the target off of combining characters and the like. */
     644    target = g_utf8_find_prev_char(e->buff, target);
     645    c = g_utf8_get_char(target);
     646  }
     647  /* If we start with a mark, something is wrong.*/
     648  if (g_unichar_ismark(c)) return;
     649
     650  /* Now our target should be acceptable. */
     651  ptr2 = strchr(ptr1, '\n');
     652  while (ptr2 != NULL && ptr2 < target) {
     653    e->buffy++;
     654    ptr1 = ptr2 + 1;
     655    ptr2 = strchr(ptr1, '\n');
     656  }
     657  ptr2 = ptr1;
     658  while (ptr2 != NULL && ptr2 < target) {
     659    c = g_utf8_get_char(ptr2);
     660    e->buffx += mk_wcwidth(c);
     661    ptr2 = g_utf8_next_char(ptr2);
     662  }
     663}
     664
     665int _owl_editwin_cursor_adjustment(owl_editwin *e)
     666{
     667  char *ptr1, *ptr2;
     668  gunichar c;
     669  int x, i;
     670
     671  ptr1 = e->buff;
     672  ptr2 = strchr(ptr1, '\n');
     673  for (i = 0; ptr2 != NULL && i < e->buffy; i++) {
     674    ptr1 = ptr2 + 1;
     675    ptr2 = strchr(ptr1, '\n');
     676  }
     677  ptr2 = ptr1;
     678  x = 0;
     679  while (ptr2 != NULL && x < e->buffx) {
     680    if (*ptr2 == '\n') return 0;
     681    c = g_utf8_get_char(ptr2);
     682    x += mk_wcwidth(c);
     683    ptr2 = g_utf8_next_char(ptr2);
     684  }
     685  return x - e->buffx;
    566686}
    567687
     
    570690  /* if we happen to have the cursor over locked text
    571691   * move it to be out of the locktext region */
    572   if (_owl_editwin_get_index_from_xy(e)<e->lock) {
     692  if (_owl_editwin_get_index_from_xy(e) < e->lock) {
    573693    _owl_editwin_set_xy_by_index(e, e->lock);
    574694  }
     
    590710{
    591711  if (e->buffy > 0) e->buffy--;
    592   if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) {
    593     e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
     712  if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) {
     713    e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
    594714  }
    595715
     
    608728
    609729  /* if we're past the last character move back */
    610   if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) {
    611     e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
     730  if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) {
     731    e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
    612732  }
    613733
     
    623743void owl_editwin_key_left(owl_editwin *e)
    624744{
    625   /* move left if we can, and maybe up a line */
    626   if (e->buffx>0) {
    627     e->buffx--;
    628   } else if (e->buffy>0) {
    629     e->buffy--;
    630     e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    631   }
    632 
    633   /* do we need to scroll up? */
    634   if (e->buffy-e->topline < 0) {
    635     e->topline-=e->winlines/2;
     745  int i;
     746  char * p;
     747  i = _owl_editwin_get_index_from_xy(e);
     748  p = e->buff + i;
     749  p = g_utf8_find_prev_char(e->buff, p);
     750  while (p && g_unichar_ismark(g_utf8_get_char(p))) {
     751    p = g_utf8_find_prev_char(e->buff, p);
     752  }
     753  if (p == NULL) p = e->buff;
     754  _owl_editwin_set_xy_by_index(e, p - e->buff);
     755
     756  if (e->buffy - e->topline < 0) {
     757    e->topline -= e->winlines / 2;
    636758  }
    637759
     
    643765{
    644766  int i;
    645 
    646   /* move right if we can, and skip down a line if needed */
    647   i=owl_editwin_get_numchars_on_line(e, e->buffy);
    648   if (e->buffx < i) {
    649     e->buffx++;
    650     /*  } else if (e->buffy+1 < owl_editwin_get_numlines(e)) { */
    651   } else if (_owl_editwin_get_index_from_xy(e) < e->bufflen) {
    652     if (e->style==OWL_EDITWIN_STYLE_MULTILINE) {
    653       e->buffx=0;
    654       e->buffy++;
    655     }
     767  char * p;
     768  i = _owl_editwin_get_index_from_xy(e);
     769  p = e->buff + i;
     770  p = g_utf8_find_next_char(p, NULL);
     771  while (p && g_unichar_ismark(g_utf8_get_char(p))) {
     772    p = g_utf8_find_next_char(p, NULL);
     773  }
     774  if (p == NULL) {
     775    _owl_editwin_set_xy_by_index(e, e->bufflen);
     776  }
     777  else {
     778    _owl_editwin_set_xy_by_index(e, p - e->buff);
    656779  }
    657780
    658781  /* do we need to scroll down? */
    659   if (e->buffy-e->topline >= e->winlines) {
    660     e->topline+=e->winlines/2;
     782  if (e->buffy - e->topline >= e->winlines) {
     783    e->topline += e->winlines / 2;
    661784  }
    662785}
     
    664787void owl_editwin_move_to_nextword(owl_editwin *e)
    665788{
     789  /* asedeno: needs fixing for utf-8*/
    666790  int i, x;
    667791
     
    703827void owl_editwin_move_to_previousword(owl_editwin *e)
    704828{
     829  /* asedeno: needs fixing for utf-8*/
    705830  int i, x;
    706831
     
    738863void owl_editwin_delete_nextword(owl_editwin *e)
    739864{
     865  /* asedeno: needs fixing for utf-8*/
    740866  int z;
    741867
     
    768894void owl_editwin_delete_previousword(owl_editwin *e)
    769895{
     896  /* asedeno: needs fixing for utf-8*/
    770897  /* go backwards to the last non-space character, then delete chars */
    771898  int i, startpos, endpos;
     
    781908void owl_editwin_delete_to_endofline(owl_editwin *e)
    782909{
     910  /* asedeno: needs fixing for utf-8*/
    783911  int i;
    784912
    785   if (owl_editwin_get_numchars_on_line(e, e->buffy)>e->buffx) {
     913  if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) {
    786914    /* normal line */
    787915    i=_owl_editwin_get_index_from_xy(e);
     
    804932void owl_editwin_move_to_line_end(owl_editwin *e)
    805933{
    806   e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
     934  e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
    807935}
    808936
     
    817945  /* go to last char */
    818946  e->buffy=owl_editwin_get_numlines(e)-1;
    819   e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
     947  e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
    820948  owl_editwin_key_right(e);
    821949
     
    841969void owl_editwin_fill_paragraph(owl_editwin *e)
    842970{
     971  /* asedeno: needs fixing for utf-8*/
    843972  int i, save;
    844973
     
    857986  /* main loop */
    858987  while (1) {
    859     i=_owl_editwin_get_index_from_xy(e);
     988    i = _owl_editwin_get_index_from_xy(e);
    860989
    861990    /* bail if we hit the end of the buffer */
    862     if (i>=e->bufflen) break;
     991    if (i >= e->bufflen || e->buff[i] == '\0') break;
    863992
    864993    /* bail if we hit the end of the paragraph */
    865     if (e->buff[i]=='\n' && e->buff[i+1]=='\n') break;
     994    if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break;
    866995
    867996    /* if we've travelled too far, linewrap */
     
    8711000
    8721001    /* did we hit the end of a line too soon? */
    873     i=_owl_editwin_get_index_from_xy(e);
    874     if (e->buff[i]=='\n' && e->buffx<e->fillcol-1) {
     1002    i = _owl_editwin_get_index_from_xy(e);
     1003    if (e->buff[i] == '\n' && e->buffx < e->fillcol - 1) {
    8751004      /* ********* we need to make sure we don't pull in a word that's too long ***********/
    8761005      e->buff[i]=' ';
     
    8781007   
    8791008    /* fix spacing */
    880     i=_owl_editwin_get_index_from_xy(e);
    881     if (e->buff[i]==' ' && e->buff[i+1]==' ') {
    882       if (e->buff[i-1]=='.' || e->buff[i-1]=='!' || e->buff[i-1]=='?') {
     1009    i = _owl_editwin_get_index_from_xy(e);
     1010    if (e->buff[i] == ' ' && e->buff[i+1] == ' ') {
     1011      if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] == '?') {
    8831012        owl_editwin_key_right(e);
    8841013      } else {
    8851014        owl_editwin_delete_char(e);
    8861015        /* if we did this ahead of the save point, adjust it */
    887         if (i<save) save--;
     1016        if (i < save) save--;
    8881017      }
    8891018    } else {
     
    9111040int owl_editwin_check_dotsend(owl_editwin *e)
    9121041{
    913   int i;
     1042  char *p, *p_n, *p_p;
     1043  gunichar c;
    9141044
    9151045  if (!e->dotsend) return(0);
    916   for (i=e->bufflen-1; i>0; i--) {
    917     if (e->buff[i] == '.'
    918         && (e->buff[i-1] == '\n' || e->buff[i-1] == '\r')
    919         && (e->buff[i+1] == '\n' || e->buff[i+1] == '\r')) {
    920       e->bufflen = i;
    921       e->buff[i] = '\0';
     1046
     1047  p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen);
     1048  p_n = g_utf8_find_next_char(p, NULL);
     1049  p_p = g_utf8_find_prev_char(e->buff, p);
     1050  c = g_utf8_get_char(p);
     1051  while (p != NULL) {
     1052    if (*p == '.'
     1053        && p_p != NULL && (*p_p == '\n' || *p_p == '\r')
     1054        && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) {
     1055      e->bufflen = p - e->buff;
     1056      e->buff[e->bufflen] = '\0';
    9221057      return(1);
    9231058    }
    924     if (!isspace((int) e->buff[i])) {
    925       return(0);
    926     }
     1059    if (c != '\0' && !g_unichar_isspace(c)) return(0);
     1060    p_n = p;
     1061    p = p_p;
     1062    c = g_utf8_get_char(p);
     1063    p_p = g_utf8_find_prev_char(e->buff, p);
    9271064  }
    9281065  return(0);
    9291066}
    9301067
    931 void owl_editwin_post_process_char(owl_editwin *e, int j)
     1068void owl_editwin_post_process_char(owl_editwin *e, gunichar j)
    9321069{
    9331070  /* check if we need to scroll down */
     
    9421079}
    9431080
    944 void owl_editwin_process_char(owl_editwin *e, int j)
     1081void owl_editwin_process_char(owl_editwin *e, gunichar j)
    9451082{
    9461083  if (j == ERR) return;
    947   if (j>127 || ((j<32) && (j!=10) && (j!=13))) {
     1084  if (g_unichar_iscntrl(j) && (j != 10) && (j != 13)) {
    9481085    return;
    949   } else {
     1086  }
     1087  else {
    9501088    owl_editwin_insert_char(e, j);
    9511089  }
     
    9751113  }
    9761114
    977   /* now go to the xth character */
    978   ptr2=strchr(ptr1, '\n');
    979   if (!ptr2) {
    980     return(e->buff + e->bufflen - ptr1);
    981   }
    982   return(ptr2-ptr1); /* don't count the newline for now */
     1115  /* now count characters */
     1116  i = 0;
     1117  ptr2 = ptr1;
     1118  while (ptr2 - e->buff < e->bufflen
     1119         && *ptr2 != '\n') {
     1120    ++i;
     1121    ptr2 = g_utf8_next_char(ptr2);
     1122  }
     1123  return i;
     1124}
     1125
     1126int owl_editwin_get_numcells_on_line(owl_editwin *e, int line)
     1127{
     1128  int i;
     1129  char *ptr1, *ptr2;
     1130  gunichar c;
     1131
     1132  if (e->bufflen==0) return(0);
     1133 
     1134  /* first go to the yth line */
     1135  ptr1=e->buff;
     1136  for (i=0; i<line; i++) {
     1137    ptr2=strchr(ptr1, '\n');
     1138    if (!ptr2) {
     1139      /* we're already on the last line */
     1140      return(0);
     1141    }
     1142    ptr1=ptr2+1;
     1143  }
     1144
     1145  /* now count cells */
     1146  i = 0;
     1147  ptr2 = ptr1;
     1148  while (ptr2 - e->buff < e->bufflen
     1149         && *ptr2 != '\n') {
     1150    c = g_utf8_get_char(ptr2);
     1151    i += mk_wcwidth(c);
     1152    ptr2 = g_utf8_next_char(ptr2);
     1153  }
     1154  return i;
    9831155}
    9841156
  • fmtext.c

    r5376a95 r47519e1b  
    248248 * must already be initiatlized with curses
    249249 */
    250 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search)
     250void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/
    251251{
    252252  /* char *tmpbuff; */
     
    264264  search_results = (do_search
    265265                    ? owl_fmtext_search(f, owl_global_get_search_string(&g))
    266                     : NULL);
    267   if (search_results) search_len = strlen(owl_global_get_search_string(&g));
     266                    : 0);
     267  search_len = (search_results
     268                ? strlen(owl_global_get_search_string(&g))
     269                : 0);
    268270  s = f->textbuff;
    269271  /* Set default attributes. */
     
    350352}
    351353
     354void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
     355{
     356  _owl_fmtext_curs_waddstr(f, w, owl_global_is_search_active(&g));
     357}
     358
     359void owl_fmtext_curs_waddstr_without_search(owl_fmtext *f, WINDOW *w)
     360{
     361  _owl_fmtext_curs_waddstr(f, w, 0);
     362}
    352363
    353364/* start with line 'aline' (where the first line is 0) and print
     
    413424    st = 0;
    414425    padding = 0;
     426    chwidth = 0;
    415427    ptr_c = ptr_s;
    416428    while(col <= bcol && ptr_c < ptr_e) {
    417429      gunichar c = g_utf8_get_char(ptr_c);
    418430      if (!_owl_fmtext_is_format_char(c)) {
    419         chwidth = wcwidth(c);
     431        chwidth = mk_wcwidth(c);
    420432     
    421433        if (col + chwidth > bcol)
  • functions.c

    r2febcae r47519e1b  
    21872187void owl_function_start_command(char *line)
    21882188{
    2189   int i, j;
    21902189  owl_editwin *tw;
    21912190
     
    21982197  owl_global_set_needrefresh(&g);
    21992198
    2200   j=strlen(line);
    2201   for (i=0; i<j; i++) {
    2202     owl_editwin_process_char(tw, line[i]);
    2203   }
     2199  owl_editwin_insert_string(tw, line);
    22042200  owl_editwin_redisplay(tw, 0);
    22052201
  • keymap.c

    rcf83b7a r47519e1b  
    202202/* processes a keypress.  returns 0 if the keypress was handled,
    203203 * 1 if not handled, -1 on error, and -2 if j==ERR. */
    204 int owl_keyhandler_process(owl_keyhandler *kh, int j)
     204int owl_keyhandler_process(owl_keyhandler *kh, gunichar j)
    205205{
    206206  owl_keymap     *km;
  • message.c

    r6201646 r47519e1b  
    540540  owl_fmtext_colorizebg(&b, bgcolor);
    541541
    542   owl_fmtext_curs_waddstr(&b, win, owl_global_is_search_active(&g));
     542  owl_fmtext_curs_waddstr(&b, win);
    543543
    544544  owl_fmtext_free(&a);
  • owl.c

    r5bc0f68 r47519e1b  
    7070  owl_editwin *tw;
    7171  owl_popwin *pw;
    72   int j, ret, initialsubs, debug, argcsave, followlast;
     72  int ret, initialsubs, debug, argcsave, followlast;
     73  gunichar j;
    7374  int newmsgs, nexttimediff;
    7475  struct sigaction sigact;
     
    546547      usleep(10000);
    547548    } else {
     549      /* Pull in a full utf-8 character. */
     550      if (j & 0x80) {
     551        char utf8buf[7];
     552        int bytes, i;
     553        memset(utf8buf,'\0',7);
     554        utf8buf[0] = j;
     555
     556        if (~j & 0x20) bytes = 2;
     557        else if (~j & 0x10) bytes = 3;
     558        else if (~j & 0x08) bytes = 4;
     559        else if (~j & 0x04) bytes = 5;
     560        else if (~j & 0x02) bytes = 6;
     561        else bytes = 1; /* This won't validate */
     562
     563        for (i = 1; i < bytes; i++) {
     564          utf8buf[i] = wgetch(typwin);
     565        }
     566        if (g_utf8_validate(utf8buf, -1, NULL)) {
     567          j = g_utf8_get_char(utf8buf);
     568        }
     569        else {
     570          j = ERR;
     571        }
     572      }
    548573      owl_global_update_lastinputtime(&g);
    549574      /* find and activate the current keymap.
  • text.c

    rdd24b6a r47519e1b  
    7777    while(col < bcol && ptr_c < ptr_e) {
    7878      gunichar c = g_utf8_get_char(ptr_c);
    79       if (col + wcwidth(c) > bcol) break;
    80       col += wcwidth(c);
     79      if (col + mk_wcwidth(c) > bcol) break;
     80      col += mk_wcwidth(c);
    8181      ptr_c = g_utf8_next_char(ptr_c);
    8282      if (col >= acol) {
  • viewwin.c

    r9866c3a r47519e1b  
    7373  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
    7474
    75   owl_fmtext_curs_waddstr(&fm2, v->curswin, 0);
     75  owl_fmtext_curs_waddstr_without_search(&fm2, v->curswin);
    7676
    7777  /* print the message at the bottom */
Note: See TracChangeset for help on using the changeset viewer.