(mu_hdrent_find): Allow negative instance indices, meaning scanning from the bottom up.
Showing
1 changed file
with
15 additions
and
3 deletions
... | @@ -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 | ... | ... |
-
Please register or sign in to post a comment