+int
+iter_comm_channels_step(rb_dlink_node *pos1, rb_dlink_node *pos2,
+ struct membership **ms1, struct membership **ms2,
+ struct Channel **chptr)
+{
+ *ms1 = pos1 ? pos1->data : NULL;
+ *ms2 = pos2 ? pos2->data : NULL;
+
+ /* we're at the end */
+ if (*ms1 == NULL && *ms2 == NULL)
+ return 0;
+
+ /* one side is at the end, keep stepping the other one */
+ if (*ms1 == NULL || *ms2 == NULL)
+ {
+ *chptr = *ms1 != NULL ? (*ms1)->chptr : (*ms2)->chptr;
+ return 1;
+ }
+
+ /* common channel */
+ if ((*ms1)->chptr == (*ms2)->chptr)
+ {
+ *chptr = (*ms1)->chptr;
+ return 1;
+ }
+
+ /* null out the channel that's further ahead; we'll get to it later */
+ if (irccmp((*ms1)->chptr->chname, (*ms2)->chptr->chname) > 0)
+ {
+ *ms1 = NULL;
+ *chptr = (*ms2)->chptr;
+ return 1;
+ }
+ else
+ {
+ *ms2 = NULL;
+ *chptr = (*ms1)->chptr;
+ return 1;
+ }
+}
+