Does `rel` (a path below the Go file's directory) match the embed * pattern: segment by segment, a matched directory taking its files except * hidden ones ('.', '_') unless `all`. */
| 860 | * pattern: segment by segment, a matched directory taking its files except |
| 861 | * hidden ones ('.', '_') unless `all`. */ |
| 862 | static bool op_embeds(const char *pattern, const char *rel, bool all) { |
| 863 | char pat[CBM_SZ_1K]; |
| 864 | char path[CBM_SZ_1K]; |
| 865 | snprintf(pat, sizeof(pat), "%s", pattern); |
| 866 | snprintf(path, sizeof(path), "%s", rel); |
| 867 | char *ps = pat; |
| 868 | char *rs = path; |
| 869 | while (ps && rs) { |
| 870 | char *pn = strchr(ps, '/'); |
| 871 | char *rn = strchr(rs, '/'); |
| 872 | if (pn) { |
| 873 | *pn = '\0'; |
| 874 | } |
| 875 | if (rn) { |
| 876 | *rn = '\0'; |
| 877 | } |
| 878 | if (!op_match(ps, rs)) { |
| 879 | return false; |
| 880 | } |
| 881 | ps = pn ? pn + SKIP_ONE : NULL; |
| 882 | rs = rn ? rn + SKIP_ONE : NULL; |
| 883 | if (!ps) { |
| 884 | /* pattern consumed: the file itself, or a file under a matched dir */ |
| 885 | for (char *seg = rs; seg && !all;) { |
| 886 | if (seg[0] == '.' || seg[0] == '_') { |
| 887 | return false; |
| 888 | } |
| 889 | char *next = strchr(seg, '/'); |
| 890 | seg = next ? next + SKIP_ONE : NULL; |
| 891 | } |
| 892 | return true; |
| 893 | } |
| 894 | } |
| 895 | return false; |
| 896 | } |
| 897 | |
| 898 | static int op_cmp_path(const void *a, const void *b) { |
| 899 | const cbm_gbuf_node_t *x = *(const cbm_gbuf_node_t *const *)a; |