Changeset 36562b0 for irc_channel.c


Ignore:
Timestamp:
2010-06-07T00:44:45Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0d9d53e
Parents:
92cb8c4
Message:

Added "channel list" command and the ability to use only part of the
channel name or a number in "chan set"/etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_channel.c

    r92cb8c4 r36562b0  
    4949                irc_channel_user_set_mode( ic, irc->root, IRC_CHANNEL_USER_OP );
    5050       
    51         irc->channels = g_slist_prepend( irc->channels, ic );
     51        irc->channels = g_slist_append( irc->channels, ic );
    5252       
    5353        set_add( &ic->set, "type", "control", set_eval_channel_type, ic );
     
    6969                irc_channel_t *ic = l->data;
    7070               
    71                 if( name[0] == ic->name[0] && nick_cmp( name + 1, ic->name + 1 ) == 0 )
     71                if( g_strcasecmp( name, ic->name ) == 0 )
    7272                        return ic;
    7373        }
    7474       
    7575        return NULL;
     76}
     77
     78irc_channel_t *irc_channel_get( irc_t *irc, char *id )
     79{
     80        irc_channel_t *ic, *ret = NULL;
     81        GSList *l;
     82        int nr;
     83       
     84        if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
     85        {
     86                for( l = irc->channels; l; l = l->next )
     87                {
     88                        ic = l->data;
     89                        if( ( nr-- ) == 0 )
     90                                return ic;
     91                }
     92               
     93                return NULL;
     94        }
     95       
     96        /* Exact match first: Partial match only sucks if there's a channel
     97           #aa and #aabb */
     98        if( ( ret = irc_channel_by_name( irc, id ) ) )
     99                return ret;
     100       
     101        for( l = irc->channels; l; l = l->next )
     102        {
     103                ic = l->data;
     104               
     105                if( strstr( ic->name, id ) )
     106                {
     107                        /* Make sure it's a unique match. */
     108                        if( !ret )
     109                                ret = ic;
     110                        else
     111                                return NULL;
     112                }
     113        }
     114       
     115        return ret;
    76116}
    77117
Note: See TracChangeset for help on using the changeset viewer.