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 * ...@@ -75,9 +75,21 @@ static struct mu_hdrent *
75 mu_hdrent_find (struct _mu_header *hdr, const char *name, int pos) 75 mu_hdrent_find (struct _mu_header *hdr, const char *name, int pos)
76 { 76 {
77 struct mu_hdrent *p; 77 struct mu_hdrent *p;
78 for (p = hdr->head; p; p = p->next) 78
79 if (strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && pos-- == 1) 79 if (pos > 0)
80 break; 80 {
81 for (p = hdr->head; p; p = p->next)
82 if (strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && pos-- == 1)
83 break;
84 }
85 else if (pos < 0)
86 {
87 for (p = hdr->tail; p; p = p->prev)
88 if (strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && ++pos == 0)
89 break;
90 }
91 else
92 p = NULL;
81 return p; 93 return p;
82 } 94 }
83 95
......