Changes in / [b7b4565:f2d72128]


Ignore:
Files:
2 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • Makefile.in

    rc60ade2 r2bdfed9  
    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 wcwidth.c glib_compat.c
     28     zbuddylist.c muxevents.c popexec.c obarray.c
    2929OWL_SRC = owl.c
    3030TESTER_SRC = tester.c
  • aim.c

    r34509d5 r9854278  
    948948 
    949949  if (modname) {
    950     if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
     950    if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
    951951      /* perror("memrequest: malloc"); */
    952952      return -1;
     
    954954    sprintf(filename, "%s/%s.ocm", priv->aimbinarypath, modname);
    955955  } else {
    956     if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
     956    if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
    957957      /* perror("memrequest: malloc"); */
    958958      return -1;
     
    964964    if (!modname) {
    965965      /* perror("memrequest: stat"); */
    966       owl_free(filename);
     966      free(filename);
    967967      return -1;
    968968    }
     
    986986    int i;
    987987   
    988     owl_free(filename); /* not needed */
     988    free(filename); /* not needed */
    989989    owl_function_error("getaimdata memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname);
    990990    i = 8;
     
    993993    }
    994994   
    995     if (!(buf = owl_malloc(i))) {
     995    if (!(buf = malloc(i))) {
    996996      return -1;
    997997    }
     
    10171017    *buflenret = i;
    10181018  } else {
    1019     if (!(buf = owl_malloc(len))) {
    1020       owl_free(filename);
     1019    if (!(buf = malloc(len))) {
     1020      free(filename);
    10211021      return -1;
    10221022    }
     
    10241024    if (!(f = fopen(filename, "r"))) {
    10251025      /* perror("memrequest: fopen"); */
    1026       owl_free(filename);
    1027       owl_free(buf);
     1026      free(filename);
     1027      free(buf);
    10281028      return -1;
    10291029    }
    10301030   
    1031     owl_free(filename);
     1031    free(filename);
    10321032   
    10331033    if (fseek(f, offset, SEEK_SET) == -1) {
    10341034      /* perror("memrequest: fseek"); */
    10351035      fclose(f);
    1036       owl_free(buf);
     1036      free(buf);
    10371037      return -1;
    10381038    }
     
    10411041      /* perror("memrequest: fread"); */
    10421042      fclose(f);
    1043       owl_free(buf);
     1043      free(buf);
    10441044      return -1;
    10451045    }
     
    10761076  if (priv->aimbinarypath && (getaimdata(sess, &buf, &buflen, offset, len, modname) == 0)) {
    10771077    aim_sendmemblock(sess, fr->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
    1078     owl_free(buf);
     1078    free(buf);
    10791079  } else {
    10801080    owl_function_debugmsg("faimtest_memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", priv->aimbinarypath, modname);
     
    13421342      int z;
    13431343     
    1344       newbuf = owl_malloc(i+1);
     1344      newbuf = malloc(i+1);
    13451345      for (z = 0; z < i; z++)
    13461346        newbuf[z] = (z % 10)+0x30;
    13471347      newbuf[i] = '\0';
    13481348      /* aim_send_im(sess, userinfo->sn, AIM_IMFLAGS_ACK | AIM_IMFLAGS_AWAY, newbuf); */
    1349       owl_free(newbuf);
     1349      free(newbuf);
    13501350    }
    13511351  } else if (strstr(tmpstr, "seticqstatus")) {
  • cmd.c

    r34509d5 r6922edd  
    7474  owl_cmd *cmd;
    7575
    76   tmpbuff=owl_strdup(cmdbuff);
     76  tmpbuff=strdup(cmdbuff);
    7777  argv=owl_parseline(tmpbuff, &argc);
    7878  if (argc < 0) {
  • config.h.in

    re23eb2b r03cf6b9  
    2222#undef HAVE_LIBCOM_ERR
    2323
     24/* Define to 1 if you have the `curses' library (-lcurses). */
     25#undef HAVE_LIBCURSES
     26
    2427/* Define to 1 if you have the `des425' library (-ldes425). */
    2528#undef HAVE_LIBDES425
     
    3639/* Define to 1 if you have the `krb5' library (-lkrb5). */
    3740#undef HAVE_LIBKRB5
     41
     42/* Define to 1 if you have the `ncurses' library (-lncurses). */
     43#undef HAVE_LIBNCURSES
    3844
    3945/* Define to 1 if you have the `ncursesw' library (-lncursesw). */
  • configure.in

    re23eb2b r18e28a4  
    1212fi
    1313
    14 m4_include(/usr/share/aclocal/pkg.m4)
    15 dnl m4_include(pkg.m4)
    1614
    1715dnl Check for Athena
     
    4644fi
    4745
    48 AC_CHECK_LIB(ncursesw, initscr,, AC_MSG_ERROR(No curses library found.))
     46AC_CHECK_LIB(ncursesw, initscr,,
     47  AC_CHECK_LIB(ncurses, initscr,,
     48    AC_CHECK_LIB(curses, initscr,, AC_MSG_ERROR(No curses library found.))))
    4949AC_CHECK_LIB(com_err, com_err)
    5050AC_CHECK_LIB(nsl, gethostbyname)
     
    109109LDFLAGS=${LDFLAGS}\ ${FOO}
    110110
    111 dnl Add CFLAGS and LDFLAGS for glib-2.0
    112 PKG_CHECK_MODULES(GLIB,glib-2.0)
    113 
    114 echo Adding glib-2.0 CFLAGS ${GLIB_CFLAGS}
    115 CFLAGS=${CFLAGS}\ ${GLIB_CFLAGS}
    116 echo Adding glib-2.0 LDFLAGS ${GLIB_LIBS}
    117 LDFLAGS=${LDFLAGS}\ ${GLIB_LIBS}
    118 
    119 
    120111dnl Checks for typedefs, structures, and compiler characteristics.
    121112
  • editwin.c

    rcc6f009 rcc6f009  
    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);
     
    256255
    257256  /* start at topline */
    258   ptr1 = e->buff;
    259   for (i = 0; i < e->topline; i++) {
    260     ptr2 = strchr(ptr1, '\n');
     257  ptr1=e->buff;
     258  for (i=0; i<e->topline; i++) {
     259    ptr2=strchr(ptr1, '\n');
    261260    if (!ptr2) {
    262261      /* we're already on the last line */
    263262      break;
    264263    }
    265     ptr1 = ptr2 + 1;
     264    ptr1=ptr2+1;
    266265  }
    267266  /* ptr1 now stores the starting point */
    268267
    269268  /* find the ending point and store it in ptr3 */
    270   ptr2 = ptr1;
    271   ptr3 = ptr1;
    272   for (i = 0; i < e->winlines; i++) {
    273     ptr3 = strchr(ptr2, '\n');
     269  ptr2=ptr1;
     270  ptr3=ptr1;
     271  for (i=0; i<e->winlines; i++) {
     272    ptr3=strchr(ptr2, '\n');
    274273    if (!ptr3) {
    275274      /* we've hit the last line */
    276275      /* print everything to the end */
    277       ptr3 = e->buff + e->bufflen - 1;
     276      ptr3=e->buff+e->bufflen-1;
    278277      ptr3--;
    279278      break;
    280279    }
    281     ptr2 = ptr3 + 1;
    282   }
    283   ptr3 += 2;
    284 
    285   buff = owl_malloc(ptr3 - ptr1 + 50);
    286   strncpy(buff, ptr1, ptr3 - ptr1);
    287   buff[ptr3 - ptr1] = '\0';
    288   if (e->echochar == '\0') {
     280    ptr2=ptr3+1;
     281  }
     282  ptr3+=2;
     283
     284  buff=owl_malloc(ptr3-ptr1+50);
     285  strncpy(buff, ptr1, ptr3-ptr1);
     286  buff[ptr3-ptr1]='\0';
     287  if (e->echochar=='\0') {
    289288    waddstr(e->curswin, buff);
    290289  } else {
    291290    /* translate to echochar, *except* for the locktext */
    292291    int len;
    293     int dolocklen = e->lock - (ptr1 - e->buff);
    294 
    295     for (i = 0; i < dolocklen; i++) {
     292    int dolocklen=e->lock-(ptr1-e->buff);
     293
     294    for (i=0; i<dolocklen; i++) {
    296295      waddch(e->curswin, buff[i]);
    297296    }
    298     len = strlen(buff);
    299     for (i = 0; i < len-dolocklen; i++) {
     297    len=strlen(buff);
     298    for (i=0; i<len-dolocklen; i++) {
    300299      waddch(e->curswin, e->echochar);
    301300    }
    302301  }
    303   wmove(e->curswin, e->buffy-e->topline, e->buffx + _owl_editwin_cursor_adjustment(e));
     302  wmove(e->curswin, e->buffy-e->topline, e->buffx);
    304303  wnoutrefresh(e->curswin);
    305   if (update == 1) {
     304  if (update==1) {
    306305    doupdate();
    307306  }
    308307  owl_free(buff);
    309 }
    310 
    311 /* Remove n bytes at cursor. */
    312 void _owl_editwin_remove_bytes(owl_editwin *e, int n) /*noproto*/
    313 {
    314   int i = _owl_editwin_get_index_from_xy(e) + n;
    315   for (; i < e->bufflen; i++) {
    316     e->buff[i-n] = e->buff[i];
    317   }
    318  
    319   e->bufflen -= n;
    320   e->buff[e->bufflen] = '\0';
    321 }
    322 
    323 /* Insert n bytes at cursor.*/
    324 void _owl_editwin_insert_bytes(owl_editwin *e, int n) /*noproto*/
    325 {
    326   int i, z;
    327  
    328   if ((e->bufflen + n) > (e->allocated - 5)) {
    329     _owl_editwin_addspace(e);
    330   }
    331 
    332   e->bufflen += n;
    333   e->buff[e->bufflen] = '\0';
    334  
    335   z = _owl_editwin_get_index_from_xy(e);
    336   for (i = e->bufflen - 1; i > z; i--) {
    337     e->buff[i] = e->buff[i - n];
    338   }
    339308}
    340309
     
    348317  int i, z;
    349318
    350   z = _owl_editwin_get_index_from_xy(e);
     319  z=_owl_editwin_get_index_from_xy(e);
    351320  /* move back and line wrap the previous word */
    352   for (i = z - 1; ; i--) {
     321  for (i=z-1; ; i--) {
    353322    /* move back until you find a space or hit the beginning of the line */
    354     if (e->buff[i] == ' ') {
     323    if (e->buff[i]==' ') {
    355324      /* replace the space with a newline */
    356       e->buff[i] = '\n';
     325      e->buff[i]='\n';
    357326      e->buffy++;
    358       e->buffx = z - i - 1;
     327      e->buffx=z-i-1;
    359328      /* were we on the last line */
    360329      return(0);
    361     } else if (e->buff[i] == '\n' || i <= e->lock) {
    362       /* we hit the beginning of the line or the buffer, we cannot
     330    } else if (e->buff[i]=='\n' || i<=e->lock) {
     331      /* we hit the begginning of the line or the buffer, we cannot
    363332       * wrap.
    364333       */
     
    371340 * characters over)
    372341 */
    373 void owl_editwin_insert_char(owl_editwin *e, gunichar c)
    374 {
    375   int z, i, ret, len;
    376   char tmp[6];
    377   memset(tmp, '\0', 6);
     342void owl_editwin_insert_char(owl_editwin *e, char c)
     343{
     344 
     345  int z, i, ret;
    378346
    379347  /* \r is \n */
    380   if (c == '\r') {
    381     c = '\n';
    382   }
    383 
    384   if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
     348  if (c=='\r') {
     349    c='\n';
     350  }
     351
     352  if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {
    385353    /* perhaps later this will change some state that allows the string
    386354       to be read */
     
    388356  }
    389357
    390   g_unichar_to_utf8(c, tmp);
    391   len = strlen(tmp);
    392 
    393358  /* make sure there is enough memory for the new text */
    394   if ((e->bufflen + len) > (e->allocated - 5)) {
     359  if ((e->bufflen+1) > (e->allocated-5)) {
    395360    _owl_editwin_addspace(e);
    396361  }
    397362
    398363  /* get the insertion point */
    399   z = _owl_editwin_get_index_from_xy(e);
     364  z=_owl_editwin_get_index_from_xy(e);
    400365
    401366  /* If we're going to insert at the last column do word wrapping, unless it's a \n */
    402   if ((e->buffx + 1 == e->wrapcol) && (c != '\n')) {
    403     ret = _owl_editwin_linewrap_word(e);
    404     if (ret == -1) {
     367  if ((e->buffx+1==e->wrapcol) && (c!='\n')) {
     368    ret=_owl_editwin_linewrap_word(e);
     369    if (ret==-1) {
    405370      /* we couldn't wrap, insert a hard newline instead */
    406371      owl_editwin_insert_char(e, '\n');
     
    408373  }
    409374
     375  z=_owl_editwin_get_index_from_xy(e);
    410376  /* shift all the other characters right */
    411   if (z != e->bufflen) {
    412     _owl_editwin_insert_bytes(e, len);
    413   }
    414 
    415   /* insert the new character */
    416   for(i = 0; i < len; i++) {
    417     e->buff[z + i] = tmp[i];
    418   }
     377  for (i=e->bufflen; i>z; i--) {
     378    e->buff[i]=e->buff[i-1];
     379  }
     380
     381  /* insert the new one */
     382  e->buff[z]=c;
    419383
    420384  /* housekeeping */
    421   e->bufflen += len;
    422   e->buff[e->bufflen] = '\0';
     385  e->bufflen++;
     386  e->buff[e->bufflen]='\0';
     387
     388  /* advance the cursor */
     389  if (c=='\n') {
     390    e->buffx=0;
     391    e->buffy++;
     392  } else {
     393    e->buffx++;
     394  }
     395}
     396
     397/* overwrite the character at the current point with 'c' */
     398void owl_editwin_overwrite_char(owl_editwin *e, char c)
     399{
     400  int z;
    423401 
    424   /* advance the cursor */
    425   z += len;
    426   _owl_editwin_set_xy_by_index(e, z);
    427 }
    428 
    429 /* overwrite the character at the current point with 'c' */
    430 void owl_editwin_overwrite_char(owl_editwin *e, gunichar c)
    431 {
    432   int z, oldlen, newlen, i;
    433   char tmp[6];
    434   memset(tmp, '\0', 6);
    435 
    436402  /* \r is \n */
    437   if (c == '\r') {
    438     c = '\n';
    439   }
    440  
    441   if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
     403  if (c=='\r') {
     404    c='\n';
     405  }
     406
     407  if (c=='\n' && e->style==OWL_EDITWIN_STYLE_ONELINE) {
    442408    /* perhaps later this will change some state that allows the string
    443409       to be read */
     
    445411  }
    446412
    447   g_unichar_to_utf8(c, tmp);
    448   newlen = strlen(tmp);
    449 
    450   z = _owl_editwin_get_index_from_xy(e);
    451   {
    452     char *t = g_utf8_find_next_char(e->buff + z, NULL);
    453     oldlen = (t ? (t - (e->buff + z)) : 0);
    454   }
    455 
    456   /* only if we are at the end of the buffer do we create new space here */
    457   if (z == e->bufflen) {
    458     if ((e->bufflen+newlen) > (e->allocated-5)) {
     413  z=_owl_editwin_get_index_from_xy(e);
     414
     415  /* only if we are at the end of the buffer do we create new space */
     416  if (z==e->bufflen) {
     417    if ((e->bufflen+1) > (e->allocated-5)) {
    459418      _owl_editwin_addspace(e);
    460419    }
    461420  }
    462   /* if not at the end of the buffer, adjust based in char size difference. */
    463   else if (oldlen > newlen) {
    464     _owl_editwin_remove_bytes(e, oldlen-newlen);
    465   }
    466   else /* oldlen < newlen */ {
    467     _owl_editwin_insert_bytes(e, newlen-oldlen);
    468   }
    469   /* Overwrite the old char*/
    470   for (i = 0; i < newlen; i++) {
    471     e->buff[z+i] = tmp[i];
    472   }
    473        
    474   /* housekeeping */
    475   if (z == e->bufflen) {
    476     e->bufflen += newlen;
    477     e->buff[e->bufflen] = '\0';
    478   }
    479421 
     422  e->buff[z]=c;
     423
     424  /* housekeeping if we are at the end of the buffer */
     425  if (z==e->bufflen) {
     426    e->bufflen++;
     427    e->buff[e->bufflen]='\0';
     428  }
     429
    480430  /* advance the cursor */
    481   z += newlen;
    482   _owl_editwin_set_xy_by_index(e, z);
     431  if (c=='\n') {
     432    e->buffx=0;
     433    e->buffy++;
     434  } else {
     435    e->buffx++;
     436  }
     437
    483438}
    484439
     
    488443void owl_editwin_delete_char(owl_editwin *e)
    489444{
    490   int z;
    491   char *p1, *p2;
    492   gunichar c;
    493 
    494   if (e->bufflen == 0) return;
     445  int z, i;
     446
     447  if (e->bufflen==0) return;
    495448 
    496449  /* get the deletion point */
    497   z = _owl_editwin_get_index_from_xy(e);
    498 
    499   if (z == e->bufflen) return;
    500 
    501   p1 = e->buff + z;
    502   p2 = g_utf8_next_char(p1);
    503   c = g_utf8_get_char(p2);
    504   while (g_unichar_ismark(c)) {
    505     p2 = g_utf8_next_char(p2);
    506     c = g_utf8_get_char(p2);
    507   }
    508   _owl_editwin_remove_bytes(e, p2-p1);
     450  z=_owl_editwin_get_index_from_xy(e);
     451
     452  if (z==e->bufflen) return;
     453
     454  for (i=z; i<e->bufflen; i++) {
     455    e->buff[i]=e->buff[i+1];
     456  }
     457  e->bufflen--;
     458  e->buff[e->bufflen]='\0';
    509459}
    510460
     
    517467{
    518468  int z;
    519   char *p1, *p2, *p3, *tmp;
    520 
    521   if (e->bufflen == 0) return;
     469  char tmp;
     470
     471  if (e->bufflen==0) return;
    522472 
    523473  /* get the cursor point */
    524   z = _owl_editwin_get_index_from_xy(e);
    525 
    526   if (z == e->bufflen) {
     474  z=_owl_editwin_get_index_from_xy(e);
     475
     476  if (z==e->bufflen) {
    527477    /* point is after last character */
    528478    z--;
    529479  } 
    530480
    531   if (z - 1 < e->lock) {
     481  if (z-1 < e->lock) {
    532482    /* point is at beginning of buffer, do nothing */
    533483    return;
    534484  }
    535485
    536   /* Transpose two utf-8 unicode glyphs. */
    537   p1 = e->buff + z;
    538 
    539   p2 = g_utf8_find_next_char(p1, NULL);
    540   while (p2 != NULL && g_unichar_ismark(g_utf8_get_char(p2))) {
    541     p2 = g_utf8_find_next_char(p2, NULL);
    542   }
    543   if (p2 == NULL) return;
    544 
    545   p3 = g_utf8_find_prev_char(e->buff, p1);
    546   while (p3 != NULL && g_unichar_ismark(g_utf8_get_char(p3))) {
    547     p3 = g_utf8_find_prev_char(p3, NULL);
    548   }
    549   if (p3 == NULL) return;
    550 
    551   tmp = owl_malloc(p2 - p3 + 5);
    552   *tmp = '\0';
    553   strncat(tmp, p1, p2 - p1);
    554   strncat(tmp, p3, p1 - p3);
    555   strncpy(p3, tmp, p2 - p3);
    556   owl_free(tmp);
    557   _owl_editwin_set_xy_by_index(e, p3 - e->buff);
     486  tmp=e->buff[z];
     487  e->buff[z]=e->buff[z-1];
     488  e->buff[z-1]=tmp;
     489  owl_editwin_key_right(e);
    558490}
    559491
     
    563495void owl_editwin_insert_string(owl_editwin *e, char *string)
    564496{
    565   char *p;
    566   gunichar c;
    567   if (!g_utf8_validate(string, -1, NULL)) {
    568     owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string.");
    569     return;
    570   }
    571   p = string;
    572   c = g_utf8_get_char(p);
    573   while (c) {
    574     _owl_editwin_process_char(e, c);
    575     p = g_utf8_next_char(p);
    576     c = g_utf8_get_char(p);
     497  int i, j;
     498
     499  j=strlen(string);
     500  for (i=0; i<j; i++) {
     501    owl_editwin_insert_char(e, string[i]);
    577502  }
    578503}
     
    584509void owl_editwin_overwrite_string(owl_editwin *e, char *string)
    585510{
    586   char *p;
    587   gunichar c;
    588 
    589   if (!g_utf8_validate(string, -1, NULL)) {
    590     owl_function_debugmsg("owl_editwin_overwrite_string: received non-utf-8 string.");
    591     return;
    592   }
    593   p = string;
    594   c = g_utf8_get_char(p);
    595   while (c) {
    596     owl_editwin_overwrite_char(e, c);
    597     p = g_utf8_next_char(p);
    598     c = g_utf8_get_char(p);
     511  int i, j;
     512
     513  j=strlen(string);
     514  for (i=0; i<j; i++) {
     515    owl_editwin_overwrite_char(e, string[i]);
    599516  }
    600517}
     
    607524  int i;
    608525  char *ptr1, *ptr2;
    609   gunichar c;
    610 
    611   if (e->bufflen == 0) return(0);
     526
     527  if (e->bufflen==0) return(0);
    612528 
    613529  /* first go to the yth line */
    614   ptr1 = e->buff;
    615   for (i = 0; i < e->buffy; i++) {
    616     ptr2= strchr(ptr1, '\n');
     530  ptr1=e->buff;
     531  for (i=0; i<e->buffy; i++) {
     532    ptr2=strchr(ptr1, '\n');
    617533    if (!ptr2) {
    618534      /* we're already on the last line */
    619535      break;
    620536    }
    621     ptr1 = ptr2 + 1;
    622   }
    623 
    624   /* now go to the xth cell */
    625   ptr2 = ptr1;
    626   i = 0;
    627   while (ptr2 != NULL && i < e->buffx && (ptr2 - e->buff) < e->bufflen) {
    628     c = g_utf8_get_char(ptr2);
    629     i += (c == '\n' ? 1 : mk_wcwidth(c));
    630     ptr2 = g_utf8_next_char(ptr2);
    631   }
    632   while(ptr2 != NULL && g_unichar_ismark(g_utf8_get_char(ptr2))) {
    633     ptr2 = g_utf8_next_char(ptr2);
    634   }
    635   if (ptr2 == NULL) return e->bufflen;
    636   return(ptr2 - e->buff);
     537    ptr1=ptr2+1;
     538  }
     539
     540  /* now go to the xth character */
     541  ptr2=strchr(ptr1, '\n');
     542  if (!ptr2) {
     543    ptr2=e->buff+e->bufflen;
     544  }
     545
     546  if ((ptr2-ptr1) < e->buffx) {
     547    ptr1=ptr2-1;
     548  } else {
     549    ptr1+=e->buffx;
     550  }
     551
     552  /* printf("DEBUG: index is %i\r\n", ptr1-e->buff); */
     553  return(ptr1-e->buff);
    637554}
    638555
    639556void _owl_editwin_set_xy_by_index(owl_editwin *e, int index)
    640557{
    641   char *ptr1, *ptr2, *target;
    642   gunichar c;
    643 
    644   e->buffx = 0;
    645   e->buffy = 0;
    646 
    647   ptr1 = e->buff;
    648   target = ptr1 + index;
    649   /* target sanitizing */
    650   if ((target[0] & 0x80) && (~target[0] & 0x40)) {
    651     /* middle of a utf-8 character, back up to previous character. */
    652     target = g_utf8_find_prev_char(e->buff, target);
    653   }
    654   c = g_utf8_get_char(target);
    655   while (g_unichar_ismark(c) && target > e->buff) {
    656     /* Adjust the target off of combining characters and the like. */
    657     target = g_utf8_find_prev_char(e->buff, target);
    658     c = g_utf8_get_char(target);
    659   }
    660   /* If we start with a mark, something is wrong.*/
    661   if (g_unichar_ismark(c)) return;
    662 
    663   /* Now our target should be acceptable. */
    664   ptr2 = strchr(ptr1, '\n');
    665   while (ptr2 != NULL && ptr2 < target) {
    666     e->buffy++;
    667     ptr1 = ptr2 + 1;
    668     ptr2 = strchr(ptr1, '\n');
    669   }
    670   ptr2 = ptr1;
    671   while (ptr2 != NULL && ptr2 < target) {
    672     c = g_utf8_get_char(ptr2);
    673     e->buffx += mk_wcwidth(c);
    674     ptr2 = g_utf8_next_char(ptr2);
    675   }
    676 }
    677 
    678 int _owl_editwin_cursor_adjustment(owl_editwin *e)
    679 {
    680   char *ptr1, *ptr2;
    681   gunichar c;
    682   int x, i;
    683 
    684   ptr1 = e->buff;
    685   ptr2 = strchr(ptr1, '\n');
    686   for (i = 0; ptr2 != NULL && i < e->buffy; i++) {
    687     ptr1 = ptr2 + 1;
    688     ptr2 = strchr(ptr1, '\n');
    689   }
    690   ptr2 = ptr1;
    691   x = 0;
    692   while (ptr2 != NULL && x < e->buffx) {
    693     if (*ptr2 == '\n') return 0;
    694     c = g_utf8_get_char(ptr2);
    695     x += mk_wcwidth(c);
    696     ptr2 = g_utf8_next_char(ptr2);
    697   }
    698   return x - e->buffx;
     558  int z, i;
     559
     560  z=_owl_editwin_get_index_from_xy(e);
     561  if (index>z) {
     562    for (i=0; i<index-z; i++) {
     563      owl_editwin_key_right(e);
     564    }
     565  } else if (index<z) {
     566    for (i=0; i<z-index; i++) {
     567      owl_editwin_key_left(e);
     568    }
     569  }
    699570}
    700571
     
    703574  /* if we happen to have the cursor over locked text
    704575   * move it to be out of the locktext region */
    705   if (_owl_editwin_get_index_from_xy(e) < e->lock) {
     576  if (_owl_editwin_get_index_from_xy(e)<e->lock) {
    706577    _owl_editwin_set_xy_by_index(e, e->lock);
    707578  }
     
    723594{
    724595  if (e->buffy > 0) e->buffy--;
    725   if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) {
    726     e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     596  if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) {
     597    e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    727598  }
    728599
     
    741612
    742613  /* if we're past the last character move back */
    743   if (e->buffx >= owl_editwin_get_numcells_on_line(e, e->buffy)) {
    744     e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     614  if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) {
     615    e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    745616  }
    746617
     
    756627void owl_editwin_key_left(owl_editwin *e)
    757628{
    758   int i;
    759   char * p;
    760   i = _owl_editwin_get_index_from_xy(e);
    761   p = e->buff + i;
    762   p = g_utf8_find_prev_char(e->buff, p);
    763   while (p && g_unichar_ismark(g_utf8_get_char(p))) {
    764     p = g_utf8_find_prev_char(e->buff, p);
    765   }
    766   if (p == NULL) p = e->buff;
    767   _owl_editwin_set_xy_by_index(e, p - e->buff);
    768 
    769   if (e->buffy - e->topline < 0) {
    770     e->topline -= e->winlines / 2;
     629  /* move left if we can, and maybe up a line */
     630  if (e->buffx>0) {
     631    e->buffx--;
     632  } else if (e->buffy>0) {
     633    e->buffy--;
     634    e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
     635  }
     636
     637  /* do we need to scroll up? */
     638  if (e->buffy-e->topline < 0) {
     639    e->topline-=e->winlines/2;
    771640  }
    772641
     
    778647{
    779648  int i;
    780   char * p;
    781   i = _owl_editwin_get_index_from_xy(e);
    782   p = e->buff + i;
    783   p = g_utf8_find_next_char(p, NULL);
    784   while (p && g_unichar_ismark(g_utf8_get_char(p))) {
    785     p = g_utf8_find_next_char(p, NULL);
    786   }
    787   if (p == NULL) {
    788     _owl_editwin_set_xy_by_index(e, e->bufflen);
    789   }
    790   else {
    791     _owl_editwin_set_xy_by_index(e, p - e->buff);
     649
     650  /* move right if we can, and skip down a line if needed */
     651  i=owl_editwin_get_numchars_on_line(e, e->buffy);
     652  if (e->buffx < i) {
     653    e->buffx++;
     654    /*  } else if (e->buffy+1 < owl_editwin_get_numlines(e)) { */
     655  } else if (_owl_editwin_get_index_from_xy(e) < e->bufflen) {
     656    if (e->style==OWL_EDITWIN_STYLE_MULTILINE) {
     657      e->buffx=0;
     658      e->buffy++;
     659    }
    792660  }
    793661
    794662  /* do we need to scroll down? */
    795   if (e->buffy - e->topline >= e->winlines) {
    796     e->topline += e->winlines / 2;
     663  if (e->buffy-e->topline >= e->winlines) {
     664    e->topline+=e->winlines/2;
    797665  }
    798666}
     
    800668void owl_editwin_move_to_nextword(owl_editwin *e)
    801669{
    802   /* asedeno: needs fixing for utf-8*/
    803670  int i, x;
    804671
     
    840707void owl_editwin_move_to_previousword(owl_editwin *e)
    841708{
    842   /* asedeno: needs fixing for utf-8*/
    843709  int i, x;
    844710
     
    876742void owl_editwin_delete_nextword(owl_editwin *e)
    877743{
    878   /* asedeno: needs fixing for utf-8*/
    879744  int z;
    880745
     
    907772void owl_editwin_delete_previousword(owl_editwin *e)
    908773{
    909   /* asedeno: needs fixing for utf-8*/
    910774  /* go backwards to the last non-space character, then delete chars */
    911775  int i, startpos, endpos;
     
    921785void owl_editwin_delete_to_endofline(owl_editwin *e)
    922786{
    923   /* asedeno: needs fixing for utf-8*/
    924787  int i;
    925788
    926   if (owl_editwin_get_numchars_on_line(e, e->buffy) > e->buffx) {
     789  if (owl_editwin_get_numchars_on_line(e, e->buffy)>e->buffx) {
    927790    /* normal line */
    928791    i=_owl_editwin_get_index_from_xy(e);
     
    945808void owl_editwin_move_to_line_end(owl_editwin *e)
    946809{
    947   e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     810  e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    948811}
    949812
     
    958821  /* go to last char */
    959822  e->buffy=owl_editwin_get_numlines(e)-1;
    960   e->buffx=owl_editwin_get_numcells_on_line(e, e->buffy);
     823  e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    961824  owl_editwin_key_right(e);
    962825
     
    982845void owl_editwin_fill_paragraph(owl_editwin *e)
    983846{
    984   /* asedeno: needs fixing for utf-8*/
    985847  int i, save;
    986848
     
    999861  /* main loop */
    1000862  while (1) {
    1001     i = _owl_editwin_get_index_from_xy(e);
     863    i=_owl_editwin_get_index_from_xy(e);
    1002864
    1003865    /* bail if we hit the end of the buffer */
    1004     if (i >= e->bufflen || e->buff[i] == '\0') break;
     866    if (i>=e->bufflen) break;
    1005867
    1006868    /* bail if we hit the end of the paragraph */
    1007     if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break;
     869    if (e->buff[i]=='\n' && e->buff[i+1]=='\n') break;
    1008870
    1009871    /* if we've travelled too far, linewrap */
     
    1013875
    1014876    /* did we hit the end of a line too soon? */
    1015     i = _owl_editwin_get_index_from_xy(e);
    1016     if (e->buff[i] == '\n' && e->buffx < e->fillcol - 1) {
     877    i=_owl_editwin_get_index_from_xy(e);
     878    if (e->buff[i]=='\n' && e->buffx<e->fillcol-1) {
    1017879      /* ********* we need to make sure we don't pull in a word that's too long ***********/
    1018880      e->buff[i]=' ';
     
    1020882   
    1021883    /* fix spacing */
    1022     i = _owl_editwin_get_index_from_xy(e);
    1023     if (e->buff[i] == ' ' && e->buff[i+1] == ' ') {
    1024       if (e->buff[i-1] == '.' || e->buff[i-1] == '!' || e->buff[i-1] == '?') {
     884    i=_owl_editwin_get_index_from_xy(e);
     885    if (e->buff[i]==' ' && e->buff[i+1]==' ') {
     886      if (e->buff[i-1]=='.' || e->buff[i-1]=='!' || e->buff[i-1]=='?') {
    1025887        owl_editwin_key_right(e);
    1026888      } else {
    1027889        owl_editwin_delete_char(e);
    1028890        /* if we did this ahead of the save point, adjust it */
    1029         if (i < save) save--;
     891        if (i<save) save--;
    1030892      }
    1031893    } else {
     
    1053915int owl_editwin_check_dotsend(owl_editwin *e)
    1054916{
    1055   char *p, *p_n, *p_p;
    1056   gunichar c;
     917  int i;
    1057918
    1058919  if (!e->dotsend) return(0);
    1059 
    1060   p = g_utf8_find_prev_char(e->buff, e->buff + e->bufflen);
    1061   p_n = g_utf8_find_next_char(p, NULL);
    1062   p_p = g_utf8_find_prev_char(e->buff, p);
    1063   c = g_utf8_get_char(p);
    1064   while (p != NULL) {
    1065     if (*p == '.'
    1066         && p_p != NULL && (*p_p == '\n' || *p_p == '\r')
    1067         && p_n != NULL && (*p_n == '\n' || *p_n == '\r')) {
    1068       e->bufflen = p - e->buff;
    1069       e->buff[e->bufflen] = '\0';
     920  for (i=e->bufflen-1; i>0; i--) {
     921    if (e->buff[i] == '.'
     922        && (e->buff[i-1] == '\n' || e->buff[i-1] == '\r')
     923        && (e->buff[i+1] == '\n' || e->buff[i+1] == '\r')) {
     924      e->bufflen = i;
     925      e->buff[i] = '\0';
    1070926      return(1);
    1071927    }
    1072     if (c != '\0' && !g_unichar_isspace(c)) return(0);
    1073     p_n = p;
    1074     p = p_p;
    1075     c = g_utf8_get_char(p);
    1076     p_p = g_utf8_find_prev_char(e->buff, p);
     928    if (!isspace((int) e->buff[i])) {
     929      return(0);
     930    }
    1077931  }
    1078932  return(0);
    1079933}
    1080934
    1081 void owl_editwin_post_process_char(owl_editwin *e, owl_input j)
     935void owl_editwin_post_process_char(owl_editwin *e, int j)
    1082936{
    1083937  /* check if we need to scroll down */
     
    1085939    e->topline+=e->winlines/2;
    1086940  }
    1087   if ((j.ch==13 || j.ch==10) && owl_editwin_check_dotsend(e)) {
     941  if ((j==13 || j==10) && owl_editwin_check_dotsend(e)) {
    1088942    owl_command_editmulti_done(e);
    1089943    return;
     
    1092946}
    1093947
    1094 void _owl_editwin_process_char(owl_editwin *e, gunichar j)
    1095 {
    1096   if (!(g_unichar_iscntrl(j) && (j != 10) && (j != 13))) {
     948void owl_editwin_process_char(owl_editwin *e, int j)
     949{
     950  if (j == ERR) return;
     951  if (j>127 || ((j<32) && (j!=10) && (j!=13))) {
     952    return;
     953  } else {
    1097954    owl_editwin_insert_char(e, j);
    1098   }
    1099 }
    1100 
    1101 
    1102 void owl_editwin_process_char(owl_editwin *e, owl_input j)
    1103 {
    1104   if (j.ch == ERR) return;
    1105   /* Ignore ncurses control characters. */
    1106   if (j.ch < 0x100) {
    1107     _owl_editwin_process_char(e, j.uch);
    1108955  }
    1109956}
     
    1132979  }
    1133980
    1134   /* now count characters */
    1135   i = 0;
    1136   ptr2 = ptr1;
    1137   while (ptr2 - e->buff < e->bufflen
    1138          && *ptr2 != '\n') {
    1139     ++i;
    1140     ptr2 = g_utf8_next_char(ptr2);
    1141   }
    1142   return i;
    1143 }
    1144 
    1145 int owl_editwin_get_numcells_on_line(owl_editwin *e, int line)
    1146 {
    1147   int i;
    1148   char *ptr1, *ptr2;
    1149   gunichar c;
    1150 
    1151   if (e->bufflen==0) return(0);
    1152  
    1153   /* first go to the yth line */
    1154   ptr1=e->buff;
    1155   for (i=0; i<line; i++) {
    1156     ptr2=strchr(ptr1, '\n');
    1157     if (!ptr2) {
    1158       /* we're already on the last line */
    1159       return(0);
    1160     }
    1161     ptr1=ptr2+1;
    1162   }
    1163 
    1164   /* now count cells */
    1165   i = 0;
    1166   ptr2 = ptr1;
    1167   while (ptr2 - e->buff < e->bufflen
    1168          && *ptr2 != '\n') {
    1169     c = g_utf8_get_char(ptr2);
    1170     i += mk_wcwidth(c);
    1171     ptr2 = g_utf8_next_char(ptr2);
    1172   }
    1173   return i;
     981  /* now go to the xth character */
     982  ptr2=strchr(ptr1, '\n');
     983  if (!ptr2) {
     984    return(e->buff + e->bufflen - ptr1);
     985  }
     986  return(ptr2-ptr1); /* don't count the newline for now */
    1174987}
    1175988
  • fmtext.c

    rc55ad84 rfa3290d  
    88void owl_fmtext_init_null(owl_fmtext *f)
    99{
    10   f->textlen = 0;
    11   f->bufflen = 5;
    12   f->textbuff = owl_malloc(5);
    13   f->textbuff[0] = 0;
    14   f->default_attrs = OWL_FMTEXT_ATTR_NONE;
    15   f->default_fgcolor = OWL_COLOR_DEFAULT;
    16   f->default_bgcolor = OWL_COLOR_DEFAULT;
     10  f->textlen=0;
     11  f->bufflen=5;
     12  f->textbuff=owl_malloc(5);
     13  f->fmbuff=owl_malloc(5);
     14  f->fgcolorbuff=owl_malloc(5 * sizeof(short));
     15  f->bgcolorbuff=owl_malloc(5 * sizeof(short));
     16  f->textbuff[0]=0;
     17  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     18  f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     19  f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
    1720}
    1821
     
    2124void owl_fmtext_clear(owl_fmtext *f)
    2225{
    23   f->textlen = 0;
    24   f->textbuff[0] = 0;
    25   f->default_attrs = OWL_FMTEXT_ATTR_NONE;
    26   f->default_fgcolor = OWL_COLOR_DEFAULT;
    27   f->default_bgcolor = OWL_COLOR_DEFAULT;
     26    f->textlen = 0;
     27    f->textbuff[0] = 0;
     28    f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     29    f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     30    f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
     31}
     32
     33/* Internal function.  Set the attribute 'attr' from index 'first' to
     34 * index 'last'
     35 */
     36void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last)
     37{
     38  int i;
     39  for (i=first; i<=last; i++) {
     40    f->fmbuff[i]=(unsigned char) attr;
     41  }
     42}
     43
     44/* Internal function.  Add the attribute 'attr' to the existing
     45 * attributes from index 'first' to index 'last'
     46 */
     47void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last)
     48{
     49  int i;
     50  for (i=first; i<=last; i++) {
     51    f->fmbuff[i]|=(unsigned char) attr;
     52  }
     53}
     54
     55/* Internal function.  Set the color to be 'color' from index 'first'
     56 * to index 'last
     57 */
     58void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last)
     59{
     60  int i;
     61  for (i=first; i<=last; i++) {
     62    f->fgcolorbuff[i]=(short)color;
     63  }
     64}
     65
     66void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last)
     67{
     68  int i;
     69  for (i=first; i<=last; i++) {
     70    f->bgcolorbuff[i]=(short)color;
     71  }
    2872}
    2973
     
    3175{
    3276    if(newlen + 1 > f->bufflen) {
    33       f->textbuff = owl_realloc(f->textbuff, newlen + 1);
     77      f->textbuff=owl_realloc(f->textbuff, newlen+1);
     78      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
     79      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short));
     80      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short));
    3481      f->bufflen = newlen+1;
    3582  }
    3683}
    3784
    38 int owl_fmtext_is_format_char(gunichar c)
    39 {
    40   if ((c & ~OWL_FMTEXT_UC_ATTR_MASK) == OWL_FMTEXT_UC_ATTR) return 1;
    41   if ((c & ~(OWL_FMTEXT_UC_ALLCOLOR_MASK)) == OWL_FMTEXT_UC_COLOR_BASE) return 1;
    42   return 0;
    43 }
    4485/* append text to the end of 'f' with attribute 'attr' and color
    4586 * 'color'
    4687 */
    47 void owl_fmtext_append_attr(owl_fmtext *f, char *text, char attr, short fgcolor, short bgcolor)
    48 {
    49   char attrbuff[6];
    50   int newlen, a = 0, fg = 0, bg = 0;
    51  
    52   if (attr != OWL_FMTEXT_ATTR_NONE) a=1;
    53   if (fgcolor != OWL_COLOR_DEFAULT) fg=1;
    54   if (bgcolor != OWL_COLOR_DEFAULT) bg=1;
    55 
    56   /* Plane-16 characters in UTF-8 are 4 bytes long. */
    57   newlen = strlen(f->textbuff) + strlen(text) + (8 * (a + fg + bg));
     88void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor)
     89{
     90  int newlen;
     91  newlen=strlen(f->textbuff)+strlen(text);
    5892  _owl_fmtext_realloc(f, newlen);
    59 
    60   /* Set attributes */
    61   if (a) {
    62     memset(attrbuff,0,6);
    63     g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);
    64     strcat(f->textbuff, attrbuff);     
    65   }
    66   if (fg) {
    67     memset(attrbuff,0,6);
    68     g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);
    69     strcat(f->textbuff, attrbuff);     
    70   }
    71   if (bg) {
    72     memset(attrbuff,0,6);
    73     g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);
    74     strcat(f->textbuff, attrbuff);     
    75   }
    7693 
    7794  strcat(f->textbuff, text);
    78 
    79   /* Reset attributes */
    80   if (bg) strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);
    81   if (fg) strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);
    82   if (a)  strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);
     95  _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
     96  _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen);
     97  _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen);
    8398  f->textlen=newlen;
    8499}
     
    114129}
    115130
    116 /* Add the attribute 'attr' to the default atts for the text in 'f' */
    117 void owl_fmtext_addattr(owl_fmtext *f, char attr)
     131/* Add the attribute 'attr' to all text in 'f' */
     132void owl_fmtext_addattr(owl_fmtext *f, int attr)
    118133{
    119134  /* add the attribute to all text */
    120   f->default_attrs |= attr;
    121 }
    122 
    123 /* Set the default foreground color for this fmtext to 'color'.
    124  * Only affects text that is colored default.
     135  int i, j;
     136
     137  j=f->textlen;
     138  for (i=0; i<j; i++) {
     139    f->fmbuff[i] |= attr;
     140  }
     141}
     142
     143/* Anywhere the color is NOT ALREDY SET, set the color to 'color'.
     144 * Other colors are left unchanged
    125145 */
    126146void owl_fmtext_colorize(owl_fmtext *f, int color)
    127147{
    128   f->default_fgcolor = color;
    129 }
    130 
    131 /* Set the default foreground color for this fmtext to 'color'.
    132  * Only affects text that is colored default.
    133  */
     148  /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
     149  int i, j;
     150
     151  j=f->textlen;
     152  for(i=0; i<j; i++) {
     153    if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color;
     154  }
     155}
     156
    134157void owl_fmtext_colorizebg(owl_fmtext *f, int color)
    135158{
    136   f->default_bgcolor = color;
    137 }
    138 
    139 /* Internal function. Parse attrbute character. */
    140 void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor) /*noproto*/
    141 {
    142   if ((c & OWL_FMTEXT_UC_ATTR) == OWL_FMTEXT_UC_ATTR) {
    143     *attr = c & OWL_FMTEXT_UC_ATTR_MASK;
    144   }
    145   else if ((c & OWL_FMTEXT_UC_FGCOLOR) == OWL_FMTEXT_UC_FGCOLOR) {
    146     *fgcolor = (c == OWL_FMTEXT_UC_FGDEFAULT
    147                 ? OWL_COLOR_DEFAULT
    148                 : c & OWL_FMTEXT_UC_COLOR_MASK);
    149   }
    150   else if ((c & OWL_FMTEXT_UC_BGCOLOR) == OWL_FMTEXT_UC_BGCOLOR) {
    151     *bgcolor = (c == OWL_FMTEXT_UC_BGDEFAULT
    152                 ? OWL_COLOR_DEFAULT
    153                 : c & OWL_FMTEXT_UC_COLOR_MASK);
    154   }
    155 }
    156 
    157 /* Internal function. Scan for attribute characters. */
    158 void _owl_fmtext_scan_attributes(owl_fmtext *f, int start, char *attr, short *fgcolor, short *bgcolor) /*noproto*/
    159 {
    160   char *p;
    161   p = strchr(f->textbuff, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    162   while (p && p < f->textbuff + start) {
    163     _owl_fmtext_update_attributes(g_utf8_get_char(p), attr, fgcolor, bgcolor);
    164     p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    165   }
    166 
     159  /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
     160  int i, j;
     161
     162  j=f->textlen;
     163  for(i=0; i<j; i++) {
     164    if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color;
     165  }
     166}
    167167
    168168/* Internal function.  Append text from 'in' between index 'start' and
    169169 * 'stop' to the end of 'f'
    170170 */
    171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/
    172 {
    173   char attrbuff[6];
    174   int newlen, a = 0, fg = 0, bg = 0;
    175   char attr = 0;
    176   short fgcolor = OWL_COLOR_DEFAULT;
    177   short bgcolor = OWL_COLOR_DEFAULT;
    178 
    179   _owl_fmtext_scan_attributes(in, start, &attr, &fgcolor, &bgcolor);
    180   if (attr != OWL_FMTEXT_ATTR_NONE) a=1;
    181   if (fgcolor != OWL_COLOR_DEFAULT) fg=1;
    182   if (bgcolor != OWL_COLOR_DEFAULT) bg=1;
    183 
    184   /* We will reset to defaults after appending the text. We may need
    185      to set initial attributes. */
    186   newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12;
     171void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop)
     172{
     173  int newlen, i;
     174
     175  newlen=strlen(f->textbuff)+(stop-start+1);
    187176  _owl_fmtext_realloc(f, newlen);
    188177
    189   if (a) {
    190     memset(attrbuff,0,6);
    191     g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);
    192     strcat(f->textbuff, attrbuff);     
    193   }
    194   if (fg) {
    195     memset(attrbuff,0,6);
    196     g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);
    197     strcat(f->textbuff, attrbuff);     
    198   }
    199   if (bg) {
    200     memset(attrbuff,0,6);
    201     g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);
    202     strcat(f->textbuff, attrbuff);     
    203   }
    204 
    205178  strncat(f->textbuff, in->textbuff+start, stop-start+1);
    206 
    207   /* Reset attributes */
    208   strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);
    209   strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);
    210   strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);
    211 
    212179  f->textbuff[newlen]='\0';
     180  for (i=start; i<=stop; i++) {
     181    f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i];
     182    f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i];
     183    f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i];
     184  }
    213185  f->textlen=newlen;
    214186}
     
    235207char *owl_fmtext_print_plain(owl_fmtext *f)
    236208{
    237   return owl_strip_format_chars(f->textbuff);
    238 }
    239 
    240 void _owl_fmtext_wattrset(WINDOW *w, int attrs) /*noproto*/
    241 {
    242   wattrset(w, A_NORMAL);
    243   if (attrs & OWL_FMTEXT_ATTR_BOLD) wattron(w, A_BOLD);
    244   if (attrs & OWL_FMTEXT_ATTR_REVERSE) wattron(w, A_REVERSE);
    245   if (attrs & OWL_FMTEXT_ATTR_UNDERLINE) wattron(w, A_UNDERLINE);
    246 }
    247 
    248 void _owl_fmtext_update_colorpair(short fg, short bg, short *pair) /*noproto*/
    249 {
    250   if (owl_global_get_hascolors(&g)) {
    251     *pair = owl_fmtext_get_colorpair(fg, bg);
    252   }
    253 }
    254 
    255 void _owl_fmtext_wcolor_set(WINDOW *w, short pair) /*noproto*/
    256 {
    257   if (owl_global_get_hascolors(&g)) {
    258       wcolor_set(w,pair,NULL);
    259   }
     209  return(owl_strdup(f->textbuff));
    260210}
    261211
     
    263213 * must already be initiatlized with curses
    264214 */
    265 void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/
    266 {
    267   /* char *tmpbuff; */
    268   /* int position, trans1, trans2, trans3, len, lastsame; */
    269   char *s, *p;
    270   char attr;
    271   short fg, bg, pair;
    272   int search_results, search_len;
    273  
     215void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
     216{
     217  char *tmpbuff;
     218  int position, trans1, trans2, trans3, len, lastsame;
     219
    274220  if (w==NULL) {
    275221    owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
     
    277223  }
    278224
    279   search_results = (do_search
    280                     ? owl_fmtext_search(f, owl_global_get_search_string(&g))
    281                     : 0);
    282   search_len = (search_results
    283                 ? strlen(owl_global_get_search_string(&g))
    284                 : 0);
    285   s = f->textbuff;
    286   /* Set default attributes. */
    287   attr = f->default_attrs;
    288   fg = f->default_fgcolor;
    289   bg = f->default_bgcolor;
    290   _owl_fmtext_wattrset(w, attr);
    291   _owl_fmtext_update_colorpair(fg, bg, &pair);
    292   _owl_fmtext_wcolor_set(w, pair);
    293 
    294   /* Find next possible format character. */
    295   p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    296   while(p) {
    297     if (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    298       /* Deal with all text from last insert to here. */
    299       char tmp;
    300    
    301       tmp = p[0];
    302       p[0] = '\0';
    303       if (search_results) {
    304         /* Search is active, so highlight search results. */
    305         char tmp2, *ss;
    306         ss = stristr(s, owl_global_get_search_string(&g));
    307         while (ss) {
    308           /* Found search string, highlight it. */
    309 
    310           tmp2 = ss[0];
    311           ss[0] = '\0';
    312           waddstr(w, s);
    313           ss[0] = tmp2;
    314 
    315           _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE);
    316           _owl_fmtext_wcolor_set(w, pair);
    317          
    318           tmp2 = ss[search_len];
    319           ss[search_len] = '\0';
    320           waddstr(w, ss);
    321           ss[search_len] = tmp2;
    322 
    323           _owl_fmtext_wattrset(w, attr);
    324           _owl_fmtext_wcolor_set(w, pair);
    325 
    326           s = ss + search_len;
    327           ss = stristr(s, owl_global_get_search_string(&g));
    328         }
    329       }
    330       /* Deal with remaining part of string. */
    331       waddstr(w, s);
    332       p[0] = tmp;
    333 
    334       /* Deal with new attributes. Initialize to defaults, then
    335          process all consecutive formatting characters. */
    336       attr = f->default_attrs;
    337       fg = f->default_fgcolor;
    338       bg = f->default_bgcolor;
    339       while (p && owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    340         _owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
    341         p = g_utf8_next_char(p);
    342       }
    343       _owl_fmtext_wattrset(w, attr | f->default_attrs);
    344       if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
    345       if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
    346       _owl_fmtext_update_colorpair(fg, bg, &pair);
    347       _owl_fmtext_wcolor_set(w, pair);
    348 
    349       /* Advance to next non-formatting character. */
    350       s = p;
    351       p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    352     }
    353     else {
    354       p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    355     }
    356   }
    357   if (s) {
    358     waddstr(w, s);
    359   }
    360 }
    361 
    362 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
    363 {
    364   _owl_fmtext_curs_waddstr(f, w, owl_global_is_search_active(&g));
    365 }
    366 
    367 void owl_fmtext_curs_waddstr_without_search(owl_fmtext *f, WINDOW *w)
    368 {
    369   _owl_fmtext_curs_waddstr(f, w, 0);
    370 }
     225  tmpbuff=owl_malloc(f->textlen+10);
     226
     227  position=0;
     228  len=f->textlen;
     229  while (position<=len) {
     230    /* find the last char with the current format and color */
     231    trans1=owl_util_find_trans(f->fmbuff+position, len-position);
     232    trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position);
     233    trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position);
     234
     235    lastsame = (trans1 < trans2) ? trans1 : trans2;
     236    lastsame = (lastsame < trans3) ? lastsame : trans3;
     237    lastsame += position;
     238
     239    /* set the format */
     240    wattrset(w, A_NORMAL);
     241    if (f->fmbuff[position] & OWL_FMTEXT_ATTR_BOLD) {
     242      wattron(w, A_BOLD);
     243    }
     244    if (f->fmbuff[position] & OWL_FMTEXT_ATTR_REVERSE) {
     245      wattron(w, A_REVERSE);
     246    }
     247    if (f->fmbuff[position] & OWL_FMTEXT_ATTR_UNDERLINE) {
     248      wattron(w, A_UNDERLINE);
     249    }
     250
     251    /* set the color */
     252    /* warning, this is sort of a hack */
     253    if (owl_global_get_hascolors(&g)) {
     254      short fg, bg, pair;
     255      fg = f->fgcolorbuff[position];
     256      bg = f->bgcolorbuff[position];
     257
     258      pair = owl_fmtext_get_colorpair(fg, bg);
     259      if (pair != -1) {
     260        wcolor_set(w,pair,NULL);
     261      }
     262    }
     263
     264    /* add the text */
     265    strncpy(tmpbuff, f->textbuff + position, lastsame-position+1);
     266    tmpbuff[lastsame-position+1]='\0';
     267    waddstr(w, tmpbuff);
     268
     269    position=lastsame+1;
     270  }
     271  owl_free(tmpbuff);
     272}
     273
    371274
    372275/* start with line 'aline' (where the first line is 0) and print
     
    379282 
    380283  /* find the starting line */
    381   ptr1 = in->textbuff;
    382   for (i = 0; i < aline; i++) {
    383     ptr1 = strchr(ptr1, '\n');
    384     if (!ptr1) return(-1);
    385     ptr1++;
    386   }
    387  
     284  ptr1=in->textbuff;
     285  if (aline!=0) {
     286    for (i=0; i<aline; i++) {
     287      ptr1=strchr(ptr1, '\n');
     288      if (!ptr1) return(-1);
     289      ptr1++;
     290    }
     291  }
    388292  /* ptr1 now holds the starting point */
    389293
    390   /* copy the default attributes */
    391   out->default_attrs = in->default_attrs;
    392   out->default_fgcolor = in->default_fgcolor;
    393   out->default_bgcolor = in->default_bgcolor;
    394    
    395294  /* copy in the next 'lines' lines */
    396   if (lines < 1) return(-1);
    397 
    398   for (i = 0; i < lines; i++) {
    399     offset = ptr1 - in->textbuff;
    400     ptr2 = strchr(ptr1, '\n');
     295  if (lines<1) return(-1);
     296
     297  for (i=0; i<lines; i++) {
     298    offset=ptr1-in->textbuff;
     299    ptr2=strchr(ptr1, '\n');
    401300    if (!ptr2) {
    402       _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) - 1);
     301      _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1);
    403302      return(-1);
    404303    }
    405     _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset);
    406     ptr1 = ptr2 + 1;
     304    _owl_fmtext_append_fmtext(out, in, offset, (ptr2-ptr1)+offset);
     305    ptr1=ptr2+1;
    407306  }
    408307  return(0);
     
    412311 * ends at 'bcol' or sooner.  The first column is number 0.  The new
    413312 * message is placed in 'out'.  The message is * expected to end in a
    414  * new line for now. NOTE: This needs to be modified to deal with
    415  * backing up if we find a SPACING COMBINING MARK at the end of a
    416  * line. If that happens, we should back up to the last non-mark
    417  * character and stop there.
     313 * new line for now
    418314 */
    419315void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
    420316{
    421   char *ptr_s, *ptr_e, *ptr_c, *last;
    422   int col, st, padding, chwidth;
    423 
    424   /* copy the default attributes */
    425   out->default_attrs = in->default_attrs;
    426   out->default_fgcolor = in->default_fgcolor;
    427   out->default_bgcolor = in->default_bgcolor;
     317  char *ptr1, *ptr2, *last;
     318  int len, offset;
    428319
    429320  last=in->textbuff+in->textlen-1;
    430   ptr_s=in->textbuff;
    431   while (ptr_s <= last) {
    432     ptr_e=strchr(ptr_s, '\n');
    433     if (!ptr_e) {
     321  ptr1=in->textbuff;
     322  while (ptr1<=last) {
     323    ptr2=strchr(ptr1, '\n');
     324    if (!ptr2) {
    434325      /* but this shouldn't happen if we end in a \n */
    435326      break;
    436327    }
    437328   
    438     if (ptr_e == ptr_s) {
     329    if (ptr2==ptr1) {
    439330      owl_fmtext_append_normal(out, "\n");
    440       ++ptr_s;
     331      ptr1++;
    441332      continue;
    442333    }
    443334
    444     col = 0;
    445     st = 0;
    446     padding = 0;
    447     chwidth = 0;
    448     ptr_c = ptr_s;
    449     while(ptr_c < ptr_e) {
    450       gunichar c = g_utf8_get_char(ptr_c);
    451       if (!owl_fmtext_is_format_char(c)) {
    452         chwidth = mk_wcwidth(c);
    453         if (col + chwidth > bcol) break;
    454        
    455         if (col >= acol) {
    456           if (st == 0) {
    457             ptr_s = ptr_c;
    458             padding = col - acol;
    459             ++st;
    460           }
    461         }
    462         col += chwidth;
    463         chwidth = 0;
    464       }
    465       ptr_c = g_utf8_next_char(ptr_c);
    466     }
    467     if (st) {
    468       /* lead padding */
    469       owl_fmtext_append_spaces(out, padding);
    470       if (ptr_c == ptr_e) {
    471         /* We made it to the newline. */
    472         _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    473       }
    474       else {
    475         if (chwidth > 1) {
    476           /* Last char is wide, truncate. */
    477           _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
    478           owl_fmtext_append_normal(out, "\n");
    479         }
    480         else {
    481           /* Last char fits perfectly, leave alone.*/
    482           _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    483         }
    484       }
    485     }
    486     else {
     335    /* we need to check that we won't run over here */
     336    len=bcol-acol;
     337    if (len > (ptr2-(ptr1+acol))) {
     338      /* the whole line fits with room to spare, don't take a full 'len' */
     339      len=ptr2-(ptr1+acol);
     340    }
     341    if (len>last-ptr1) {
     342      /* the whole rest of the text fits with room to spare, adjust for it */
     343      len-=(last-ptr1);
     344    }
     345    if (len<=0) {
     346      /* saftey check */
    487347      owl_fmtext_append_normal(out, "\n");
    488     }
    489     ptr_s = g_utf8_next_char(ptr_e);
     348      ptr1=ptr2+1;
     349      continue;
     350    }
     351
     352    offset=ptr1-in->textbuff;
     353    _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len);
     354
     355    ptr1=ptr2+1;
    490356  }
    491357}
     
    515381
    516382/* set the charater at 'index' to be 'char'.  If index is out of
    517  * bounds don't do anything. If c or char at index is not ASCII, don't
    518  * do anything because it's not UTF-8 safe. */
    519 void owl_fmtext_set_char(owl_fmtext *f, int index, char ch)
     383 * bounds don't do anything */
     384void owl_fmtext_set_char(owl_fmtext *f, int index, int ch)
    520385{
    521386  if ((index < 0) || (index > f->textlen-1)) return;
    522   /* NOT ASCII*/
    523   if (f->textbuff[index] & 0x80 || ch & 0x80) return;
    524387  f->textbuff[index]=ch;
    525388}
     
    537400  dst->textlen=src->textlen;
    538401  dst->textbuff=owl_malloc(mallocsize);
     402  dst->fmbuff=owl_malloc(mallocsize);
     403  dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));
     404  dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));
    539405  memcpy(dst->textbuff, src->textbuff, src->textlen+1);
    540   dst->default_attrs = src->default_attrs;
    541   dst->default_fgcolor = src->default_fgcolor;
    542   dst->default_bgcolor = src->default_bgcolor;
     406  memcpy(dst->fmbuff, src->fmbuff, src->textlen);
     407  memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short));
     408  memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short));
     409}
     410
     411/* highlight all instances of "string".  Return the number of
     412 * instances found.  This is a case insensitive search.
     413 */
     414int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string)
     415{
     416
     417  int found, len;
     418  char *ptr1, *ptr2;
     419
     420  len=strlen(string);
     421  found=0;
     422  ptr1=f->textbuff;
     423  while (ptr1-f->textbuff <= f->textlen) {
     424    ptr2=stristr(ptr1, string);
     425    if (!ptr2) return(found);
     426
     427    found++;
     428    _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE,
     429                         ptr2 - f->textbuff,
     430                         ptr2 - f->textbuff + len - 1);
     431
     432    ptr1=ptr2+len;
     433  }
     434  return(found);
    543435}
    544436
     
    548440int owl_fmtext_search(owl_fmtext *f, char *string)
    549441{
     442
    550443  if (stristr(f->textbuff, string)) return(1);
    551444  return(0);
     
    788681{
    789682  if (f->textbuff) owl_free(f->textbuff);
     683  if (f->fmbuff) owl_free(f->fmbuff);
     684  if (f->fgcolorbuff) owl_free(f->fgcolorbuff);
     685  if (f->bgcolorbuff) owl_free(f->bgcolorbuff);
    790686}
    791687
  • functions.c

    rf9eea4c r3617286  
    16061606          sprintf(buff, "  Field %i   : ", i+1);
    16071607         
    1608           ptr=owl_zephyr_get_field_as_utf8(n, i+1);
     1608          ptr=owl_zephyr_get_field(n, i+1);
    16091609          len=strlen(ptr);
    16101610          if (len<30) {
     
    21872187void owl_function_start_command(char *line)
    21882188{
     2189  int i, j;
    21892190  owl_editwin *tw;
    21902191
     
    21972198  owl_global_set_needrefresh(&g);
    21982199
    2199   owl_editwin_insert_string(tw, line);
     2200  j=strlen(line);
     2201  for (i=0; i<j; i++) {
     2202    owl_editwin_process_char(tw, line[i]);
     2203  }
    22002204  owl_editwin_redisplay(tw, 0);
    22012205
     
    25952599  }
    25962600  /* downcase it */
    2597   {
    2598     char *temp = g_utf8_strdown(filtname, -1);
    2599     if (temp) {
    2600       owl_free(filtname);
    2601       filtname = temp;
    2602     }
    2603   }
     2601  downstr(filtname);
    26042602  /* turn spaces, single quotes, and double quotes into dots */
    26052603  owl_text_tr(filtname, ' ', '.');
     
    30263024  char *quoted;
    30273025
    3028   buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
     3026  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
    30293027  strcpy(buff, "class");
    30303028  if (!strcmp(class, "*")) {
     
    33303328          if (ret==0) {
    33313329            for (x=0; x<numlocs; x++) {
    3332               line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
     3330              line=malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
    33333331              tmp=short_zuser(user);
    33343332              sprintf(line, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
     
    33733371  owl_view *v;
    33743372  FILE *file;
    3375   char *plaintext;
    33763373
    33773374  v=owl_global_get_current_view(&g);
     
    33963393  for (i=0; i<j; i++) {
    33973394    m=owl_view_get_element(v, i);
    3398     plaintext = owl_strip_format_chars(owl_message_get_text(m));
    3399     if (plaintext) {
    3400       fputs(plaintext, file);
    3401       owl_free(plaintext);
    3402     }
     3395    fputs(owl_message_get_text(m), file);
    34033396  }
    34043397  fclose(file);
     
    34413434          _exit(127);
    34423435        }
    3443         parsed=owl_realloc(parsed, sizeof(*parsed) * (myargc+1));
     3436        parsed=realloc(parsed, sizeof(*parsed) * (myargc+1));
    34443437        parsed[myargc] = NULL;
    34453438       
  • global.c

    rc0f9e30 rc0f9e30  
    549549    len+=strlen(argv[i])+5;
    550550  }
    551   g->startupargs=owl_malloc(len+5);
     551  g->startupargs=malloc(len+5);
    552552
    553553  strcpy(g->startupargs, "");
  • keymap.c

    r428834d rcf83b7a  
    55
    66/* returns 0 on success */
    7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
     7int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
    88{
    99  if (!name || !desc) return(-1);
     
    151151}
    152152
    153 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
     153owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
    154154{
    155155  owl_keymap *km;
     
    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, owl_input j)
     204int owl_keyhandler_process(owl_keyhandler *kh, int j)
    205205{
    206206  owl_keymap     *km;
     
    214214
    215215  /* temporarily disallow C-`/C-SPACE until we fix associated bugs */
    216   if (j.ch == ERR || j.ch == 0) {
     216  if (j==ERR || j==0) {
    217217        return(-1);
    218218  }
     
    224224
    225225  /* deal with ESC prefixing */
    226   if (!kh->in_esc && j.ch == 27) {
     226  if (!kh->in_esc && j==27) {
    227227    kh->in_esc = 1;
    228228    return(0);
    229229  }
    230230  if (kh->in_esc) {
    231     j.ch = OWL_META(j.ch);
     231    j = OWL_META(j);
    232232    kh->in_esc = 0;
    233233  }
    234234 
    235   kh->kpstack[++(kh->kpstackpos)] = j.ch;
     235  kh->kpstack[++(kh->kpstackpos)] = j;
    236236  if (kh->kpstackpos >= OWL_KEYMAP_MAXSTACK) {
    237237    owl_keyhandler_reset(kh);
     
    260260      } else if (match == 2) {  /* exact match */
    261261        /* owl_function_debugmsg("processkey: found exact match in %s", km->name); */
    262         owl_keybinding_execute(kb, j.ch);
     262        owl_keybinding_execute(kb, j);
    263263        owl_keyhandler_reset(kh);
    264264        if (km->postalways_fn) {
  • keypress.c

    r428834d r948b942  
    148148  }
    149149  if (!*kb) {
    150     if (j & OWL_META(0)) {
     150    if (j&OWL_META(0)) {
    151151      strcat(kb, "M-");
    152152      j &= ~OWL_META(0);
     
    163163      strcat(kb, kb2);   
    164164    }
    165    
    166165  } 
    167166  if (!*kb) {
  • keys.c

    rfac5463 r8938188  
    294294/****************************************************************/
    295295
    296 void owl_keys_recwin_prealways(owl_input j) {
     296void owl_keys_recwin_prealways(int j) {
    297297  /* Clear the message line on subsequent key presses */
    298298  owl_function_makemsg("");
    299299}
    300300
    301 void owl_keys_editwin_default(owl_input j) {
     301void owl_keys_editwin_default(int j) {
    302302  owl_editwin *e;
    303303  if (NULL != (e=owl_global_get_typwin(&g))) {
    304        owl_editwin_process_char(e, j);
     304    owl_editwin_process_char(e, j);
    305305  }
    306306}
    307307
    308 void owl_keys_editwin_postalways(owl_input j) {
     308void owl_keys_editwin_postalways(int j) {
    309309  owl_editwin *e;
    310310  if (NULL != (e=owl_global_get_typwin(&g))) {
    311311    owl_editwin_post_process_char(e, j);
    312   }
     312  } 
    313313  owl_global_set_needrefresh(&g);
    314314}
    315315
    316 void owl_keys_popless_postalways(owl_input j) {
     316void owl_keys_popless_postalways(int j) {
    317317  owl_viewwin *v = owl_global_get_viewwin(&g);
    318318  owl_popwin *pw = owl_global_get_popwin(&g);
     
    323323}
    324324
    325 void owl_keys_default_invalid(owl_input j) {
    326   if (j.ch==ERR) return;
    327   if (j.ch==410) return;
     325void owl_keys_default_invalid(int j) {
     326  if (j==ERR) return;
     327  if (j==410) return;
    328328  owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g));
    329329}
  • logging.c

    r28ee32b rd0961fe  
    155155    to = owl_sprintf("jabber:%s", owl_message_get_recipient(m));
    156156  } else if (owl_message_is_type_aim(m)) {
    157     char *temp2;
    158157    temp = owl_aim_normalize_screenname(owl_message_get_recipient(m));
    159     temp2 = g_utf8_strdown(temp,-1);
    160     to = owl_sprintf("aim:%s", temp2);
    161     owl_free(temp2);
     158    downstr(temp);
     159    to = owl_sprintf("aim:%s", temp);
    162160    owl_free(temp);
    163161  } else {
     
    269267  } else if (owl_message_is_type_aim(m)) {
    270268    /* we do not yet handle chat rooms */
    271     char *normalto, *temp;
    272     temp = owl_aim_normalize_screenname(owl_message_get_sender(m));
    273     normalto = g_utf8_strdown(temp, -1);
     269    char *normalto;
     270    normalto=owl_aim_normalize_screenname(owl_message_get_sender(m));
     271    downstr(normalto);
    274272    from=frombuff=owl_sprintf("aim:%s", normalto);
    275273    owl_free(normalto);
    276     owl_free(temp);
    277274  } else if (owl_message_is_type_loopback(m)) {
    278275    from=frombuff=owl_strdup("loopback");
     
    293290
    294291  ch=frombuff[0];
    295   if (!g_ascii_isalnum(ch)) from="weird";
     292  if (!isalnum(ch)) from="weird";
    296293
    297294  for (i=0; i<len; i++) {
     
    302299
    303300  if (!personal) {
    304     if (strcmp(from, "weird")) {
    305       char* temp = g_utf8_strdown(frombuff, -1);
    306       if (temp) {
    307         owl_free(frombuff);
    308         from = frombuff = temp;
    309       }
    310     }
     301    if (strcmp(from, "weird")) downstr(from);
    311302  }
    312303
  • message.c

    r635881c r635881c  
    7979    owl_list_append_element(&(m->attributes), pair);
    8080  }
    81   owl_pair_set_value(pair, owl_validate_or_convert(attrvalue));
     81  owl_pair_set_value(pair, owl_strdup(attrvalue));
    8282}
    8383
     
    493493{
    494494  if(m->zwriteline) owl_free(m->zwriteline);
    495   m->zwriteline=owl_strdup(line);
     495  m->zwriteline=strdup(line);
    496496}
    497497
     
    535535  owl_fmtext_init_null(&b);
    536536 
    537   owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline, &a);
     537  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
    538538  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    539   owl_fmtext_colorize(&b, fgcolor);
    540   owl_fmtext_colorizebg(&b, bgcolor);
    541 
     539  if (fgcolor!=OWL_COLOR_DEFAULT) {
     540    owl_fmtext_colorize(&b, fgcolor);
     541  }
     542  if (bgcolor!=OWL_COLOR_DEFAULT) {
     543    owl_fmtext_colorizebg(&b, bgcolor);
     544  }
     545
     546  if (owl_global_is_search_active(&g)) {
     547    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
     548  }
     549     
    542550  owl_fmtext_curs_waddstr(&b, win);
    543551
     
    882890  }
    883891
    884   m->zwriteline=owl_strdup("");
     892  m->zwriteline=strdup("");
    885893
    886894  /* save the hostname */
     
    964972  }
    965973
    966   m->zwriteline=owl_strdup("");
     974  m->zwriteline=strdup("");
    967975
    968976  owl_message_set_body(m, "<uninitialized>");
  • owl.c

    rf2d72128 rf2d72128  
    4848#include <termios.h>
    4949#include <sys/stat.h>
    50 #include <locale.h>
    5150#include "owl.h"
    5251
     
    7069  owl_editwin *tw;
    7170  owl_popwin *pw;
    72   int ret, initialsubs, debug, argcsave, followlast;
    73   owl_input j;
     71  int j, ret, initialsubs, debug, argcsave, followlast;
    7472  int newmsgs, nexttimediff;
    7573  struct sigaction sigact;
     
    8684  int newstderr;
    8785#endif
    88  
    89   if (!GLIB_CHECK_VERSION (2, 12, 0))
    90     g_error ("GLib version 2.12.0 or above is needed.");
    9186
    9287  argcsave=argc;
     
    9792  debug=0;
    9893  initialsubs=1;
    99 
    100   setlocale(LC_ALL, "");
    101  
    10294  if (argc>0) {
    10395    argv++;
     
    538530     * little bit, but otherwise do not.  This lets input be grabbed
    539531     * as quickly as possbile */
    540     j.ch = wgetch(typwin);
    541     if (j.ch == ERR) {
     532    j=wgetch(typwin);
     533    if (j==ERR) {
    542534      usleep(10000);
    543535    } else {
    544       j.uch = '\0';
    545       if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
    546         /* This is a curses control character. */
    547       }
    548       else if (j.ch > 0x7f && j.ch < 0xfe) {
    549         /* Pull in a full utf-8 character. */
    550         int bytes, i;
    551         char utf8buf[7];
    552         memset(utf8buf, '\0', 7);
    553 
    554         utf8buf[0] = j.ch;
    555 
    556         if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
    557         else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
    558         else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
    559         else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
    560         else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
    561         else bytes = 1;
    562        
    563         for (i = 1; i < bytes; i++) {
    564           utf8buf[i] = wgetch(typwin);
    565         }
    566         if (g_utf8_validate(utf8buf, -1, NULL)) {
    567           j.uch = g_utf8_get_char(utf8buf);
    568         }
    569         else {
    570           j.ch = ERR;
    571         }
    572       }
    573       else if (j.ch <= 0x7f) {
    574         j.uch = j.ch;
    575       }
    576      
    577536      owl_global_update_lastinputtime(&g);
    578537      /* find and activate the current keymap.
  • owl.h

    r88dc766 r88dc766  
    5252#include <termios.h>
    5353#include <libfaim/aim.h>
    54 #include <wchar.h>
    5554#include "config.h"
    56 #include "glib.h"
    5755#ifdef HAVE_LIBZEPHYR
    5856#include <zephyr/zephyr.h>
     
    102100#define OWL_FMTEXT_ATTR_REVERSE   2
    103101#define OWL_FMTEXT_ATTR_UNDERLINE 4
    104 
    105 #define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/
    106 #define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 )
    107 #define OWL_FMTEXT_UC_ATTR_MASK 0x7
    108 #define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 )
    109 #define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE
    110 #define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 )
    111 #define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100
    112 #define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
    113 #define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
    114 #define OWL_FMTEXT_UC_COLOR_MASK 0xFF
    115 #define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200)
    116 #define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4'
    117 
    118 #define OWL_FMTEXT_UTF8_ATTR_NONE "\xf4\x80\xa0\x80"
    119 #define OWL_FMTEXT_UTF8_FGDEFAULT "\xf4\x80\x94\x80"
    120 #define OWL_FMTEXT_UTF8_BGDEFAULT "\xf4\x80\x96\x80"
    121 
    122 
    123 
    124102
    125103#define OWL_COLOR_BLACK     0
     
    234212#endif
    235213
    236 #define OWL_META(key) ((key)|010000)
     214#define OWL_META(key) ((key)|0200)
    237215/* OWL_CTRL is definied in kepress.c */
    238216
     
    274252} owl_variable;
    275253
    276 typedef struct _owl_input {
    277   int ch;
    278   gunichar uch;
    279 } owl_input;
    280 
    281254typedef struct _owl_fmtext {
    282255  int textlen;
    283256  int bufflen;
    284257  char *textbuff;
    285   char default_attrs;
    286   short default_fgcolor;
    287   short default_bgcolor;
     258  char *fmbuff;
     259  short *fgcolorbuff;
     260  short *bgcolorbuff;
    288261} owl_fmtext;
    289262
     
    518491  owl_list  bindings;           /* key bindings */
    519492  struct _owl_keymap *submap;   /* submap */
    520   void (*default_fn)(owl_input j);      /* default action (takes a keypress) */
    521   void (*prealways_fn)(owl_input j);   /* always called before a keypress is received */
    522   void (*postalways_fn)(owl_input j);  /* always called after keypress is processed */
     493  void (*default_fn)(int j);    /* default action (takes a keypress) */
     494  void (*prealways_fn)(int j);  /* always called before a keypress is received */
     495  void (*postalways_fn)(int j); /* always called after keypress is processed */
    523496} owl_keymap;
    524497
  • perlconfig.c

    rff13a6f rff13a6f  
    5555    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
    5656    for (i=0; i<j; i++) {
    57       ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1);
     57      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1);
    5858      av_push(av_zfields, newSVpvn(ptr, strlen(ptr)));
    5959      owl_free(ptr);
  • text.c

    r47519e1b r72db971  
    5050void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)
    5151{
    52   char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;
    53   int col, cnt, padding;
    54  
     52  char *ptr1, *ptr2, *tmpbuff, *last;
     53  int len;
     54
    5555  tmpbuff=owl_malloc(strlen(in)+20);
    5656
    5757  strcpy(tmpbuff, "");
    5858  last=in+strlen(in)-1;
    59   ptr_s=in;
    60   while (ptr_s<last) {
    61     ptr_e=strchr(ptr_s, '\n');
    62     if (!ptr_e) {
     59  ptr1=in;
     60  while (ptr1<last) {
     61    ptr2=strchr(ptr1, '\n');
     62    if (!ptr2) {
    6363      /* but this shouldn't happen if we end in a \n */
    6464      break;
    6565    }
    6666   
    67     if (ptr_e==ptr_s) {
     67    if (ptr2==ptr1) {
    6868      strcat(tmpbuff, "\n");
    69       ptr_s++;
    70       continue;
    71     }
    72 
    73     col = 0;
    74     cnt = 0;
    75     padding = 0;
    76     ptr_c = ptr_s;
    77     while(col < bcol && ptr_c < ptr_e) {
    78       gunichar c = g_utf8_get_char(ptr_c);
    79       if (col + mk_wcwidth(c) > bcol) break;
    80       col += mk_wcwidth(c);
    81       ptr_c = g_utf8_next_char(ptr_c);
    82       if (col >= acol) {
    83         if (cnt == 0) {
    84           ptr_s = ptr_c;
    85           padding = col - acol;
    86         }
    87         ++cnt;
    88       }
    89     }
    90     if (cnt) {
    91       while(padding-- > 0) {
    92         strcat(tmpbuff, " ");
    93       }
    94       strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
    95     }
    96     strcat(tmpbuff, "\n");
    97     ptr_s = ptr_e + 1;
    98 #if 0
     69      ptr1++;
     70      continue;
     71    }
     72
    9973    /* we need to check that we won't run over here */
    100     if ( (ptr_e-ptr_s) < (bcol-acol) ) {
    101       len=ptr_e-(ptr_s+acol);
     74    if ( (ptr2-ptr1) < (bcol-acol) ) {
     75      len=ptr2-(ptr1+acol);
    10276    } else {
    10377      len=bcol-acol;
    10478    }
    105     if ((ptr_s+len)>=last) {
    106       len-=last-(ptr_s+len);
    107     }
    108 
    109     strncat(tmpbuff, ptr_s+acol, len);
     79    if ((ptr1+len)>=last) {
     80      len-=last-(ptr1+len);
     81    }
     82
     83    strncat(tmpbuff, ptr1+acol, len);
    11084    strcat(tmpbuff, "\n");
    11185
    112     ptr_s=ptr_e+1;
    113 #endif
     86    ptr1=ptr2+1;
    11487  }
    11588  strcpy(out, tmpbuff);
     
    302275char *stristr(char *a, char *b)
    303276{
    304   char *x, *y;
    305   char *ret = NULL;
    306   if ((x = g_utf8_casefold(a, -1)) != NULL) {
    307     if ((y = g_utf8_casefold(b, -1)) != NULL) {
    308       ret = strstr(x, y);
    309       if (ret != NULL) {
    310         ret = ret - x + a;
    311       }
    312       g_free(y);
    313     }
    314     g_free(x);
    315   }
     277  char *x, *y, *ret;
     278
     279  if ((x=owl_strdup(a))==NULL) return(NULL);
     280  if ((y=owl_strdup(b))==NULL) return(NULL);
     281  downstr(x);
     282  downstr(y);
     283  ret=strstr(x, y);
     284  if (ret==NULL) {
     285    owl_free(x);
     286    owl_free(y);
     287    return(NULL);
     288  }
     289  ret=ret-x+a;
     290  owl_free(x);
     291  owl_free(y);
    316292  return(ret);
    317293}
     
    320296int only_whitespace(char *s)
    321297{
    322   if (g_utf8_validate(s,-1,NULL)) {
    323     char *p;
    324     for(p = s; p[0]; p=g_utf8_next_char(p)) {
    325       if (!g_unichar_isspace(g_utf8_get_char(p))) return 0;
    326     }
    327   }
    328   else {
    329     int i;
    330     for (i=0; s[i]; i++) {
    331       if (!isspace((int) s[i])) return(0);
    332     }
     298  int i;
     299  for (i=0; s[i]; i++) {
     300    if (!isspace((int) s[i])) return(0);
    333301  }
    334302  return(1);
     
    359327  tolen  = strlen(to);
    360328  fromlen  = strlen(from);
    361   out = owl_malloc(outlen);
     329  out = malloc(outlen);
    362330
    363331  while (in[inpos]) {
  • util.c

    rc1522ec r89f5338  
    399399}
    400400
     401/* downcase the string 'foo' */
     402void downstr(char *foo)
     403{
     404  int i;
     405  for (i=0; foo[i]!='\0'; i++) {
     406    foo[i]=tolower(foo[i]);
     407  }
     408}
     409
    401410/* Caller must free response.
    402411 * Takes in strings which are space-separated lists of tokens
     
    437446void *owl_malloc(size_t size)
    438447{
    439   return(g_malloc(size));
     448  return(malloc(size));
    440449}
    441450
    442451void owl_free(void *ptr)
    443452{
    444   g_free(ptr);
     453  free(ptr);
    445454}
    446455
    447456char *owl_strdup(const char *s1)
    448457{
    449   return(g_strdup(s1));
     458  return(strdup(s1));
    450459}
    451460
    452461void *owl_realloc(void *ptr, size_t size)
    453462{
    454   return(g_realloc(ptr, size));
     463  return(realloc(ptr, size));
    455464}
    456465
    457466/* allocates memory and returns the string or null.
    458467 * caller must free the string.
     468 * from Linux sprintf man page.
    459469 */
    460470char *owl_sprintf(const char *fmt, ...)
    461471{
     472  int n, size = 100;
     473  char *p;
    462474  va_list ap;
    463   char *ret = NULL;
    464   va_start(ap, fmt);
    465   ret = g_strdup_vprintf(fmt, ap);
    466   va_end(ap);
    467   return ret;
    468 }
    469 
     475  if ((p = owl_malloc (size)) == NULL) return (NULL);
     476  while (1) {
     477    /* Try to print in the allocated space. */
     478    va_start(ap, fmt);
     479    n = vsnprintf (p, size, fmt, ap);
     480    va_end(ap);
     481    /* If that worked, return the string. */
     482    if (n > -1 && n < size)
     483      return p;
     484    /* Else try again with more space. */
     485    if (n > -1)    /* glibc 2.1 */
     486      size = n+1; /* precisely what is needed */
     487    else           /* glibc 2.0 */
     488      size *= 2;  /* twice the old size */
     489    if ((p = owl_realloc (p, size)) == NULL)
     490      return NULL;
     491  }
     492}
    470493
    471494/* Return the owl color associated with the named color.  Return -1
     
    753776}
    754777
    755 char * owl_get_datadir()
    756 {
    757   char * datadir = getenv("BARNOWL_DATA_DIR");
    758   if(datadir != NULL)
    759     return strchr(datadir, '=') + 1;
    760   return DATADIR;
    761 }
    762 
    763 /* Strips format characters from a valid utf-8 string. Returns the
    764    empty string if 'in' does not validate. */
    765 char * owl_strip_format_chars(char *in)
    766 {
    767   char *r;
    768   if (g_utf8_validate(in, -1, NULL)) {
    769     char *s, *p;
    770     r = owl_malloc(strlen(in)+1);
    771     r[0] = '\0';
    772     s = in;
    773     p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    774     while(p) {
    775       /* If it's a format character, copy up to it, and skip all
    776          immediately following format characters. */
    777       if (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    778         strncat(r, s, p-s);
    779         p = g_utf8_next_char(p);
    780         while (p && owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    781           p = g_utf8_next_char(p);
    782         }
    783         s = p;
    784         p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    785       }
    786       else {
    787         p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    788       }
    789     }
    790     if (s) strcat(r,s);
    791   }
    792   else {
    793     r = owl_strdup("");
    794   }
    795   return r;
    796 }
    797 
    798 /* If in is not UTF-8, convert from ISO-8859-1. We may want to allow
    799  * the caller to specify an alternative in the future. We also strip
    800  * out characters in Unicode Plane 16, as we use that plane internally
    801  * for formatting.
    802  */
    803 char * owl_validate_or_convert(char *in)
    804 {
    805   if (g_utf8_validate(in, -1, NULL)) {
    806     return owl_strip_format_chars(in);
    807   }
    808   else {
    809     return g_convert(in, -1,
    810                      "UTF-8", "ISO-8859-1",
    811                      NULL, NULL, NULL);
    812   }
    813 }
    814 /* Attempts to convert 'in' to ISO-8859-1. Returns that if possible,
    815    else returns UTF-8.
    816  */
    817 char * owl_get_iso_8859_1_if_possible(char *in)
    818 {
    819   char *out;
    820   if (g_utf8_validate(in, -1, NULL)) {
    821     out = g_convert(in, -1,
    822                     "ISO-8859-1", "UTF-8",
    823                     NULL, NULL, NULL);
    824     if (!out) {
    825       out = owl_strdup(in);
    826     }
    827   }
    828   else {
    829     out = owl_strdup("");
    830   }
    831   return out;
     778char * owl_get_datadir() {
     779    char * datadir = getenv("BARNOWL_DATA_DIR");
     780    if(datadir != NULL)
     781        return strchr(datadir, '=') + 1;
     782    return DATADIR;
    832783}
    833784
  • viewwin.c

    r47519e1b r8721756  
    7373  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
    7474
    75   owl_fmtext_curs_waddstr_without_search(&fm2, v->curswin);
     75  owl_fmtext_curs_waddstr(&fm2, v->curswin);
    7676
    7777  /* print the message at the bottom */
  • zcrypt.c

    r34509d5 r9ceee9d  
    385385
    386386/* Build a space-separated string from argv from elements between start  *
    387  * and end - 1.  owl_malloc()'s the returned string. */
     387 * and end - 1.  malloc()'s the returned string. */
    388388char *BuildArgString(char **argv, int start, int end) {
    389389  int len = 1;
     
    397397
    398398  /* Allocate memory */
    399   result = (char *)owl_malloc(len);
     399  result = (char *)malloc(len);
    400400  if (result) {
    401401    /* Build the string */
     
    482482      /* Prepare result to be returned */
    483483      char *temp = keyfile;
    484       keyfile = (char *)owl_malloc(strlen(temp) + 1);
     484      keyfile = (char *)malloc(strlen(temp) + 1);
    485485      if (keyfile) {
    486486        strcpy(keyfile, temp);
     
    611611      }
    612612      use_buffer = TRUE;
    613       if ((inptr = inbuff = (char *)owl_malloc(MAX_RESULT)) == NULL) {
     613      if ((inptr = inbuff = (char *)malloc(MAX_RESULT)) == NULL) {
    614614        printf("Memory allocation error\n");
    615615        return FALSE;
     
    639639      printf("Could not run zwrite\n");
    640640      if (freein && inbuff) {
    641         owl_free(inbuff);
     641        free(inbuff);
    642642      }
    643643      return(FALSE);
     
    685685
    686686  /* Free the input buffer, if necessary */
    687   if (freein && inbuff) owl_free(inbuff);
     687  if (freein && inbuff) free(inbuff);
    688688
    689689  return(!error);
  • zephyr.c

    r60c2e1e r60c2e1e  
    354354  return(owl_strdup(""));
    355355}
    356 
    357 char *owl_zephyr_get_field_as_utf8(ZNotice_t *n, int j)
    358 {
    359   int i, count, save;
    360 
    361   /* If there's no message here, just run along now */
    362   if (n->z_message_len == 0)
    363     return(owl_strdup(""));
    364 
    365   count=save=0;
    366   for (i = 0; i < n->z_message_len; i++) {
    367     if (n->z_message[i]=='\0') {
    368       count++;
    369       if (count == j) {
    370         /* just found the end of the field we're looking for */
    371         return(owl_validate_or_convert(n->z_message + save));
    372       } else {
    373         save = i + 1;
    374       }
    375     }
    376   }
    377   /* catch the last field, which might not be null terminated */
    378   if (count == j - 1) {
    379     char *tmp, *out;
    380     tmp = owl_malloc(n->z_message_len-save+5);
    381     memcpy(tmp, n->z_message+save, n->z_message_len-save);
    382     tmp[n->z_message_len-save]='\0';
    383     out = owl_validate_or_convert(tmp);
    384     owl_free(tmp);
    385     return out;
    386   }
    387 
     356#else
     357char *owl_zephyr_get_field(void *n, int j)
     358{
    388359  return(owl_strdup(""));
    389 }
    390 #else
    391 char *owl_zephyr_get_field(void *n, int j)
    392 {
    393   return(owl_strdup(""));
    394 }
    395 char *owl_zephyr_get_field_as_utf8(ZNotice_t *n, int j)
    396 {
    397   return owl_zephyr_get_field(n, j);
    398360}
    399361#endif
  • zwrite.c

    r7b1d048 r1fe100c  
    4444        break;
    4545      }
    46       z->class=owl_get_iso_8859_1_if_possible(myargv[1]);
     46      z->class=owl_strdup(myargv[1]);
    4747      myargv+=2;
    4848      myargc-=2;
     
    5252        break;
    5353      }
    54       z->inst=owl_get_iso_8859_1_if_possible(myargv[1]);
     54      z->inst=owl_strdup(myargv[1]);
    5555      myargv+=2;
    5656      myargc-=2;
     
    6060        break;
    6161      }
    62       z->realm=owl_get_iso_8859_1_if_possible(myargv[1]);
     62      z->realm=owl_strdup(myargv[1]);
    6363      myargv+=2;
    6464      myargc-=2;
     
    6868        break;
    6969      }
    70       z->zsig=owl_get_iso_8859_1_if_possible(myargv[1]);
     70      z->zsig=owl_strdup(myargv[1]);
    7171      myargv+=2;
    7272      myargc-=2;
     
    7676        break;
    7777      }
    78       z->opcode=owl_get_iso_8859_1_if_possible(myargv[1]);
     78      z->opcode=owl_strdup(myargv[1]);
    7979      myargv+=2;
    8080      myargc-=2;
     
    9393      myargv++;
    9494      myargc--;
    95       z->message=owl_get_iso_8859_1_if_possible("");
     95      z->message=owl_strdup("");
    9696      while (myargc) {
    97         z->message=owl_realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
     97        z->message=realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
    9898        strcat(z->message, myargv[0]);
    9999        strcat(z->message, " ");
     
    113113    } else {
    114114      /* anything unattached is a recipient */
    115       owl_list_append_element(&(z->recips), owl_get_iso_8859_1_if_possible(myargv[0]));
     115      owl_list_append_element(&(z->recips), strdup(myargv[0]));
    116116      myargv++;
    117117      myargc--;
     
    146146
    147147    if (zsigowlvar && *zsigowlvar) {
    148       z->zsig=owl_get_iso_8859_1_if_possible(zsigowlvar);
     148      z->zsig=owl_strdup(zsigowlvar);
    149149    } else if (zsigproc && *zsigproc) {
    150150      FILE *file;
     
    161161      if (!file) {
    162162        if (zsigzvar && *zsigzvar) {
    163           z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar);
     163          z->zsig=owl_strdup(zsigzvar);
    164164        }
    165165      } else {
     
    175175      }
    176176    } else if (zsigzvar) {
    177       z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar);
     177      z->zsig=owl_strdup(zsigzvar);
    178178    } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
    179       z->zsig=owl_get_iso_8859_1_if_possible(pw->pw_gecos);
     179      z->zsig=strdup(pw->pw_gecos);
    180180      ptr=strchr(z->zsig, ',');
    181181      if (ptr) {
     
    218218  int i, j;
    219219  char toline[LINE];
    220   char *tmp = NULL;
    221220
    222221  if (z->message) owl_free(z->message);
     
    232231      }
    233232    }
    234     tmp = owl_get_iso_8859_1_if_possible(msg);
    235     z->message=owl_sprintf("%s\n%s", toline, tmp);
     233    z->message=owl_sprintf("%s\n%s", toline, msg);
    236234  } else {
    237     z->message=owl_get_iso_8859_1_if_possible(msg);
    238   }
    239   if (tmp) owl_free(tmp);
     235    z->message=owl_strdup(msg);
     236  }
    240237}
    241238
     
    308305{
    309306  if (z->opcode) owl_free(z->opcode);
    310   z->opcode=owl_get_iso_8859_1_if_possible(opcode);
     307  z->opcode=owl_strdup(opcode);
    311308}
    312309
Note: See TracChangeset for help on using the changeset viewer.