| 12 | static int order_cnt; |
| 13 | |
| 14 | static void prepare_order(const char *orderfile) |
| 15 | { |
| 16 | int cnt, pass; |
| 17 | struct strbuf sb = STRBUF_INIT; |
| 18 | const char *cp, *endp; |
| 19 | ssize_t sz; |
| 20 | |
| 21 | if (order) |
| 22 | return; |
| 23 | |
| 24 | sz = strbuf_read_file(&sb, orderfile, 0); |
| 25 | if (sz < 0) |
| 26 | die_errno(_("failed to read orderfile '%s'"), orderfile); |
| 27 | endp = sb.buf + sz; |
| 28 | |
| 29 | for (pass = 0; pass < 2; pass++) { |
| 30 | cnt = 0; |
| 31 | cp = sb.buf; |
| 32 | while (cp < endp) { |
| 33 | const char *ep; |
| 34 | for (ep = cp; ep < endp && *ep != '\n'; ep++) |
| 35 | ; |
| 36 | /* cp to ep has one line */ |
| 37 | if (*cp == '\n' || *cp == '#') |
| 38 | ; /* comment */ |
| 39 | else if (pass == 0) |
| 40 | cnt++; |
| 41 | else { |
| 42 | order[cnt] = xmemdupz(cp, ep - cp); |
| 43 | cnt++; |
| 44 | } |
| 45 | if (ep < endp) |
| 46 | ep++; |
| 47 | cp = ep; |
| 48 | } |
| 49 | if (pass == 0) { |
| 50 | order_cnt = cnt; |
| 51 | ALLOC_ARRAY(order, cnt); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | strbuf_release(&sb); |
| 56 | } |
| 57 | |
| 58 | static int match_order(const char *path) |
| 59 | { |
no test coverage detected