Changeset 19cc7b00


Ignore:
Timestamp:
Jul 28, 2009, 11:39:29 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
2b37be2
Parents:
c4efb46 (diff), d4ecc78 (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:
Merge davidben's changes.

Merge commit 'davidben/master'
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • dict.c

    r4d86e06 r7cd5878  
    33 * Stores as a sorted list of key/value pairs.
    44 * O(n) on inserts and deletes.
    5  * O(n) on searches, although it should switch to a binary search for O(log n)
     5 * O(log n) on searches
    66 */
    77
     
    3030/* Finds the position of an element with key k, or of the element where
    3131 * this element would logically go, and stores the index in pos.
    32  * TODO: optimize to do a binary search.
    3332 * Returns 1 if found, else 0. */
    3433int _owl_dict_find_pos(owl_dict *d, char *k, int *pos) {
    35   int i;
    36   for (i=0; (i<d->size) && strcmp(k,d->els[i].k)>0; i++);
    37   *pos = i;
    38   if (i>=d->size || strcmp(k,d->els[i].k)) {
    39     return(0);
    40   } else {
    41     return(1);
     34  int lo, hi, mid, cmp;
     35  lo = 0;
     36  hi = d->size;
     37  while (lo < hi) {
     38    mid = (lo+hi)/2; // lo goes up and we can't hit hi, so no +1
     39    cmp = strcmp(k, d->els[mid].k);
     40    if (cmp == 0) {
     41      lo = hi = mid;
     42    } else if (cmp < 0) {
     43      hi = mid;
     44    } else { // cmp > 0
     45      lo = mid+1;
     46    }
    4247  }
     48  *pos = lo;
     49  return !!(lo < d->size && !strcmp(k, d->els[lo].k));
    4350}
    4451
  • perl/lib/BarnOwl/Complete/Zephyr.pm

    r8f16dcd r84db778  
    3030}
    3131
    32 sub complete_sub {
    33     my $ctx = shift;
    34     return complete_flags($ctx,
    35         [],
    36         {
    37             "-r" => \&complete_realm,
    38         });
    39 }
    40 
    4132sub on_message {
    4233    my $m = shift;
     
    5041BarnOwl::Completion::register_completer(zcrypt    => \&complete_zwrite);
    5142
    52 # TODO: Handle aliases transparently in the core completion code?
    53 BarnOwl::Completion::register_completer(sub       => \&complete_sub);
    54 BarnOwl::Completion::register_completer(subscribe => \&complete_sub);
    55 
    5643$BarnOwl::Hooks::newMessage->add("BarnOwl::Complete::Zephyr::on_message");
    5744
  • perl/lib/BarnOwl/Completion.pm

    rf987504 rc4efb46  
    1818                        point_move replace_region);
    1919
    20 use List::Util qw(max first);
     20use List::Util qw(min first);
    2121
    2222our %completers = ();
     
    7676sub common_prefix {
    7777    my @words = @_;
    78     my $len   = max(map {length($_)} @words);
     78    my $len   = min(map {length($_)} @words);
    7979    my $pfx = '';
    8080    for my $i (1..$len) {
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    r96f7b07 rab9cd8f  
    1818use BarnOwl::Message::IRC;
    1919use BarnOwl::Module::IRC::Connection qw(is_private);
     20use BarnOwl::Module::IRC::Completion;
    2021
    2122use Net::IRC;
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    r004d683 r57ba9f1  
    1919use BarnOwl::Module::Jabber::Connection;
    2020use BarnOwl::Module::Jabber::ConnectionManager;
     21use BarnOwl::Completion::Util qw(complete_flags);
    2122
    2223use Authen::SASL qw(Perl);
     
    6263$conn ||= BarnOwl::Module::Jabber::ConnectionManager->new;
    6364our %vars;
     65our %completion_jids;
    6466
    6567sub onStart {
     
    164166
    165167    $blistStr .= sprintf '%-15s %s', $name, $buddy->GetJID();
     168    $completion_jids{$name} = 1;
     169    $completion_jids{$buddy->GetJID()} = 1;
    166170
    167171    if ($res) {
     
    427431                BarnOwl::error( "Error in connect: " . join( " ", @result ) );
    428432            } else {
    429                 $conn->getRosterFromJID($jidStr)->fetch();
     433                my $roster = $conn->getRosterFromJID($jidStr);
     434                $roster->fetch();
    430435                $client->PresenceSend( priority => 1 );
    431436                my $fullJid = $client->{SESSION}->{FULLJID} || $jidStr;
     
    437442                #queue_admin_msg("Connected to jabber as $fullJid ($client->{fileno})");
    438443                BarnOwl::add_dispatch($client->{fileno}, sub { $client->OwlProcess() });
     444
     445                # populate completion from roster.
     446                for my $buddy ( $roster->jids('all') ) {
     447                    my %jq  = $roster->query($buddy);
     448                    my $name = $jq{name} || $buddy->GetUserID();
     449                    $completion_jids{$name} = 1;
     450                    $completion_jids{$buddy->GetJID()} = 1;
     451                }
    439452            }
    440453        }
     
    647660                                                   MaxChars => 0
    648661                                                  });
     662    $completion_jids{$muc} = 1;
    649663    return;
    650664}
     
    701715
    702716    my $presence = "JIDs present in " . $m->BaseJID;
     717    $completion_jids{$m->BaseJID} = 1;
    703718    if($m->Anonymous) {
    704719        $presence .= " [anonymous MUC]";
     
    875890    $name = "" unless (1 == scalar(@ARGV));
    876891
     892    $completion_jids{$baseJID} = 1;
     893    $completion_jids{$name} = 1 if $name;
     894
    877895    foreach my $to (@ARGV) {
    878896        my %jq  = $roster->query($to);
     
    10571075
    10581076sub process_presence_available {
    1059     return unless (BarnOwl::getvar('jabber:show_logins') eq 'on');
    10601077    my ( $sid, $p ) = @_;
    10611078    my $from = $p->GetFrom('jid')->GetJID('base');
     1079    $completion_jids{$from} = 1;
     1080    return unless (BarnOwl::getvar('jabber:show_logins') eq 'on');
    10621081    my $to = $p->GetTo();
    10631082    my $type = $p->GetType();
     
    12091228              if ($connection->FindMUC(jid => $to));
    12101229        }
     1230
     1231        # Populate completion.
     1232        if ($dir eq 'in') {
     1233            $completion_jids{ $props{sender} }= 1;
     1234        }
     1235        else {
     1236            $completion_jids{ $props{recipient} } = 1;
     1237        }
    12111238    }
    12121239    elsif ( $jtype eq 'groupchat' ) {
    12131240        my $nick = $props{nick} = $from->GetResource();
    12141241        my $room = $props{room} = $from->GetJID('base');
     1242        $completion_jids{$room} = 1;
    12151243
    12161244        $props{sender} = $nick || $room;
     
    13841412}
    13851413
     1414################################################################################
     1415### Completion
     1416
     1417sub complete_user_or_muc { return keys %completion_jids; }
     1418sub complete_account { return $conn->getJIDs(); }
     1419
     1420sub complete_jwrite {
     1421    my $ctx = shift;
     1422    return complete_flags($ctx,
     1423                          [qw(-t -i -s)],
     1424                          {
     1425                              "-a" => \&complete_account,
     1426                          },
     1427                          \&complete_user_or_muc
     1428        );
     1429}
     1430
     1431BarnOwl::Completion::register_completer(jwrite => sub { BarnOwl::Module::Jabber::complete_jwrite(@_) });
     1432
    138614331;
  • perlglue.xs

    r6dc2d6b rd77e909  
    332332        CODE:
    333333        owl_select_remove_perl_dispatch(fd);
     334
     335
     336AV*
     337all_filters()
     338        PREINIT:
     339                AV *filters;
     340                owl_list *fl;
     341                owl_filter *f;
     342                int i;
     343        CODE:
     344        {
     345                fl = owl_global_get_filterlist(&g);
     346                filters = newAV();
     347                for(i=0;i<owl_list_get_size(fl);i++) {
     348                        f = owl_list_get_element(fl, i);
     349                        av_push(filters, newSVpv(owl_filter_get_name(f), 0));
     350                }
     351                RETVAL = filters;
     352                sv_2mortal((SV*)RETVAL);
     353        }
     354        OUTPUT:
     355                RETVAL
    334356
    335357MODULE = BarnOwl                PACKAGE = BarnOwl::Internal
  • t/completion.t

    r7be5d8b rc4efb46  
    122122is(BarnOwl::Completion::common_prefix(qw(abc abc)), 'abc');
    123123
     124is(BarnOwl::Completion::common_prefix('a', ''), '');
     125
    124126## Test complete_flags
    125127
Note: See TracChangeset for help on using the changeset viewer.