+\f
+/* Multiple response sets. */
+
+/* Returns the multiple response set in DICT with index IDX, which must be
+ between 0 and the count returned by dict_get_n_mrsets(), exclusive. */
+const struct mrset *
+dict_get_mrset (const struct dictionary *dict, size_t idx)
+{
+ assert (idx < dict->n_mrsets);
+ return dict->mrsets[idx];
+}
+
+/* Returns the number of multiple response sets in DICT. */
+size_t
+dict_get_n_mrsets (const struct dictionary *dict)
+{
+ return dict->n_mrsets;
+}
+
+/* Looks for a multiple response set named NAME in DICT. If it finds one,
+ returns its index; otherwise, returns SIZE_MAX. */
+static size_t
+dict_lookup_mrset_idx (const struct dictionary *dict, const char *name)
+{
+ size_t i;
+
+ for (i = 0; i < dict->n_mrsets; i++)
+ if (!utf8_strcasecmp (name, dict->mrsets[i]->name))
+ return i;
+
+ return SIZE_MAX;
+}
+
+/* Looks for a multiple response set named NAME in DICT. If it finds one,
+ returns it; otherwise, returns NULL. */
+const struct mrset *
+dict_lookup_mrset (const struct dictionary *dict, const char *name)
+{
+ size_t idx = dict_lookup_mrset_idx (dict, name);
+ return idx != SIZE_MAX ? dict->mrsets[idx] : NULL;
+}
+
+/* Adds MRSET to DICT, replacing any existing set with the same name. Returns
+ true if a set was replaced, false if none existed with the specified name.
+
+ Ownership of MRSET is transferred to DICT. */
+bool
+dict_add_mrset (struct dictionary *dict, struct mrset *mrset)
+{
+ size_t idx;
+
+ assert (mrset_ok (mrset, dict));
+
+ idx = dict_lookup_mrset_idx (dict, mrset->name);
+ if (idx == SIZE_MAX)
+ {
+ dict->mrsets = xrealloc (dict->mrsets,
+ (dict->n_mrsets + 1) * sizeof *dict->mrsets);
+ dict->mrsets[dict->n_mrsets++] = mrset;
+ return true;
+ }
+ else
+ {
+ mrset_destroy (dict->mrsets[idx]);
+ dict->mrsets[idx] = mrset;
+ return false;
+ }
+}
+
+/* Looks for a multiple response set in DICT named NAME. If found, removes it
+ from DICT and returns true. If none is found, returns false without
+ modifying DICT.