+static FontLayoutCategory *
+configure_category (FontLayoutCategory *category, MFLTFont *font)
+{
+ if (! mflt_font_id || ! mflt_iterate_otf_feature)
+ {
+ FontLayoutCategory *new = malloc (sizeof (FontLayoutCategory));
+ new->definition = NULL;
+ new->table = category->table;
+ M17N_OBJECT_REF (new->table);
+ return new;
+ }
+ return load_category_table (category->definition, font);
+}
+
+static MFLT *
+configure_flt (MFLT *flt, MFLTFont *font, MSymbol font_id)
+{
+ MPlist *plist;
+ MFLT *configured;
+
+ if (! mflt_font_id || ! mflt_iterate_otf_feature)
+ return flt;
+ MPLIST_DO (plist, flt_list)
+ {
+ configured = MPLIST_VAL (plist);
+ if (! configured->font_id)
+ break;
+ if (configured->name == flt->name
+ && configured->font_id == font_id)
+ return configured;
+ }
+ if (! MSTRUCT_CALLOC_SAFE (configured))
+ return flt;
+ *configured = *flt;
+ configured->stages = mplist_copy (flt->stages);
+ MPLIST_DO (plist, configured->stages)
+ {
+ FontLayoutStage *stage = MPLIST_VAL (plist);
+ if (stage->category->definition)
+ {
+ MSTRUCT_CALLOC (stage, MERROR_FLT);
+ *stage = *((FontLayoutStage *) MPLIST_VAL (plist));
+ stage->category = configure_category (stage->category, font);
+ MPLIST_VAL (plist) = stage;
+ }
+ else
+ M17N_OBJECT_REF (stage->category->table);
+ }
+ configured->need_config = 0;
+ configured->font_id = font_id;
+ mplist_push (flt_list, flt->name, configured);
+ return configured;
+}