+static bool
+is_all_ascii (const char *s)
+{
+ for (; *s; s++)
+ if (!encoding_guess_is_ascii_text (*s))
+ return false;
+
+ return true;
+}
+
+static void
+dump_strings (const char *encoding, struct string_array *strings)
+{
+ string_array_sort (strings);
+ string_array_uniq (strings);
+
+ if (raw)
+ {
+ if (exclude_ascii_only || include_utf8_only)
+ {
+ size_t i = 0;
+ for (size_t j = 0; j < strings->n; j++)
+ {
+ char *s = strings->strings[j];
+ bool is_ascii = is_all_ascii (s);
+ bool is_utf8 = !u8_check (CHAR_CAST (uint8_t *, s), strlen (s));
+ if (!is_ascii && (!include_utf8_only || is_utf8))
+ strings->strings[i++] = s;
+ else
+ free (s);
+ }
+ strings->n = i;
+ }
+ for (size_t i = 0; i < strings->n; i++)
+ puts (strings->strings[i]);
+ }
+ else
+ {
+ size_t n_nonascii = 0;
+ size_t n_utf8 = 0;
+ for (size_t i = 0; i < strings->n; i++)
+ {
+ const char *s = strings->strings[i];
+ if (!is_all_ascii (s))
+ {
+ n_nonascii++;
+ if (!u8_check (CHAR_CAST (uint8_t *, s), strlen (s)))
+ n_utf8++;
+ }
+ }
+ printf ("%s: %zu unique strings, %zu non-ASCII, %zu UTF-8.\n",
+ encoding, strings->n, n_nonascii, n_utf8);
+ }
+}
+
+static void
+run_strings (int argc UNUSED, char **argv)
+{
+ struct spv_reader *spv;
+ char *err = spv_open (argv[1], &spv);
+ if (err)
+ error (1, 0, "%s", err);
+
+ struct encoded_strings
+ {
+ char *encoding;
+ struct string_array strings;
+ }
+ *es = NULL;
+ size_t n_es = 0;
+ size_t allocated_es = 0;
+
+ struct spv_item **items;
+ size_t n_items;
+ spv_select (spv, criteria, n_criteria, &items, &n_items);
+ for (size_t i = 0; i < n_items; i++)
+ {
+ if (!spv_item_is_light_table (items[i]))
+ continue;
+
+ char *error;
+ struct spvlb_table *table;
+ error = spv_item_get_light_table (items[i], &table);
+ if (error)
+ {
+ msg (ME, "%s", error);
+ free (error);
+ continue;
+ }
+
+ const char *table_encoding = spvlb_table_get_encoding (table);
+ size_t j = 0;
+ for (j = 0; j < n_es; j++)
+ if (!strcmp (es[j].encoding, table_encoding))
+ break;
+ if (j >= n_es)
+ {
+ if (n_es >= allocated_es)
+ es = x2nrealloc (es, &allocated_es, sizeof *es);
+ es[n_es++] = (struct encoded_strings) {
+ .encoding = xstrdup (table_encoding),
+ .strings = STRING_ARRAY_INITIALIZER,
+ };
+ }
+ collect_spvlb_strings (table, &es[j].strings);
+ }
+ free (items);
+
+ for (size_t i = 0; i < n_es; i++)
+ {
+ dump_strings (es[i].encoding, &es[i].strings);
+ free (es[i].encoding);
+ string_array_destroy (&es[i].strings);
+ }
+ free (es);
+
+ spv_close (spv);
+}
+