Changeset b7b4565


Ignore:
Timestamp:
Jan 16, 2008, 1:46:37 PM (13 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
8574801
Parents:
c55ad84 (diff), f2d72128 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merged revisions 847-881 via svnmerge from 
file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk

........
  r848 | nelhage | 2008-01-12 02:00:53 -0500 (Sat, 12 Jan 2008) | 2 lines
  
  Adding a note about IRC deps
........
  r853 | asedeno | 2008-01-12 11:56:20 -0500 (Sat, 12 Jan 2008) | 2 lines
  
  Fixing a pet peeve.
  Clearing the line should preserve the echochar.
........
  r854 | asedeno | 2008-01-12 15:07:20 -0500 (Sat, 12 Jan 2008) | 3 lines
  
  Jabber - 
  * fix logins to jabber.org - reported by gendalia
........
  r860 | nelhage | 2008-01-13 18:08:14 -0500 (Sun, 13 Jan 2008) | 2 lines
  
  Kill a uninitialized warning
........
  r861 | nelhage | 2008-01-13 18:10:13 -0500 (Sun, 13 Jan 2008) | 1 line
  
  Show JOIN and PART for login/outs
........
  r862 | nelhage | 2008-01-13 18:10:44 -0500 (Sun, 13 Jan 2008) | 1 line
  
  'motd' is a method of Net::IRC::Connection, don't clobber it
........
  r863 | nelhage | 2008-01-13 22:08:52 -0500 (Sun, 13 Jan 2008) | 2 lines
  
  Don't clober our parent's connected() method, either.
........
  r864 | nelhage | 2008-01-14 00:24:43 -0500 (Mon, 14 Jan 2008) | 3 lines
  
  Right, _connected doesn't work either. I think I need to refactor this
  to not be a subclass...
........
  r875 | nelhage | 2008-01-15 14:40:02 -0500 (Tue, 15 Jan 2008) | 2 lines
  
  Actually free the right thing when freeing perl commands
........
  r881 | nelhage | 2008-01-16 02:59:06 -0500 (Wed, 16 Jan 2008) | 1 line
  
  Move oneline style to perl. closes 43
........
Files:
2 added
30 edited

Legend:

Unmodified
Added
Removed
  • README

    r6933082 r6824a76  
    2828We plan to soon add targets to the Makefile to check for and install
    2929these for you.
     30
     31The IRC module requires:
     32
     33Net::IRC
     34Class::Accessor
  • editwin.c

    rfac5463 rb7b4565  
    198198  int dotsend=e->dotsend;
    199199  char *locktext=NULL;
     200  char echochar=e->echochar;
    200201
    201202  lock=0;
     
    216217  if (dotsend) {
    217218    owl_editwin_set_dotsend(e);
     219  }
     220  if (echochar) {
     221    owl_editwin_set_echochar(e, echochar);
    218222  }
    219223
  • owl.c

    rf92080c rb7b4565  
    262262  owl_style_create_internal(s, "basic", &owl_stylefunc_basic, "Basic message formatting.");
    263263  owl_global_add_style(&g, s);
    264   s=owl_malloc(sizeof(owl_style));
    265   owl_style_create_internal(s, "oneline", &owl_stylefunc_oneline, "Formats for one-line-per-message");
    266   owl_global_add_style(&g, s);
    267264
    268265  /* setup the default filters */
  • perl/modules/IRC/lib/BarnOwl/Message/IRC.pm

    r2fb58e4 r1fd5041b  
    5656sub long_sender {shift->{from} || ""};
    5757
     58sub login_type {
     59    my $self = shift;
     60    return " (" . ($self->is_login ? "JOIN" : "PART") . ")";
     61}
     62
    5863sub login_extra { shift->channel; }
    5964
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    rfe8cad8 r56e72d5  
    104104    BarnOwl::new_command('irc-names'      => \&cmd_names);
    105105    BarnOwl::new_command('irc-whois'      => \&cmd_whois);
     106    BarnOwl::new_command('irc-motd'       => \&cmd_motd);
    106107}
    107108
     
    245246}
    246247
     248sub cmd_motd {
     249    my $cmd = shift;
     250    my $conn = get_connection(\@_);
     251    $conn->motd;
     252}
     253
    247254################################################################################
    248255########################### Utilities/Helpers ##################################
     
    256263    }
    257264    my $channel = $args->[-1];
    258     if ($channel =~ /^#/ and $channels{$channel} and @{$channels{$channel}} == 1) {
     265    if (defined($channel) && $channel =~ /^#/
     266        and $channels{$channel} and @{$channels{$channel}} == 1) {
    259267        return $channels{$channel}[0];
    260268    }
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r9e02bb7 reab7a4c  
    1616
    1717use base qw(Net::IRC::Connection Class::Accessor Exporter);
    18 __PACKAGE__->mk_accessors(qw(alias channels motd));
     18__PACKAGE__->mk_accessors(qw(alias channels owl_connected owl_motd));
    1919our @EXPORT_OK = qw(&is_private);
    2020
     
    2929    $self->alias($alias);
    3030    $self->channels([]);
    31     $self->motd("");
     31    $self->owl_motd("");
     32    $self->owl_connected(0);
    3233    bless($self, $class);
    3334
    3435    $self->add_default_handler(sub { goto &on_event; });
    35     $self->add_handler(376 => sub { goto &on_connect });
    3636    $self->add_handler(['msg', 'notice', 'public', 'caction'],
    3737            sub { goto &on_msg });
     
    5757############################### IRC callbacks ##################################
    5858################################################################################
    59 
    60 sub on_connect {
    61     my ($self, $evt) = @_;
    62     BarnOwl::admin_message("IRC", "Connected to " . $self->server . " (" . $self->alias . ")");
    63 }
    6459
    6560sub new_message {
     
    115110sub on_motdstart {
    116111    my ($self, $evt) = @_;
    117     $self->motd(join "\n", cdr $evt->args);
     112    $self->owl_motd(join "\n", cdr $evt->args);
    118113}
    119114
    120115sub on_motd {
    121116    my ($self, $evt) = @_;
    122     $self->motd(join "\n", $self->motd, cdr $evt->args);
     117    $self->owl_motd(join "\n", $self->owl_motd, cdr $evt->args);
    123118}
    124119
    125120sub on_endofmotd {
    126121    my ($self, $evt) = @_;
    127     $self->motd(join "\n", $self->motd, cdr $evt->args);
    128     BarnOwl::admin_message("IRC",
    129             BarnOwl::Style::boldify('MOTD for ' . $evt->alias) . "\n"
    130             . strip_irc_formatting($self->motd));
     122    $self->owl_motd(join "\n", $self->owl_motd, cdr $evt->args);
     123    if(!$self->owl_connected) {
     124        BarnOwl::admin_message("IRC", "Connected to " .
     125                               $self->server . " (" . $self->alias . ")");
     126        $self->owl_connected(1);
     127       
     128    }
     129    BarnOwl::admin_message("IRC",
     130            BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n"
     131            . strip_irc_formatting($self->owl_motd));
    131132}
    132133
     
    162163                           "[" . $self->alias . "] " .
    163164                           [$evt->args]->[1] . ": Nick already in use");
     165    unless($self->owl_connected) {
     166        $self->disconnect;
     167    }
    164168}
    165169
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    r892568b r05f0061  
    370370
    371371            if ( !@result || $result[0] ne 'ok' ) {
    372                 if ( !$vars{jlogin_havepass} && ( !@result || $result[0] eq '401' ) ) {
     372                if ( !$vars{jlogin_havepass} && ( !@result || $result[0] eq '401' || $result[0] eq 'error') ) {
    373373                    $vars{jlogin_havepass} = 1;
    374374                    $conn->removeConnection($jidStr);
  • perlconfig.c

    r5376a95 rb7b4565  
    482482void owl_perlconfig_cmd_free(owl_cmd *cmd)
    483483{
    484   SvREFCNT_dec(cmd);
     484  SvREFCNT_dec(cmd->cmd_perl);
    485485}
    486486
  • perlwrap.pm

    rb0c8011 rf2d72128  
    831831    # newline plus four spaces and that thing.
    832832    $body =~ s/\n(.)/\n    $1/g;
    833 
     833    # Trim trailing newlines.
     834    $body =~ s/\n*$//;
    834835    return "    ".$body;
    835836}
    836837
     838package BarnOwl::Style::OneLine;
     839################################################################################
     840# Branching point for various formatting functions in this style.
     841################################################################################
     842use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s ';
     843sub format_message($) {
     844  my $m = shift;
     845
     846#  if ( $m->is_zephyr ) {
     847#    return format_zephyr($m);
     848#  }
     849  if ( $m->is_login ) {
     850    return format_login($m);
     851  }
     852  elsif ( $m->is_ping) {
     853    return format_ping($m);
     854  }
     855  elsif ( $m->is_admin || $m->is_loopback) {
     856    return format_local($m);
     857  }
     858  else {
     859    return format_chat($m);
     860  }
     861}
     862
     863BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message");
     864
     865################################################################################
     866
     867sub format_login($) {
     868  my $m = shift;
     869  return sprintf(
     870    BASE_FORMAT,
     871    '<',
     872    $m->type,
     873    uc( $m->login ),
     874    $m->pretty_sender)
     875    . ($m->login_extra ? "at ".$m->login_extra : '');
     876}
     877
     878sub format_ping($) {
     879  my $m = shift;
     880  return sprintf(
     881    BASE_FORMAT,
     882    '<',
     883    $m->type,
     884    'PING',
     885    $m->pretty_sender)
     886}
     887
     888sub format_chat($)
     889{
     890  my $m = shift;
     891  my $dir = lc($m->{direction});
     892  my $dirsym = '-';
     893  if ($dir eq 'in') {
     894    $dirsym = '<';
     895  }
     896  elsif ($dir eq 'out') {
     897    $dirsym = '>';
     898  }
     899
     900  my $line;
     901  if ($m->is_personal) {
     902    $line= sprintf(BASE_FORMAT,
     903                   $dirsym,
     904                   $m->type,
     905                   '',
     906                   ($dir eq 'out'
     907                      ? $m->pretty_recipient
     908                      : $m->pretty_sender));
     909  }
     910  else {
     911    $line = sprintf(BASE_FORMAT,
     912                    $dirsym,
     913                    $m->context,
     914                    $m->subcontext,
     915                    ($dir eq 'out'
     916                       ? $m->pretty_recipient
     917                       : $m->pretty_sender));
     918  }
     919
     920  my $body = $m->{body};
     921  $body =~ tr/\n/ /;
     922  $line .= $body;
     923  $line = BarnOwl::Style::boldify($line) if ($m->is_personal && lc($m->direction) eq 'in');
     924  return $line;
     925}
     926
     927# Format locally generated messages
     928sub format_local($)
     929{
     930  my $m = shift;
     931  my $type = uc($m->{type});
     932  my $line = sprintf(BASE_FORMAT, '<', $type, '', '');
     933  my $body = $m->{body};
     934  $body =~ tr/\n/ /;
     935  return $line.$body;
     936}
    837937
    838938package BarnOwl::Style;
  • stylefunc.c

    r0b7082c rf2d72128  
    220220  }
    221221}
    222 
    223 void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
    224 {
    225   char *tmp;
    226   char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
    227   char *sender, *recip;
    228 #ifdef HAVE_LIBZEPHYR
    229   ZNotice_t *n;
    230 #endif
    231 
    232   sender=short_zuser(owl_message_get_sender(m));
    233   recip=short_zuser(owl_message_get_recipient(m));
    234  
    235   if (owl_message_is_type_zephyr(m)) {
    236 #ifdef HAVE_LIBZEPHYR
    237     n=owl_message_get_notice(m);
    238    
    239     owl_fmtext_append_spaces(fm, OWL_TAB);
    240 
    241     if (owl_message_is_loginout(m)) {
    242       char *host, *tty;
    243      
    244       host=owl_message_get_attribute_value(m, "loginhost");
    245       tty=owl_message_get_attribute_value(m, "logintty");
    246 
    247       if (owl_message_is_login(m)) {
    248         tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGIN-P":"LOGIN", "", sender);
    249         owl_fmtext_append_normal(fm, tmp);
    250         owl_free(tmp);
    251       } else if (owl_message_is_logout(m)) {
    252         tmp=owl_sprintf(baseformat, "<", owl_message_is_pseudo(m)?"LOGOUT-P":"LOGOUT", "", sender);
    253         owl_fmtext_append_normal(fm, tmp);
    254         owl_free(tmp);
    255       }
    256 
    257       owl_fmtext_append_normal(fm, "at ");
    258       owl_fmtext_append_normal(fm, host ? host : "");
    259       owl_fmtext_append_normal(fm, " ");
    260       owl_fmtext_append_normal(fm, tty ? tty : "");
    261       owl_fmtext_append_normal(fm, "\n");
    262 
    263     } else if (owl_message_is_ping(m)) {
    264       tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
    265       owl_fmtext_append_normal(fm, tmp);
    266       owl_fmtext_append_normal(fm, "\n");
    267       owl_free(tmp);
    268 
    269     } else {
    270       if (owl_message_is_direction_in(m)) {
    271         tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
    272       } else if (owl_message_is_direction_out(m)) {
    273         tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
    274       } else {
    275         tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
    276       }
    277       owl_fmtext_append_normal(fm, tmp);
    278       if (tmp) owl_free(tmp);
    279      
    280       tmp=owl_strdup(owl_message_get_body(m));
    281       owl_text_tr(tmp, '\n', ' ');
    282       owl_fmtext_append_ztext(fm, tmp);
    283       owl_fmtext_append_normal(fm, "\n");
    284       if (tmp) owl_free(tmp);
    285     }
    286      
    287     /* make personal messages bold for smaat users */
    288     if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
    289         owl_message_is_personal(m) &&
    290         owl_message_is_direction_in(m)) {
    291       owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
    292     }
    293 
    294     owl_free(sender);
    295     owl_free(recip);
    296 #endif
    297   } else if (owl_message_is_type_aim(m)) {
    298     owl_fmtext_append_spaces(fm, OWL_TAB);
    299     if (owl_message_is_login(m)) {
    300       tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
    301       owl_fmtext_append_normal(fm, tmp);
    302       owl_fmtext_append_normal(fm, "\n");
    303       if (tmp) owl_free(tmp);
    304     } else if (owl_message_is_logout(m)) {
    305       tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
    306       owl_fmtext_append_normal(fm, tmp);
    307       owl_fmtext_append_normal(fm, "\n");
    308       if (tmp) owl_free(tmp);
    309     } else {
    310       if (owl_message_is_direction_in(m)) {
    311         tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
    312         owl_fmtext_append_normal(fm, tmp);
    313         if (tmp) owl_free(tmp);
    314       } else if (owl_message_is_direction_out(m)) {
    315         tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
    316         owl_fmtext_append_normal(fm, tmp);
    317         if (tmp) owl_free(tmp);
    318       }
    319      
    320       tmp=owl_strdup(owl_message_get_body(m));
    321       owl_text_tr(tmp, '\n', ' ');
    322       owl_fmtext_append_normal(fm, tmp);
    323       owl_fmtext_append_normal(fm, "\n");
    324       if (tmp) owl_free(tmp);
    325 
    326       /* make personal messages bold for smaat users */
    327       if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) {
    328         owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
    329       }
    330     }
    331   } else if (owl_message_is_type_admin(m)) {
    332     owl_fmtext_append_spaces(fm, OWL_TAB);
    333     owl_fmtext_append_normal(fm, "< ADMIN                                  ");
    334    
    335     tmp=owl_strdup(owl_message_get_body(m));
    336     owl_text_tr(tmp, '\n', ' ');
    337     owl_fmtext_append_normal(fm, tmp);
    338     owl_fmtext_append_normal(fm, "\n");
    339     if (tmp) owl_free(tmp);
    340   } else {
    341     owl_fmtext_append_spaces(fm, OWL_TAB);
    342     owl_fmtext_append_normal(fm, "< LOOPBACK                               ");
    343    
    344     tmp=owl_strdup(owl_message_get_body(m));
    345     owl_text_tr(tmp, '\n', ' ');
    346     owl_fmtext_append_normal(fm, tmp);
    347     owl_fmtext_append_normal(fm, "\n");
    348     if (tmp) owl_free(tmp);
    349   }   
    350 
    351 }
  • Makefile.in

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

    r9854278 r34509d5  
    948948 
    949949  if (modname) {
    950     if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
     950    if (!(filename = owl_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 = malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
     956    if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
    957957      /* perror("memrequest: malloc"); */
    958958      return -1;
     
    964964    if (!modname) {
    965965      /* perror("memrequest: stat"); */
    966       free(filename);
     966      owl_free(filename);
    967967      return -1;
    968968    }
     
    986986    int i;
    987987   
    988     free(filename); /* not needed */
     988    owl_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 = malloc(i))) {
     995    if (!(buf = owl_malloc(i))) {
    996996      return -1;
    997997    }
     
    10171017    *buflenret = i;
    10181018  } else {
    1019     if (!(buf = malloc(len))) {
    1020       free(filename);
     1019    if (!(buf = owl_malloc(len))) {
     1020      owl_free(filename);
    10211021      return -1;
    10221022    }
     
    10241024    if (!(f = fopen(filename, "r"))) {
    10251025      /* perror("memrequest: fopen"); */
    1026       free(filename);
    1027       free(buf);
     1026      owl_free(filename);
     1027      owl_free(buf);
    10281028      return -1;
    10291029    }
    10301030   
    1031     free(filename);
     1031    owl_free(filename);
    10321032   
    10331033    if (fseek(f, offset, SEEK_SET) == -1) {
    10341034      /* perror("memrequest: fseek"); */
    10351035      fclose(f);
    1036       free(buf);
     1036      owl_free(buf);
    10371037      return -1;
    10381038    }
     
    10411041      /* perror("memrequest: fread"); */
    10421042      fclose(f);
    1043       free(buf);
     1043      owl_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     free(buf);
     1078    owl_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 = malloc(i+1);
     1344      newbuf = owl_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       free(newbuf);
     1349      owl_free(newbuf);
    13501350    }
    13511351  } else if (strstr(tmpstr, "seticqstatus")) {
  • cmd.c

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

    r03cf6b9 re23eb2b  
    2222#undef HAVE_LIBCOM_ERR
    2323
    24 /* Define to 1 if you have the `curses' library (-lcurses). */
    25 #undef HAVE_LIBCURSES
    26 
    2724/* Define to 1 if you have the `des425' library (-ldes425). */
    2825#undef HAVE_LIBDES425
     
    3936/* Define to 1 if you have the `krb5' library (-lkrb5). */
    4037#undef HAVE_LIBKRB5
    41 
    42 /* Define to 1 if you have the `ncurses' library (-lncurses). */
    43 #undef HAVE_LIBNCURSES
    4438
    4539/* Define to 1 if you have the `ncursesw' library (-lncursesw). */
  • configure.in

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

    rfa3290d rc55ad84  
    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->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;
     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;
    2017}
    2118
     
    2421void owl_fmtext_clear(owl_fmtext *f)
    2522{
    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  */
    36 void _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  */
    47 void _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  */
    58 void _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 
    66 void _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   }
     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;
    7228}
    7329
     
    7531{
    7632    if(newlen + 1 > f->bufflen) {
    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));
     33      f->textbuff = owl_realloc(f->textbuff, newlen + 1);
    8134      f->bufflen = newlen+1;
    8235  }
    8336}
    8437
     38int 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}
    8544/* append text to the end of 'f' with attribute 'attr' and color
    8645 * 'color'
    8746 */
    88 void 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);
     47void 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));
    9258  _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  }
    9376 
    9477  strcat(f->textbuff, text);
    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);
     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);
    9883  f->textlen=newlen;
    9984}
     
    129114}
    130115
    131 /* Add the attribute 'attr' to all text in 'f' */
    132 void owl_fmtext_addattr(owl_fmtext *f, int attr)
     116/* Add the attribute 'attr' to the default atts for the text in 'f' */
     117void owl_fmtext_addattr(owl_fmtext *f, char attr)
    133118{
    134119  /* add the attribute to all text */
    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
     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.
    145125 */
    146126void owl_fmtext_colorize(owl_fmtext *f, int color)
    147127{
    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 
     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 */
    157134void owl_fmtext_colorizebg(owl_fmtext *f, int color)
    158135{
    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 }
     136  f->default_bgcolor = color;
     137}
     138
     139/* Internal function. Parse attrbute character. */
     140void _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. */
     158void _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
    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)
    172 {
    173   int newlen, i;
    174 
    175   newlen=strlen(f->textbuff)+(stop-start+1);
     171void _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;
    176187  _owl_fmtext_realloc(f, newlen);
    177188
     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
    178205  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
    179212  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   }
    185213  f->textlen=newlen;
    186214}
     
    207235char *owl_fmtext_print_plain(owl_fmtext *f)
    208236{
    209   return(owl_strdup(f->textbuff));
     237  return owl_strip_format_chars(f->textbuff);
     238}
     239
     240void _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
     248void _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
     255void _owl_fmtext_wcolor_set(WINDOW *w, short pair) /*noproto*/
     256{
     257  if (owl_global_get_hascolors(&g)) {
     258      wcolor_set(w,pair,NULL);
     259  }
    210260}
    211261
     
    213263 * must already be initiatlized with curses
    214264 */
    215 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
    216 {
    217   char *tmpbuff;
    218   int position, trans1, trans2, trans3, len, lastsame;
    219 
     265void _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 
    220274  if (w==NULL) {
    221275    owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
     
    223277  }
    224278
    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 
     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
     362void 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
     367void owl_fmtext_curs_waddstr_without_search(owl_fmtext *f, WINDOW *w)
     368{
     369  _owl_fmtext_curs_waddstr(f, w, 0);
     370}
    274371
    275372/* start with line 'aline' (where the first line is 0) and print
     
    282379 
    283380  /* find the starting line */
    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   }
     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 
    292388  /* ptr1 now holds the starting point */
    293389
     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   
    294395  /* copy in the next 'lines' lines */
    295   if (lines<1) return(-1);
    296 
    297   for (i=0; i<lines; i++) {
    298     offset=ptr1-in->textbuff;
    299     ptr2=strchr(ptr1, '\n');
     396  if (lines < 1) return(-1);
     397
     398  for (i = 0; i < lines; i++) {
     399    offset = ptr1 - in->textbuff;
     400    ptr2 = strchr(ptr1, '\n');
    300401    if (!ptr2) {
    301       _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1);
     402      _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) - 1);
    302403      return(-1);
    303404    }
    304     _owl_fmtext_append_fmtext(out, in, offset, (ptr2-ptr1)+offset);
    305     ptr1=ptr2+1;
     405    _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset);
     406    ptr1 = ptr2 + 1;
    306407  }
    307408  return(0);
     
    311412 * ends at 'bcol' or sooner.  The first column is number 0.  The new
    312413 * message is placed in 'out'.  The message is * expected to end in a
    313  * new line for now
     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.
    314418 */
    315419void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
    316420{
    317   char *ptr1, *ptr2, *last;
    318   int len, offset;
     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;
    319428
    320429  last=in->textbuff+in->textlen-1;
    321   ptr1=in->textbuff;
    322   while (ptr1<=last) {
    323     ptr2=strchr(ptr1, '\n');
    324     if (!ptr2) {
     430  ptr_s=in->textbuff;
     431  while (ptr_s <= last) {
     432    ptr_e=strchr(ptr_s, '\n');
     433    if (!ptr_e) {
    325434      /* but this shouldn't happen if we end in a \n */
    326435      break;
    327436    }
    328437   
    329     if (ptr2==ptr1) {
     438    if (ptr_e == ptr_s) {
    330439      owl_fmtext_append_normal(out, "\n");
    331       ptr1++;
     440      ++ptr_s;
    332441      continue;
    333442    }
    334443
    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 */
     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 {
    347487      owl_fmtext_append_normal(out, "\n");
    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;
     488    }
     489    ptr_s = g_utf8_next_char(ptr_e);
    356490  }
    357491}
     
    381515
    382516/* set the charater at 'index' to be 'char'.  If index is out of
    383  * bounds don't do anything */
    384 void owl_fmtext_set_char(owl_fmtext *f, int index, int ch)
     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. */
     519void owl_fmtext_set_char(owl_fmtext *f, int index, char ch)
    385520{
    386521  if ((index < 0) || (index > f->textlen-1)) return;
     522  /* NOT ASCII*/
     523  if (f->textbuff[index] & 0x80 || ch & 0x80) return;
    387524  f->textbuff[index]=ch;
    388525}
     
    400537  dst->textlen=src->textlen;
    401538  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));
    405539  memcpy(dst->textbuff, src->textbuff, src->textlen+1);
    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  */
    414 int 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);
     540  dst->default_attrs = src->default_attrs;
     541  dst->default_fgcolor = src->default_fgcolor;
     542  dst->default_bgcolor = src->default_bgcolor;
    435543}
    436544
     
    440548int owl_fmtext_search(owl_fmtext *f, char *string)
    441549{
    442 
    443550  if (stristr(f->textbuff, string)) return(1);
    444551  return(0);
     
    681788{
    682789  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);
    686790}
    687791
  • functions.c

    r3617286 rf9eea4c  
    16061606          sprintf(buff, "  Field %i   : ", i+1);
    16071607         
    1608           ptr=owl_zephyr_get_field(n, i+1);
     1608          ptr=owl_zephyr_get_field_as_utf8(n, i+1);
    16091609          len=strlen(ptr);
    16101610          if (len<30) {
     
    21872187void owl_function_start_command(char *line)
    21882188{
    2189   int i, j;
    21902189  owl_editwin *tw;
    21912190
     
    21982197  owl_global_set_needrefresh(&g);
    21992198
    2200   j=strlen(line);
    2201   for (i=0; i<j; i++) {
    2202     owl_editwin_process_char(tw, line[i]);
    2203   }
     2199  owl_editwin_insert_string(tw, line);
    22042200  owl_editwin_redisplay(tw, 0);
    22052201
     
    25992595  }
    26002596  /* downcase it */
    2601   downstr(filtname);
     2597  {
     2598    char *temp = g_utf8_strdown(filtname, -1);
     2599    if (temp) {
     2600      owl_free(filtname);
     2601      filtname = temp;
     2602    }
     2603  }
    26022604  /* turn spaces, single quotes, and double quotes into dots */
    26032605  owl_text_tr(filtname, ' ', '.');
     
    30243026  char *quoted;
    30253027
    3026   buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
     3028  buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
    30273029  strcpy(buff, "class");
    30283030  if (!strcmp(class, "*")) {
     
    33283330          if (ret==0) {
    33293331            for (x=0; x<numlocs; x++) {
    3330               line=malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
     3332              line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
    33313333              tmp=short_zuser(user);
    33323334              sprintf(line, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
     
    33713373  owl_view *v;
    33723374  FILE *file;
     3375  char *plaintext;
    33733376
    33743377  v=owl_global_get_current_view(&g);
     
    33933396  for (i=0; i<j; i++) {
    33943397    m=owl_view_get_element(v, i);
    3395     fputs(owl_message_get_text(m), file);
     3398    plaintext = owl_strip_format_chars(owl_message_get_text(m));
     3399    if (plaintext) {
     3400      fputs(plaintext, file);
     3401      owl_free(plaintext);
     3402    }
    33963403  }
    33973404  fclose(file);
     
    34343441          _exit(127);
    34353442        }
    3436         parsed=realloc(parsed, sizeof(*parsed) * (myargc+1));
     3443        parsed=owl_realloc(parsed, sizeof(*parsed) * (myargc+1));
    34373444        parsed[myargc] = NULL;
    34383445       
  • global.c

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

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

    r948b942 r428834d  
    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   
    165166  } 
    166167  if (!*kb) {
  • keys.c

    r8938188 rfac5463  
    294294/****************************************************************/
    295295
    296 void owl_keys_recwin_prealways(int j) {
     296void owl_keys_recwin_prealways(owl_input j) {
    297297  /* Clear the message line on subsequent key presses */
    298298  owl_function_makemsg("");
    299299}
    300300
    301 void owl_keys_editwin_default(int j) {
     301void owl_keys_editwin_default(owl_input 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(int j) {
     308void owl_keys_editwin_postalways(owl_input 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(int j) {
     316void owl_keys_popless_postalways(owl_input 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(int j) {
    326   if (j==ERR) return;
    327   if (j==410) return;
     325void owl_keys_default_invalid(owl_input j) {
     326  if (j.ch==ERR) return;
     327  if (j.ch==410) return;
    328328  owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g));
    329329}
  • logging.c

    rd0961fe r28ee32b  
    155155    to = owl_sprintf("jabber:%s", owl_message_get_recipient(m));
    156156  } else if (owl_message_is_type_aim(m)) {
     157    char *temp2;
    157158    temp = owl_aim_normalize_screenname(owl_message_get_recipient(m));
    158     downstr(temp);
    159     to = owl_sprintf("aim:%s", temp);
     159    temp2 = g_utf8_strdown(temp,-1);
     160    to = owl_sprintf("aim:%s", temp2);
     161    owl_free(temp2);
    160162    owl_free(temp);
    161163  } else {
     
    267269  } else if (owl_message_is_type_aim(m)) {
    268270    /* we do not yet handle chat rooms */
    269     char *normalto;
    270     normalto=owl_aim_normalize_screenname(owl_message_get_sender(m));
    271     downstr(normalto);
     271    char *normalto, *temp;
     272    temp = owl_aim_normalize_screenname(owl_message_get_sender(m));
     273    normalto = g_utf8_strdown(temp, -1);
    272274    from=frombuff=owl_sprintf("aim:%s", normalto);
    273275    owl_free(normalto);
     276    owl_free(temp);
    274277  } else if (owl_message_is_type_loopback(m)) {
    275278    from=frombuff=owl_strdup("loopback");
     
    290293
    291294  ch=frombuff[0];
    292   if (!isalnum(ch)) from="weird";
     295  if (!g_ascii_isalnum(ch)) from="weird";
    293296
    294297  for (i=0; i<len; i++) {
     
    299302
    300303  if (!personal) {
    301     if (strcmp(from, "weird")) downstr(from);
     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    }
    302311  }
    303312
  • message.c

    r635881c ra827529  
    7979    owl_list_append_element(&(m->attributes), pair);
    8080  }
    81   owl_pair_set_value(pair, owl_strdup(attrvalue));
     81  owl_pair_set_value(pair, owl_validate_or_convert(attrvalue));
    8282}
    8383
     
    493493{
    494494  if(m->zwriteline) owl_free(m->zwriteline);
    495   m->zwriteline=strdup(line);
     495  m->zwriteline=owl_strdup(line);
    496496}
    497497
     
    535535  owl_fmtext_init_null(&b);
    536536 
    537   owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
     537  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline, &a);
    538538  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    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      
     539  owl_fmtext_colorize(&b, fgcolor);
     540  owl_fmtext_colorizebg(&b, bgcolor);
     541
    550542  owl_fmtext_curs_waddstr(&b, win);
    551543
     
    890882  }
    891883
    892   m->zwriteline=strdup("");
     884  m->zwriteline=owl_strdup("");
    893885
    894886  /* save the hostname */
     
    972964  }
    973965
    974   m->zwriteline=strdup("");
     966  m->zwriteline=owl_strdup("");
    975967
    976968  owl_message_set_body(m, "<uninitialized>");
  • owl.h

    r88dc766 rf92080c  
    5252#include <termios.h>
    5353#include <libfaim/aim.h>
     54#include <wchar.h>
    5455#include "config.h"
     56#include "glib.h"
    5557#ifdef HAVE_LIBZEPHYR
    5658#include <zephyr/zephyr.h>
     
    100102#define OWL_FMTEXT_ATTR_REVERSE   2
    101103#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
    102124
    103125#define OWL_COLOR_BLACK     0
     
    212234#endif
    213235
    214 #define OWL_META(key) ((key)|0200)
     236#define OWL_META(key) ((key)|010000)
    215237/* OWL_CTRL is definied in kepress.c */
    216238
     
    252274} owl_variable;
    253275
     276typedef struct _owl_input {
     277  int ch;
     278  gunichar uch;
     279} owl_input;
     280
    254281typedef struct _owl_fmtext {
    255282  int textlen;
    256283  int bufflen;
    257284  char *textbuff;
    258   char *fmbuff;
    259   short *fgcolorbuff;
    260   short *bgcolorbuff;
     285  char default_attrs;
     286  short default_fgcolor;
     287  short default_bgcolor;
    261288} owl_fmtext;
    262289
     
    491518  owl_list  bindings;           /* key bindings */
    492519  struct _owl_keymap *submap;   /* submap */
    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 */
     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 */
    496523} owl_keymap;
    497524
  • text.c

    r72db971 r47519e1b  
    5050void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)
    5151{
    52   char *ptr1, *ptr2, *tmpbuff, *last;
    53   int len;
    54 
     52  char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;
     53  int col, cnt, padding;
     54 
    5555  tmpbuff=owl_malloc(strlen(in)+20);
    5656
    5757  strcpy(tmpbuff, "");
    5858  last=in+strlen(in)-1;
    59   ptr1=in;
    60   while (ptr1<last) {
    61     ptr2=strchr(ptr1, '\n');
    62     if (!ptr2) {
     59  ptr_s=in;
     60  while (ptr_s<last) {
     61    ptr_e=strchr(ptr_s, '\n');
     62    if (!ptr_e) {
    6363      /* but this shouldn't happen if we end in a \n */
    6464      break;
    6565    }
    6666   
    67     if (ptr2==ptr1) {
     67    if (ptr_e==ptr_s) {
    6868      strcat(tmpbuff, "\n");
    69       ptr1++;
    70       continue;
    71     }
    72 
     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
    7399    /* we need to check that we won't run over here */
    74     if ( (ptr2-ptr1) < (bcol-acol) ) {
    75       len=ptr2-(ptr1+acol);
     100    if ( (ptr_e-ptr_s) < (bcol-acol) ) {
     101      len=ptr_e-(ptr_s+acol);
    76102    } else {
    77103      len=bcol-acol;
    78104    }
    79     if ((ptr1+len)>=last) {
    80       len-=last-(ptr1+len);
    81     }
    82 
    83     strncat(tmpbuff, ptr1+acol, len);
     105    if ((ptr_s+len)>=last) {
     106      len-=last-(ptr_s+len);
     107    }
     108
     109    strncat(tmpbuff, ptr_s+acol, len);
    84110    strcat(tmpbuff, "\n");
    85111
    86     ptr1=ptr2+1;
     112    ptr_s=ptr_e+1;
     113#endif
    87114  }
    88115  strcpy(out, tmpbuff);
     
    275302char *stristr(char *a, char *b)
    276303{
    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);
     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  }
    292316  return(ret);
    293317}
     
    296320int only_whitespace(char *s)
    297321{
    298   int i;
    299   for (i=0; s[i]; i++) {
    300     if (!isspace((int) s[i])) return(0);
     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    }
    301333  }
    302334  return(1);
     
    327359  tolen  = strlen(to);
    328360  fromlen  = strlen(from);
    329   out = malloc(outlen);
     361  out = owl_malloc(outlen);
    330362
    331363  while (in[inpos]) {
  • util.c

    r89f5338 rc1522ec  
    399399}
    400400
    401 /* downcase the string 'foo' */
    402 void downstr(char *foo)
    403 {
    404   int i;
    405   for (i=0; foo[i]!='\0'; i++) {
    406     foo[i]=tolower(foo[i]);
    407   }
    408 }
    409 
    410401/* Caller must free response.
    411402 * Takes in strings which are space-separated lists of tokens
     
    446437void *owl_malloc(size_t size)
    447438{
    448   return(malloc(size));
     439  return(g_malloc(size));
    449440}
    450441
    451442void owl_free(void *ptr)
    452443{
    453   free(ptr);
     444  g_free(ptr);
    454445}
    455446
    456447char *owl_strdup(const char *s1)
    457448{
    458   return(strdup(s1));
     449  return(g_strdup(s1));
    459450}
    460451
    461452void *owl_realloc(void *ptr, size_t size)
    462453{
    463   return(realloc(ptr, size));
     454  return(g_realloc(ptr, size));
    464455}
    465456
    466457/* allocates memory and returns the string or null.
    467458 * caller must free the string.
    468  * from Linux sprintf man page.
    469459 */
    470460char *owl_sprintf(const char *fmt, ...)
    471461{
    472   int n, size = 100;
    473   char *p;
    474462  va_list ap;
    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 }
     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
    493470
    494471/* Return the owl color associated with the named color.  Return -1
     
    776753}
    777754
    778 char * owl_get_datadir() {
    779     char * datadir = getenv("BARNOWL_DATA_DIR");
    780     if(datadir != NULL)
    781         return strchr(datadir, '=') + 1;
    782     return DATADIR;
     755char * 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. */
     765char * 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 */
     803char * 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 */
     817char * 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;
    783832}
    784833
  • viewwin.c

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

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

    r60c2e1e rf92080c  
    354354  return(owl_strdup(""));
    355355}
     356
     357char *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
     388  return(owl_strdup(""));
     389}
    356390#else
    357391char *owl_zephyr_get_field(void *n, int j)
    358392{
    359393  return(owl_strdup(""));
     394}
     395char *owl_zephyr_get_field_as_utf8(ZNotice_t *n, int j)
     396{
     397  return owl_zephyr_get_field(n, j);
    360398}
    361399#endif
  • zwrite.c

    r1fe100c r7b1d048  
    4444        break;
    4545      }
    46       z->class=owl_strdup(myargv[1]);
     46      z->class=owl_get_iso_8859_1_if_possible(myargv[1]);
    4747      myargv+=2;
    4848      myargc-=2;
     
    5252        break;
    5353      }
    54       z->inst=owl_strdup(myargv[1]);
     54      z->inst=owl_get_iso_8859_1_if_possible(myargv[1]);
    5555      myargv+=2;
    5656      myargc-=2;
     
    6060        break;
    6161      }
    62       z->realm=owl_strdup(myargv[1]);
     62      z->realm=owl_get_iso_8859_1_if_possible(myargv[1]);
    6363      myargv+=2;
    6464      myargc-=2;
     
    6868        break;
    6969      }
    70       z->zsig=owl_strdup(myargv[1]);
     70      z->zsig=owl_get_iso_8859_1_if_possible(myargv[1]);
    7171      myargv+=2;
    7272      myargc-=2;
     
    7676        break;
    7777      }
    78       z->opcode=owl_strdup(myargv[1]);
     78      z->opcode=owl_get_iso_8859_1_if_possible(myargv[1]);
    7979      myargv+=2;
    8080      myargc-=2;
     
    9393      myargv++;
    9494      myargc--;
    95       z->message=owl_strdup("");
     95      z->message=owl_get_iso_8859_1_if_possible("");
    9696      while (myargc) {
    97         z->message=realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
     97        z->message=owl_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), strdup(myargv[0]));
     115      owl_list_append_element(&(z->recips), owl_get_iso_8859_1_if_possible(myargv[0]));
    116116      myargv++;
    117117      myargc--;
     
    146146
    147147    if (zsigowlvar && *zsigowlvar) {
    148       z->zsig=owl_strdup(zsigowlvar);
     148      z->zsig=owl_get_iso_8859_1_if_possible(zsigowlvar);
    149149    } else if (zsigproc && *zsigproc) {
    150150      FILE *file;
     
    161161      if (!file) {
    162162        if (zsigzvar && *zsigzvar) {
    163           z->zsig=owl_strdup(zsigzvar);
     163          z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar);
    164164        }
    165165      } else {
     
    175175      }
    176176    } else if (zsigzvar) {
    177       z->zsig=owl_strdup(zsigzvar);
     177      z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar);
    178178    } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
    179       z->zsig=strdup(pw->pw_gecos);
     179      z->zsig=owl_get_iso_8859_1_if_possible(pw->pw_gecos);
    180180      ptr=strchr(z->zsig, ',');
    181181      if (ptr) {
     
    218218  int i, j;
    219219  char toline[LINE];
     220  char *tmp = NULL;
    220221
    221222  if (z->message) owl_free(z->message);
     
    231232      }
    232233    }
    233     z->message=owl_sprintf("%s\n%s", toline, msg);
     234    tmp = owl_get_iso_8859_1_if_possible(msg);
     235    z->message=owl_sprintf("%s\n%s", toline, tmp);
    234236  } else {
    235     z->message=owl_strdup(msg);
    236   }
     237    z->message=owl_get_iso_8859_1_if_possible(msg);
     238  }
     239  if (tmp) owl_free(tmp);
    237240}
    238241
     
    305308{
    306309  if (z->opcode) owl_free(z->opcode);
    307   z->opcode=owl_strdup(opcode);
     310  z->opcode=owl_get_iso_8859_1_if_possible(opcode);
    308311}
    309312
Note: See TracChangeset for help on using the changeset viewer.