Changeset 830c36e for editwin.c


Ignore:
Timestamp:
Jan 2, 2008, 10:51:28 PM (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:
3a7cf49
Parents:
987a93c
Message:
fixing bugs in editwin bufflen calculations.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r47519e1b r830c36e  
    316316  e->buff[e->bufflen] = '\0';
    317317}
     318
    318319/* Insert n bytes at cursor.*/
    319320void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/
     
    371372  char tmp[6];
    372373  memset(tmp, '\0', 6);
    373  
     374
    374375  /* \r is \n */
    375376  if (c == '\r') {
     
    385386  g_unichar_to_utf8(c, tmp);
    386387  len = strlen(tmp);
    387  
     388
    388389  /* make sure there is enough memory for the new text */
    389390  if ((e->bufflen + len) > (e->allocated - 5)) {
     
    404405
    405406  /* shift all the other characters right */
    406   _owl_editwin_insert_bytes(e, len);
     407  if (z != e->bufflen) {
     408    _owl_editwin_insert_bytes(e, len);
     409  }
    407410
    408411  /* insert the new character */
     
    414417  e->bufflen += len;
    415418  e->buff[e->bufflen] = '\0';
    416 
     419 
    417420  /* advance the cursor */
    418421  z += len;
     
    426429  char tmp[6];
    427430  memset(tmp, '\0', 6);
    428  
     431
    429432  /* \r is \n */
    430433  if (c == '\r') {
    431434    c = '\n';
    432435  }
    433 
     436 
    434437  if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
    435438    /* perhaps later this will change some state that allows the string
     
    444447  {
    445448    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) {
     449    oldlen = (t ? (t - (e->buff + z)) : 0);
     450  }
     451
     452  /* only if we are at the end of the buffer do we create new space here */
     453  if (z == e->bufflen) {
     454    if ((e->bufflen+newlen) > (e->allocated-5)) {
     455      _owl_editwin_addspace(e);
     456    }
     457  }
     458  /* if not at the end of the buffer, adjust based in char size difference. */
     459  else if (oldlen > newlen) {
    454460    _owl_editwin_remove_bytes(e, oldlen-newlen);
    455461  }
     
    463469       
    464470  /* housekeeping */
    465   e->buff[e->bufflen] = '\0';
    466 
     471  if (z == e->bufflen) {
     472    e->bufflen += newlen;
     473    e->buff[e->bufflen] = '\0';
     474  }
     475 
    467476  /* advance the cursor */
    468477  z += newlen;
Note: See TracChangeset for help on using the changeset viewer.