Commit bcf509b0 bcf509b08c28b5ec3d915d4c5e5f2fff0ecbbb2c by Sergey Poznyakoff

(mu_hdrent_find): Allow negative instance indices, meaning scanning from the bottom up.

1 parent ab8cfdaf
......@@ -75,9 +75,21 @@ static struct mu_hdrent *
mu_hdrent_find (struct _mu_header *hdr, const char *name, int pos)
{
struct mu_hdrent *p;
if (pos > 0)
{
for (p = hdr->head; p; p = p->next)
if (strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && pos-- == 1)
break;
}
else if (pos < 0)
{
for (p = hdr->tail; p; p = p->prev)
if (strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && ++pos == 0)
break;
}
else
p = NULL;
return p;
}
......