Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r830c36e r9a6cc40  
    143143  e->buffy=0;
    144144  owl_editwin_overwrite_string(e, text);
    145   owl_editwin_overwrite_char(e, '\0');
    146145  e->lock=strlen(text);
    147146  /* if (text[e->lock-1]=='\n') e->lock--; */
    148   /*  e->buffx=x; */
    149   /*  e->buffy=y; */
     147  e->buffx=x;
     148  e->buffy=y;
    150149  owl_editwin_adjust_for_locktext(e);
    151150  owl_editwin_redisplay(e, 0);
     
    252251
    253252  /* start at topline */
    254   ptr1 = e->buff;
    255   for (i = 0; i < e->topline; i++) {
    256     ptr2 = strchr(ptr1, '\n');
     253  ptr1=e->buff;
     254  for (i=0; i<e->topline; i++) {
     255    ptr2=strchr(ptr1, '\n');
    257256    if (!ptr2) {
    258257      /* we're already on the last line */
    259258      break;
    260259    }
    261     ptr1 = ptr2 + 1;
     260    ptr1=ptr2+1;
    262261  }
    263262  /* ptr1 now stores the starting point */
    264263
    265264  /* find the ending point and store it in ptr3 */
    266   ptr2 = ptr1;
    267   ptr3 = ptr1;
    268   for (i = 0; i < e->winlines; i++) {
    269     ptr3 = strchr(ptr2, '\n');
     265  ptr2=ptr1;
     266  ptr3=ptr1;
     267  for (i=0; i<e->winlines; i++) {
     268    ptr3=strchr(ptr2, '\n');
    270269    if (!ptr3) {
    271270      /* we've hit the last line */
    272271      /* print everything to the end */
    273       ptr3 = e->buff + e->bufflen - 1;
     272      ptr3=e->buff+e->bufflen-1;
    274273      ptr3--;
    275274      break;
    276275    }
    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') {
     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') {
    285284    waddstr(e->curswin, buff);
    286285  } else {
    287286    /* translate to echochar, *except* for the locktext */
    288287    int len;
    289     int dolocklen = e->lock - (ptr1 - e->buff);
    290 
    291     for (i = 0; i < dolocklen; i++) {
     288    int dolocklen=e->lock-(ptr1-e->buff);
     289
     290    for (i=0; i<dolocklen; i++) {
    292291      waddch(e->curswin, buff[i]);
    293292    }
    294     len = strlen(buff);
    295     for (i = 0; i < len-dolocklen; i++) {
     293    len=strlen(buff);
     294    for (i=0; i<len-dolocklen; i++) {
    296295      waddch(e->curswin, e->echochar);
    297296    }
    298297  }
    299   wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e));
     298  wmove(e->curswin, e->buffy-e->topline, e->buffx);
    300299  wnoutrefresh(e->curswin);
    301   if (update == 1) {
     300  if (update==1) {
    302301    doupdate();
    303302  }
    304303  owl_free(buff);
    305 }
    306 
    307 /* Remove n bytes at cursor. */
    308 void _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 
    319 /* Insert n bytes at cursor.*/
    320 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/
    321 {
    322   int i, z;
    323  
    324   if ((e->bufflen + n) > (e->allocated - 5)) {
    325     _owl_editwin_addspace(e);
    326   }
    327 
    328   e->bufflen += n;
    329   e->buff[e->bufflen] = '\0';
    330  
    331   z = _owl_editwin_get_index_from_xy(e);
    332   for (i = e->bufflen - 1; i > z; i--) {
    333     e->buff[i] = e->buff[i - n];
    334   }
    335304}
    336305
     
    344313  int i, z;
    345314
    346   z = _owl_editwin_get_index_from_xy(e);
     315  z=_owl_editwin_get_index_from_xy(e);
    347316  /* move back and line wrap the previous word */
    348   for (i = z - 1; ; i--) {
     317  for (i=z-1; ; i--) {
    349318    /* move back until you find a space or hit the beginning of the line */
    350     if (e->buff[i] == ' ') {
     319    if (e->buff[i]==' ') {
    351320      /* replace the space with a newline */
    352       e->buff[i] = '\n';
     321      e->buff[i]='\n';
    353322      e->buffy++;
    354       e->buffx = z - i - 1;
     323      e->buffx=z-i-1;
    355324      /* were we on the last line */
    356325      return(0);
    357     } else if (e->buff[i] == '\n' || i <= e->lock) {
    358       /* we hit the beginning of the line or the buffer, we cannot
     326    } else if (e->buff[i]=='\n' || i<=e->lock) {
     327      /* we hit the begginning of the line or the buffer, we cannot
    359328       * wrap.
    360329       */
     
    367336 * characters over)
    368337 */
    369 void owl_editwin_insert_char(owl_editwin *e, gunichar c)
    370 {
    371   int z, i, ret, len;
    372   char tmp[6];
    373   memset(tmp, '\0', 6);
     338void owl_editwin_insert_char(owl_editwin *e, char c)
     339{
     340 
     341  int z, i, ret;
    374342
    375343  /* \r is \n */
    376   if (c == '\r') {
    377     c = '\n';
    378   }
    379 
    380   if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
     344  if (c=='\r') {
     345    c='\n';
     346  }
     347
     348  if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {
    381349    /* perhaps later this will change some state that allows the string
    382350       to be read */
     
    384352  }
    385353
    386   g_unichar_to_utf8(c, tmp);
    387   len = strlen(tmp);
    388 
    389354  /* make sure there is enough memory for the new text */
    390   if ((e->bufflen + len) > (e->allocated - 5)) {
     355  if ((e->bufflen+1) > (e->allocated-5)) {
    391356    _owl_editwin_addspace(e);
    392357  }
    393358
    394359  /* get the insertion point */
    395   z = _owl_editwin_get_index_from_xy(e);
     360  z=_owl_editwin_get_index_from_xy(e);
    396361
    397362  /* If we're going to insert at the last column do word wrapping, unless it's a \n */
    398   if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) {
    399     ret = _owl_editwin_linewrap_word(e);
    400     if (ret == -1) {
     363  if ((e->buffx+1==e->wrapcol) && (c!='\n')) {
     364    ret=_owl_editwin_linewrap_word(e);
     365    if (ret==-1) {
    401366      /* we couldn't wrap, insert a hard newline instead */
    402367      owl_editwin_insert_char(e, '\n');
     
    404369  }
    405370
     371  z=_owl_editwin_get_index_from_xy(e);
    406372  /* shift all the other characters right */
    407   if (z != e->bufflen) {
    408     _owl_editwin_insert_bytes(e, len);
    409   }
    410 
    411   /* insert the new character */
    412   for(i = 0; i < len; i++) {
    413     e->buff[z + i] = tmp[i];
    414   }
     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;
    415379
    416380  /* housekeeping */
    417   e->bufflen += len;
    418   e->buff[e->bufflen] = '\0';
     381  e->bufflen++;
     382  e->buff[e->bufflen]='\0';
     383
     384  /* advance the cursor */
     385  if (c=='\n') {
     386    e->buffx=0;
     387    e->buffy++;
     388  } else {
     389    e->buffx++;
     390  }
     391}
     392
     393/* overwrite the character at the current point with 'c' */
     394void owl_editwin_overwrite_char(owl_editwin *e, char c)
     395{
     396  int z;
    419397 
    420   /* advance the cursor */
    421   z += len;
    422   _owl_editwin_set_xy_by_index(e, z);
    423 }
    424 
    425 /* overwrite the character at the current point with 'c' */
    426 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c)
    427 {
    428   int z, oldlen, newlen, i;
    429   char tmp[6];
    430   memset(tmp, '\0', 6);
    431 
    432398  /* \r is \n */
    433   if (c == '\r') {
    434     c = '\n';
    435   }
    436  
    437   if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
     399  if (c=='\r') {
     400    c='\n';
     401  }
     402
     403  if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {
    438404    /* perhaps later this will change some state that allows the string
    439405       to be read */
     
    441407  }
    442408
    443   g_unichar_to_utf8(c, tmp);
    444   newlen = strlen(tmp);
    445 
    446   z = _owl_editwin_get_index_from_xy(e);
    447   {
    448     char *t = g_utf8_find_next_char(e->buff + z, NULL);
    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)) {
     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)) {
    455414      _owl_editwin_addspace(e);
    456415    }
    457416  }
    458   /* if not at the end of the buffer, adjust based in char size difference. */
    459   else if (oldlen > newlen) {
    460     _owl_editwin_remove_bytes(e, oldlen-newlen);
    461   }
    462   else /* oldlen < newlen */ {
    463     _owl_editwin_insert_bytes(e, newlen-oldlen);
    464   }
    465   /* Overwrite the old char*/
    466   for (i = 0; i < newlen; i++) {
    467     e->buff[z+i] = tmp[i];
    468   }
    469        
    470   /* housekeeping */
    471   if (z == e->bufflen) {
    472     e->bufflen += newlen;
    473     e->buff[e->bufflen] = '\0';
    474   }
    475417 
     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  }
     425
    476426  /* advance the cursor */
    477   z += newlen;
    478   _owl_editwin_set_xy_by_index(e, z);
     427  if (c=='\n') {
     428    e->buffx=0;
     429    e->buffy++;
     430  } else {
     431    e->buffx++;
     432  }
     433
    479434}
    480435
     
    484439void owl_editwin_delete_char(owl_editwin *e)
    485440{
    486   int z;
    487   char *p1, *p2;
    488   gunichar c;
    489 
    490   if (e->bufflen == 0) return;
     441  int z, i;
     442
     443  if (e->bufflen==0) return;
    491444 
    492445  /* get the deletion point */
    493   z = _owl_editwin_get_index_from_xy(e);
    494 
    495   if (z == e->bufflen) return;
    496 
    497   p1 = e->buff + z;
    498   p2 = g_utf8_next_char(p1);
    499   c = g_utf8_get_char(p2);
    500   while (g_unichar_ismark(c)) {
    501     p2 = g_utf8_next_char(p2);
    502     c = g_utf8_get_char(p2);
    503   }
    504   _owl_editwin_remove_bytes(e, p2-p1);
     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';
    505455}
    506456
     
    513463{
    514464  int z;
    515   char *p1, *p2, *p3, *tmp;
    516 
    517   if (e->bufflen == 0) return;
     465  char tmp;
     466
     467  if (e->bufflen==0) return;
    518468 
    519469  /* get the cursor point */
    520   z = _owl_editwin_get_index_from_xy(e);
    521 
    522   if (z == e->bufflen) {
     470  z=_owl_editwin_get_index_from_xy(e);
     471
     472  if (z==e->bufflen) {
    523473    /* point is after last character */
    524474    z--;
    525475  } 
    526476
    527   if (z - 1 < e->lock) {
     477  if (z-1 < e->lock) {
    528478    /* point is at beginning of buffer, do nothing */
    529479    return;
    530480  }
    531481
    532   /* Transpose two utf-8 unicode glyphs. */
    533   p1 = e->buff + z;
    534 
    535   p2 = g_utf8_find_next_char(p1, NULL);
    536   while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) {
    537     p2 = g_utf8_find_next_char(p2, NULL);
    538   }
    539   if (p2 == NULL) return;
    540 
    541   p3 = g_utf8_find_prev_char(e->buff, p1);
    542   while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) {
    543     p3 = g_utf8_find_prev_char(p3, NULL);
    544   }
    545   if (p3 == NULL) return;
    546 
    547   tmp = owl_malloc(p2 - p3 + 5);
    548   *tmp = '\0';
    549   strncat(tmp, p1, p2 - p1);
    550   strncat(tmp, p3, p1 - p3);
    551   strncpy(p3, tmp, p2 - p3);
    552   owl_free(tmp);
    553   _owl_editwin_set_xy_by_index(e, p3 - e->buff);
     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);
    554486}
    555487
     
    559491void owl_editwin_insert_string(owl_editwin *e, char *string)
    560492{
    561   char *p;
    562   gunichar c;
    563   if (!g_utf8_validate(string, -1, NULL)) {
    564     owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string.");
    565     return;
    566   }
    567   p = string;
    568   c = g_utf8_get_char(p);
    569   while (c) {
    570     owl_editwin_process_char(e, c);
    571     p = g_utf8_next_char(p);
    572     c = g_utf8_get_char(p);
     493  int i, j;
     494
     495  j=strlen(string);
     496  for (i=0; i<j; i++) {
     497    owl_editwin_insert_char(e, string[i]);
    573498  }
    574499}
     
    580505void owl_editwin_overwrite_string(owl_editwin *e, char *string)
    581506{
    582   char *p;
    583   gunichar c;
    584 
    585   if (!g_utf8_validate(string, -1, NULL)) {
    586     owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string.");
    587     return;
    588   }
    589   p = string;
    590   c = g_utf8_get_char(p);
    591   while (c) {
    592     owl_editwin_overwrite_char(e, c);
    593     p = g_utf8_next_char(p);
    594     c = g_utf8_get_char(p);
     507  int i, j;
     508
     509  j=strlen(string);
     510  for (i=0; i<j; i++) {
     511    owl_editwin_overwrite_char(e, string[i]);
    595512  }
    596513}
     
    603520  int i;
    604521  char *ptr1, *ptr2;
    605   gunichar c;
    606 
    607   if (e->bufflen == 0) return(0);
     522
     523  if (e->bufflen==0) return(0);
    608524 
    609525  /* first go to the yth line */
    610   ptr1 = e->buff;
    611   for (i = 0; i < e->buffy; i++) {
    612     ptr2= strchr(ptr1, '\n');
     526  ptr1=e->buff;
     527  for (i=0; i<e->buffy; i++) {
     528    ptr2=strchr(ptr1, '\n');
    613529    if (!ptr2) {
    614530      /* we're already on the last line */
    615531      break;
    616532    }
    617     ptr1 = ptr2 + 1;
    618   }
    619 
    620   /* now go to the xth cell */
    621   ptr2 = ptr1;
    622   i = 0;
    623   while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) {
    624     c = g_utf8_get_char(ptr2);
    625     i += (c == '\n' ? 1 : mk_wcwidth(c));
    626     ptr2 = g_utf8_next_char(ptr2);
    627   }
    628   while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) {
    629     ptr2 = g_utf8_next_char(ptr2);
    630   }
    631   if (ptr2 == NULL) return e->bufflen;
    632   return(ptr2 - e->buff);
     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);
    633550}
    634551
    635552void _owl_editwin_set_xy_by_index(owl_editwin *e, int index)
    636553{
    637   char *ptr1, *ptr2, *target;
    638   gunichar c;
    639 
    640   e->buffx = 0;
    641   e->buffy = 0;
    642 
    643   ptr1 = e->buff;
    644   target = ptr1 + index;
    645   /* target sanitizing */
    646   if ((target[0] & 0x80) && (~target[0] & 0x40)) {
    647     /* middle of a utf-8 character, back up to previous character. */
    648     target = g_utf8_find_prev_char(e->buff, target);
    649   }
    650   c = g_utf8_get_char(target);
    651   while (g_unichar_ismark(c) && target > e->buff) {
    652     /* Adjust the target off of combining characters and the like. */
    653     target = g_utf8_find_prev_char(e->buff, target);
    654     c = g_utf8_get_char(target);
    655   }
    656   /* If we start with a mark, something is wrong.*/
    657   if (g_unichar_ismark(c)) return;
    658 
    659   /* Now our target should be acceptable. */
    660   ptr2 = strchr(ptr1, '\n');
    661   while (ptr2 != NULL && ptr2 < target) {
    662     e->buffy++;
    663     ptr1 = ptr2 + 1;
    664     ptr2 = strchr(ptr1, '\n');
    665   }
    666   ptr2 = ptr1;
    667   while (ptr2 != NULL && ptr2 < target) {
    668     c = g_utf8_get_char(ptr2);
    669     e->buffx += mk_wcwidth(c);
    670     ptr2 = g_utf8_next_char(ptr2);
    671   }
    672 }
    673 
    674 int _owl_editwin_cursor_adjustment(owl_editwin *e)
    675 {
    676   char *ptr1, *ptr2;
    677   gunichar c;
    678   int x, i;
    679 
    680   ptr1 = e->buff;
    681   ptr2 = strchr(ptr1, '\n');
    682   for (i = 0; ptr2 != NULL && i < e->buffy; i++) {
    683     ptr1 = ptr2 + 1;
    684     ptr2 = strchr(ptr1, '\n');
    685   }
    686   ptr2 = ptr1;
    687   x = 0;
    688   while (ptr2 != NULL && x < e->buffx) {
    689     if (*ptr2 == '\n') return 0;
    690     c = g_utf8_get_char(ptr2);
    691     x += mk_wcwidth(c);
    692     ptr2 = g_utf8_next_char(ptr2);
    693   }
    694   return x - e->buffx;
     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  }
    695566}
    696567
     
    699570  /* if we happen to have the cursor over locked text
    700571   * move it to be out of the locktext region */
    701   if (_owl_editwin_get_index_from_xy(e) < e->lock) {
     572  if (_owl_editwin_get_index_from_xy(e)<e->lock) {
    702573    _owl_editwin_set_xy_by_index(e, e->lock);
    703574  }
     
    719590{
    720591  if (e->buffy > 0) e->buffy--;
    721   if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) {
    722     e->buffx=owl_editwin_get_numcells_on_line(e, 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);
    723594  }
    724595
     
    737608
    738609  /* if we're past the last character move back */
    739   if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) {
    740     e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     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);
    741612  }
    742613
     
    752623void owl_editwin_key_left(owl_editwin *e)
    753624{
    754   int i;
    755   char * p;
    756   i = _owl_editwin_get_index_from_xy(e);
    757   p = e->buff + i;
    758   p = g_utf8_find_prev_char(e->buff, p);
    759   while (p && g_unichar_ismark(g_utf8_get_char(p))) {
    760     p = g_utf8_find_prev_char(e->buff, p);
    761   }
    762   if (p == NULL) p = e->buff;
    763   _owl_editwin_set_xy_by_index(e, p - e->buff);
    764 
    765   if (e->buffy - e->topline < 0) {
    766     e->topline -= e->winlines / 2;
     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;
    767636  }
    768637
     
    774643{
    775644  int i;
    776   char * p;
    777   i = _owl_editwin_get_index_from_xy(e);
    778   p = e->buff + i;
    779   p = g_utf8_find_next_char(p, NULL);
    780   while (p && g_unichar_ismark(g_utf8_get_char(p))) {
    781     p = g_utf8_find_next_char(p, NULL);
    782   }
    783   if (p == NULL) {
    784     _owl_editwin_set_xy_by_index(e, e->bufflen);
    785   }
    786   else {
    787     _owl_editwin_set_xy_by_index(e, p - e->buff);
     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    }
    788656  }
    789657
    790658  /* do we need to scroll down? */
    791   if (e->buffy - e->topline >= e->winlines) {
    792     e->topline += e->winlines / 2;
     659  if (e->buffy-e->topline >= e->winlines) {
     660    e->topline+=e->winlines/2;
    793661  }
    794662}
     
    796664void owl_editwin_move_to_nextword(owl_editwin *e)
    797665{
    798   /* asedeno: needs fixing for utf-8*/
    799666  int i, x;
    800667
     
    836703void owl_editwin_move_to_previousword(owl_editwin *e)
    837704{
    838   /* asedeno: needs fixing for utf-8*/
    839705  int i, x;
    840706
     
    872738void owl_editwin_delete_nextword(owl_editwin *e)
    873739{
    874   /* asedeno: needs fixing for utf-8*/
    875740  int z;
    876741
     
    903768void owl_editwin_delete_previousword(owl_editwin *e)
    904769{
    905   /* asedeno: needs fixing for utf-8*/
    906770  /* go backwards to the last non-space character, then delete chars */
    907771  int i, startpos, endpos;
     
    917781void owl_editwin_delete_to_endofline(owl_editwin *e)
    918782{
    919   /* asedeno: needs fixing for utf-8*/
    920783  int i;
    921784
    922   if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) {
     785  if (owl_editwin_get_numchars_on_line(e, e->buffy)>e->buffx) {
    923786    /* normal line */
    924787    i=_owl_editwin_get_index_from_xy(e);
     
    941804void owl_editwin_move_to_line_end(owl_editwin *e)
    942805{
    943   e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     806  e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    944807}
    945808
     
    954817  /* go to last char */
    955818  e->buffy=owl_editwin_get_numlines(e)-1;
    956   e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     819  e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    957820  owl_editwin_key_right(e);
    958821
     
    978841void owl_editwin_fill_paragraph(owl_editwin *e)
    979842{
    980   /* asedeno: needs fixing for utf-8*/
    981843  int i, save;
    982844
     
    995857  /* main loop */
    996858  while (1) {
    997     i = _owl_editwin_get_index_from_xy(e);
     859    i=_owl_editwin_get_index_from_xy(e);
    998860
    999861    /* bail if we hit the end of the buffer */
    1000     if (i >= e->bufflen || e->buff[i] == '\0') break;
     862    if (i>=e->bufflen) break;
    1001863
    1002864    /* bail if we hit the end of the paragraph */
    1003     if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break;
     865    if (e->buff[i]=='\n' && e->buff[i+1]=='\n') break;
    1004866
    1005867    /* if we've travelled too far, linewrap */
     
    1009871
    1010872    /* did we hit the end of a line too soon? */
    1011     i = _owl_editwin_get_index_from_xy(e);
    1012     if (e->buff[i] == '\n' && e->buffx < e->fillcol - 1) {
     873    i=_owl_editwin_get_index_from_xy(e);
     874    if (e->buff[i]=='\n' && e->buffx<e->fillcol-1) {
    1013875      /* ********* we need to make sure we don't pull in a word that's too long ***********/
    1014876      e->buff[i]=' ';
     
    1016878   
    1017879    /* fix spacing */
    1018     i = _owl_editwin_get_index_from_xy(e);
    1019     if (e->buff[i] == ' ' && e->buff[i+1] == ' ') {
    1020       if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] == '?') {
     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]=='?') {
    1021883        owl_editwin_key_right(e);
    1022884      } else {
    1023885        owl_editwin_delete_char(e);
    1024886        /* if we did this ahead of the save point, adjust it */
    1025         if (i < save) save--;
     887        if (i<save) save--;
    1026888      }
    1027889    } else {
     
    1049911int owl_editwin_check_dotsend(owl_editwin *e)
    1050912{
    1051   char *p, *p_n, *p_p;
    1052   gunichar c;
     913  int i;
    1053914
    1054915  if (!e->dotsend) return(0);
    1055 
    1056   p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen);
    1057   p_n = g_utf8_find_next_char(p, NULL);
    1058   p_p = g_utf8_find_prev_char(e->buff, p);
    1059   c = g_utf8_get_char(p);
    1060   while (p != NULL) {
    1061     if (*p == '.'
    1062         && p_p != NULL && (*p_p == '\n' || *p_p == '\r')
    1063         && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) {
    1064       e->bufflen = p - e->buff;
    1065       e->buff[e->bufflen] = '\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';
    1066922      return(1);
    1067923    }
    1068     if (c != '\0' && !g_unichar_isspace(c)) return(0);
    1069     p_n = p;
    1070     p = p_p;
    1071     c = g_utf8_get_char(p);
    1072     p_p = g_utf8_find_prev_char(e->buff, p);
     924    if (!isspace((int) e->buff[i])) {
     925      return(0);
     926    }
    1073927  }
    1074928  return(0);
    1075929}
    1076930
    1077 void owl_editwin_post_process_char(owl_editwin *e, gunichar j)
     931void owl_editwin_post_process_char(owl_editwin *e, int j)
    1078932{
    1079933  /* check if we need to scroll down */
     
    1088942}
    1089943
    1090 void owl_editwin_process_char(owl_editwin *e, gunichar j)
     944void owl_editwin_process_char(owl_editwin *e, int j)
    1091945{
    1092946  if (j == ERR) return;
    1093   if (g_unichar_iscntrl(j) && (j != 10) && (j != 13)) {
     947  if (j>127 || ((j<32) && (j!=10) && (j!=13))) {
    1094948    return;
    1095   }
    1096   else {
     949  } else {
    1097950    owl_editwin_insert_char(e, j);
    1098951  }
     
    1122975  }
    1123976
    1124   /* now count characters */
    1125   i = 0;
    1126   ptr2 = ptr1;
    1127   while (ptr2 - e->buff < e->bufflen
    1128          && *ptr2 != '\n') {
    1129     ++i;
    1130     ptr2 = g_utf8_next_char(ptr2);
    1131   }
    1132   return i;
    1133 }
    1134 
    1135 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line)
    1136 {
    1137   int i;
    1138   char *ptr1, *ptr2;
    1139   gunichar c;
    1140 
    1141   if (e->bufflen==0) return(0);
    1142  
    1143   /* first go to the yth line */
    1144   ptr1=e->buff;
    1145   for (i=0; i<line; i++) {
    1146     ptr2=strchr(ptr1, '\n');
    1147     if (!ptr2) {
    1148       /* we're already on the last line */
    1149       return(0);
    1150     }
    1151     ptr1=ptr2+1;
    1152   }
    1153 
    1154   /* now count cells */
    1155   i = 0;
    1156   ptr2 = ptr1;
    1157   while (ptr2 - e->buff < e->bufflen
    1158          && *ptr2 != '\n') {
    1159     c = g_utf8_get_char(ptr2);
    1160     i += mk_wcwidth(c);
    1161     ptr2 = g_utf8_next_char(ptr2);
    1162   }
    1163   return i;
     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 */
    1164983}
    1165984
Note: See TracChangeset for help on using the changeset viewer.