+#if NCURSES_USE_TERMCAP
+ if (_nc_is_dir_path(path))
+#endif
+ {
+ unsigned need = (unsigned) (LEAF_LEN + 3 + strlen(path) + strlen(name));
+
+ if (need <= limit) {
+ _nc_SPRINTF(filename, _nc_SLIMIT(limit)
+ "%s/" LEAF_FMT "/%s", path, *name, name);
+ result = TRUE;
+ }
+ }
+ return result;
+}
+
+static int
+lookup_b64(int *target, const char **source)
+{
+ int result = 3;
+ int j;
+ /*
+ * ncurses' quickdump writes only RFC 4648 "url/filename-safe" encoding,
+ * but accepts RFC-3548
+ */
+ for (j = 0; j < 4; ++j) {
+ int ch = UChar(**source);
+ *source += 1;
+ if (ch >= 'A' && ch <= 'Z') {
+ target[j] = (ch - 'A');
+ } else if (ch >= 'a' && ch <= 'z') {
+ target[j] = 26 + (ch - 'a');
+ } else if (ch >= '0' && ch <= '9') {
+ target[j] = 52 + (ch - '0');
+ } else if (ch == '-' || ch == '+') {
+ target[j] = 62;
+ } else if (ch == '_' || ch == '/') {
+ target[j] = 63;
+ } else if (ch == '=') {
+ target[j] = 64;
+ result--;
+ } else {
+ result = -1;
+ break;
+ }
+ }
+ return result;
+}
+
+static int
+decode_hex(const char **source)
+{
+ int result = 0;
+ int nibble;
+ int ch;
+
+ for (nibble = 0; nibble < 2; ++nibble) {
+ result <<= 4;
+ ch = UChar(**source);
+ *source += 1;
+ if (ch >= '0' && ch <= '9') {
+ ch -= '0';
+ } else if (ch >= 'A' && ch <= 'F') {
+ ch -= 'A';
+ ch += 10;
+ } else if (ch >= 'a' && ch <= 'f') {
+ ch -= 'a';
+ ch += 10;
+ } else {
+ result = -1;
+ break;
+ }
+ result |= ch;
+ }
+ return result;
+}
+
+static int
+decode_quickdump(char *target, const char *source)
+{
+ char *base = target;
+ int result = 0;
+
+ if (!strncmp(source, "b64:", 4)) {
+ source += 4;
+ while (*source != '\0') {
+ int bits[4];
+ int ch = lookup_b64(bits, &source);
+ if (ch < 0 || (ch + target - base) >= MAX_ENTRY_SIZE) {
+ result = 0;
+ break;
+ }
+ result += ch;
+ *target++ = (char) ((bits[0] << 2) | (bits[1] >> 4));
+ if (bits[2] < 64) {
+ *target++ = (char) ((bits[1] << 4) | (bits[2] >> 2));
+ if (bits[3] < 64) {
+ *target++ = (char) ((bits[2] << 6) | bits[3]);
+ }
+ }
+ }
+ } else if (!strncmp(source, "hex:", 4)) {
+ source += 4;
+ while (*source != '\0') {
+ int ch = decode_hex(&source);
+ if (ch < 0 || (target - base) >= MAX_ENTRY_SIZE) {
+ result = 0;
+ break;
+ }
+ *target++ = (char) ch;
+ ++result;
+ }