- if(qhead.prev == &qhead /* Empty queue. */
- || qhead.prev->state != playing_random) /* No random track */
- l_add(qhead.prev, q);
- else
- l_add(qhead.prev->prev, q); /* Before random track. */
+ /* We want to find the point in the queue before the block of random tracks
+ * at the end. */
+ beforeme = &qhead;
+ while(beforeme->prev != &qhead
+ && beforeme->prev->state == playing_random)
+ beforeme = beforeme->prev;
+ l_add(beforeme->prev, q);