+struct refglob_set {
+ const tchar **globs;
+ unsigned num_globs;
+ unsigned num_alloc_globs;
+};
+
+#define REFGLOB_SET_INITIALIZER \
+ { .globs = NULL, .num_globs = 0, .num_alloc_globs = 0, }
+
+#define REFGLOB_SET(_refglobs) \
+ struct refglob_set _refglobs = REFGLOB_SET_INITIALIZER
+
+static int
+refglob_set_append(struct refglob_set *set, const tchar *glob)
+{
+ unsigned num_alloc_globs = set->num_alloc_globs;
+
+ if (set->num_globs == num_alloc_globs) {
+ const tchar **new_globs;
+
+ num_alloc_globs += 4;
+ new_globs = realloc(set->globs, sizeof(set->globs[0]) * num_alloc_globs);
+ if (!new_globs) {
+ imagex_error(T("Out of memory!"));
+ return -1;
+ }
+ set->globs = new_globs;
+ set->num_alloc_globs = num_alloc_globs;
+ }
+ set->globs[set->num_globs++] = glob;
+ return 0;
+}
+
+static int
+wim_reference_globs(WIMStruct *wim, struct refglob_set *set, int open_flags)
+{
+ return wimlib_reference_resource_files(wim, set->globs, set->num_globs,
+ WIMLIB_REF_FLAG_GLOB_ENABLE,
+ open_flags,
+ imagex_progress_func);
+}
+
+static void
+refglob_set_destroy(struct refglob_set *set)
+{
+ free(set->globs);
+}
+
+static void
+do_resource_not_found_warning(const tchar *wimfile,
+ const struct wimlib_wim_info *info,
+ const struct refglob_set *refglobs)
+{
+ if (info->total_parts > 1) {
+ if (refglobs->num_globs == 0) {
+ imagex_error(T("\"%"TS"\" is part of a split WIM. "
+ "Use --ref to specify the other parts."),
+ wimfile);
+ } else {
+ imagex_error(T("Perhaps the '--ref' argument did not "
+ "specify all other parts of the split "
+ "WIM?"));
+ }
+ } else {
+ imagex_error(T("If this is a delta WIM, use the --ref argument "
+ "to specify the WIM on which it is based."));
+ }
+}
+