+ int n;
+ int result = 0;
+ char *cap;
+ char name[10];
+
+ for (n = 0; n <= 10; ++n) {
+ _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "lf%d", n);
+ cap = find_string(tterm, name);
+ if (VALID_STRING(cap)
+ && kill_string(tterm, cap)) {
+ target -= (int) (strlen(cap) + 5);
+ ++result;
+ if (target < 0)
+ break;
+ }
+ }
+ return result;
+}
+
+/*
+ * This is used to remove function-key definitions from a termcap entry to
+ * make it smaller.
+ */
+static int
+kill_fkeys(TERMTYPE2 *tterm, int target)
+{
+ int n;
+ int result = 0;
+ char *cap;
+ char name[10];
+
+ for (n = 60; n >= 0; --n) {
+ _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "kf%d", n);
+ cap = find_string(tterm, name);
+ if (VALID_STRING(cap)
+ && kill_string(tterm, cap)) {
+ target -= (int) (strlen(cap) + 5);
+ ++result;
+ if (target < 0)
+ break;
+ }
+ }
+ return result;
+}
+
+/*
+ * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
+ * Also, since this is for termcap, we only care about the line-drawing map.
+ */
+#define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
+
+static bool
+one_one_mapping(const char *mapping)
+{
+ bool result = TRUE;
+
+ if (VALID_STRING(mapping)) {
+ int n = 0;
+ while (mapping[n] != '\0') {
+ if (isLine(mapping[n]) &&
+ mapping[n] != mapping[n + 1]) {
+ result = FALSE;
+ break;
+ }
+ n += 2;
+ }
+ }
+ return result;
+}
+
+#define FMT_ENTRY() \
+ fmt_entry(tterm, pred, \
+ 0, \
+ suppress_untranslatable, \
+ infodump, numbers)
+
+#define SHOW_WHY PRINTF
+
+static bool
+purged_acs(TERMTYPE2 *tterm)
+{
+ bool result = FALSE;
+
+ if (VALID_STRING(acs_chars)) {
+ if (!one_one_mapping(acs_chars)) {
+ enter_alt_charset_mode = ABSENT_STRING;
+ exit_alt_charset_mode = ABSENT_STRING;
+ SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
+ }
+ result = TRUE;
+ }
+ return result;
+}
+
+static void
+encode_b64(char *target, char *source, unsigned state, int *saved)
+{
+ /* RFC-4648 */
+ static const char data[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789" "-_";
+ int ch = UChar(source[state]);
+
+ switch (state % 3) {
+ case 0:
+ *target++ = data[(ch >> 2) & 077];
+ *saved = (ch << 4);
+ break;
+ case 1:
+ *target++ = data[((ch >> 4) | *saved) & 077];
+ *saved = (ch << 2);
+ break;
+ case 2:
+ *target++ = data[((ch >> 6) | *saved) & 077];
+ *target++ = data[ch & 077];
+ *saved = 0;
+ break;
+ }
+ *target = '\0';
+}
+
+/*
+ * Dump a single entry.
+ */
+void
+dump_entry(TERMTYPE2 *tterm,
+ int suppress_untranslatable,
+ int limited,
+ int numbers,
+ PredFunc pred)
+{
+ TERMTYPE2 save_tterm;